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

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

Issue 2042083002: Add role lists to ChromeVox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: /chromevox/background/keymaps$ git cl upload 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 ChromeVox panel and menus. 6 * @fileoverview The ChromeVox panel and menus.
7 */ 7 */
8 8
9 goog.provide('Panel'); 9 goog.provide('Panel');
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 this.brailleTextElement_.textContent = command.data.text; 178 this.brailleTextElement_.textContent = command.data.text;
179 this.brailleCellsElement_.textContent = command.data.braille; 179 this.brailleCellsElement_.textContent = command.data.braille;
180 break; 180 break;
181 case PanelCommandType.ENABLE_MENUS: 181 case PanelCommandType.ENABLE_MENUS:
182 Panel.onEnableMenus(); 182 Panel.onEnableMenus();
183 break; 183 break;
184 case PanelCommandType.DISABLE_MENUS: 184 case PanelCommandType.DISABLE_MENUS:
185 Panel.onDisableMenus(); 185 Panel.onDisableMenus();
186 break; 186 break;
187 case PanelCommandType.OPEN_MENUS: 187 case PanelCommandType.OPEN_MENUS:
188 Panel.onOpenMenus(); 188 Panel.onOpenMenus(undefined, command.data);
189 break; 189 break;
190 case PanelCommandType.SEARCH: 190 case PanelCommandType.SEARCH:
191 Panel.onSearch(); 191 Panel.onSearch();
192 break; 192 break;
193 } 193 }
194 }; 194 };
195 195
196 /** 196 /**
197 * Enable the ChromeVox Menus. 197 * Enable the ChromeVox Menus.
198 */ 198 */
199 Panel.onEnableMenus = function() { 199 Panel.onEnableMenus = function() {
200 Panel.menusEnabled_ = true; 200 Panel.menusEnabled_ = true;
201 $('menus_button').disabled = false; 201 $('menus_button').disabled = false;
202 $('triangle').style.display = ''; 202 $('triangle').style.display = '';
203 }; 203 };
204 204
205 /** 205 /**
206 * Disable the ChromeVox Menus. 206 * Disable the ChromeVox Menus.
207 */ 207 */
208 Panel.onDisableMenus = function() { 208 Panel.onDisableMenus = function() {
209 Panel.menusEnabled_ = false; 209 Panel.menusEnabled_ = false;
210 $('menus_button').disabled = true; 210 $('menus_button').disabled = true;
211 $('triangle').style.display = 'none'; 211 $('triangle').style.display = 'none';
212 }; 212 };
213 213
214 /** 214 /**
215 * Open / show the ChromeVox Menus. 215 * Open / show the ChromeVox Menus.
216 * @param {Event=} opt_event An optional event that triggered this. 216 * @param {Event=} opt_event An optional event that triggered this.
217 * @param {*=} opt_activateMenuTitle Title msg id of menu to open.
217 */ 218 */
218 Panel.onOpenMenus = function(opt_event) { 219 Panel.onOpenMenus = function(opt_event, opt_activateMenuTitle) {
219 // Don't open the menu if it's not enabled, such as when ChromeVox Next 220 // Don't open the menu if it's not enabled, such as when ChromeVox Next
220 // is not active. 221 // is not active.
221 if (!Panel.menusEnabled_) 222 if (!Panel.menusEnabled_)
222 return; 223 return;
223 224
224 // Eat the event so that a mousedown isn't turned into a drag, allowing 225 // Eat the event so that a mousedown isn't turned into a drag, allowing
225 // users to click-drag-release to select a menu item. 226 // users to click-drag-release to select a menu item.
226 if (opt_event) { 227 if (opt_event) {
227 opt_event.stopPropagation(); 228 opt_event.stopPropagation();
228 opt_event.preventDefault(); 229 opt_event.preventDefault();
229 } 230 }
230 231
231 // Change the url fragment to 'fullscreen', which signals the native 232 // Change the url fragment to 'fullscreen', which signals the native
232 // host code to make the window fullscreen, revealing the menus. 233 // host code to make the window fullscreen, revealing the menus.
233 window.location = '#fullscreen'; 234 window.location = '#fullscreen';
234 235
235 // Clear any existing menus and clear the callback. 236 // Clear any existing menus and clear the callback.
236 Panel.clearMenus(); 237 Panel.clearMenus();
237 Panel.pendingCallback_ = null; 238 Panel.pendingCallback_ = null;
238 239
239 // Build the top-level menus. 240 // Build the top-level menus.
240 var jumpMenu = Panel.addMenu('Jump'); 241 var jumpMenu = Panel.addMenu('panel_menu_jump');
241 var speechMenu = Panel.addMenu('Speech'); 242 var speechMenu = Panel.addMenu('panel_menu_speech');
242 var tabsMenu = Panel.addMenu('Tabs'); 243 var tabsMenu = Panel.addMenu('panel_menu_tabs');
243 var chromevoxMenu = Panel.addMenu('ChromeVox'); 244 var chromevoxMenu = Panel.addMenu('panel_menu_chromevox');
244 245
245 // Create a mapping between categories from CommandStore, and our 246 // Create a mapping between categories from CommandStore, and our
246 // top-level menus. Some categories aren't mapped to any menu. 247 // top-level menus. Some categories aren't mapped to any menu.
247 var categoryToMenu = { 248 var categoryToMenu = {
248 'navigation': jumpMenu, 249 'navigation': jumpMenu,
249 'jump_commands': jumpMenu, 250 'jump_commands': jumpMenu,
250 'controlling_speech': speechMenu, 251 'controlling_speech': speechMenu,
251 'modifier_keys': chromevoxMenu, 252 'modifier_keys': chromevoxMenu,
252 'help_commands': chromevoxMenu, 253 'help_commands': chromevoxMenu,
253 254
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 320 }
320 }); 321 });
321 }); 322 });
322 323
323 // Add a menu item that disables / closes ChromeVox. 324 // Add a menu item that disables / closes ChromeVox.
324 chromevoxMenu.addMenuItem( 325 chromevoxMenu.addMenuItem(
325 Msgs.getMsg('disable_chromevox'), 'Ctrl+Alt+Z', function() { 326 Msgs.getMsg('disable_chromevox'), 'Ctrl+Alt+Z', function() {
326 Panel.onClose(); 327 Panel.onClose();
327 }); 328 });
328 329
329 // Activate the first menu. 330 // Add menus for various role types.
330 Panel.activateMenu(Panel.menus_[0]); 331 var node = bkgnd.ChromeVoxState.instance.getCurrentRange().start.node;
332 Panel.addNodeMenu('role_heading', node, AutomationPredicate.heading);
333 Panel.addNodeMenu('role_landmark', node, AutomationPredicate.landmark);
334 Panel.addNodeMenu('role_link', node, AutomationPredicate.link);
335 Panel.addNodeMenu('role_form', node, AutomationPredicate.formField);
336 Panel.addNodeMenu('table_strategy', node, AutomationPredicate.table);
dmazzoni 2016/06/07 16:36:06 Is this just because 'table_strategy' already exis
David Tseng 2016/06/08 19:28:33 Done.
337
338 // Activate either the specified menu or the first menu.
339 var selectedMenu = Panel.menus_[0];
340 for (var i = 0; i < Panel.menus_.length; i++) {
341 if (this.menus_[i].menuMsg == opt_activateMenuTitle)
342 selectedMenu = this.menus_[i];
343 }
344 Panel.activateMenu(selectedMenu);
331 }; 345 };
332 346
333 /** Open incremental search. */ 347 /** Open incremental search. */
334 Panel.onSearch = function() { 348 Panel.onSearch = function() {
335 Panel.clearMenus(); 349 Panel.clearMenus();
336 Panel.pendingCallback_ = null; 350 Panel.pendingCallback_ = null;
337 Panel.searching_ = true; 351 Panel.searching_ = true;
338 Panel.updateFromPrefs(); 352 Panel.updateFromPrefs();
339 353
340 window.location = '#focus'; 354 window.location = '#focus';
341 355
342 ISearchUI.get(Panel.searchInput_); 356 ISearchUI.get(Panel.searchInput_);
343 }; 357 };
344 358
345 /** 359 /**
346 * Clear any previous menus. The menus are all regenerated each time the 360 * Clear any previous menus. The menus are all regenerated each time the
347 * menus are opened. 361 * menus are opened.
348 */ 362 */
349 Panel.clearMenus = function() { 363 Panel.clearMenus = function() {
350 while (this.menus_.length) { 364 while (this.menus_.length) {
351 var menu = this.menus_.pop(); 365 var menu = this.menus_.pop();
352 $('menu-bar').removeChild(menu.menuBarItemElement); 366 $('menu-bar').removeChild(menu.menuBarItemElement);
353 $('menus_background').removeChild(menu.menuContainerElement); 367 $('menus_background').removeChild(menu.menuContainerElement);
354 } 368 }
355 this.activeMenu_ = null; 369 this.activeMenu_ = null;
356 }; 370 };
357 371
358 /** 372 /**
359 * Create a new menu with the given name and add it to the menu bar. 373 * Create a new menu with the given name and add it to the menu bar.
360 * @param {string} menuTitle The title of the new menu to add. 374 * @param {string} menuMsg The msg id of the new menu to add.
361 * @return {PanelMenu} The menu just created. 375 * @return {PanelMenu} The menu just created.
362 */ 376 */
363 Panel.addMenu = function(menuTitle) { 377 Panel.addMenu = function(menuMsg) {
364 var menu = new PanelMenu(menuTitle); 378 var menu = new PanelMenu(menuMsg);
365 $('menu-bar').appendChild(menu.menuBarItemElement); 379 $('menu-bar').appendChild(menu.menuBarItemElement);
366 menu.menuBarItemElement.addEventListener('mouseover', function() { 380 menu.menuBarItemElement.addEventListener('mouseover', function() {
367 Panel.activateMenu(menu); 381 Panel.activateMenu(menu);
382 }, false);
383
384 $('menus_background').appendChild(menu.menuContainerElement);
385 this.menus_.push(menu);
386 return menu;
387 };
388
389
390 /**
391 * Create a new node menu with the given name and add it to the menu bar.
392 * @param {string} menuMsg The msg id of the new menu to add.
393 * @param {chrome.automation.AutomationNode} node
394 * @param {AutomationPredicate.Unary} pred
395 * @return {PanelMenu} The menu just created.
396 */
397 Panel.addNodeMenu = function(menuMsg, node, pred) {
398 var menu = new PanelNodeMenu(menuMsg, node, pred);
399 $('menu-bar').appendChild(menu.menuBarItemElement);
400 menu.menuBarItemElement.addEventListener('mouseover', function() {
401 Panel.activateMenu(menu);
368 }, false); 402 }, false);
369 403
370 $('menus_background').appendChild(menu.menuContainerElement); 404 $('menus_background').appendChild(menu.menuContainerElement);
371 this.menus_.push(menu); 405 this.menus_.push(menu);
372 return menu; 406 return menu;
373 }; 407 };
374 408
375 /** 409 /**
376 * Activate a menu, which implies hiding the previous active menu. 410 * Activate a menu, which implies hiding the previous active menu.
377 * @param {PanelMenu} menu The new menu to activate. 411 * @param {PanelMenu} menu The new menu to activate.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 /** 569 /**
536 * Close the menus and restore focus to the page. If a menu item's callback 570 * Close the menus and restore focus to the page. If a menu item's callback
537 * was queued, execute it once focus is restored. 571 * was queued, execute it once focus is restored.
538 */ 572 */
539 Panel.closeMenusAndRestoreFocus = function() { 573 Panel.closeMenusAndRestoreFocus = function() {
540 // Make sure we're not in full-screen mode. 574 // Make sure we're not in full-screen mode.
541 window.location = '#'; 575 window.location = '#';
542 576
543 var bkgnd = 577 var bkgnd =
544 chrome.extension.getBackgroundPage()['global']['backgroundObj']; 578 chrome.extension.getBackgroundPage()['global']['backgroundObj'];
545 bkgnd['endExcursion'](); 579 bkgnd['endExcursion'](Panel.pendingCallback_);
546 if (Panel.pendingCallback_)
547 Panel.pendingCallback_();
548 }; 580 };
549 581
550 window.addEventListener('load', function() { 582 window.addEventListener('load', function() {
551 Panel.init(); 583 Panel.init();
552 }, false); 584 }, false);
553 585
554 window.addEventListener('hashchange', function() { 586 window.addEventListener('hashchange', function() {
555 if (location.hash == '#fullscreen' || location.hash == '#focus') { 587 if (location.hash == '#fullscreen' || location.hash == '#focus') {
556 this.originalStickyState_ = cvox.ChromeVox.isStickyPrefOn; 588 this.originalStickyState_ = cvox.ChromeVox.isStickyPrefOn;
557 cvox.ChromeVox.isStickyPrefOn = false; 589 cvox.ChromeVox.isStickyPrefOn = false;
558 } else { 590 } else {
559 cvox.ChromeVox.isStickyPrefOn = this.originalStickyState_; 591 cvox.ChromeVox.isStickyPrefOn = this.originalStickyState_;
560 } 592 }
561 }, false); 593 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698