Add support for pointer event input detection (#810)
This commit is contained in:
parent
6afbda8dfe
commit
a5845df123
@ -20,10 +20,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class KeyboardMouseInputField extends EventDispatcher {
|
class KeyboardMouseInputField extends EventDispatcher {
|
||||||
constructor(inputNode, mouseButton, os) {
|
constructor(inputNode, mouseButton, os, isPointerTypeSupported=null) {
|
||||||
super();
|
super();
|
||||||
this._inputNode = inputNode;
|
this._inputNode = inputNode;
|
||||||
this._mouseButton = mouseButton;
|
this._mouseButton = mouseButton;
|
||||||
|
this._isPointerTypeSupported = isPointerTypeSupported;
|
||||||
this._keySeparator = ' + ';
|
this._keySeparator = ' + ';
|
||||||
this._inputNameMap = new Map(DocumentUtil.getModifierKeys(os));
|
this._inputNameMap = new Map(DocumentUtil.getModifierKeys(os));
|
||||||
this._keyPriorities = new Map([
|
this._keyPriorities = new Map([
|
||||||
@ -54,6 +55,7 @@ class KeyboardMouseInputField extends EventDispatcher {
|
|||||||
if (type === 'modifierInputs' && this._mouseButton !== null) {
|
if (type === 'modifierInputs' && this._mouseButton !== null) {
|
||||||
events.push(
|
events.push(
|
||||||
[this._mouseButton, 'mousedown', this._onMouseButtonMouseDown.bind(this), false],
|
[this._mouseButton, 'mousedown', this._onMouseButtonMouseDown.bind(this), false],
|
||||||
|
[this._mouseButton, 'pointerdown', this._onMouseButtonPointerDown.bind(this), false],
|
||||||
[this._mouseButton, 'mouseup', this._onMouseButtonMouseUp.bind(this), false],
|
[this._mouseButton, 'mouseup', this._onMouseButtonMouseUp.bind(this), false],
|
||||||
[this._mouseButton, 'contextmenu', this._onMouseButtonContextMenu.bind(this), false]
|
[this._mouseButton, 'contextmenu', this._onMouseButtonContextMenu.bind(this), false]
|
||||||
);
|
);
|
||||||
@ -175,6 +177,19 @@ class KeyboardMouseInputField extends EventDispatcher {
|
|||||||
this._addInputs(DocumentUtil.getActiveButtons(e));
|
this._addInputs(DocumentUtil.getActiveButtons(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onMouseButtonPointerDown(e) {
|
||||||
|
const {isPrimary, pointerType} = e;
|
||||||
|
if (
|
||||||
|
!isPrimary ||
|
||||||
|
typeof this._isPointerTypeSupported !== 'function' ||
|
||||||
|
!this._isPointerTypeSupported(pointerType)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
this._addInputs(DocumentUtil.getActiveButtons(e));
|
||||||
|
}
|
||||||
|
|
||||||
_onMouseButtonMouseUp(e) {
|
_onMouseButtonMouseUp(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
@ -138,8 +138,9 @@ class ScanInputField {
|
|||||||
this._node = node;
|
this._node = node;
|
||||||
container.appendChild(node);
|
container.appendChild(node);
|
||||||
|
|
||||||
this._includeInputField = new KeyboardMouseInputField(includeInputNode, includeMouseButton, this._os);
|
const isPointerTypeSupported = this._isPointerTypeSupported.bind(this);
|
||||||
this._excludeInputField = new KeyboardMouseInputField(excludeInputNode, excludeMouseButton, this._os);
|
this._includeInputField = new KeyboardMouseInputField(includeInputNode, includeMouseButton, this._os, isPointerTypeSupported);
|
||||||
|
this._excludeInputField = new KeyboardMouseInputField(excludeInputNode, excludeMouseButton, this._os, isPointerTypeSupported);
|
||||||
this._includeInputField.prepare(include, 'modifierInputs');
|
this._includeInputField.prepare(include, 'modifierInputs');
|
||||||
this._excludeInputField.prepare(exclude, 'modifierInputs');
|
this._excludeInputField.prepare(exclude, 'modifierInputs');
|
||||||
|
|
||||||
@ -184,4 +185,10 @@ class ScanInputField {
|
|||||||
const content = document.importNode(template.content, true);
|
const content = document.importNode(template.content, true);
|
||||||
return content.firstChild;
|
return content.firstChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isPointerTypeSupported(pointerType) {
|
||||||
|
if (this._node === null) { return false; }
|
||||||
|
const node = this._node.querySelector(`input.scan-input-type-checkbox[data-type=${pointerType}]`);
|
||||||
|
return node !== null && node.checked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user