Add workaround for Firefox bug not detecting pen input type correctly (#820)

This commit is contained in:
toasted-nutbread 2020-09-13 11:28:13 -04:00 committed by GitHub
parent fcb8806717
commit efd0de6bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,7 @@ class KeyboardMouseInputField extends EventDispatcher {
this._eventListeners = new EventListenerCollection(); this._eventListeners = new EventListenerCollection();
this._value = ''; this._value = '';
this._type = null; this._type = null;
this._penPointerIds = new Set();
} }
get value() { get value() {
@ -56,6 +57,9 @@ class KeyboardMouseInputField extends EventDispatcher {
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, 'pointerdown', this._onMouseButtonPointerDown.bind(this), false],
[this._mouseButton, 'pointerover', this._onMouseButtonPointerOver.bind(this), false],
[this._mouseButton, 'pointerout', this._onMouseButtonPointerOut.bind(this), false],
[this._mouseButton, 'pointercancel', this._onMouseButtonPointerCancel.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]
); );
@ -70,6 +74,7 @@ class KeyboardMouseInputField extends EventDispatcher {
this._eventListeners.removeAllEventListeners(); this._eventListeners.removeAllEventListeners();
this._value = ''; this._value = '';
this._type = null; this._type = null;
this._penPointerIds.clear();
} }
// Private // Private
@ -178,9 +183,13 @@ class KeyboardMouseInputField extends EventDispatcher {
} }
_onMouseButtonPointerDown(e) { _onMouseButtonPointerDown(e) {
const {isPrimary, pointerType} = e; if (!e.isPrimary) { return; }
let {pointerType, pointerId} = e;
// Workaround for Firefox bug not detecting certain 'touch' events as 'pen' events.
if (this._penPointerIds.has(pointerId)) { pointerType = 'pen'; }
if ( if (
!isPrimary ||
typeof this._isPointerTypeSupported !== 'function' || typeof this._isPointerTypeSupported !== 'function' ||
!this._isPointerTypeSupported(pointerType) !this._isPointerTypeSupported(pointerType)
) { ) {
@ -190,6 +199,22 @@ class KeyboardMouseInputField extends EventDispatcher {
this._addInputs(DocumentUtil.getActiveButtons(e)); this._addInputs(DocumentUtil.getActiveButtons(e));
} }
_onMouseButtonPointerOver(e) {
const {pointerType, pointerId} = e;
if (pointerType === 'pen') {
this._penPointerIds.add(pointerId);
}
}
_onMouseButtonPointerOut(e) {
const {pointerId} = e;
this._penPointerIds.delete(pointerId);
}
_onMouseButtonPointerCancel(e) {
this._onMouseButtonPointerOut(e);
}
_onMouseButtonMouseUp(e) { _onMouseButtonMouseUp(e) {
e.preventDefault(); e.preventDefault();
} }