VulpesOS/host/actors/TouchChild.sys.mjs
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

28 lines
1.2 KiB
JavaScript

// Reuse Gecko's own responsive-design touch implementation. No application
// gets privileged input methods; only physical mouse events are transformed.
export class VulpesTouchChild extends JSWindowActorChild {
handleEvent() {
if (Services.cpmm.sharedData.get('vulpes:native-touch')) return;
const allowed = Services.cpmm.sharedData.get('vulpes:host-contexts') || [];
if (!allowed.includes(this.browsingContext.top.id) || this.simulator) return;
const { require } = ChromeUtils.importESModule(
'resource://devtools/shared/loader/Loader.sys.mjs',
);
const { TouchSimulator } = require('devtools/server/actors/emulation/touch-simulator');
this.simulator = new TouchSimulator({ chromeEventHandler: this.contentWindow, emit() {} });
this.simulator.start();
this.contentWindow.addEventListener('contextmenu', (event) => event.preventDefault(), true);
}
receiveMessage(message) {
if (message.name !== 'Vulpes:CancelTouch') throw new Error('METHOD_NOT_SUPPORTED');
this.contentWindow.synthesizeTouchEvent('touchcancel', message.data, 0, {
isAsyncEnabled: true,
});
return true;
}
didDestroy() {
try {
this.simulator?.stop();
} catch (_) {}
}
}