Skip to content

Commit b08ca62

Browse files
Fabianopbsandersn
authored andcommitted
Add focusin/focusout to GlobalEventHandlers (#696)
* Add onfocusin and onfocusout properties and respective events to GlobalEventHandlers. * Revert "Add onfocusin and onfocusout properties and respective events to GlobalEventHandlers." This reverts commit a8f8875. * Implement methods to add attributeless events to interfaces. * Add focusin and focusout attributeless events to GlobalEventHandlers. * Hotfix convertOpertion in the CI.
1 parent 4b13a8d commit b08ca62

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

baselines/dom.generated.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5588,6 +5588,8 @@ interface GlobalEventHandlersEventMap {
55885588
"ended": Event;
55895589
"error": ErrorEvent;
55905590
"focus": FocusEvent;
5591+
"focusin": FocusEvent;
5592+
"focusout": FocusEvent;
55915593
"gotpointercapture": PointerEvent;
55925594
"input": Event;
55935595
"invalid": Event;

inputfiles/addedTypes.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@
7272
}
7373
},
7474
"GlobalEventHandlers": {
75+
"attributeless-events": {
76+
"event": [
77+
{
78+
"name": "focusin",
79+
"type": "FocusEvent"
80+
},
81+
{
82+
"name": "focusout",
83+
"type": "FocusEvent"
84+
}
85+
]
86+
},
7587
"events": {
7688
"event": [
7789
{

src/emitter.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
165165
return { name: p.name, eventName, eventType };
166166
}));
167167

168+
const iNameToAttributelessEhList = arrayToMap(allInterfaces, i => i.name, i =>
169+
!i["attributeless-events"] ? [] : i["attributeless-events"].event.map(e => {
170+
return { name: "on" + e.name, eventName: e.name, eventType: e.type };
171+
}));
172+
168173
const iNameToConstList = arrayToMap(allInterfaces, i => i.name, i =>
169174
!i.constants ? [] : mapToArray(i.constants.constant));
170175

@@ -246,6 +251,12 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
246251
return event.type;
247252
}
248253
}
254+
if (i["attributeless-events"]) {
255+
const event = i["attributeless-events"].event.find(e => e.name === eName);
256+
if (event && event.type) {
257+
return event.type;
258+
}
259+
}
249260
return eNameToEType[eName] || "Event";
250261
}
251262

@@ -885,9 +896,10 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
885896
}
886897

887898
const hasEventHandlers = iNameToEhList[i.name] && iNameToEhList[i.name].length;
899+
const hasAttributelessEventHandlers = iNameToAttributelessEhList[i.name] && iNameToAttributelessEhList[i.name].length;
888900
const ehParentCount = iNameToEhParents[i.name] && iNameToEhParents[i.name].length;
889901

890-
if (hasEventHandlers || ehParentCount > 1) {
902+
if (hasEventHandlers || hasAttributelessEventHandlers || ehParentCount > 1) {
891903
printer.print(`interface ${i.name}EventMap`);
892904
if (ehParentCount) {
893905
const extend = iNameToEhParents[i.name].map(i => i.name + "EventMap");
@@ -897,6 +909,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
897909
printer.endLine();
898910
printer.increaseIndent();
899911
iNameToEhList[i.name]
912+
.concat(iNameToAttributelessEhList[i.name])
900913
.sort(compareName)
901914
.forEach(emitInterfaceEventMapEntry);
902915
printer.decreaseIndent();
@@ -1005,7 +1018,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
10051018
function emitNamespace(namespace: Browser.Interface) {
10061019
printer.printLine(`declare namespace ${namespace.name} {`);
10071020
printer.increaseIndent();
1008-
1021+
10091022
if (namespace.nested) {
10101023
namespace.nested.interfaces
10111024
.sort(compareName)

src/types.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ export interface Interface {
161161
events?: {
162162
event: Event[];
163163
}
164+
"attributeless-events"?: {
165+
event: Event[];
166+
}
164167
properties?: {
165168
property: Record<string, Property>;
166169
}

0 commit comments

Comments
 (0)