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

Refactor Switch Access constants into their own file

This is a pure refactor, with no functional changes.

Bug: None
Change-Id: Id66cf951a8b060fdb2a0d4458dd48620d28b9d05
Reviewed-on: https://chromium-review.googlesource.com/c/1487873
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Auto-Submit: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635835}
parent 3e878286
...@@ -56,6 +56,7 @@ run_jsbundler("switch_access_copied_files") { ...@@ -56,6 +56,7 @@ run_jsbundler("switch_access_copied_files") {
"options.js", "options.js",
"prefs.js", "prefs.js",
"switch_access.js", "switch_access.js",
"switch_access_constants.js",
"switch_access_predicate.js", "switch_access_predicate.js",
"text_input_manager.js", "text_input_manager.js",
] ]
...@@ -162,6 +163,7 @@ js_type_check("closure_compile") { ...@@ -162,6 +163,7 @@ js_type_check("closure_compile") {
":options", ":options",
":prefs", ":prefs",
":switch_access", ":switch_access",
":switch_access_constants",
":switch_access_interface", ":switch_access_interface",
":switch_access_predicate", ":switch_access_predicate",
":text_input_manager", ":text_input_manager",
...@@ -181,6 +183,7 @@ js_library("navigation_manager") { ...@@ -181,6 +183,7 @@ js_library("navigation_manager") {
deps = [ deps = [
":menu_manager", ":menu_manager",
":menu_panel_interface", ":menu_panel_interface",
":switch_access_constants",
":switch_access_predicate", ":switch_access_predicate",
":text_input_manager", ":text_input_manager",
"../chromevox:constants", "../chromevox:constants",
...@@ -252,6 +255,9 @@ js_library("switch_access") { ...@@ -252,6 +255,9 @@ js_library("switch_access") {
] ]
} }
js_library("switch_access_constants") {
}
js_library("switch_access_interface") { js_library("switch_access_interface") {
deps = [ deps = [
":menu_panel_interface", ":menu_panel_interface",
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
"background": { "background": {
"scripts": [ "scripts": [
"auto_scan_manager.js", "auto_scan_manager.js",
"switch_access_predicate.js",
"closure_shim.js", "closure_shim.js",
"commands.js", "commands.js",
"constants.js", "constants.js",
...@@ -21,6 +20,8 @@ ...@@ -21,6 +20,8 @@
"navigation_manager.js", "navigation_manager.js",
"prefs.js", "prefs.js",
"switch_access.js", "switch_access.js",
"switch_access_constants.js",
"switch_access_predicate.js",
"text_input_manager.js", "text_input_manager.js",
"tree_walker.js", "tree_walker.js",
"background.js" "background.js"
......
...@@ -15,7 +15,7 @@ class MenuManager { ...@@ -15,7 +15,7 @@ class MenuManager {
constructor(navigationManager, desktop) { constructor(navigationManager, desktop) {
/** /**
* A list of the Menu actions that are currently enabled. * A list of the Menu actions that are currently enabled.
* @private {!Array<MenuManager.Action>} * @private {!Array<SAConstants.MenuAction>}
*/ */
this.actions_ = []; this.actions_ = [];
...@@ -109,7 +109,7 @@ class MenuManager { ...@@ -109,7 +109,7 @@ class MenuManager {
this.node_ = null; this.node_ = null;
chrome.accessibilityPrivate.setSwitchAccessMenuState( chrome.accessibilityPrivate.setSwitchAccessMenuState(
false, MenuManager.EmptyLocation, 0); false, SAConstants.EMPTY_LOCATION, 0);
} }
/** /**
...@@ -231,14 +231,14 @@ class MenuManager { ...@@ -231,14 +231,14 @@ class MenuManager {
* should select the current node automatically. * should select the current node automatically.
* *
* @param {!chrome.automation.AutomationNode} node * @param {!chrome.automation.AutomationNode} node
* @return {Array<MenuManager.Action>} * @return {Array<!SAConstants.MenuAction>}
* @private * @private
*/ */
getActionsForNode_(node) { getActionsForNode_(node) {
let actions = []; let actions = [];
if (SwitchAccessPredicate.isTextInput(node)) if (SwitchAccessPredicate.isTextInput(node))
actions.push(MenuManager.Action.DICTATION); actions.push(SAConstants.MenuAction.DICTATION);
let scrollableAncestor = node; let scrollableAncestor = node;
while (!scrollableAncestor.scrollable && scrollableAncestor.parent) while (!scrollableAncestor.scrollable && scrollableAncestor.parent)
...@@ -246,23 +246,24 @@ class MenuManager { ...@@ -246,23 +246,24 @@ class MenuManager {
if (scrollableAncestor.scrollable) { if (scrollableAncestor.scrollable) {
if (scrollableAncestor.scrollX > scrollableAncestor.scrollXMin) if (scrollableAncestor.scrollX > scrollableAncestor.scrollXMin)
actions.push(MenuManager.Action.SCROLL_LEFT); actions.push(SAConstants.MenuAction.SCROLL_LEFT);
if (scrollableAncestor.scrollX < scrollableAncestor.scrollXMax) if (scrollableAncestor.scrollX < scrollableAncestor.scrollXMax)
actions.push(MenuManager.Action.SCROLL_RIGHT); actions.push(SAConstants.MenuAction.SCROLL_RIGHT);
if (scrollableAncestor.scrollY > scrollableAncestor.scrollYMin) if (scrollableAncestor.scrollY > scrollableAncestor.scrollYMin)
actions.push(MenuManager.Action.SCROLL_UP); actions.push(SAConstants.MenuAction.SCROLL_UP);
if (scrollableAncestor.scrollY < scrollableAncestor.scrollYMax) if (scrollableAncestor.scrollY < scrollableAncestor.scrollYMax)
actions.push(MenuManager.Action.SCROLL_DOWN); actions.push(SAConstants.MenuAction.SCROLL_DOWN);
} }
const standardActions = /** @type {!Array<MenuManager.Action>} */ ( const standardActions = /** @type {!Array<SAConstants.MenuAction>} */ (
node.standardActions.filter(action => action in MenuManager.Action)); node.standardActions.filter(
action => action in SAConstants.MenuAction));
actions = actions.concat(standardActions); actions = actions.concat(standardActions);
if (actions.length === 0) if (actions.length === 0)
return null; return null;
actions.push(MenuManager.Action.SELECT, MenuManager.Action.OPTIONS); actions.push(SAConstants.MenuAction.SELECT, SAConstants.MenuAction.OPTIONS);
return actions; return actions;
} }
...@@ -274,17 +275,17 @@ class MenuManager { ...@@ -274,17 +275,17 @@ class MenuManager {
performAction(action) { performAction(action) {
this.exit(); this.exit();
if (action === MenuManager.Action.SELECT) if (action === SAConstants.MenuAction.SELECT)
this.navigationManager_.selectCurrentNode(); this.navigationManager_.selectCurrentNode();
else if (action === MenuManager.Action.DICTATION) else if (action === SAConstants.MenuAction.DICTATION)
chrome.accessibilityPrivate.toggleDictation(); chrome.accessibilityPrivate.toggleDictation();
else if (action === MenuManager.Action.OPTIONS) else if (action === SAConstants.MenuAction.OPTIONS)
window.switchAccess.showOptionsPage(); window.switchAccess.showOptionsPage();
else if ( else if (
action === MenuManager.Action.SCROLL_DOWN || action === SAConstants.MenuAction.SCROLL_DOWN ||
action === MenuManager.Action.SCROLL_UP || action === SAConstants.MenuAction.SCROLL_UP ||
action === MenuManager.Action.SCROLL_LEFT || action === SAConstants.MenuAction.SCROLL_LEFT ||
action === MenuManager.Action.SCROLL_RIGHT) action === SAConstants.MenuAction.SCROLL_RIGHT)
this.navigationManager_.scroll(action); this.navigationManager_.scroll(action);
else else
this.navigationManager_.performActionOnCurrentNode(action); this.navigationManager_.performActionOnCurrentNode(action);
...@@ -334,43 +335,3 @@ class MenuManager { ...@@ -334,43 +335,3 @@ class MenuManager {
return this.node_; return this.node_;
} }
} }
/**
* Actions available in the Switch Access Menu.
* @enum {string}
* @const
*/
MenuManager.Action = {
DECREMENT: chrome.automation.ActionType.DECREMENT,
DICTATION: 'dictation',
INCREMENT: chrome.automation.ActionType.INCREMENT,
// This opens the Switch Access settings in a new Chrome tab.
OPTIONS: 'options',
SCROLL_BACKWARD: chrome.automation.ActionType.SCROLL_BACKWARD,
SCROLL_DOWN: chrome.automation.ActionType.SCROLL_DOWN,
SCROLL_FORWARD: chrome.automation.ActionType.SCROLL_FORWARD,
SCROLL_LEFT: chrome.automation.ActionType.SCROLL_LEFT,
SCROLL_RIGHT: chrome.automation.ActionType.SCROLL_RIGHT,
SCROLL_UP: chrome.automation.ActionType.SCROLL_UP,
// This either performs the default action or enters a new scope, as
// applicable.
SELECT: 'select',
SHOW_CONTEXT_MENU: chrome.automation.ActionType.SHOW_CONTEXT_MENU
};
/**
* The ID for the div containing the Switch Access menu.
* @const
*/
MenuManager.MenuId = 'switchaccess_menu_actions';
/**
* Empty location, used for hiding the menu.
* @const
*/
MenuManager.EmptyLocation = {
left: 0,
top: 0,
width: 0,
height: 0
};
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Switch Access Menu</title> <title>Switch Access Menu</title>
<script type="text/javascript" src="closure/base.js"></script> <script type="text/javascript" src="closure/base.js"></script>
<script type="text/javascript" src="switch_access_constants.js"></script>
<script type="text/javascript" src="menu_panel.js"></script> <script type="text/javascript" src="menu_panel.js"></script>
<link rel="stylesheet" href="menu_panel.css"> <link rel="stylesheet" href="menu_panel.css">
</head> </head>
......
...@@ -19,7 +19,7 @@ class Panel { ...@@ -19,7 +19,7 @@ class Panel {
* Initialize the panel and buttons. * Initialize the panel and buttons.
*/ */
init() { init() {
const div = document.getElementById(Panel.MENU_ID); const div = document.getElementById(SAConstants.MENU_ID);
for (const button of div.children) for (const button of div.children)
this.setupButton_(button); this.setupButton_(button);
...@@ -60,7 +60,7 @@ class Panel { ...@@ -60,7 +60,7 @@ class Panel {
* @param {boolean} enable * @param {boolean} enable
*/ */
setFocusRing(id, enable) { setFocusRing(id, enable) {
this.updateClass_(id, Panel.FOCUS_CLASS, enable); this.updateClass_(id, SAConstants.FOCUS_CLASS, enable);
return; return;
} }
...@@ -69,7 +69,7 @@ class Panel { ...@@ -69,7 +69,7 @@ class Panel {
* @param {!Array<string>} actions * @param {!Array<string>} actions
*/ */
setActions(actions) { setActions(actions) {
const div = document.getElementById(Panel.MENU_ID); const div = document.getElementById(SAConstants.MENU_ID);
for (const button of div.children) for (const button of div.children)
button.hidden = !actions.includes(button.id); button.hidden = !actions.includes(button.id);
...@@ -104,21 +104,10 @@ class Panel { ...@@ -104,21 +104,10 @@ class Panel {
const maxCols = 3; const maxCols = 3;
const numRows = Math.ceil(numActions / maxCols); const numRows = Math.ceil(numActions / maxCols);
const height = 60 * numRows; const height = 60 * numRows;
document.getElementById(Panel.MENU_ID).style.height = height + 'px'; document.getElementById(SAConstants.MENU_ID).style.height = height + 'px';
} }
} }
/**
* This must be kept in sync with the div ID in menu_panel.html.
* @type {string}
*/
Panel.MENU_ID = 'switchaccess_menu_actions';
/**
* This must be kept in sync with the class name in menu_panel.css.
* @type {string}
*/
Panel.FOCUS_CLASS = 'focus';
let switchAccessMenuPanel = new Panel(); let switchAccessMenuPanel = new Panel();
if (document.readyState === 'complete') if (document.readyState === 'complete')
......
...@@ -141,7 +141,7 @@ class NavigationManager { ...@@ -141,7 +141,7 @@ class NavigationManager {
/** /**
* Scrolls the current node in the direction indicated by |scrollAction|. * Scrolls the current node in the direction indicated by |scrollAction|.
* @param {!MenuManager.Action} scrollAction * @param {!SAConstants.MenuAction} scrollAction
*/ */
scroll(scrollAction) { scroll(scrollAction) {
// Find the closest ancestor to the current node that is scrollable. // Find the closest ancestor to the current node that is scrollable.
...@@ -151,17 +151,17 @@ class NavigationManager { ...@@ -151,17 +151,17 @@ class NavigationManager {
if (!scrollNode) if (!scrollNode)
return; return;
if (scrollAction === MenuManager.Action.SCROLL_DOWN) if (scrollAction === SAConstants.MenuAction.SCROLL_DOWN)
scrollNode.scrollDown(() => {}); scrollNode.scrollDown(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_UP) else if (scrollAction === SAConstants.MenuAction.SCROLL_UP)
scrollNode.scrollUp(() => {}); scrollNode.scrollUp(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_LEFT) else if (scrollAction === SAConstants.MenuAction.SCROLL_LEFT)
scrollNode.scrollLeft(() => {}); scrollNode.scrollLeft(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_RIGHT) else if (scrollAction === SAConstants.MenuAction.SCROLL_RIGHT)
scrollNode.scrollRight(() => {}); scrollNode.scrollRight(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_FORWARD) else if (scrollAction === SAConstants.MenuAction.SCROLL_FORWARD)
scrollNode.scrollForward(() => {}); scrollNode.scrollForward(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_BACKWARD) else if (scrollAction === SAConstants.MenuAction.SCROLL_BACKWARD)
scrollNode.scrollBackward(() => {}); scrollNode.scrollBackward(() => {});
else else
console.log('Unrecognized scroll action: ', scrollAction); console.log('Unrecognized scroll action: ', scrollAction);
...@@ -217,7 +217,7 @@ class NavigationManager { ...@@ -217,7 +217,7 @@ class NavigationManager {
/** /**
* Performs |action| on the current node, if an appropriate action exists. * Performs |action| on the current node, if an appropriate action exists.
* @param {!MenuManager.Action} action * @param {!SAConstants.MenuAction} action
*/ */
performActionOnCurrentNode(action) { performActionOnCurrentNode(action) {
if (action in chrome.automation.ActionType) if (action in chrome.automation.ActionType)
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/** Constants used in Switch Access */
const SAConstants = {
/**
* The ID of the menu panel.
* This must be kept in sync with the div ID in menu_panel.html.
* @type {string}
* @const
*/
MENU_ID: 'switchaccess_menu_actions',
/**
* The ID of the back button.
* This must be kept in sync with the back button ID in menu_panel.html.
* @type {string}
* @const
*/
BACK_ID: 'back',
/**
* The name of the focus class for the menu.
* This must be kept in sync with the class name in menu_panel.css.
* @type {string}
* @const
*/
FOCUS_CLASS: 'focus',
/**
* Actions available in the Switch Access Menu.
* @enum {string}
* @const
*/
MenuAction: {
DECREMENT: chrome.automation.ActionType.DECREMENT,
DICTATION: 'dictation',
INCREMENT: chrome.automation.ActionType.INCREMENT,
// This opens the Switch Access settings in a new Chrome tab.
OPTIONS: 'options',
SCROLL_BACKWARD: chrome.automation.ActionType.SCROLL_BACKWARD,
SCROLL_DOWN: chrome.automation.ActionType.SCROLL_DOWN,
SCROLL_FORWARD: chrome.automation.ActionType.SCROLL_FORWARD,
SCROLL_LEFT: chrome.automation.ActionType.SCROLL_LEFT,
SCROLL_RIGHT: chrome.automation.ActionType.SCROLL_RIGHT,
SCROLL_UP: chrome.automation.ActionType.SCROLL_UP,
// This either performs the default action or enters a new scope, as
// applicable.
SELECT: 'select',
SHOW_CONTEXT_MENU: chrome.automation.ActionType.SHOW_CONTEXT_MENU
},
/**
* Empty location, used for hiding the menu.
* @const
*/
EMPTY_LOCATION: {left: 0, top: 0, width: 0, height: 0}
};
...@@ -168,7 +168,7 @@ const SwitchAccessPredicate = { ...@@ -168,7 +168,7 @@ const SwitchAccessPredicate = {
* @param {!chrome.automation.AutomationNode} node * @param {!chrome.automation.AutomationNode} node
* @return {boolean} * @return {boolean}
*/ */
isSwitchAccessMenu: (node) => node.htmlAttributes.id === MenuManager.MenuId, isSwitchAccessMenu: (node) => node.htmlAttributes.id === SAConstants.MENU_ID,
/** /**
* Returns a Restrictions object ready to be passed to AutomationTreeWalker. * Returns a Restrictions object ready to be passed to AutomationTreeWalker.
......
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