Chromium Code Reviews| 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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 var end = range.end.node; | 758 var end = range.end.node; |
| 759 if (start.state.focused || end.state.focused) | 759 if (start.state.focused || end.state.focused) |
| 760 return; | 760 return; |
| 761 | 761 |
| 762 // Iframes, when focused, causes the child webArea to fire focus | 762 // Iframes, when focused, causes the child webArea to fire focus |
| 763 // event. This can result in getting stuck when navigating | 763 // event. This can result in getting stuck when navigating |
| 764 // backward. | 764 // backward. |
| 765 var isFocusable = function(node) { | 765 var isFocusable = function(node) { |
| 766 return node.role != RoleType.iframe && | 766 return node.role != RoleType.iframe && |
| 767 node.state.focusable && | 767 node.state.focusable && |
| 768 !node.state.focused && | |
| 769 !AutomationPredicate.structuralContainer(node); | 768 !AutomationPredicate.structuralContainer(node); |
| 770 }; | 769 }; |
| 770 | |
| 771 // First, try to focus the start or end node. | |
| 771 if (isFocusable(start)) { | 772 if (isFocusable(start)) { |
| 772 start.focus(); | 773 if (!start.state.focused) |
| 774 start.focus(); | |
| 773 return; | 775 return; |
| 774 } | 776 } else if (isFocusable(end)) { |
| 775 if (isFocusable(end)) { | 777 if (!end.state.focused) |
| 776 end.focus(); | 778 end.focus(); |
| 777 return; | 779 return; |
| 778 } | 780 } |
| 779 | 781 |
| 780 // TODO(dmazzoni): Set sequential focus. | 782 // Next, see if an ancestor of both |start| and |end| is focusable. |
| 783 var startAncestors = AutomationUtil.getAncestors(start); | |
| 784 var endAncestors = AutomationUtil.getAncestors(end); | |
| 785 var commonAncestorCount = (start == end ? startAncestors.length : | |
| 786 AutomationUtil.getDivergence(startAncestors, endAncestors)); | |
|
David Tseng
2016/10/27 01:09:50
As mentioned, AutomationUtil.getLeastCommonAncesto
dmazzoni
2016/10/27 06:27:27
Done.
| |
| 787 | |
| 788 for (var i = commonAncestorCount - 1; i >= 0; --i) { | |
|
David Tseng
2016/10/27 01:09:50
Thanks for doing this, but I don't really like the
dmazzoni
2016/10/27 03:59:25
OK, what if we limit it to just links, and text fi
dmazzoni
2016/10/27 06:27:27
Switched to just links within the same frame, that
| |
| 789 var ancestor = startAncestors[i]; | |
| 790 if (isFocusable(ancestor)) { | |
| 791 if (!ancestor.state.focused) | |
| 792 ancestor.focus(); | |
| 793 return; | |
| 794 } | |
| 795 } | |
| 796 | |
| 797 // If nothing is focusable, set the sequential focus navigation starting | |
| 798 // point, which ensures that the next time you press Tab, you'll reach | |
| 799 // the next or previous focusable node from |start|. | |
| 800 start.setSequentialFocusNavigationStartingPoint(); | |
| 781 } | 801 } |
| 782 }; | 802 }; |
| 783 | 803 |
| 784 /** | 804 /** |
| 785 * Converts a list of globs, as used in the extension manifest, to a regular | 805 * Converts a list of globs, as used in the extension manifest, to a regular |
| 786 * expression that matches if and only if any of the globs in the list matches. | 806 * expression that matches if and only if any of the globs in the list matches. |
| 787 * @param {!Array<string>} globs | 807 * @param {!Array<string>} globs |
| 788 * @return {!RegExp} | 808 * @return {!RegExp} |
| 789 * @private | 809 * @private |
| 790 */ | 810 */ |
| 791 Background.globsToRegExp_ = function(globs) { | 811 Background.globsToRegExp_ = function(globs) { |
| 792 return new RegExp('^(' + globs.map(function(glob) { | 812 return new RegExp('^(' + globs.map(function(glob) { |
| 793 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 813 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 794 .replace(/\*/g, '.*') | 814 .replace(/\*/g, '.*') |
| 795 .replace(/\?/g, '.'); | 815 .replace(/\?/g, '.'); |
| 796 }).join('|') + ')$'); | 816 }).join('|') + ')$'); |
| 797 }; | 817 }; |
| 798 | 818 |
| 799 new Background(); | 819 new Background(); |
| 800 | 820 |
| 801 }); // goog.scope | 821 }); // goog.scope |
| OLD | NEW |