Commit cbae7eaa authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Clarify singleton object

The Switch Access object has always had a singleton object that lived
in the background page. Clarify where the object lives by accessing it
through a static method on the class.

Bug: None
Change-Id: I5b131e9a5679d27b6ad10dffc342c39ec9f75edc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875383Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#709162}
parent fb6cafb9
...@@ -2,9 +2,4 @@ ...@@ -2,9 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/** SwitchAccess.initialize();
* Initializes SwitchAccess and adds it to the extension's background page.
*
* @type {SwitchAccess}
*/
window.switchAccess = new SwitchAccess();
...@@ -128,7 +128,7 @@ class MenuManager { ...@@ -128,7 +128,7 @@ class MenuManager {
* @private * @private
*/ */
init_() { init_() {
if (window.switchAccess.improvedTextInputEnabled()) { if (SwitchAccess.get().improvedTextInputEnabled()) {
chrome.clipboard.onClipboardDataChanged.addListener( chrome.clipboard.onClipboardDataChanged.addListener(
this.updateClipboardHasData.bind(this)); this.updateClipboardHasData.bind(this));
} }
...@@ -243,7 +243,7 @@ class MenuManager { ...@@ -243,7 +243,7 @@ class MenuManager {
const autoNode = this.menuOriginNode_.automationNode; const autoNode = this.menuOriginNode_.automationNode;
if (autoNode && !shouldReloadMenu && if (autoNode && !shouldReloadMenu &&
window.switchAccess.improvedTextInputEnabled()) { SwitchAccess.get().improvedTextInputEnabled()) {
const callback = this.reloadMenuForSelectionChange_.bind(this); const callback = this.reloadMenuForSelectionChange_.bind(this);
autoNode.addEventListener( autoNode.addEventListener(
...@@ -516,7 +516,7 @@ class MenuManager { ...@@ -516,7 +516,7 @@ class MenuManager {
// Add text editing and navigation options. // Add text editing and navigation options.
// TODO(anastasi): Move these actions into the node. // TODO(anastasi): Move these actions into the node.
const autoNode = node.automationNode; const autoNode = node.automationNode;
if (autoNode && window.switchAccess.improvedTextInputEnabled() && if (autoNode && SwitchAccess.get().improvedTextInputEnabled() &&
SwitchAccessPredicate.isTextInput(autoNode) && SwitchAccessPredicate.isTextInput(autoNode) &&
autoNode.state[StateType.FOCUSED]) { autoNode.state[StateType.FOCUSED]) {
actions.push(SAConstants.MenuAction.MOVE_CURSOR); actions.push(SAConstants.MenuAction.MOVE_CURSOR);
......
...@@ -251,7 +251,7 @@ class NavigationManager { ...@@ -251,7 +251,7 @@ class NavigationManager {
/** @private */ /** @private */
init_() { init_() {
if (window.switchAccess.prefsAreReady()) { if (SwitchAccess.get().prefsAreReady()) {
this.onPrefsReady(); this.onPrefsReady();
} }
...@@ -354,6 +354,6 @@ class NavigationManager { ...@@ -354,6 +354,6 @@ class NavigationManager {
this.node_ = node; this.node_ = node;
this.node_.onFocus(); this.node_.onFocus();
this.focusRingManager_.setFocusNodes(this.node_, this.group_); this.focusRingManager_.setFocusNodes(this.node_, this.group_);
window.switchAccess.restartAutoScan(); SwitchAccess.get().restartAutoScan();
} }
} }
...@@ -18,7 +18,7 @@ class BackButtonNode extends SAChildNode { ...@@ -18,7 +18,7 @@ class BackButtonNode extends SAChildNode {
this.group_ = group; this.group_ = group;
/** @private {chrome.automation.AutomationNode} */ /** @private {chrome.automation.AutomationNode} */
this.node_ = window.switchAccess.getBackButtonAutomationNode(); this.node_ = SwitchAccess.get().getBackButtonAutomationNode();
} }
/** @override */ /** @override */
......
...@@ -7,6 +7,15 @@ ...@@ -7,6 +7,15 @@
* @implements {SwitchAccessInterface} * @implements {SwitchAccessInterface}
*/ */
class SwitchAccess { class SwitchAccess {
static initialize() {
window.switchAccess = new SwitchAccess();
}
static get() {
return window.switchAccess;
}
/** @private */
constructor() { constructor() {
console.log('Switch access is enabled'); console.log('Switch access is enabled');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment