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

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

Issue 2447773002: Use setSequentialFocusNavigationStartingPoint in ChromeVox (Closed)
Patch Set: Links or controls 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 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 /** 759 /**
760 * @param {!cursors.Range} range 760 * @param {!cursors.Range} range
761 * @private 761 * @private
762 */ 762 */
763 setFocusToRange_: function(range) { 763 setFocusToRange_: function(range) {
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 var isFocusableLinkOrControl = function(node) {
770 // event. This can result in getting stuck when navigating 770 return node.state.focusable &&
771 // backward. 771 AutomationPredicate.linkOrControl(node);
772 var isFocusable = function(node) {
773 return node.role != RoleType.iframe &&
774 node.state.focusable &&
775 !node.state.focused &&
776 !AutomationPredicate.structuralContainer(node);
777 }; 772 };
778 if (isFocusable(start)) { 773
779 start.focus(); 774 // First, try to focus the start or end node.
775 if (isFocusableLinkOrControl(start)) {
776 if (!start.state.focused)
777 start.focus();
780 return; 778 return;
781 } 779 } else if (isFocusableLinkOrControl(end)) {
782 if (isFocusable(end)) { 780 if (!end.state.focused)
783 end.focus(); 781 end.focus();
784 return; 782 return;
785 } 783 }
786 784
787 // TODO(dmazzoni): Set sequential focus. 785 // If a common ancestor of |start| and |end| is a link, focus that.
786 var ancestor = AutomationUtil.getLeastCommonAncestor(start, end);
787 while (ancestor && ancestor.root == start.root) {
788 if (isFocusableLinkOrControl(ancestor)) {
789 if (!ancestor.state.focused)
790 ancestor.focus();
791 return;
792 }
793 ancestor = ancestor.parent;
794 }
795
796 // If nothing is focusable, set the sequential focus navigation starting
797 // point, which ensures that the next time you press Tab, you'll reach
798 // the next or previous focusable node from |start|.
799 start.setSequentialFocusNavigationStartingPoint();
788 } 800 }
789 }; 801 };
790 802
791 /** 803 /**
792 * Converts a list of globs, as used in the extension manifest, to a regular 804 * 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. 805 * expression that matches if and only if any of the globs in the list matches.
794 * @param {!Array<string>} globs 806 * @param {!Array<string>} globs
795 * @return {!RegExp} 807 * @return {!RegExp}
796 * @private 808 * @private
797 */ 809 */
798 Background.globsToRegExp_ = function(globs) { 810 Background.globsToRegExp_ = function(globs) {
799 return new RegExp('^(' + globs.map(function(glob) { 811 return new RegExp('^(' + globs.map(function(glob) {
800 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') 812 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&')
801 .replace(/\*/g, '.*') 813 .replace(/\*/g, '.*')
802 .replace(/\?/g, '.'); 814 .replace(/\?/g, '.');
803 }).join('|') + ')$'); 815 }).join('|') + ')$');
804 }; 816 };
805 817
806 new Background(); 818 new Background();
807 819
808 }); // goog.scope 820 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698