| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Class to manage SwitchAccess and interact with other controllers. | 6 * Class to manage interactions with the accessibility tree, including moving |
| 7 * to and selecting nodes. |
| 7 * | 8 * |
| 8 * @constructor | 9 * @constructor |
| 9 * @implements {SwitchAccessInterface} | |
| 10 */ | 10 */ |
| 11 function SwitchAccess() { | 11 function AutomationManager() { |
| 12 console.log('Switch access is enabled'); | 12 /** |
| 13 * Currently selected node. |
| 14 * |
| 15 * @private {chrome.automation.AutomationNode} |
| 16 */ |
| 17 this.node_ = null; |
| 13 | 18 |
| 14 /** | 19 /** |
| 15 * User preferences. | 20 * Root node (i.e., the desktop). |
| 16 * | 21 * |
| 17 * @type {SwitchAccessPrefs} | 22 * @private {chrome.automation.AutomationNode} |
| 18 */ | 23 */ |
| 19 this.switchAccessPrefs = null; | 24 this.root_ = null; |
| 20 | |
| 21 /** | |
| 22 * Handles changes to auto-scan. | |
| 23 * | |
| 24 * @private {AutoScanManager} | |
| 25 */ | |
| 26 this.autoScanManager_ = null; | |
| 27 | |
| 28 /** | |
| 29 * Handles keyboard input. | |
| 30 * | |
| 31 * @private {KeyboardHandler} | |
| 32 */ | |
| 33 this.keyboardHandler_ = null; | |
| 34 | 25 |
| 35 /** | 26 /** |
| 36 * Moves to the appropriate node in the accessibility tree. | 27 * Moves to the appropriate node in the accessibility tree. |
| 37 * | 28 * |
| 38 * @private {AutomationTreeWalker} | 29 * @private {AutomationTreeWalker} |
| 39 */ | 30 */ |
| 40 this.treeWalker_ = null; | 31 this.treeWalker_ = null; |
| 41 | 32 |
| 42 /** | |
| 43 * Currently selected node. | |
| 44 * | |
| 45 * @private {chrome.automation.AutomationNode} | |
| 46 */ | |
| 47 this.node_ = null; | |
| 48 | |
| 49 /** | |
| 50 * Root node (i.e., the desktop). | |
| 51 * | |
| 52 * @private {chrome.automation.AutomationNode} | |
| 53 */ | |
| 54 this.root_ = null; | |
| 55 | |
| 56 this.init_(); | 33 this.init_(); |
| 57 }; | 34 }; |
| 58 | 35 |
| 59 SwitchAccess.prototype = { | 36 AutomationManager.prototype = { |
| 60 /** | 37 /** |
| 61 * Set this.node_ and this.root_ to the desktop node, and set up preferences, | 38 * Set this.node_ and this.root_ to the desktop node, and initialize the |
| 62 * controllers, and event listeners. | 39 * tree walker. |
| 63 * | 40 * |
| 64 * @private | 41 * @private |
| 65 */ | 42 */ |
| 66 init_: function() { | 43 init_: function() { |
| 67 this.switchAccessPrefs = new SwitchAccessPrefs(); | |
| 68 this.autoScanManager_ = new AutoScanManager(this); | |
| 69 this.keyboardHandler_ = new KeyboardHandler(this); | |
| 70 this.treeWalker_ = new AutomationTreeWalker(); | 44 this.treeWalker_ = new AutomationTreeWalker(); |
| 71 | 45 |
| 72 chrome.automation.getDesktop(function(desktop) { | 46 chrome.automation.getDesktop(function(desktop) { |
| 73 this.node_ = desktop; | 47 this.node_ = desktop; |
| 74 this.root_ = desktop; | 48 this.root_ = desktop; |
| 75 console.log('AutomationNode for desktop is loaded'); | 49 console.log('AutomationNode for desktop is loaded'); |
| 76 this.printNode_(this.node_); | 50 this.printNode_(this.node_); |
| 77 }.bind(this)); | 51 }.bind(this)); |
| 78 | |
| 79 document.addEventListener( | |
| 80 'prefsUpdate', this.handlePrefsUpdate_.bind(this)); | |
| 81 }, | 52 }, |
| 82 | 53 |
| 83 /** | 54 /** |
| 84 * Set this.node_ to the next/previous interesting node. If no interesting | 55 * Set this.node_ to the next/previous interesting node, and then highlight |
| 85 * node is found, set this.node_ to the first/last interesting node. If | 56 * it on the screen. If no interesting node is found, set this.node_ to the |
| 86 * |doNext| is true, will search for next node. Otherwise, will search for | 57 * first/last interesting node. If |doNext| is true, will search for next |
| 87 * previous node. | 58 * node. Otherwise, will search for previous node. |
| 88 * | 59 * |
| 89 * @param {boolean} doNext | 60 * @param {boolean} doNext |
| 90 * @override | |
| 91 */ | 61 */ |
| 92 moveToNode: function(doNext) { | 62 moveToNode: function(doNext) { |
| 93 let node = this.treeWalker_.moveToNode(this.node_, this.root_, doNext); | 63 let node = this.treeWalker_.moveToNode(this.node_, this.root_, doNext); |
| 94 if (node) { | 64 if (node) { |
| 95 this.node_ = node; | 65 this.node_ = node; |
| 96 this.printNode_(this.node_); | 66 this.printNode_(this.node_); |
| 97 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); | 67 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); |
| 98 } | 68 } |
| 99 }, | 69 }, |
| 100 | 70 |
| 101 /** | 71 /** |
| 102 * Perform the default action on the currently selected node. | 72 * Perform the default action on the currently selected node. |
| 103 * | |
| 104 * @override | |
| 105 */ | 73 */ |
| 106 doDefault: function() { | 74 doDefault: function() { |
| 107 if (!this.node_) | 75 if (!this.node_) |
| 108 return; | 76 return; |
| 109 | 77 |
| 110 this.node_.doDefault(); | 78 this.node_.doDefault(); |
| 111 }, | 79 }, |
| 112 | 80 |
| 113 /** | |
| 114 * Open the options page in a new tab. | |
| 115 * | |
| 116 * @override | |
| 117 */ | |
| 118 showOptionsPage: function() { | |
| 119 let optionsPage = {url: 'options.html'}; | |
| 120 chrome.tabs.create(optionsPage); | |
| 121 }, | |
| 122 | |
| 123 /** | |
| 124 * Perform actions as the result of actions by the user. Currently, restarts | |
| 125 * auto-scan if it is enabled. | |
| 126 * | |
| 127 * @override | |
| 128 */ | |
| 129 performedUserAction: function() { | |
| 130 this.autoScanManager_.restartIfRunning(); | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 134 * Handle a change in user preferences. | |
| 135 * | |
| 136 * @param {!Event} event | |
| 137 * @private | |
| 138 */ | |
| 139 handlePrefsUpdate_: function(event) { | |
| 140 let updatedPrefs = event.detail; | |
| 141 for (let key of Object.keys(updatedPrefs)) { | |
| 142 switch (key) { | |
| 143 case 'enableAutoScan': | |
| 144 this.autoScanManager_.setEnabled(updatedPrefs[key]); | |
| 145 break; | |
| 146 case 'autoScanTime': | |
| 147 this.autoScanManager_.setScanTime(updatedPrefs[key]); | |
| 148 break; | |
| 149 } | |
| 150 } | |
| 151 }, | |
| 152 | |
| 153 // TODO(elichtenberg): Move print functions to a custom logger class. Only | 81 // TODO(elichtenberg): Move print functions to a custom logger class. Only |
| 154 // log when debuggingEnabled is true. | 82 // log when debuggingEnabled is true. |
| 155 /** | 83 /** |
| 156 * Print out details about a node. | 84 * Print out details about a node. |
| 157 * | 85 * |
| 158 * @param {chrome.automation.AutomationNode} node | 86 * @param {chrome.automation.AutomationNode} node |
| 159 * @private | 87 * @private |
| 160 */ | 88 */ |
| 161 printNode_: function(node) { | 89 printNode_: function(node) { |
| 162 if (node) { | 90 if (node) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 174 console.log('Has ' + node.children.length + ' children'); | 102 console.log('Has ' + node.children.length + ' children'); |
| 175 } else { | 103 } else { |
| 176 console.log('Node is null'); | 104 console.log('Node is null'); |
| 177 } | 105 } |
| 178 console.log(node); | 106 console.log(node); |
| 179 console.log('\n'); | 107 console.log('\n'); |
| 180 }, | 108 }, |
| 181 | 109 |
| 182 /** | 110 /** |
| 183 * Move to the next sibling of this.node_ if it has one. | 111 * Move to the next sibling of this.node_ if it has one. |
| 184 * | |
| 185 * @override | |
| 186 */ | 112 */ |
| 187 debugMoveToNext: function() { | 113 debugMoveToNext: function() { |
| 188 let next = this.treeWalker_.debugMoveToNext(this.node_); | 114 let next = this.treeWalker_.debugMoveToNext(this.node_); |
| 189 if (next) { | 115 if (next) { |
| 190 this.node_ = next; | 116 this.node_ = next; |
| 191 this.printNode_(this.node_); | 117 this.printNode_(this.node_); |
| 192 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); | 118 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); |
| 193 } | 119 } |
| 194 }, | 120 }, |
| 195 | 121 |
| 196 /** | 122 /** |
| 197 * Move to the previous sibling of this.node_ if it has one. | 123 * Move to the previous sibling of this.node_ if it has one. |
| 198 * | |
| 199 * @override | |
| 200 */ | 124 */ |
| 201 debugMoveToPrevious: function() { | 125 debugMoveToPrevious: function() { |
| 202 let prev = this.treeWalker_.debugMoveToPrevious(this.node_); | 126 let prev = this.treeWalker_.debugMoveToPrevious(this.node_); |
| 203 if (prev) { | 127 if (prev) { |
| 204 this.node_ = prev; | 128 this.node_ = prev; |
| 205 this.printNode_(this.node_); | 129 this.printNode_(this.node_); |
| 206 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); | 130 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); |
| 207 } | 131 } |
| 208 }, | 132 }, |
| 209 | 133 |
| 210 /** | 134 /** |
| 211 * Move to the first child of this.node_ if it has one. | 135 * Move to the first child of this.node_ if it has one. |
| 212 * | |
| 213 * @override | |
| 214 */ | 136 */ |
| 215 debugMoveToFirstChild: function() { | 137 debugMoveToFirstChild: function() { |
| 216 let child = this.treeWalker_.debugMoveToFirstChild(this.node_); | 138 let child = this.treeWalker_.debugMoveToFirstChild(this.node_); |
| 217 if (child) { | 139 if (child) { |
| 218 this.node_ = child; | 140 this.node_ = child; |
| 219 this.printNode_(this.node_); | 141 this.printNode_(this.node_); |
| 220 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); | 142 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); |
| 221 } | 143 } |
| 222 }, | 144 }, |
| 223 | 145 |
| 224 /** | 146 /** |
| 225 * Move to the parent of this.node_ if it has one. | 147 * Move to the parent of this.node_ if it has one. |
| 226 * | |
| 227 * @override | |
| 228 */ | 148 */ |
| 229 debugMoveToParent: function() { | 149 debugMoveToParent: function() { |
| 230 let parent = this.treeWalker_.debugMoveToParent(this.node_); | 150 let parent = this.treeWalker_.debugMoveToParent(this.node_); |
| 231 if (parent) { | 151 if (parent) { |
| 232 this.node_ = parent; | 152 this.node_ = parent; |
| 233 this.printNode_(this.node_); | 153 this.printNode_(this.node_); |
| 234 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); | 154 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); |
| 235 } | 155 } |
| 236 } | 156 } |
| 237 }; | 157 }; |
| OLD | NEW |