aboutsummaryrefslogtreecommitdiff
path: root/ext/js/accessibility
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-01-31 08:40:57 -0500
committerGitHub <noreply@github.com>2024-01-31 13:40:57 +0000
commit2356223942a21d1683ac38eed8e7b9485f453d87 (patch)
tree4e97b53a9d4829378ebc60eb5b8e40b6f5b665ee /ext/js/accessibility
parent87ed7c8affd3ade9d3cd2d9ed1a61dd5f224e473 (diff)
Document util + google docs util state refactor (#590)
* Remove static from GoogleDocsUtil since it has state * Create TextSourceGenerator * Remove DocumentUtil custom registrations * Use TextSourceGenerator
Diffstat (limited to 'ext/js/accessibility')
-rw-r--r--ext/js/accessibility/google-docs-util.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/ext/js/accessibility/google-docs-util.js b/ext/js/accessibility/google-docs-util.js
index 34a5dd555..969e650e 100644
--- a/ext/js/accessibility/google-docs-util.js
+++ b/ext/js/accessibility/google-docs-util.js
@@ -23,8 +23,10 @@ import {TextSourceRange} from '../dom/text-source-range.js';
* This class is a helper for handling Google Docs content in content scripts.
*/
export class GoogleDocsUtil {
- /** @type {HTMLStyleElement|undefined} */
- static _styleNode = void 0;
+ constructor() {
+ /** @type {?HTMLStyleElement} */
+ this._styleNode = null;
+ }
/**
* Scans the document for text or elements with text information at the given coordinate.
@@ -34,7 +36,7 @@ export class GoogleDocsUtil {
* @param {import('document-util').GetRangeFromPointOptions} options Options to configure how element detection is performed.
* @returns {?TextSourceRange} A range for the hovered text or element, or `null` if no applicable content was found.
*/
- static getRangeFromPoint(x, y, {normalizeCssZoom}) {
+ getRangeFromPoint(x, y, {normalizeCssZoom}) {
const styleNode = this._getStyleNode();
styleNode.disabled = false;
const element = document.elementFromPoint(x, y);
@@ -55,8 +57,8 @@ export class GoogleDocsUtil {
* which allows them to be included in document.elementsFromPoint's return value.
* @returns {HTMLStyleElement}
*/
- static _getStyleNode() {
- if (typeof this._styleNode === 'undefined') {
+ _getStyleNode() {
+ if (this._styleNode === null) {
const style = document.createElement('style');
style.textContent = [
'.kix-canvas-tile-content{pointer-events:none!important;}',
@@ -79,7 +81,7 @@ export class GoogleDocsUtil {
* @param {boolean} normalizeCssZoom
* @returns {TextSourceRange}
*/
- static _createRange(element, text, x, y, normalizeCssZoom) {
+ _createRange(element, text, x, y, normalizeCssZoom) {
// Create imposter
const content = document.createTextNode(text);
const svgText = document.createElementNS('http://www.w3.org/2000/svg', 'text');
@@ -120,7 +122,7 @@ export class GoogleDocsUtil {
* @param {boolean} normalizeCssZoom
* @returns {Range}
*/
- static _getRangeWithPoint(textNode, x, y, normalizeCssZoom) {
+ _getRangeWithPoint(textNode, x, y, normalizeCssZoom) {
if (normalizeCssZoom) {
const scale = DocumentUtil.computeZoomScale(textNode);
x /= scale;
@@ -149,7 +151,7 @@ export class GoogleDocsUtil {
* @param {string} propertyName
* @param {string} value
*/
- static _setImportantStyle(style, propertyName, value) {
+ _setImportantStyle(style, propertyName, value) {
style.setProperty(propertyName, value, 'important');
}
}