| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview The entry point for all ChromeVox2 related code for the | 6 * @fileoverview The entry point for all ChromeVox2 related code for the |
| 7 * background page. | 7 * background page. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 goog.provide('Background'); | 10 goog.provide('Background'); |
| 11 | 11 |
| 12 goog.require('AutomationPredicate'); | 12 goog.require('AutomationPredicate'); |
| 13 goog.require('AutomationUtil'); | 13 goog.require('AutomationUtil'); |
| 14 goog.require('ChromeVoxState'); | 14 goog.require('ChromeVoxState'); |
| 15 goog.require('LiveRegions'); | 15 goog.require('LiveRegions'); |
| 16 goog.require('NextEarcons'); | 16 goog.require('NextEarcons'); |
| 17 goog.require('Notifications'); | 17 goog.require('Notifications'); |
| 18 goog.require('Output'); | 18 goog.require('Output'); |
| 19 goog.require('Output.EventType'); | 19 goog.require('Output.EventType'); |
| 20 goog.require('PanelCommand'); | 20 goog.require('PanelCommand'); |
| 21 goog.require('Stubs'); |
| 21 goog.require('constants'); | 22 goog.require('constants'); |
| 22 goog.require('cursors.Cursor'); | 23 goog.require('cursors.Cursor'); |
| 23 goog.require('cvox.BrailleKeyCommand'); | 24 goog.require('cvox.BrailleKeyCommand'); |
| 24 goog.require('cvox.ChromeVoxBackground'); | 25 goog.require('cvox.ChromeVoxBackground'); |
| 25 goog.require('cvox.ChromeVoxEditableTextBase'); | 26 goog.require('cvox.ChromeVoxEditableTextBase'); |
| 26 goog.require('cvox.ChromeVoxKbHandler'); | 27 goog.require('cvox.ChromeVoxKbHandler'); |
| 27 goog.require('cvox.ClassicEarcons'); | 28 goog.require('cvox.ClassicEarcons'); |
| 28 goog.require('cvox.ExtensionBridge'); | 29 goog.require('cvox.ExtensionBridge'); |
| 29 goog.require('cvox.NavBraille'); | 30 goog.require('cvox.NavBraille'); |
| 30 | 31 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return this.nextEarcons_; | 100 return this.nextEarcons_; |
| 100 } else { | 101 } else { |
| 101 return this.classicEarcons_; | 102 return this.classicEarcons_; |
| 102 } | 103 } |
| 103 }).bind(this) | 104 }).bind(this) |
| 104 }); | 105 }); |
| 105 | 106 |
| 106 if (cvox.ChromeVox.isChromeOS) { | 107 if (cvox.ChromeVox.isChromeOS) { |
| 107 Object.defineProperty(cvox.ChromeVox, 'modKeyStr', { | 108 Object.defineProperty(cvox.ChromeVox, 'modKeyStr', { |
| 108 get: function() { | 109 get: function() { |
| 109 return (this.mode == ChromeVoxMode.CLASSIC || this.mode == | 110 return (this.mode == ChromeVoxMode.CLASSIC || |
| 110 ChromeVoxMode.COMPAT) ? | 111 this.mode == ChromeVoxMode.COMPAT) ? |
| 111 'Search+Shift' : 'Search'; | 112 'Search+Shift' : 'Search'; |
| 112 }.bind(this) | 113 }.bind(this) |
| 113 }); | 114 }); |
| 114 } | 115 } |
| 115 | 116 |
| 116 Object.defineProperty(cvox.ChromeVox, 'isActive', { | 117 Object.defineProperty(cvox.ChromeVox, 'isActive', { |
| 117 get: function() { | 118 get: function() { |
| 118 return localStorage['active'] !== 'false'; | 119 return localStorage['active'] !== 'false'; |
| 119 }, | 120 }, |
| 120 set: function(value) { | 121 set: function(value) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 | 140 |
| 140 /** @type {boolean} @private */ | 141 /** @type {boolean} @private */ |
| 141 this.inExcursion_ = false; | 142 this.inExcursion_ = false; |
| 142 | 143 |
| 143 /** | 144 /** |
| 144 * Stores the mode as computed the last time a current range was set. | 145 * Stores the mode as computed the last time a current range was set. |
| 145 * @type {?ChromeVoxMode} | 146 * @type {?ChromeVoxMode} |
| 146 */ | 147 */ |
| 147 this.mode_ = null; | 148 this.mode_ = null; |
| 148 | 149 |
| 149 if (!chrome.accessibilityPrivate.setKeyboardListener) | 150 chrome.accessibilityPrivate.onAccessibilityGesture.addListener( |
| 150 chrome.accessibilityPrivate.setKeyboardListener = function() {}; | 151 this.onAccessibilityGesture_); |
| 151 | 152 Notifications.onStartup(); |
| 152 if (cvox.ChromeVox.isChromeOS) { | 153 }; |
| 153 chrome.accessibilityPrivate.onAccessibilityGesture.addListener( | |
| 154 this.onAccessibilityGesture_); | |
| 155 | |
| 156 Notifications.onStartup(); | |
| 157 }}; | |
| 158 | 154 |
| 159 /** | 155 /** |
| 160 * @const {string} | 156 * @const {string} |
| 161 */ | 157 */ |
| 162 Background.ISSUE_URL = 'https://code.google.com/p/chromium/issues/entry?' + | 158 Background.ISSUE_URL = 'https://code.google.com/p/chromium/issues/entry?' + |
| 163 'labels=Type-Bug,Pri-2,cvox2,OS-Chrome&' + | 159 'labels=Type-Bug,Pri-2,cvox2,OS-Chrome&' + |
| 164 'components=UI>accessibility&' + | 160 'components=UI>accessibility&' + |
| 165 'description='; | 161 'description='; |
| 166 | 162 |
| 167 /** | 163 /** |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 }, | 228 }, |
| 233 | 229 |
| 234 /** | 230 /** |
| 235 * Handles a mode change. | 231 * Handles a mode change. |
| 236 * @param {ChromeVoxMode} newMode | 232 * @param {ChromeVoxMode} newMode |
| 237 * @param {?ChromeVoxMode} oldMode Can be null at startup when no range was | 233 * @param {?ChromeVoxMode} oldMode Can be null at startup when no range was |
| 238 * previously set. | 234 * previously set. |
| 239 * @private | 235 * @private |
| 240 */ | 236 */ |
| 241 onModeChanged_: function(newMode, oldMode) { | 237 onModeChanged_: function(newMode, oldMode) { |
| 242 // Switching key maps potentially affects the key codes that involve | |
| 243 // sequencing. Without resetting this list, potentially stale key codes | |
| 244 // remain. The key codes themselves get pushed in | |
| 245 // cvox.KeySequence.deserialize which gets called by cvox.KeyMap. | |
| 246 cvox.ChromeVox.sequenceSwitchKeyCodes = []; | |
| 247 | |
| 248 var selectedKeyMap = | |
| 249 newMode == ChromeVoxMode.CLASSIC || newMode == ChromeVoxMode.COMPAT ? | |
| 250 'keymap_classic' : 'keymap_next'; | |
| 251 window['prefs'].switchToKeyMap(selectedKeyMap); | |
| 252 | |
| 253 if (newMode == ChromeVoxMode.CLASSIC) { | 238 if (newMode == ChromeVoxMode.CLASSIC) { |
| 254 if (chrome.commands && | 239 if (chrome.commands && |
| 255 chrome.commands.onCommand.hasListener(this.onGotCommand)) | 240 chrome.commands.onCommand.hasListener(this.onGotCommand)) |
| 256 chrome.commands.onCommand.removeListener(this.onGotCommand); | 241 chrome.commands.onCommand.removeListener(this.onGotCommand); |
| 257 chrome.accessibilityPrivate.setKeyboardListener(false, false); | 242 chrome.accessibilityPrivate.setKeyboardListener(false, false); |
| 258 | 243 chrome.accessibilityPrivate.setFocusRing([]); |
| 259 if (cvox.ChromeVox.isChromeOS) | |
| 260 chrome.accessibilityPrivate.setFocusRing([]); | |
| 261 } else { | 244 } else { |
| 262 if (chrome.commands && | 245 if (chrome.commands && |
| 263 !chrome.commands.onCommand.hasListener(this.onGotCommand)) | 246 !chrome.commands.onCommand.hasListener(this.onGotCommand)) |
| 264 chrome.commands.onCommand.addListener(this.onGotCommand); | 247 chrome.commands.onCommand.addListener(this.onGotCommand); |
| 265 chrome.accessibilityPrivate.setKeyboardListener( | 248 chrome.accessibilityPrivate.setKeyboardListener( |
| 266 true, cvox.ChromeVox.isStickyPrefOn); | 249 true, cvox.ChromeVox.isStickyPrefOn); |
| 267 } | 250 } |
| 268 | 251 |
| 269 // note that |this.currentRange_| can *change* because the request is | 252 // note that |this.currentRange_| can *change* because the request is |
| 270 // async. Save it to ensure we're looking at the currentRange at this moment | 253 // async. Save it to ensure we're looking at the currentRange at this moment |
| (...skipping 14 matching lines...) Expand all Loading... |
| 285 // If we're focused in the desktop tree, do nothing. | 268 // If we're focused in the desktop tree, do nothing. |
| 286 if (cur && !cur.isWebRange()) | 269 if (cur && !cur.isWebRange()) |
| 287 return; | 270 return; |
| 288 | 271 |
| 289 // If we're entering compat mode or next mode for just one tab, | 272 // If we're entering compat mode or next mode for just one tab, |
| 290 // disable Classic for that tab only. | 273 // disable Classic for that tab only. |
| 291 this.disableClassicChromeVox_(tabs); | 274 this.disableClassicChromeVox_(tabs); |
| 292 } | 275 } |
| 293 }.bind(this)); | 276 }.bind(this)); |
| 294 | 277 |
| 295 // If switching out of a ChromeVox Next mode, make sure we cancel | 278 // Switching into either compat or classic. |
| 296 // the progress loading sound just in case. | |
| 297 if (oldMode === ChromeVoxMode.NEXT || | 279 if (oldMode === ChromeVoxMode.NEXT || |
| 298 oldMode === ChromeVoxMode.FORCE_NEXT) | 280 oldMode === ChromeVoxMode.FORCE_NEXT) { |
| 281 // Make sure we cancel the progress loading sound just in case. |
| 299 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); | 282 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); |
| 283 (new PanelCommand(PanelCommandType.DISABLE_MENUS)).send(); |
| 284 } |
| 300 | 285 |
| 286 // Switching out of next, force next, or uninitialized (on startup). |
| 301 if (newMode === ChromeVoxMode.NEXT || | 287 if (newMode === ChromeVoxMode.NEXT || |
| 302 newMode === ChromeVoxMode.FORCE_NEXT) { | 288 newMode === ChromeVoxMode.FORCE_NEXT) { |
| 303 (new PanelCommand(PanelCommandType.ENABLE_MENUS)).send(); | 289 (new PanelCommand(PanelCommandType.ENABLE_MENUS)).send(); |
| 304 if (cvox.TabsApiHandler) | 290 if (cvox.TabsApiHandler) |
| 305 cvox.TabsApiHandler.shouldOutputSpeechAndBraille = false; | 291 cvox.TabsApiHandler.shouldOutputSpeechAndBraille = false; |
| 292 |
| 293 window['prefs'].switchToKeyMap('keymap_next'); |
| 306 } else { | 294 } else { |
| 307 (new PanelCommand(PanelCommandType.DISABLE_MENUS)).send(); | 295 // |newMode| is either classic or compat. |
| 308 if (cvox.TabsApiHandler) | 296 if (cvox.TabsApiHandler) |
| 309 cvox.TabsApiHandler.shouldOutputSpeechAndBraille = true; | 297 cvox.TabsApiHandler.shouldOutputSpeechAndBraille = true; |
| 298 |
| 299 // Moving from next to classic/compat should be the only case where |
| 300 // keymaps get reset. Note the classic <-> compat switches should preserve |
| 301 // keymaps especially if a user selected a different one. |
| 302 if (oldMode && |
| 303 oldMode != ChromeVoxMode.CLASSIC && |
| 304 oldMode != ChromeVoxMode.COMPAT) { |
| 305 // The user's configured key map gets wiped here; this is consistent |
| 306 // with previous behavior when switching keymaps. |
| 307 window['prefs'].switchToKeyMap('keymap_next'); |
| 308 } |
| 310 } | 309 } |
| 311 }, | 310 }, |
| 312 | 311 |
| 313 /** | 312 /** |
| 314 * Toggles between force next and classic/compat modes. | 313 * Toggles between force next and classic/compat modes. |
| 315 * This toggle automatically handles deciding between classic/compat based on | 314 * This toggle automatically handles deciding between classic/compat based on |
| 316 * the start of the current range. | 315 * the start of the current range. |
| 317 * @param {boolean=} opt_setValue Directly set to force next (true) or | 316 * @param {boolean=} opt_setValue Directly set to force next (true) or |
| 318 * classic/compat (false). | 317 * classic/compat (false). |
| 319 * @return {boolean} True to announce current position. | 318 * @return {boolean} True to announce current position. |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 return new RegExp('^(' + globs.map(function(glob) { | 1230 return new RegExp('^(' + globs.map(function(glob) { |
| 1232 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 1231 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 1233 .replace(/\*/g, '.*') | 1232 .replace(/\*/g, '.*') |
| 1234 .replace(/\?/g, '.'); | 1233 .replace(/\?/g, '.'); |
| 1235 }).join('|') + ')$'); | 1234 }).join('|') + ')$'); |
| 1236 }; | 1235 }; |
| 1237 | 1236 |
| 1238 new Background(); | 1237 new Background(); |
| 1239 | 1238 |
| 1240 }); // goog.scope | 1239 }); // goog.scope |
| OLD | NEW |