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'); |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 /** | 476 /** |
477 * Provides all feedback once a focus event fires. | 477 * Provides all feedback once a focus event fires. |
478 * @param {Object} evt | 478 * @param {Object} evt |
479 */ | 479 */ |
480 onFocus: function(evt) { | 480 onFocus: function(evt) { |
481 // Invalidate any previous editable text handler state. | 481 // Invalidate any previous editable text handler state. |
482 this.editableTextHandler_ = null; | 482 this.editableTextHandler_ = null; |
483 | 483 |
484 var node = evt.target; | 484 var node = evt.target; |
485 | 485 |
| 486 |
| 487 // Discard focus events on embeddedObject nodes. |
| 488 if (node.role == RoleType.embeddedObject) |
| 489 return; |
| 490 |
486 // It almost never makes sense to place focus directly on a rootWebArea. | 491 // It almost never makes sense to place focus directly on a rootWebArea. |
487 if (node.role == RoleType.rootWebArea) { | 492 if (node.role == RoleType.rootWebArea) { |
| 493 // Discard focus events for root web areas when focus was previously |
| 494 // placed on a descendant. |
| 495 if (this.currentRange_.start.node.root == node) |
| 496 return; |
| 497 |
| 498 // Discard focused root nodes without focused state set. |
| 499 if (!node.state.focused) |
| 500 return; |
| 501 |
488 // Try to find a focusable descendant. | 502 // Try to find a focusable descendant. |
489 node = AutomationUtil.findNodePost(node, | 503 node = node.find({state: {focused: true}}) || node; |
490 Dir.FORWARD, | |
491 AutomationPredicate.focused) || node; | |
492 | |
493 // Fall back to the first leaf node in the document. | |
494 if (node.role == RoleType.rootWebArea) { | |
495 node = AutomationUtil.findNodePost(node, | |
496 Dir.FORWARD, | |
497 AutomationPredicate.leaf); | |
498 } | |
499 } | 504 } |
500 | 505 |
501 if (evt.target.role == RoleType.textField) | 506 if (evt.target.role == RoleType.textField) |
502 this.createEditableTextHandlerIfNeeded_(evt.target); | 507 this.createEditableTextHandlerIfNeeded_(evt.target); |
503 | 508 |
504 this.onEventDefault({target: node, type: 'focus'}); | 509 this.onEventDefault({target: node, type: 'focus'}); |
505 }, | 510 }, |
506 | 511 |
507 /** | 512 /** |
508 * Provides all feedback once a load complete event fires. | 513 * Provides all feedback once a load complete event fires. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 */ | 556 */ |
552 onTextOrTextSelectionChanged: function(evt) { | 557 onTextOrTextSelectionChanged: function(evt) { |
553 // Don't process nodes inside of web content if ChromeVox Next is inactive. | 558 // Don't process nodes inside of web content if ChromeVox Next is inactive. |
554 if (evt.target.root.role != RoleType.desktop && | 559 if (evt.target.root.role != RoleType.desktop && |
555 this.mode_ === ChromeVoxMode.CLASSIC) | 560 this.mode_ === ChromeVoxMode.CLASSIC) |
556 return; | 561 return; |
557 | 562 |
558 if (!evt.target.state.focused) | 563 if (!evt.target.state.focused) |
559 return; | 564 return; |
560 | 565 |
| 566 if (evt.target.role != RoleType.textField) |
| 567 return; |
| 568 |
561 if (!this.currentRange_) { | 569 if (!this.currentRange_) { |
562 this.onEventDefault(evt); | 570 this.onEventDefault(evt); |
563 this.currentRange_ = cursors.Range.fromNode(evt.target); | 571 this.currentRange_ = cursors.Range.fromNode(evt.target); |
564 } | 572 } |
565 | 573 |
566 this.createEditableTextHandlerIfNeeded_(evt.target); | 574 this.createEditableTextHandlerIfNeeded_(evt.target); |
567 var textChangeEvent = new cvox.TextChangeEvent( | 575 var textChangeEvent = new cvox.TextChangeEvent( |
568 evt.target.value, | 576 evt.target.value, |
569 evt.target.textSelStart, | 577 evt.target.textSelStart, |
570 evt.target.textSelEnd, | 578 evt.target.textSelEnd, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 node.state.protected, | 799 node.state.protected, |
792 cvox.ChromeVox.tts); | 800 cvox.ChromeVox.tts); |
793 } | 801 } |
794 } | 802 } |
795 }; | 803 }; |
796 | 804 |
797 /** @type {Background} */ | 805 /** @type {Background} */ |
798 global.backgroundObj = new Background(); | 806 global.backgroundObj = new Background(); |
799 | 807 |
800 }); // goog.scope | 808 }); // goog.scope |
OLD | NEW |