Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js

Issue 2447773002: Use setSequentialFocusNavigationStartingPoint in ChromeVox (Closed)
Patch Set: Use getLeastCommonAncestor and only focus links Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 var start = range.start.node; 764 var start = range.start.node;
765 var end = range.end.node; 765 var end = range.end.node;
766 if (start.state.focused || end.state.focused) 766 if (start.state.focused || end.state.focused)
767 return; 767 return;
768 768
769 // Iframes, when focused, causes the child webArea to fire focus 769 // Iframes, when focused, causes the child webArea to fire focus
770 // event. This can result in getting stuck when navigating 770 // event. This can result in getting stuck when navigating
771 // backward. 771 // backward.
772 var isFocusable = function(node) { 772 var isFocusable = function(node) {
773 return node.role != RoleType.iframe && 773 return node.role != RoleType.iframe &&
774 node.role != RoleType.rootWebArea &&
774 node.state.focusable && 775 node.state.focusable &&
775 !node.state.focused &&
776 !AutomationPredicate.structuralContainer(node); 776 !AutomationPredicate.structuralContainer(node);
777 }; 777 };
778
779 // First, try to focus the start or end node.
778 if (isFocusable(start)) { 780 if (isFocusable(start)) {
779 start.focus(); 781 if (!start.state.focused)
782 start.focus();
780 return; 783 return;
781 } 784 } else if (isFocusable(end)) {
782 if (isFocusable(end)) { 785 if (!end.state.focused)
783 end.focus(); 786 end.focus();
784 return; 787 return;
785 } 788 }
786 789
787 // TODO(dmazzoni): Set sequential focus. 790 // If a common ancestor of |start| and |end| is a link, focus that.
791 var ancestor = AutomationUtil.getLeastCommonAncestor(start, end);
792 while (ancestor && ancestor.root == start.root) {
David Tseng 2016/10/27 17:03:18 Counter example: <a href="test"> <button>ok</bu
dmazzoni 2016/10/27 19:42:50 As discussed in person, NVDA behaves the same for
793 if (ancestor.role == RoleType.link && ancestor.state.focusable) {
794 if (!ancestor.state.focused)
795 ancestor.focus();
796 return;
797 }
798 ancestor = ancestor.parent;
799 }
800
801 // If nothing is focusable, set the sequential focus navigation starting
802 // point, which ensures that the next time you press Tab, you'll reach
803 // the next or previous focusable node from |start|.
804 start.setSequentialFocusNavigationStartingPoint();
788 } 805 }
789 }; 806 };
790 807
791 /** 808 /**
792 * Converts a list of globs, as used in the extension manifest, to a regular 809 * Converts a list of globs, as used in the extension manifest, to a regular
793 * expression that matches if and only if any of the globs in the list matches. 810 * expression that matches if and only if any of the globs in the list matches.
794 * @param {!Array<string>} globs 811 * @param {!Array<string>} globs
795 * @return {!RegExp} 812 * @return {!RegExp}
796 * @private 813 * @private
797 */ 814 */
798 Background.globsToRegExp_ = function(globs) { 815 Background.globsToRegExp_ = function(globs) {
799 return new RegExp('^(' + globs.map(function(glob) { 816 return new RegExp('^(' + globs.map(function(glob) {
800 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') 817 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&')
801 .replace(/\*/g, '.*') 818 .replace(/\*/g, '.*')
802 .replace(/\?/g, '.'); 819 .replace(/\?/g, '.');
803 }).join('|') + ')$'); 820 }).join('|') + ')$');
804 }; 821 };
805 822
806 new Background(); 823 new Background();
807 824
808 }); // goog.scope 825 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698