-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (52 loc) · 1.82 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
const {EventEmitter} = require('events');
const addon = require('bindings')('addon.node');
class TabletEventReceiver extends EventEmitter {
constructor(browserWindow) {
super();
this.captureArea = {left: 0, top: 0, width: 0, height: 0};
this.capturedPointers = new Set();
this.browserWindow = browserWindow;
this.windowHandle = browserWindow.getNativeWindowHandle();
addon.intercept(this.windowHandle, this.handleEvent.bind(this));
addon.onReload(this.windowHandle);
browserWindow.webContents.on("dom-ready", () => {
addon.onReload(this.windowHandle);
});
}
insideCaptureArea(clientX, clientY) {
const {left, top, width, height} = this.captureArea;
return left <= clientX && clientX < left + width && top <= clientY && clientY < top + height;
}
handleEvent(type, button, clientX, clientY, pressure, pointerType, pointerId, altKey, ctrlKey, metaKey, shiftKey) {
switch (type) {
case "down":
if (this.insideCaptureArea(clientX, clientY)) {
this.capturedPointers.add(pointerId);
} else {
return false;
}
break;
case "up":
if (!this.capturedPointers.has(pointerId)) {
return false;
}
this.capturedPointers.delete(pointerId);
break;
case "move":
if (!this.capturedPointers.has(pointerId)) {
return false;
}
break;
}
this.browserWindow.webContents.focus();
this.emit(type, {button, clientX, clientY, pressure, pointerType, pointerId, altKey, ctrlKey, metaKey, shiftKey})
// do not prevent original event handler outside Windows
return process.platform == "win32";
}
dispose() {
this.browserWindow = undefined;
addon.unintercept(this.windowHandle);
}
}
exports.TabletEventReceiver = TabletEventReceiver;