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") {
"options.js",
"prefs.js",
"switch_access.js",
"switch_access_constants.js",
"switch_access_predicate.js",
"text_input_manager.js",
]
......@@ -162,6 +163,7 @@ js_type_check("closure_compile") {
":options",
":prefs",
":switch_access",
":switch_access_constants",
":switch_access_interface",
":switch_access_predicate",
":text_input_manager",
......@@ -181,6 +183,7 @@ js_library("navigation_manager") {
deps = [
":menu_manager",
":menu_panel_interface",
":switch_access_constants",
":switch_access_predicate",
":text_input_manager",
"../chromevox:constants",
......@@ -252,6 +255,9 @@ js_library("switch_access") {
]
}
js_library("switch_access_constants") {
}
js_library("switch_access_interface") {
deps = [
":menu_panel_interface",
......
......@@ -12,7 +12,6 @@
"background": {
"scripts": [
"auto_scan_manager.js",
"switch_access_predicate.js",
"closure_shim.js",
"commands.js",
"constants.js",
......@@ -21,6 +20,8 @@
"navigation_manager.js",
"prefs.js",
"switch_access.js",
"switch_access_constants.js",
"switch_access_predicate.js",
"text_input_manager.js",
"tree_walker.js",
"background.js"
......
......@@ -15,7 +15,7 @@ class MenuManager {
constructor(navigationManager, desktop) {
/**
* A list of the Menu actions that are currently enabled.
* @private {!Array<MenuManager.Action>}
* @private {!Array<SAConstants.MenuAction>}
*/
this.actions_ = [];
......@@ -109,7 +109,7 @@ class MenuManager {
this.node_ = null;
chrome.accessibilityPrivate.setSwitchAccessMenuState(
false, MenuManager.EmptyLocation, 0);
false, SAConstants.EMPTY_LOCATION, 0);
}
/**
......@@ -231,14 +231,14 @@ class MenuManager {
* should select the current node automatically.
*
* @param {!chrome.automation.AutomationNode} node
* @return {Array<MenuManager.Action>}
* @return {Array<!SAConstants.MenuAction>}
* @private
*/
getActionsForNode_(node) {
let actions = [];
if (SwitchAccessPredicate.isTextInput(node))
actions.push(MenuManager.Action.DICTATION);
actions.push(SAConstants.MenuAction.DICTATION);
let scrollableAncestor = node;
while (!scrollableAncestor.scrollable && scrollableAncestor.parent)
......@@ -246,23 +246,24 @@ class MenuManager {
if (scrollableAncestor.scrollable) {
if (scrollableAncestor.scrollX > scrollableAncestor.scrollXMin)
actions.push(MenuManager.Action.SCROLL_LEFT);
actions.push(SAConstants.MenuAction.SCROLL_LEFT);
if (scrollableAncestor.scrollX < scrollableAncestor.scrollXMax)
actions.push(MenuManager.Action.SCROLL_RIGHT);
actions.push(SAConstants.MenuAction.SCROLL_RIGHT);
if (scrollableAncestor.scrollY > scrollableAncestor.scrollYMin)
actions.push(MenuManager.Action.SCROLL_UP);
actions.push(SAConstants.MenuAction.SCROLL_UP);
if (scrollableAncestor.scrollY < scrollableAncestor.scrollYMax)
actions.push(MenuManager.Action.SCROLL_DOWN);
actions.push(SAConstants.MenuAction.SCROLL_DOWN);
}
const standardActions = /** @type {!Array<MenuManager.Action>} */ (
node.standardActions.filter(action => action in MenuManager.Action));
const standardActions = /** @type {!Array<SAConstants.MenuAction>} */ (
node.standardActions.filter(
action => action in SAConstants.MenuAction));
actions = actions.concat(standardActions);
if (actions.length === 0)
return null;
actions.push(MenuManager.Action.SELECT, MenuManager.Action.OPTIONS);
actions.push(SAConstants.MenuAction.SELECT, SAConstants.MenuAction.OPTIONS);
return actions;
}
......@@ -274,17 +275,17 @@ class MenuManager {
performAction(action) {
this.exit();
if (action === MenuManager.Action.SELECT)
if (action === SAConstants.MenuAction.SELECT)
this.navigationManager_.selectCurrentNode();
else if (action === MenuManager.Action.DICTATION)
else if (action === SAConstants.MenuAction.DICTATION)
chrome.accessibilityPrivate.toggleDictation();
else if (action === MenuManager.Action.OPTIONS)
else if (action === SAConstants.MenuAction.OPTIONS)
window.switchAccess.showOptionsPage();
else if (
action === MenuManager.Action.SCROLL_DOWN ||
action === MenuManager.Action.SCROLL_UP ||
action === MenuManager.Action.SCROLL_LEFT ||
action === MenuManager.Action.SCROLL_RIGHT)
action === SAConstants.MenuAction.SCROLL_DOWN ||
action === SAConstants.MenuAction.SCROLL_UP ||
action === SAConstants.MenuAction.SCROLL_LEFT ||
action === SAConstants.MenuAction.SCROLL_RIGHT)
this.navigationManager_.scroll(action);
else
this.navigationManager_.performActionOnCurrentNode(action);
......@@ -334,43 +335,3 @@ class MenuManager {
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 @@
<meta charset="utf-8">
<title>Switch Access Menu</title>
<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>
<link rel="stylesheet" href="menu_panel.css">
</head>
......
......@@ -19,7 +19,7 @@ class Panel {
* Initialize the panel and buttons.
*/
init() {
const div = document.getElementById(Panel.MENU_ID);
const div = document.getElementById(SAConstants.MENU_ID);
for (const button of div.children)
this.setupButton_(button);
......@@ -60,7 +60,7 @@ class Panel {
* @param {boolean} enable
*/
setFocusRing(id, enable) {
this.updateClass_(id, Panel.FOCUS_CLASS, enable);
this.updateClass_(id, SAConstants.FOCUS_CLASS, enable);
return;
}
......@@ -69,7 +69,7 @@ class Panel {
* @param {!Array<string>} actions
*/
setActions(actions) {
const div = document.getElementById(Panel.MENU_ID);
const div = document.getElementById(SAConstants.MENU_ID);
for (const button of div.children)
button.hidden = !actions.includes(button.id);
......@@ -104,21 +104,10 @@ class Panel {
const maxCols = 3;
const numRows = Math.ceil(numActions / maxCols);
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();
if (document.readyState === 'complete')
......
......@@ -141,7 +141,7 @@ class NavigationManager {
/**
* Scrolls the current node in the direction indicated by |scrollAction|.
* @param {!MenuManager.Action} scrollAction
* @param {!SAConstants.MenuAction} scrollAction
*/
scroll(scrollAction) {
// Find the closest ancestor to the current node that is scrollable.
......@@ -151,17 +151,17 @@ class NavigationManager {
if (!scrollNode)
return;
if (scrollAction === MenuManager.Action.SCROLL_DOWN)
if (scrollAction === SAConstants.MenuAction.SCROLL_DOWN)
scrollNode.scrollDown(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_UP)
else if (scrollAction === SAConstants.MenuAction.SCROLL_UP)
scrollNode.scrollUp(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_LEFT)
else if (scrollAction === SAConstants.MenuAction.SCROLL_LEFT)
scrollNode.scrollLeft(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_RIGHT)
else if (scrollAction === SAConstants.MenuAction.SCROLL_RIGHT)
scrollNode.scrollRight(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_FORWARD)
else if (scrollAction === SAConstants.MenuAction.SCROLL_FORWARD)
scrollNode.scrollForward(() => {});
else if (scrollAction === MenuManager.Action.SCROLL_BACKWARD)
else if (scrollAction === SAConstants.MenuAction.SCROLL_BACKWARD)
scrollNode.scrollBackward(() => {});
else
console.log('Unrecognized scroll action: ', scrollAction);
......@@ -217,7 +217,7 @@ class NavigationManager {
/**
* Performs |action| on the current node, if an appropriate action exists.
* @param {!MenuManager.Action} action
* @param {!SAConstants.MenuAction} action
*/
performActionOnCurrentNode(action) {
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 = {
* @param {!chrome.automation.AutomationNode} node
* @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.
......
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