diff --git a/ext/data/schemas/options-schema.json b/ext/data/schemas/options-schema.json index 26d921cd5..5ce334196 100644 --- a/ext/data/schemas/options-schema.json +++ b/ext/data/schemas/options-schema.json @@ -453,8 +453,6 @@ "required": [ "inputs", "preventMiddleMouse", - "touchInputEnabled", - "pointerEventsEnabled", "selectText", "alphanumeric", "autoHideResults", @@ -676,14 +674,6 @@ } } }, - "touchInputEnabled": { - "type": "boolean", - "default": true - }, - "pointerEventsEnabled": { - "type": "boolean", - "default": false - }, "selectText": { "type": "boolean", "default": true diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index e58828df1..b6f0eb381 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -506,8 +506,6 @@ export class Frontend { normalizeCssZoom: scanningOptions.normalizeCssZoom, selectText: scanningOptions.selectText, delay: scanningOptions.delay, - touchInputEnabled: scanningOptions.touchInputEnabled, - pointerEventsEnabled: scanningOptions.pointerEventsEnabled, scanLength: scanningOptions.length, layoutAwareScan: scanningOptions.layoutAwareScan, matchTypePrefix: scanningOptions.matchTypePrefix, diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 98417e43e..5f9cfc7a5 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -566,6 +566,7 @@ export class OptionsUtil { this._updateVersion52, this._updateVersion53, this._updateVersion54, + this._updateVersion55, ]; /* eslint-enable @typescript-eslint/unbound-method */ if (typeof targetVersion === 'number' && targetVersion < result.length) { @@ -1521,6 +1522,18 @@ export class OptionsUtil { } } + /** + * - Remove scanning.touchInputEnabled + * - Remove scanning.pointerEventsEnabled + * @type {import('options-util').UpdateFunction} + */ + async _updateVersion55(options) { + for (const profile of options.profiles) { + delete profile.options.scanning.touchInputEnabled; + delete profile.options.scanning.pointerEventsEnabled; + } + } + /** * @param {string} url * @returns {Promise} diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 610f65939..a85d84948 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -457,8 +457,6 @@ export class Display extends EventDispatcher { normalizeCssZoom: scanningOptions.normalizeCssZoom, selectText: scanningOptions.selectText, delay: scanningOptions.delay, - touchInputEnabled: scanningOptions.touchInputEnabled, - pointerEventsEnabled: scanningOptions.pointerEventsEnabled, scanLength: scanningOptions.length, layoutAwareScan: scanningOptions.layoutAwareScan, preventMiddleMouse: scanningOptions.preventMiddleMouse.onSearchQuery, @@ -2054,8 +2052,6 @@ export class Display extends EventDispatcher { normalizeCssZoom: scanningOptions.normalizeCssZoom, selectText: false, delay: scanningOptions.delay, - touchInputEnabled: false, - pointerEventsEnabled: false, scanLength: scanningOptions.length, layoutAwareScan: scanningOptions.layoutAwareScan, preventMiddleMouse: false, diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index ae6e45961..c1bccad13 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -93,7 +93,7 @@ export class TextScanner extends EventDispatcher { /** @type {?import('text-scanner').SelectionRestoreInfo} */ this._selectionRestoreInfo = null; - /** @type {MouseEvent | null} */ + /** @type {PointerEvent | null} */ this._lastMouseMove = null; /** @type {boolean} */ @@ -104,10 +104,6 @@ export class TextScanner extends EventDispatcher { this._selectText = false; /** @type {number} */ this._delay = 0; - /** @type {boolean} */ - this._touchInputEnabled = false; - /** @type {boolean} */ - this._pointerEventsEnabled = false; /** @type {number} */ this._scanLength = 1; /** @type {boolean} */ @@ -261,8 +257,6 @@ export class TextScanner extends EventDispatcher { normalizeCssZoom, selectText, delay, - touchInputEnabled, - pointerEventsEnabled, scanLength, layoutAwareScan, preventMiddleMouse, @@ -286,12 +280,6 @@ export class TextScanner extends EventDispatcher { if (typeof delay === 'number') { this._delay = delay; } - if (typeof touchInputEnabled === 'boolean') { - this._touchInputEnabled = touchInputEnabled; - } - if (typeof pointerEventsEnabled === 'boolean') { - this._pointerEventsEnabled = pointerEventsEnabled; - } if (typeof scanLength === 'number') { this._scanLength = scanLength; } @@ -582,40 +570,13 @@ export class TextScanner extends EventDispatcher { } /** - * @param {MouseEvent} e + * @param {PointerEvent} e */ - _onSearchClickMouseDown(e) { + _onSearchClickPointerDown(e) { if (e.button !== 0) { return; } this._resetPreventNextClickScan(); } - /** */ - _onSearchClickTouchStart() { - this._resetPreventNextClickScan(); - } - - /** - * @param {MouseEvent} e - */ - _onMouseOver(e) { - if (this._ignoreElements !== null && this._ignoreElements().includes(/** @type {Element} */ (e.target))) { - this._scanTimerClear(); - } - } - - /** - * @param {MouseEvent} e - */ - _onMouseMove(e) { - this._scanTimerClear(); - this._lastMouseMove = e; - - const inputInfo = this._getMatchingInputGroupFromEvent('mouse', 'mouseMove', e); - if (inputInfo === null) { return; } - - void this._searchAtFromMouseMove(e.clientX, e.clientY, inputInfo); - } - /** * @param {KeyboardEvent} e */ @@ -623,7 +584,7 @@ export class TextScanner extends EventDispatcher { const modifiers = getActiveModifiers(e); if (this._lastMouseMove !== null && (modifiers.length > 0)) { if (this._inputtingText()) { return; } - const syntheticMouseEvent = new MouseEvent(this._lastMouseMove.type, { + const syntheticMousePointerEvent = new PointerEvent(this._lastMouseMove.type, { screenX: this._lastMouseMove.screenX, screenY: this._lastMouseMove.screenY, clientX: this._lastMouseMove.clientX, @@ -636,7 +597,7 @@ export class TextScanner extends EventDispatcher { buttons: this._lastMouseMove.buttons, relatedTarget: this._lastMouseMove.relatedTarget, }); - this._onMouseMove(syntheticMouseEvent); + this._onMousePointerMove(syntheticMousePointerEvent); } } @@ -653,7 +614,7 @@ export class TextScanner extends EventDispatcher { } /** - * @param {MouseEvent} e + * @param {PointerEvent} e * @returns {boolean|void} */ _onMouseDown(e) { @@ -680,7 +641,7 @@ export class TextScanner extends EventDispatcher { break; } - this._onMouseMove(e); + this._onMousePointerMove(e); } /** */ @@ -690,7 +651,7 @@ export class TextScanner extends EventDispatcher { } /** - * @param {MouseEvent} e + * @param {PointerEvent} e * @returns {boolean|void} */ _onClick(e) { @@ -706,11 +667,11 @@ export class TextScanner extends EventDispatcher { return; } - this._onMouseMove(e); + this._onMousePointerMove(e); } /** - * @param {MouseEvent} e + * @param {PointerEvent} e */ _onSearchClick(e) { const preventNextClickScan = this._preventNextClickScan; @@ -734,7 +695,7 @@ export class TextScanner extends EventDispatcher { } /** - * @param {MouseEvent} e + * @param {PointerEvent} e * @returns {boolean|void} */ _onContextMenu(e) { @@ -746,18 +707,6 @@ export class TextScanner extends EventDispatcher { } } - /** - * @param {TouchEvent} e - */ - _onTouchStart(e) { - if (this._primaryTouchIdentifier !== null || e.changedTouches.length === 0) { - return; - } - - const {clientX, clientY, identifier} = e.changedTouches[0]; - this._onPrimaryTouchStart(e, clientX, clientY, identifier); - } - /** * @param {TouchEvent|PointerEvent} e * @param {number} x @@ -822,50 +771,9 @@ export class TextScanner extends EventDispatcher { } } - /** - * @param {TouchEvent} e - */ - _onTouchCancel(e) { - if (this._primaryTouchIdentifier === null) { return; } - - const primaryTouch = this._getTouch(e.changedTouches, this._primaryTouchIdentifier); - if (primaryTouch === null) { return; } - - this._onPrimaryTouchEnd(e, 0, 0, false); - } - - /** - * @param {TouchEvent} e - */ - _onTouchMove(e) { - this._touchTapValid = false; - - if (this._primaryTouchIdentifier === null) { return; } - - if (!e.cancelable) { - this._onPrimaryTouchEnd(e, 0, 0, false); - return; - } - - if (!this._preventScroll) { return; } - - const primaryTouch = this._getTouch(e.changedTouches, this._primaryTouchIdentifier); - if (primaryTouch === null) { return; } - - const inputInfo = this._getMatchingInputGroupFromEvent('touch', 'touchMove', e); - if (inputInfo === null) { return; } - - const {input} = inputInfo; - if (input !== null && input.scanOnTouchMove) { - void this._searchAt(primaryTouch.clientX, primaryTouch.clientY, inputInfo); - } - - e.preventDefault(); // Disable scroll - } - /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onPointerOver(e) { const {pointerType, pointerId, isPrimary} = e; @@ -896,7 +804,7 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onPointerMove(e) { if (!e.isPrimary) { return; } @@ -909,7 +817,7 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onPointerUp(e) { if (!e.isPrimary) { return; } @@ -922,7 +830,7 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onPointerCancel(e) { this._pointerIdTypeMap.delete(e.pointerId); @@ -936,7 +844,7 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onPointerOut(e) { this._pointerIdTypeMap.delete(e.pointerId); @@ -950,10 +858,12 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onMousePointerOver(e) { - return this._onMouseOver(e); + if (this._ignoreElements !== null && this._ignoreElements().includes(/** @type {Element} */ (e.target))) { + this._scanTimerClear(); + } } /** @@ -966,10 +876,16 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onMousePointerMove(e) { - return this._onMouseMove(e); + this._scanTimerClear(); + this._lastMouseMove = e; + + const inputInfo = this._getMatchingInputGroupFromEvent('mouse', 'mouseMove', e); + if (inputInfo === null) { return; } + + void this._searchAtFromMouseMove(e.clientX, e.clientY, inputInfo); } /** */ @@ -978,17 +894,17 @@ export class TextScanner extends EventDispatcher { } /** - * @returns {boolean|void} + * @returns {void} */ _onMousePointerCancel() { - return this._onMouseOut(); + this._onMouseOut(); } /** - * @returns {boolean|void} + * @returns {void} */ _onMousePointerOut() { - return this._onMouseOut(); + this._onMouseOut(); } /** */ @@ -998,7 +914,7 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onTouchPointerDown(e) { const {clientX, clientY, pointerId} = e; @@ -1007,12 +923,13 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onTouchPointerMove(e) { if (!this._preventScroll || !e.cancelable) { return; } + this._touchTapValid = false; const inputInfo = this._getMatchingInputGroupFromEvent('touch', 'touchMove', e); if (inputInfo === null || !(inputInfo.input !== null && inputInfo.input.scanOnTouchMove)) { return; } @@ -1022,19 +939,19 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onTouchPointerUp(e) { const {clientX, clientY} = e; - return this._onPrimaryTouchEnd(e, clientX, clientY, true); + this._onPrimaryTouchEnd(e, clientX, clientY, true); } /** * @param {PointerEvent} e - * @returns {boolean|void} + * @returns {void} */ _onTouchPointerCancel(e) { - return this._onPrimaryTouchEnd(e, 0, 0, false); + this._onPrimaryTouchEnd(e, 0, 0, false); } /** */ @@ -1045,7 +962,9 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e */ - _onTouchMovePreventScroll(e) { + _onTouchMove(e) { + this._touchTapValid = false; + if (!this._preventScroll) { return; } if (e.cancelable) { @@ -1139,33 +1058,20 @@ export class TextScanner extends EventDispatcher { this._scanTimerPromise = null; } - /** - * @returns {boolean} - */ - _arePointerEventsSupported() { - return (this._pointerEventsEnabled && typeof PointerEvent !== 'undefined'); - } - /** */ _hookEvents() { const capture = true; /** @type {import('event-listener-collection').AddEventListenerArgs[]} */ - let eventListenerInfos; - if (this._searchOnClickOnly) { - eventListenerInfos = this._getMouseClickOnlyEventListeners(capture); - } else if (this._arePointerEventsSupported()) { - eventListenerInfos = this._getPointerEventListeners(capture); - } else { - eventListenerInfos = [...this._getMouseEventListeners(capture)]; + const eventListenerInfos = []; + eventListenerInfos.push(...this._getClickEventListeners(capture)); + if (!this._searchOnClickOnly) { + eventListenerInfos.push(...this._getPointerEventListeners(capture)); if (this._scanWithoutMousemove) { eventListenerInfos.push(...this._getKeyboardEventListeners(capture)); } - if (this._touchInputEnabled) { - eventListenerInfos.push(...this._getTouchEventListeners(capture)); - } } if (this._searchOnClick) { - eventListenerInfos.push(...this._getMouseClickOnlyEventListeners2(capture)); + eventListenerInfos.push(...this._getSearchOnClickEventListeners(capture)); } eventListenerInfos.push(this._getSelectionChangeCheckUserSelectionListener()); @@ -1187,24 +1093,11 @@ export class TextScanner extends EventDispatcher { [this._node, 'pointerup', this._onPointerUp.bind(this), capture], [this._node, 'pointercancel', this._onPointerCancel.bind(this), capture], [this._node, 'pointerout', this._onPointerOut.bind(this), capture], - [this._node, 'touchmove', this._onTouchMovePreventScroll.bind(this), {passive: false, capture}], [this._node, 'mousedown', this._onMouseDown.bind(this), capture], - [this._node, 'click', this._onClick.bind(this), capture], + [this._node, 'touchmove', this._onTouchMove.bind(this), {passive: false, capture}], + [this._node, 'touchend', this._onTouchEnd.bind(this), capture], [this._node, 'auxclick', this._onAuxClick.bind(this), capture], - ]; - } - - /** - * @param {boolean} capture - * @returns {import('event-listener-collection').AddEventListenerArgs[]} - */ - _getMouseEventListeners(capture) { - return [ - [this._node, 'mousedown', this._onMouseDown.bind(this), capture], - [this._node, 'mousemove', this._onMouseMove.bind(this), capture], - [this._node, 'mouseover', this._onMouseOver.bind(this), capture], - [this._node, 'mouseout', this._onMouseOut.bind(this), capture], - [this._node, 'click', this._onClick.bind(this), capture], + [this._node, 'contextmenu', this._onContextMenu.bind(this), capture], ]; } @@ -1222,22 +1115,7 @@ export class TextScanner extends EventDispatcher { * @param {boolean} capture * @returns {import('event-listener-collection').AddEventListenerArgs[]} */ - _getTouchEventListeners(capture) { - return [ - [this._node, 'auxclick', this._onAuxClick.bind(this), capture], - [this._node, 'touchstart', this._onTouchStart.bind(this), {passive: true, capture}], - [this._node, 'touchend', this._onTouchEnd.bind(this), capture], - [this._node, 'touchcancel', this._onTouchCancel.bind(this), capture], - [this._node, 'touchmove', this._onTouchMove.bind(this), {passive: false, capture}], - [this._node, 'contextmenu', this._onContextMenu.bind(this), capture], - ]; - } - - /** - * @param {boolean} capture - * @returns {import('event-listener-collection').AddEventListenerArgs[]} - */ - _getMouseClickOnlyEventListeners(capture) { + _getClickEventListeners(capture) { return [ [this._node, 'click', this._onClick.bind(this), capture], ]; @@ -1247,17 +1125,14 @@ export class TextScanner extends EventDispatcher { * @param {boolean} capture * @returns {import('event-listener-collection').AddEventListenerArgs[]} */ - _getMouseClickOnlyEventListeners2(capture) { + _getSearchOnClickEventListeners(capture) { const {documentElement} = document; /** @type {import('event-listener-collection').AddEventListenerArgs[]} */ const entries = [ [document, 'selectionchange', this._onSelectionChange.bind(this)], ]; if (documentElement !== null) { - entries.push([documentElement, 'mousedown', this._onSearchClickMouseDown.bind(this), capture]); - if (this._touchInputEnabled) { - entries.push([documentElement, 'touchstart', this._onSearchClickTouchStart.bind(this), {passive: true, capture}]); - } + entries.push([documentElement, 'pointerdown', this._onSearchClickPointerDown.bind(this), capture]); } return entries; } @@ -1521,7 +1396,7 @@ export class TextScanner extends EventDispatcher { /** * @param {import('input').PointerType} pointerType * @param {import('input').PointerEventType} eventType - * @param {MouseEvent|TouchEvent} event + * @param {PointerEvent|TouchEvent} event * @returns {?import('text-scanner').InputInfo} */ _getMatchingInputGroupFromEvent(pointerType, eventType, event) { diff --git a/ext/settings.html b/ext/settings.html index 9c0e114fd..6e704b2e1 100644 --- a/ext/settings.html +++ b/ext/settings.html @@ -544,42 +544,6 @@

Yomitan Settings

-
-
-
-
- Support inputs for devices with touch screens - (?) -
-
-
-
- - -
-
-
- -
Configure input action prevention…
diff --git a/test/options-util.test.js b/test/options-util.test.js index 29cada765..c6af0e75c 100644 --- a/test/options-util.test.js +++ b/test/options-util.test.js @@ -81,7 +81,6 @@ function createProfileOptionsTestData1() { }, scanning: { middleMouse: true, - touchInputEnabled: true, selectText: true, alphanumeric: true, autoHideResults: false, @@ -329,7 +328,6 @@ function createProfileOptionsUpdatedTestData1() { autoPlay: false, }, scanning: { - touchInputEnabled: true, selectText: true, alphanumeric: true, autoHideResults: false, @@ -343,7 +341,6 @@ function createProfileOptionsUpdatedTestData1() { enableSearchTags: false, layoutAwareScan: false, hideDelay: 0, - pointerEventsEnabled: false, matchTypePrefix: false, hidePopupOnCursorExit: false, hidePopupOnCursorExitDelay: 0, @@ -645,7 +642,7 @@ function createOptionsUpdatedTestData1() { }, ], profileCurrent: 0, - version: 54, + version: 55, global: { database: { prefixWildcardsSupported: false, diff --git a/types/ext/settings.d.ts b/types/ext/settings.d.ts index 38bf65cff..c388eca28 100644 --- a/types/ext/settings.d.ts +++ b/types/ext/settings.d.ts @@ -179,8 +179,6 @@ export type AudioSourceOptions = { export type ScanningOptions = { inputs: ScanningInput[]; preventMiddleMouse: ScanningPreventMiddleMouseOptions; - touchInputEnabled: boolean; - pointerEventsEnabled: boolean; selectText: boolean; alphanumeric: boolean; autoHideResults: boolean; diff --git a/types/ext/text-scanner.d.ts b/types/ext/text-scanner.d.ts index dd733e371..90f04369a 100644 --- a/types/ext/text-scanner.d.ts +++ b/types/ext/text-scanner.d.ts @@ -34,8 +34,6 @@ export type Options = { normalizeCssZoom?: boolean; selectText?: boolean; delay?: number; - touchInputEnabled?: boolean; - pointerEventsEnabled?: boolean; scanLength?: number; layoutAwareScan?: boolean; preventMiddleMouse?: boolean;