| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 /** | 420 /** |
| 421 * Navigate to the given range - it both sets the range and outputs it. | 421 * Navigate to the given range - it both sets the range and outputs it. |
| 422 * @param {!cursors.Range} range The new range. | 422 * @param {!cursors.Range} range The new range. |
| 423 * @param {boolean=} opt_focus Focus the range; defaults to true. | 423 * @param {boolean=} opt_focus Focus the range; defaults to true. |
| 424 * @param {Object=} opt_speechProps Speech properties. | 424 * @param {Object=} opt_speechProps Speech properties. |
| 425 * @private | 425 * @private |
| 426 */ | 426 */ |
| 427 navigateToRange: function(range, opt_focus, opt_speechProps) { | 427 navigateToRange: function(range, opt_focus, opt_speechProps) { |
| 428 opt_focus = opt_focus === undefined ? true : opt_focus; | 428 opt_focus = opt_focus === undefined ? true : opt_focus; |
| 429 opt_speechProps = opt_speechProps || {}; | 429 opt_speechProps = opt_speechProps || {}; |
| 430 var prevRange = this.currentRange_; |
| 431 if (opt_focus) |
| 432 this.setFocusToRange_(range, prevRange); |
| 430 | 433 |
| 431 if (opt_focus) | |
| 432 this.setFocusToRange_(range); | |
| 433 | |
| 434 var prevRange = this.currentRange_; | |
| 435 this.setCurrentRange(range); | 434 this.setCurrentRange(range); |
| 436 | 435 |
| 437 var o = new Output(); | 436 var o = new Output(); |
| 438 var selectedRange; | 437 var selectedRange; |
| 439 if (this.pageSel_ && | 438 if (this.pageSel_ && |
| 440 this.pageSel_.isValid() && | 439 this.pageSel_.isValid() && |
| 441 range.isValid()) { | 440 range.isValid()) { |
| 442 // Compute the direction of the endpoints of each range. | 441 // Compute the direction of the endpoints of each range. |
| 443 | 442 |
| 444 // Casts are ok because isValid checks node start and end nodes are | 443 // Casts are ok because isValid checks node start and end nodes are |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 chrome.automation.getFocus(function(focus) { | 752 chrome.automation.getFocus(function(focus) { |
| 754 if (focus) | 753 if (focus) |
| 755 this.setCurrentRange(cursors.Range.fromNode(focus)); | 754 this.setCurrentRange(cursors.Range.fromNode(focus)); |
| 756 else | 755 else |
| 757 this.setCurrentRange(null); | 756 this.setCurrentRange(null); |
| 758 }.bind(this)); | 757 }.bind(this)); |
| 759 }, | 758 }, |
| 760 | 759 |
| 761 /** | 760 /** |
| 762 * @param {!cursors.Range} range | 761 * @param {!cursors.Range} range |
| 762 * @param {cursors.Range} prevRange |
| 763 * @private | 763 * @private |
| 764 */ | 764 */ |
| 765 setFocusToRange_: function(range) { | 765 setFocusToRange_: function(range, prevRange) { |
| 766 var start = range.start.node; | 766 var start = range.start.node; |
| 767 var end = range.end.node; | 767 var end = range.end.node; |
| 768 if (start.state.focused || end.state.focused) | 768 if (start.state.focused || end.state.focused) |
| 769 return; | 769 return; |
| 770 | 770 |
| 771 var isFocusableLinkOrControl = function(node) { | 771 var isFocusableLinkOrControl = function(node) { |
| 772 return node.state.focusable && | 772 return node.state.focusable && |
| 773 AutomationPredicate.linkOrControl(node); | 773 AutomationPredicate.linkOrControl(node); |
| 774 }; | 774 }; |
| 775 | 775 |
| 776 // First, try to focus the start or end node. | 776 // First, see if we've crossed a root. Remove once webview handles focus |
| 777 // correctly. |
| 778 if (prevRange && prevRange.start.node) { |
| 779 var entered = AutomationUtil.getUniqueAncestors( |
| 780 prevRange.start.node, start); |
| 781 var embeddedObject = entered.find(function(f) { |
| 782 return f.role == RoleType.embeddedObject; }); |
| 783 if (embeddedObject) |
| 784 embeddedObject.focus(); |
| 785 } |
| 786 |
| 787 // Next, try to focus the start or end node. |
| 777 if (isFocusableLinkOrControl(start)) { | 788 if (isFocusableLinkOrControl(start)) { |
| 778 if (!start.state.focused) | 789 if (!start.state.focused) |
| 779 start.focus(); | 790 start.focus(); |
| 780 return; | 791 return; |
| 781 } else if (isFocusableLinkOrControl(end)) { | 792 } else if (isFocusableLinkOrControl(end)) { |
| 782 if (!end.state.focused) | 793 if (!end.state.focused) |
| 783 end.focus(); | 794 end.focus(); |
| 784 return; | 795 return; |
| 785 } | 796 } |
| 786 | 797 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 813 return new RegExp('^(' + globs.map(function(glob) { | 824 return new RegExp('^(' + globs.map(function(glob) { |
| 814 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 825 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 815 .replace(/\*/g, '.*') | 826 .replace(/\*/g, '.*') |
| 816 .replace(/\?/g, '.'); | 827 .replace(/\?/g, '.'); |
| 817 }).join('|') + ')$'); | 828 }).join('|') + ')$'); |
| 818 }; | 829 }; |
| 819 | 830 |
| 820 new Background(); | 831 new Background(); |
| 821 | 832 |
| 822 }); // goog.scope | 833 }); // goog.scope |
| OLD | NEW |