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 SwitchAccess and interact with other controllers. |
7 * | 7 * |
8 * @constructor | 8 * @constructor |
9 * @implements {SwitchAccessInterface} | 9 * @implements {SwitchAccessInterface} |
10 */ | 10 */ |
11 function SwitchAccess() { | 11 function SwitchAccess() { |
12 console.log('Switch access is enabled'); | 12 console.log('Switch access is enabled'); |
13 | 13 |
14 /** | 14 /** |
| 15 * User commands. |
| 16 * |
| 17 * @private {Commands} |
| 18 */ |
| 19 this.commands_ = null; |
| 20 |
| 21 /** |
15 * User preferences. | 22 * User preferences. |
16 * | 23 * |
17 * @type {SwitchAccessPrefs} | 24 * @private {SwitchAccessPrefs} |
18 */ | 25 */ |
19 this.switchAccessPrefs = null; | 26 this.switchAccessPrefs_ = null; |
20 | 27 |
21 /** | 28 /** |
22 * Handles changes to auto-scan. | 29 * Handles changes to auto-scan. |
23 * | 30 * |
24 * @private {AutoScanManager} | 31 * @private {AutoScanManager} |
25 */ | 32 */ |
26 this.autoScanManager_ = null; | 33 this.autoScanManager_ = null; |
27 | 34 |
28 /** | 35 /** |
29 * Handles keyboard input. | 36 * Handles keyboard input. |
(...skipping 13 matching lines...) Expand all Loading... |
43 this.init_(); | 50 this.init_(); |
44 } | 51 } |
45 | 52 |
46 SwitchAccess.prototype = { | 53 SwitchAccess.prototype = { |
47 /** | 54 /** |
48 * Set up preferences, controllers, and event listeners. | 55 * Set up preferences, controllers, and event listeners. |
49 * | 56 * |
50 * @private | 57 * @private |
51 */ | 58 */ |
52 init_: function() { | 59 init_: function() { |
53 this.switchAccessPrefs = new SwitchAccessPrefs(); | 60 this.commands_ = new Commands(this); |
| 61 this.switchAccessPrefs_ = new SwitchAccessPrefs(this); |
54 this.autoScanManager_ = new AutoScanManager(this); | 62 this.autoScanManager_ = new AutoScanManager(this); |
55 this.keyboardHandler_ = new KeyboardHandler(this); | 63 this.keyboardHandler_ = new KeyboardHandler(this); |
56 | 64 |
57 chrome.automation.getDesktop(function(desktop) { | 65 chrome.automation.getDesktop(function(desktop) { |
58 this.automationManager_ = new AutomationManager(desktop); | 66 this.automationManager_ = new AutomationManager(desktop); |
59 }.bind(this)); | 67 }.bind(this)); |
60 | 68 |
61 document.addEventListener( | 69 document.addEventListener( |
62 'prefsUpdate', this.handlePrefsUpdate_.bind(this)); | 70 'prefsUpdate', this.handlePrefsUpdate_.bind(this)); |
63 }, | 71 }, |
(...skipping 24 matching lines...) Expand all Loading... |
88 * Open the options page in a new tab. | 96 * Open the options page in a new tab. |
89 * | 97 * |
90 * @override | 98 * @override |
91 */ | 99 */ |
92 showOptionsPage: function() { | 100 showOptionsPage: function() { |
93 let optionsPage = {url: 'options.html'}; | 101 let optionsPage = {url: 'options.html'}; |
94 chrome.tabs.create(optionsPage); | 102 chrome.tabs.create(optionsPage); |
95 }, | 103 }, |
96 | 104 |
97 /** | 105 /** |
| 106 * Return a list of the names of all user commands. |
| 107 * |
| 108 * @override |
| 109 * @return {!Array<string>} |
| 110 */ |
| 111 getCommands: function() { |
| 112 return this.commands_.getCommands(); |
| 113 }, |
| 114 |
| 115 /** |
| 116 * Return the default key code for a command. |
| 117 * |
| 118 * @override |
| 119 * @param {string} command |
| 120 * @return {number} |
| 121 */ |
| 122 getDefaultKeyCodeFor: function(command) { |
| 123 return this.commands_.getDefaultKeyCodeFor(command); |
| 124 }, |
| 125 |
| 126 /** |
| 127 * Run the function binding for the specified command. |
| 128 * |
| 129 * @override |
| 130 * @param {string} command |
| 131 */ |
| 132 runCommand: function(command) { |
| 133 this.commands_.runCommand(command); |
| 134 }, |
| 135 |
| 136 /** |
98 * Perform actions as the result of actions by the user. Currently, restarts | 137 * Perform actions as the result of actions by the user. Currently, restarts |
99 * auto-scan if it is enabled. | 138 * auto-scan if it is enabled. |
100 * | 139 * |
101 * @override | 140 * @override |
102 */ | 141 */ |
103 performedUserAction: function() { | 142 performedUserAction: function() { |
104 this.autoScanManager_.restartIfRunning(); | 143 this.autoScanManager_.restartIfRunning(); |
105 }, | 144 }, |
106 | 145 |
107 /** | 146 /** |
108 * Handle a change in user preferences. | 147 * Handle a change in user preferences. |
109 * | 148 * |
110 * @param {!Event} event | 149 * @param {!Event} event |
111 * @private | 150 * @private |
112 */ | 151 */ |
113 handlePrefsUpdate_: function(event) { | 152 handlePrefsUpdate_: function(event) { |
114 let updatedPrefs = event.detail; | 153 let updatedPrefs = event.detail; |
115 for (let key of Object.keys(updatedPrefs)) { | 154 for (let key of Object.keys(updatedPrefs)) { |
116 switch (key) { | 155 switch (key) { |
117 case 'enableAutoScan': | 156 case 'enableAutoScan': |
118 this.autoScanManager_.setEnabled(updatedPrefs[key]); | 157 this.autoScanManager_.setEnabled(updatedPrefs[key]); |
119 break; | 158 break; |
120 case 'autoScanTime': | 159 case 'autoScanTime': |
121 this.autoScanManager_.setScanTime(updatedPrefs[key]); | 160 this.autoScanManager_.setScanTime(updatedPrefs[key]); |
122 break; | 161 break; |
| 162 default: |
| 163 if (this.commands_.getCommands().includes(key)) |
| 164 this.keyboardHandler_.updateSwitchAccessKeys(); |
123 } | 165 } |
124 } | 166 } |
125 }, | 167 }, |
126 | 168 |
127 /** | 169 /** |
| 170 * Set the value of the preference |key| to |value| in chrome.storage.sync. |
| 171 * this.prefs_ is not set until handleStorageChange_. |
| 172 * |
| 173 * @override |
| 174 * @param {string} key |
| 175 * @param {boolean|string|number} value |
| 176 */ |
| 177 setPref: function(key, value) { |
| 178 this.switchAccessPrefs_.setPref(key, value); |
| 179 }, |
| 180 |
| 181 /** |
| 182 * Get the value of type 'boolean' of the preference |key|. Will throw a type |
| 183 * error if the value of |key| is not 'boolean'. |
| 184 * |
| 185 * @override |
| 186 * @param {string} key |
| 187 * @return {boolean} |
| 188 */ |
| 189 getBooleanPref: function(key) { |
| 190 return this.switchAccessPrefs_.getBooleanPref(key); |
| 191 }, |
| 192 |
| 193 /** |
| 194 * Get the value of type 'number' of the preference |key|. Will throw a type |
| 195 * error if the value of |key| is not 'number'. |
| 196 * |
| 197 * @override |
| 198 * @param {string} key |
| 199 * @return {number} |
| 200 */ |
| 201 getNumberPref: function(key) { |
| 202 return this.switchAccessPrefs_.getNumberPref(key); |
| 203 }, |
| 204 |
| 205 /** |
| 206 * Get the value of type 'string' of the preference |key|. Will throw a type |
| 207 * error if the value of |key| is not 'string'. |
| 208 * |
| 209 * @override |
| 210 * @param {string} key |
| 211 * @return {string} |
| 212 */ |
| 213 getStringPref: function(key) { |
| 214 return this.switchAccessPrefs_.getStringPref(key); |
| 215 }, |
| 216 |
| 217 /** |
| 218 * Returns true if |keyCode| is already used to run a command from the |
| 219 * keyboard. |
| 220 * |
| 221 * @override |
| 222 * @param {number} keyCode |
| 223 * @return {boolean} |
| 224 */ |
| 225 keyCodeIsUsed: function(keyCode) { |
| 226 return this.switchAccessPrefs_.keyCodeIsUsed(keyCode); |
| 227 }, |
| 228 |
| 229 /** |
128 * Move to the next sibling of the current node if it has one. | 230 * Move to the next sibling of the current node if it has one. |
129 * | 231 * |
130 * @override | 232 * @override |
131 */ | 233 */ |
132 debugMoveToNext: function() { | 234 debugMoveToNext: function() { |
133 if (this.automationManager_) | 235 if (this.automationManager_) |
134 this.automationManager_.debugMoveToNext(); | 236 this.automationManager_.debugMoveToNext(); |
135 }, | 237 }, |
136 | 238 |
137 /** | 239 /** |
(...skipping 19 matching lines...) Expand all Loading... |
157 /** | 259 /** |
158 * Move to the parent of the current node if it has one. | 260 * Move to the parent of the current node if it has one. |
159 * | 261 * |
160 * @override | 262 * @override |
161 */ | 263 */ |
162 debugMoveToParent: function() { | 264 debugMoveToParent: function() { |
163 if (this.automationManager_) | 265 if (this.automationManager_) |
164 this.automationManager_.debugMoveToParent(); | 266 this.automationManager_.debugMoveToParent(); |
165 } | 267 } |
166 }; | 268 }; |
OLD | NEW |