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

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

Issue 2042083002: Add role lists to ChromeVox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 11
11 goog.require('PanelMenuItem'); 12 goog.require('PanelMenuItem');
13 goog.require('constants');
12 14
13 /** 15 /**
14 * @param {string} menuTitle The title of the menu. 16 * @param {string} menuMsg The msg id of the menu.
15 * @constructor 17 * @constructor
16 */ 18 */
17 PanelMenu = function(menuTitle) { 19 PanelMenu = function(menuMsg) {
20 /** @type {string} */
21 this.menuMsg = menuMsg;
18 // The item in the menu bar containing the menu's title. 22 // The item in the menu bar containing the menu's title.
19 this.menuBarItemElement = document.createElement('div'); 23 this.menuBarItemElement = document.createElement('div');
20 this.menuBarItemElement.className = 'menu-bar-item'; 24 this.menuBarItemElement.className = 'menu-bar-item';
21 this.menuBarItemElement.setAttribute('role', 'menu'); 25 this.menuBarItemElement.setAttribute('role', 'menu');
26 var menuTitle = Msgs.getMsg(menuMsg);
22 this.menuBarItemElement.textContent = menuTitle; 27 this.menuBarItemElement.textContent = menuTitle;
23 28
24 // The container for the menu. This part is fixed and scrolls its 29 // The container for the menu. This part is fixed and scrolls its
25 // contents if necessary. 30 // contents if necessary.
26 this.menuContainerElement = document.createElement('div'); 31 this.menuContainerElement = document.createElement('div');
27 this.menuContainerElement.className = 'menu-container'; 32 this.menuContainerElement.className = 'menu-container';
28 this.menuContainerElement.style.visibility = 'hidden'; 33 this.menuContainerElement.style.visibility = 'hidden';
29 34
30 // The menu itself. It contains all of the items, and it scrolls within 35 // The menu itself. It contains all of the items, and it scrolls within
31 // its container. 36 // its container.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 * @return {Function} The callback. 182 * @return {Function} The callback.
178 */ 183 */
179 getCallbackForElement: function(element) { 184 getCallbackForElement: function(element) {
180 for (var i = 0; i < this.items_.length; i++) { 185 for (var i = 0; i < this.items_.length; i++) {
181 if (element == this.items_[i].element) 186 if (element == this.items_[i].element)
182 return this.items_[i].callback; 187 return this.items_[i].callback;
183 } 188 }
184 return null; 189 return null;
185 } 190 }
186 }; 191 };
192
193 /**
194 * @param {string} menuMsg The msg id of the menu.
195 * @param {chrome.automation.AutomationNode} node ChromeVox's current position.
196 * @param {AutomationPredicate.Unary} pred Filter to use on the document.
197 * @extends {PanelMenu}
198 * @constructor
199 */
200 PanelNodeMenu = function(menuMsg, node, pred) {
201 PanelMenu.call(this, menuMsg);
202 var nodes = [];
203 var selectNext = false;
204 var activeIndex = -1;
205 AutomationUtil.findNodePre(node.root, constants.Dir.FORWARD,
206 /** @type {AutomationPredicate.Unary} */(function(n) {
207 if (n === node)
208 selectNext = true;
209
210 if (pred(n)) {
211 this.addMenuItem(n.name, '', function() {
212 chrome.extension.getBackgroundPage().ChromeVoxState
213 .instance['navigateToRange'](cursors.Range.fromNode(n));
214 });
215 if (selectNext) {
216 activeIndex = this.items_.length - 1;
217 selectNext = false;
218 }
219 }
220 }).bind(this)
221 );
222
223 if (!this.items_.length) {
224 this.addMenuItem(
225 Msgs.getMsg('panel_menu_item_none'), '', function() {});
226 this.activateItem(0);
227 }
228 if (activeIndex >= 0)
229 this.activateItem(activeIndex);
230 };
231
232 PanelNodeMenu.prototype = {
233 __proto__: PanelMenu.prototype,
234
235 /** @override */
236 activate: function() {
237 var activeItem = this.activeIndex_;
238 PanelMenu.prototype.activate.call(this);
239 this.activateItem(activeItem);
240 }
241 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698