From 642dcb8fc9e78007d8704717b2ff10b8ab4ecafc Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 25 Sep 2022 09:42:20 -0400 Subject: Google Docs accessibility simplifications (#2237) * Use getAttribute instead of dataset, in case SVG node APIs are unusual * Use pointer-events instead of fill * Use elementFromPoint instead of elementsFromPoint --- ext/js/accessibility/google-docs-util.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'ext/js/accessibility') diff --git a/ext/js/accessibility/google-docs-util.js b/ext/js/accessibility/google-docs-util.js index 12f2db24..ada0ff2d 100644 --- a/ext/js/accessibility/google-docs-util.js +++ b/ext/js/accessibility/google-docs-util.js @@ -33,26 +33,28 @@ class GoogleDocsUtil { * @returns {?TextSourceRange|TextSourceElement} A range for the hovered text or element, or `null` if no applicable content was found. */ static getRangeFromPoint(x, y, {normalizeCssZoom}) { - const selector = '.kix-canvas-tile-content svg>g>rect'; - const styleNode = this._getStyleNode(selector); + const styleNode = this._getStyleNode(); styleNode.disabled = false; - const elements = document.elementsFromPoint(x, y); + const element = document.elementFromPoint(x, y); styleNode.disabled = true; - for (const element of elements) { - if (!element.matches(selector)) { continue; } + if (element !== null && element.matches('.kix-canvas-tile-content svg>g>rect')) { const ariaLabel = element.getAttribute('aria-label'); - if (typeof ariaLabel !== 'string' || ariaLabel.length === 0) { continue; } - return this._createRange(element, ariaLabel, x, y, normalizeCssZoom); + if (typeof ariaLabel === 'string' && ariaLabel.length > 0) { + return this._createRange(element, ariaLabel, x, y, normalizeCssZoom); + } } return null; } - static _getStyleNode(selector) { + static _getStyleNode() { // This