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

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

Issue 2144873002: Support first letter navigation in Panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 4 years, 5 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 A drop-down menu in the ChromeVox panel. 6 * @fileoverview A drop-down menu in the ChromeVox panel.
7 */ 7 */
8 8
9 goog.provide('PanelMenu'); 9 goog.provide('PanelMenu');
10 goog.provide('PanelNodeMenu'); 10 goog.provide('PanelNodeMenu');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 * @private 55 * @private
56 */ 56 */
57 this.updateScrollbarsTimeout_ = null; 57 this.updateScrollbarsTimeout_ = null;
58 58
59 /** 59 /**
60 * The current active menu item index, or -1 if none. 60 * The current active menu item index, or -1 if none.
61 * @type {number} 61 * @type {number}
62 * @private 62 * @private
63 */ 63 */
64 this.activeIndex_ = -1; 64 this.activeIndex_ = -1;
65
66 this.menuElement.addEventListener(
67 'keypress', this.onKeyPress_.bind(this), true);
65 }; 68 };
66 69
67 PanelMenu.prototype = { 70 PanelMenu.prototype = {
68 /** 71 /**
69 * @param {string} menuItemTitle The title of the menu item. 72 * @param {string} menuItemTitle The title of the menu item.
70 * @param {string} menuItemShortcut The keystrokes to select this item. 73 * @param {string} menuItemShortcut The keystrokes to select this item.
71 * @param {Function} callback The function to call if this item is selected. 74 * @param {Function} callback The function to call if this item is selected.
72 * @return {!PanelMenuItem} The menu item just created. 75 * @return {!PanelMenuItem} The menu item just created.
73 */ 76 */
74 addMenuItem: function(menuItemTitle, menuItemShortcut, callback) { 77 addMenuItem: function(menuItemTitle, menuItemShortcut, callback) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 * Get the callback for a menu item given its DOM element. 183 * Get the callback for a menu item given its DOM element.
181 * @param {Element} element The DOM element. 184 * @param {Element} element The DOM element.
182 * @return {Function} The callback. 185 * @return {Function} The callback.
183 */ 186 */
184 getCallbackForElement: function(element) { 187 getCallbackForElement: function(element) {
185 for (var i = 0; i < this.items_.length; i++) { 188 for (var i = 0; i < this.items_.length; i++) {
186 if (element == this.items_[i].element) 189 if (element == this.items_[i].element)
187 return this.items_[i].callback; 190 return this.items_[i].callback;
188 } 191 }
189 return null; 192 return null;
193 },
194
195 /**
196 * Handles key presses for first letter accelerators.
197 */
198 onKeyPress_: function(evt) {
199 var query = String.fromCharCode(evt.charCode).toLowerCase();
200
201 for (var i = this.activeIndex_ + 1; i < this.items_.length; i++) {
202 if (this.items_[i].text.toLowerCase().indexOf(query) == 0) {
203 this.activateItem(i);
204 break;
205 }
206 }
190 } 207 }
191 }; 208 };
192 209
193 /** 210 /**
194 * @param {string} menuMsg The msg id of the menu. 211 * @param {string} menuMsg The msg id of the menu.
195 * @param {chrome.automation.AutomationNode} node ChromeVox's current position. 212 * @param {chrome.automation.AutomationNode} node ChromeVox's current position.
196 * @param {AutomationPredicate.Unary} pred Filter to use on the document. 213 * @param {AutomationPredicate.Unary} pred Filter to use on the document.
197 * @extends {PanelMenu} 214 * @extends {PanelMenu}
198 * @constructor 215 * @constructor
199 */ 216 */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 PanelNodeMenu.prototype = { 249 PanelNodeMenu.prototype = {
233 __proto__: PanelMenu.prototype, 250 __proto__: PanelMenu.prototype,
234 251
235 /** @override */ 252 /** @override */
236 activate: function() { 253 activate: function() {
237 var activeItem = this.activeIndex_; 254 var activeItem = this.activeIndex_;
238 PanelMenu.prototype.activate.call(this); 255 PanelMenu.prototype.activate.call(this);
239 this.activateItem(activeItem); 256 this.activateItem(activeItem);
240 } 257 }
241 }; 258 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698