chore: Handle use implicit event function calls for glance, b=no-bug, c=common, glance

This commit is contained in:
mr. m
2025-11-04 21:35:02 +01:00
parent 0d80532bf1
commit 40af25998f
2 changed files with 14 additions and 19 deletions

View File

@@ -42,6 +42,9 @@ let JSWINDOWACTORS = {
esModuleURI: 'resource:///actors/ZenGlanceChild.sys.mjs',
events: {
DOMContentLoaded: {},
click: {
capture: true,
},
keydown: {
capture: true,
},

View File

@@ -6,18 +6,12 @@ export class ZenGlanceChild extends JSWindowActorChild {
constructor() {
super();
this.clickListener = this.handleClick.bind(this);
}
async handleEvent(event) {
switch (event.type) {
case 'DOMContentLoaded':
await this.initiateGlance();
break;
case 'keydown':
this.onKeyDown(event);
break;
default:
const handler = this[`on_${event.type}`];
if (typeof handler === 'function') {
await handler.call(this, event);
}
}
@@ -25,13 +19,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
this.#activationMethod = await this.sendQuery('ZenGlance:GetActivationMethod');
}
async initiateGlance() {
this.mouseIsDown = false;
await this.#initActivationMethod();
this.contentWindow.document.addEventListener('click', this.clickListener, { capture: true });
}
ensureOnlyKeyModifiers(event) {
#ensureOnlyKeyModifiers(event) {
return !(event.ctrlKey ^ event.altKey ^ event.shiftKey ^ event.metaKey);
}
@@ -66,7 +54,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
});
}
handleClick(event) {
on_click(event) {
if (event.button !== 0 || event.defaultPrevented) {
return;
}
@@ -79,7 +67,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
// The problem is that at that stage we don't know the rect or even what
// element has been clicked, so we send the data here.
this.#sendClickDataToParent(target, elementToRecord);
if (this.ensureOnlyKeyModifiers(event)) {
if (this.#ensureOnlyKeyModifiers(event)) {
return;
}
const activationMethod = this.#activationMethod;
@@ -100,7 +88,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
}
}
onKeyDown(event) {
on_keydown(event) {
if (event.defaultPrevented || event.key !== 'Escape') {
return;
}
@@ -108,4 +96,8 @@ export class ZenGlanceChild extends JSWindowActorChild {
hasFocused: this.contentWindow.document.activeElement !== this.contentWindow.document.body,
});
}
async on_DOMContentLoaded() {
await this.#initActivationMethod();
}
}