| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 Handles automation from a desktop automation node. | 6 * @fileoverview Handles automation from a desktop automation node. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('DesktopAutomationHandler'); | 9 goog.provide('DesktopAutomationHandler'); |
| 10 | 10 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Discard focus events on embeddedObject. | 256 // Discard focus events on embeddedObject. |
| 257 if (node.role == RoleType.embeddedObject) | 257 if (node.role == RoleType.embeddedObject) |
| 258 return; | 258 return; |
| 259 | 259 |
| 260 this.createTextEditHandlerIfNeeded_(evt.target); | 260 this.createTextEditHandlerIfNeeded_(evt.target); |
| 261 | 261 |
| 262 // Category flush speech triggered by events with no source. This includes | 262 // Category flush speech triggered by events with no source. This includes |
| 263 // views. | 263 // views. |
| 264 if (evt.eventFrom == '') | 264 if (evt.eventFrom == '') |
| 265 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.CATEGORY_FLUSH); | 265 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.CATEGORY_FLUSH); |
| 266 if (!node.root) |
| 267 return; |
| 268 |
| 269 var root = AutomationUtil.getTopLevelRoot(node.root); |
| 270 |
| 271 // If we're crossing out of a root, save it in case it needs recovering. |
| 272 var prevRange = ChromeVoxState.instance.currentRange; |
| 273 var prevNode = prevRange ? prevRange.start.node : null; |
| 274 if (prevNode) { |
| 275 var prevRoot = AutomationUtil.getTopLevelRoot(prevNode); |
| 276 if (prevRoot && prevRoot !== root) |
| 277 ChromeVoxState.instance.focusRecoveryMap.set(prevRoot, prevRange); |
| 278 } |
| 279 |
| 280 // If a previous node was saved for this focus, restore it. |
| 281 var savedRange = ChromeVoxState.instance.focusRecoveryMap.get(root); |
| 282 ChromeVoxState.instance.focusRecoveryMap.delete(root); |
| 283 if (savedRange) { |
| 284 ChromeVoxState.instance.navigateToRange(savedRange, false); |
| 285 return; |
| 286 } |
| 287 |
| 266 this.onEventDefault(new chrome.automation.AutomationEvent( | 288 this.onEventDefault(new chrome.automation.AutomationEvent( |
| 267 EventType.focus, node, evt.eventFrom)); | 289 EventType.focus, node, evt.eventFrom)); |
| 268 }, | 290 }, |
| 269 | 291 |
| 270 /** | 292 /** |
| 271 * Provides all feedback once a load complete event fires. | 293 * Provides all feedback once a load complete event fires. |
| 272 * @param {!AutomationEvent} evt | 294 * @param {!AutomationEvent} evt |
| 273 */ | 295 */ |
| 274 onLoadComplete: function(evt) { | 296 onLoadComplete: function(evt) { |
| 275 // Don't process nodes inside of web content if ChromeVox Next is inactive. | 297 // Don't process nodes inside of web content if ChromeVox Next is inactive. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 if (override || AutomationUtil.isDescendantOf(evt.target, focus)) | 460 if (override || AutomationUtil.isDescendantOf(evt.target, focus)) |
| 439 this.onEventDefault(evt); | 461 this.onEventDefault(evt); |
| 440 }.bind(this)); | 462 }.bind(this)); |
| 441 }, | 463 }, |
| 442 | 464 |
| 443 /** | 465 /** |
| 444 * Provides all feedback once a menu start event fires. | 466 * Provides all feedback once a menu start event fires. |
| 445 * @param {!AutomationEvent} evt | 467 * @param {!AutomationEvent} evt |
| 446 */ | 468 */ |
| 447 onMenuStart: function(evt) { | 469 onMenuStart: function(evt) { |
| 448 ChromeVoxState.instance.startExcursion(); | 470 ChromeVoxState.instance.markCurrentRange(); |
| 449 this.onEventDefault(evt); | 471 this.onEventDefault(evt); |
| 450 }, | 472 }, |
| 451 | 473 |
| 452 /** | 474 /** |
| 453 * Provides all feedback once a menu end event fires. | 475 * Provides all feedback once a menu end event fires. |
| 454 * @param {!AutomationEvent} evt | 476 * @param {!AutomationEvent} evt |
| 455 */ | 477 */ |
| 456 onMenuEnd: function(evt) { | 478 onMenuEnd: function(evt) { |
| 457 this.onEventDefault(evt); | 479 this.onEventDefault(evt); |
| 458 ChromeVoxState.instance.endExcursion(); | 480 |
| 481 // This is a work around for Chrome context menus not firing a focus event |
| 482 // after you close them. |
| 483 chrome.automation.getFocus(function(focus) { |
| 484 if (focus) { |
| 485 this.onFocus( |
| 486 new chrome.automation.AutomationEvent( |
| 487 EventType.focus, focus, 'page')); |
| 488 } |
| 489 }.bind(this)); |
| 459 }, | 490 }, |
| 460 | 491 |
| 461 /** | 492 /** |
| 462 * Create an editable text handler for the given node if needed. | 493 * Create an editable text handler for the given node if needed. |
| 463 * @param {!AutomationNode} node | 494 * @param {!AutomationNode} node |
| 464 */ | 495 */ |
| 465 createTextEditHandlerIfNeeded_: function(node) { | 496 createTextEditHandlerIfNeeded_: function(node) { |
| 466 if (!this.textEditHandler_ || | 497 if (!this.textEditHandler_ || |
| 467 this.textEditHandler_.node !== node) { | 498 this.textEditHandler_.node !== node) { |
| 468 this.textEditHandler_ = editing.TextEditHandler.createForNode(node); | 499 this.textEditHandler_ = editing.TextEditHandler.createForNode(node); |
| 469 } | 500 } |
| 470 } | 501 } |
| 471 }; | 502 }; |
| 472 | 503 |
| 473 /** | 504 /** |
| 474 * Initializes global state for DesktopAutomationHandler. | 505 * Initializes global state for DesktopAutomationHandler. |
| 475 * @private | 506 * @private |
| 476 */ | 507 */ |
| 477 DesktopAutomationHandler.init_ = function() { | 508 DesktopAutomationHandler.init_ = function() { |
| 478 chrome.automation.getDesktop(function(desktop) { | 509 chrome.automation.getDesktop(function(desktop) { |
| 479 ChromeVoxState.desktopAutomationHandler = | 510 ChromeVoxState.desktopAutomationHandler = |
| 480 new DesktopAutomationHandler(desktop); | 511 new DesktopAutomationHandler(desktop); |
| 481 }); | 512 }); |
| 482 }; | 513 }; |
| 483 | 514 |
| 484 DesktopAutomationHandler.init_(); | 515 DesktopAutomationHandler.init_(); |
| 485 | 516 |
| 486 }); // goog.scope | 517 }); // goog.scope |
| OLD | NEW |