| 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 goog.provide('global'); | 11 goog.provide('global'); |
| 12 | 12 |
| 13 goog.require('AutomationPredicate'); | 13 goog.require('AutomationPredicate'); |
| 14 goog.require('AutomationUtil'); | 14 goog.require('AutomationUtil'); |
| 15 goog.require('Output'); |
| 15 goog.require('cursors.Cursor'); | 16 goog.require('cursors.Cursor'); |
| 16 goog.require('cvox.TabsApiHandler'); | 17 goog.require('cvox.TabsApiHandler'); |
| 17 | 18 |
| 18 goog.scope(function() { | 19 goog.scope(function() { |
| 19 var AutomationNode = chrome.automation.AutomationNode; | 20 var AutomationNode = chrome.automation.AutomationNode; |
| 20 var Dir = AutomationUtil.Dir; | 21 var Dir = AutomationUtil.Dir; |
| 21 var EventType = chrome.automation.EventType; | 22 var EventType = chrome.automation.EventType; |
| 22 | 23 |
| 23 /** Classic Chrome accessibility API. */ | 24 /** Classic Chrome accessibility API. */ |
| 24 global.accessibility = | 25 global.accessibility = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 51 */ | 52 */ |
| 52 this.currentRange_ = null; | 53 this.currentRange_ = null; |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Whether ChromeVox Next is active. | 56 * Whether ChromeVox Next is active. |
| 56 * @type {boolean} | 57 * @type {boolean} |
| 57 * @private | 58 * @private |
| 58 */ | 59 */ |
| 59 this.active_ = false; | 60 this.active_ = false; |
| 60 | 61 |
| 62 /** |
| 63 * @type {!Output} |
| 64 * @private |
| 65 */ |
| 66 this.output_ = new Output(); |
| 67 |
| 61 // Only needed with unmerged ChromeVox classic loaded before. | 68 // Only needed with unmerged ChromeVox classic loaded before. |
| 62 global.accessibility.setAccessibilityEnabled(false); | 69 global.accessibility.setAccessibilityEnabled(false); |
| 63 | 70 |
| 64 // Manually bind all functions to |this|. | 71 // Manually bind all functions to |this|. |
| 65 for (var func in this) { | 72 for (var func in this) { |
| 66 if (typeof(this[func]) == 'function') | 73 if (typeof(this[func]) == 'function') |
| 67 this[func] = this[func].bind(this); | 74 this[func] = this[func].bind(this); |
| 68 } | 75 } |
| 69 | 76 |
| 70 /** | 77 /** |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 var pred = null; | 144 var pred = null; |
| 138 switch (command) { | 145 switch (command) { |
| 139 case 'nextHeading': | 146 case 'nextHeading': |
| 140 dir = Dir.FORWARD; | 147 dir = Dir.FORWARD; |
| 141 pred = AutomationPredicate.heading; | 148 pred = AutomationPredicate.heading; |
| 142 break; | 149 break; |
| 143 case 'previousHeading': | 150 case 'previousHeading': |
| 144 dir = Dir.BACKWARD; | 151 dir = Dir.BACKWARD; |
| 145 pred = AutomationPredicate.heading; | 152 pred = AutomationPredicate.heading; |
| 146 break; | 153 break; |
| 154 case 'nextCharacter': |
| 155 current = current.move(cursors.Unit.CHARACTER, Dir.FORWARD); |
| 156 break; |
| 157 case 'previousCharacter': |
| 158 current = current.move(cursors.Unit.CHARACTER, Dir.BACKWARD); |
| 159 break; |
| 160 case 'nextWord': |
| 161 current = current.move(cursors.Unit.WORD, Dir.FORWARD); |
| 162 break; |
| 163 case 'previousWord': |
| 164 current = current.move(cursors.Unit.WORD, Dir.BACKWARD); |
| 165 break; |
| 147 case 'nextLine': | 166 case 'nextLine': |
| 148 current = current.move(cursors.Unit.LINE, Dir.FORWARD); | 167 current = current.move(cursors.Unit.LINE, Dir.FORWARD); |
| 149 break; | 168 break; |
| 150 case 'previousLine': | 169 case 'previousLine': |
| 151 current = current.move(cursors.Unit.LINE, Dir.BACKWARD); | 170 current = current.move(cursors.Unit.LINE, Dir.BACKWARD); |
| 152 break; | 171 break; |
| 153 case 'nextLink': | 172 case 'nextLink': |
| 154 dir = Dir.FORWARD; | 173 dir = Dir.FORWARD; |
| 155 pred = AutomationPredicate.link; | 174 pred = AutomationPredicate.link; |
| 156 break; | 175 break; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 187 | 206 |
| 188 if (node) | 207 if (node) |
| 189 current = cursors.Range.fromNode(node); | 208 current = cursors.Range.fromNode(node); |
| 190 } | 209 } |
| 191 | 210 |
| 192 if (current) { | 211 if (current) { |
| 193 // TODO(dtseng): Figure out what it means to focus a range. | 212 // TODO(dtseng): Figure out what it means to focus a range. |
| 194 current.getStart().getNode().focus(); | 213 current.getStart().getNode().focus(); |
| 195 | 214 |
| 196 this.currentRange_ = current; | 215 this.currentRange_ = current; |
| 197 this.handleOutput(this.currentRange_); | 216 this.output_.output(this.currentRange_); |
| 198 } | 217 } |
| 199 }, | 218 }, |
| 200 | 219 |
| 201 /** | 220 /** |
| 202 * Provides all feedback once ChromeVox's focus changes. | 221 * Provides all feedback once ChromeVox's focus changes. |
| 203 * @param {Object} evt | 222 * @param {Object} evt |
| 204 */ | 223 */ |
| 205 onFocus: function(evt) { | 224 onFocus: function(evt) { |
| 206 var node = evt.target; | 225 var node = evt.target; |
| 207 if (!node) | 226 if (!node) |
| 208 return; | 227 return; |
| 209 | 228 |
| 210 this.currentRange_ = cursors.Range.fromNode(node); | 229 this.currentRange_ = cursors.Range.fromNode(node); |
| 211 this.handleOutput(this.currentRange_); | 230 this.output_.output(this.currentRange_); |
| 212 }, | 231 }, |
| 213 | 232 |
| 214 /** | 233 /** |
| 215 * Provides all feedback once a load complete event fires. | 234 * Provides all feedback once a load complete event fires. |
| 216 * @param {Object} evt | 235 * @param {Object} evt |
| 217 */ | 236 */ |
| 218 onLoadComplete: function(evt) { | 237 onLoadComplete: function(evt) { |
| 219 if (this.currentRange_) | 238 if (this.currentRange_) |
| 220 return; | 239 return; |
| 221 | 240 |
| 222 var node = AutomationUtil.findNodePost(evt.target, | 241 var node = AutomationUtil.findNodePost(evt.target, |
| 223 Dir.FORWARD, | 242 Dir.FORWARD, |
| 224 AutomationPredicate.leaf); | 243 AutomationPredicate.leaf); |
| 225 if (node) | 244 if (node) |
| 226 this.currentRange_ = cursors.Range.fromNode(node); | 245 this.currentRange_ = cursors.Range.fromNode(node); |
| 227 | 246 |
| 228 if (this.currentRange_) | 247 if (this.currentRange_) |
| 229 this.handleOutput(this.currentRange_); | 248 this.output_.output(this.currentRange_); |
| 230 }, | 249 }, |
| 231 | 250 |
| 232 /** | 251 /** |
| 233 * @private | 252 * @private |
| 234 * @param {string} url | 253 * @param {string} url |
| 235 * @return {boolean} Whether the given |url| is whitelisted. | 254 * @return {boolean} Whether the given |url| is whitelisted. |
| 236 */ | 255 */ |
| 237 isWhitelisted_: function(url) { | 256 isWhitelisted_: function(url) { |
| 238 return this.whitelist_.some(function(item) { | 257 return this.whitelist_.some(function(item) { |
| 239 return url.indexOf(item) != -1; | 258 return url.indexOf(item) != -1; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 cvox.ChromeVox.tts.speak(output, cvox.QueueMode.FLUSH); | 340 cvox.ChromeVox.tts.speak(output, cvox.QueueMode.FLUSH); |
| 322 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); | 341 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); |
| 323 chrome.accessibilityPrivate.setFocusRing(nodeLocations); | 342 chrome.accessibilityPrivate.setFocusRing(nodeLocations); |
| 324 } | 343 } |
| 325 }; | 344 }; |
| 326 | 345 |
| 327 /** @type {Background} */ | 346 /** @type {Background} */ |
| 328 global.backgroundObj = new Background(); | 347 global.backgroundObj = new Background(); |
| 329 | 348 |
| 330 }); // goog.scope | 349 }); // goog.scope |
| OLD | NEW |