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

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

Issue 2108963003: Initial draft of ChromeVox Next tutorial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched to use showNextUpdatePage 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 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
11 goog.require('ISearchUI'); 11 goog.require('ISearchUI');
12 goog.require('Msgs'); 12 goog.require('Msgs');
13 goog.require('PanelCommand'); 13 goog.require('PanelCommand');
14 goog.require('PanelMenu'); 14 goog.require('PanelMenu');
15 goog.require('PanelMenuItem'); 15 goog.require('PanelMenuItem');
16 goog.require('Tutorial');
16 goog.require('cvox.ChromeVoxKbHandler'); 17 goog.require('cvox.ChromeVoxKbHandler');
17 goog.require('cvox.CommandStore'); 18 goog.require('cvox.CommandStore');
18 19
19 /** 20 /**
20 * Class to manage the panel. 21 * Class to manage the panel.
21 * @constructor 22 * @constructor
22 */ 23 */
23 Panel = function() { 24 Panel = function() {
24 }; 25 };
25 26
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 */ 80 */
80 this.pendingCallback_ = null; 81 this.pendingCallback_ = null;
81 82
82 /** 83 /**
83 * True if we're currently in incremental search mode. 84 * True if we're currently in incremental search mode.
84 * @type {boolean} 85 * @type {boolean}
85 * @private 86 * @private
86 */ 87 */
87 this.searching_ = false; 88 this.searching_ = false;
88 89
90 /**
91 * @type {Tutorial}
92 * @private
93 */
94 this.tutorial_ = new Tutorial();
95
89 Panel.updateFromPrefs(); 96 Panel.updateFromPrefs();
90 97
91 Msgs.addTranslatedMessagesToDom(document); 98 Msgs.addTranslatedMessagesToDom(document);
92 99
93 window.addEventListener('storage', function(event) { 100 window.addEventListener('storage', function(event) {
94 if (event.key == 'brailleCaptions') { 101 if (event.key == 'brailleCaptions') {
95 Panel.updateFromPrefs(); 102 Panel.updateFromPrefs();
96 } 103 }
97 }, false); 104 }, false);
98 105
99 window.addEventListener('message', function(message) { 106 window.addEventListener('message', function(message) {
100 var command = JSON.parse(message.data); 107 var command = JSON.parse(message.data);
101 Panel.exec(/** @type {PanelCommand} */(command)); 108 Panel.exec(/** @type {PanelCommand} */(command));
102 }, false); 109 }, false);
103 110
104 $('menus_button').addEventListener('mousedown', Panel.onOpenMenus, false); 111 $('menus_button').addEventListener('mousedown', Panel.onOpenMenus, false);
105 $('options').addEventListener('click', Panel.onOptions, false); 112 $('options').addEventListener('click', Panel.onOptions, false);
106 $('close').addEventListener('click', Panel.onClose, false); 113 $('close').addEventListener('click', Panel.onClose, false);
107 114
115 $('tutorial_next').addEventListener('click', Panel.onTutorialNext, false);
116 $('tutorial_previous').addEventListener(
117 'click', Panel.onTutorialPrevious, false);
118 $('close_tutorial').addEventListener('click', Panel.onCloseTutorial, false);
119
108 document.addEventListener('keydown', Panel.onKeyDown, false); 120 document.addEventListener('keydown', Panel.onKeyDown, false);
109 document.addEventListener('mouseup', Panel.onMouseUp, false); 121 document.addEventListener('mouseup', Panel.onMouseUp, false);
110 122
111 Panel.searchInput_.addEventListener('blur', Panel.onSearchInputBlur, false); 123 Panel.searchInput_.addEventListener('blur', Panel.onSearchInputBlur, false);
112 }; 124 };
113 125
114 /** 126 /**
115 * Update the display based on prefs. 127 * Update the display based on prefs.
116 */ 128 */
117 Panel.updateFromPrefs = function() { 129 Panel.updateFromPrefs = function() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 break; 195 break;
184 case PanelCommandType.DISABLE_MENUS: 196 case PanelCommandType.DISABLE_MENUS:
185 Panel.onDisableMenus(); 197 Panel.onDisableMenus();
186 break; 198 break;
187 case PanelCommandType.OPEN_MENUS: 199 case PanelCommandType.OPEN_MENUS:
188 Panel.onOpenMenus(undefined, command.data); 200 Panel.onOpenMenus(undefined, command.data);
189 break; 201 break;
190 case PanelCommandType.SEARCH: 202 case PanelCommandType.SEARCH:
191 Panel.onSearch(); 203 Panel.onSearch();
192 break; 204 break;
205 case PanelCommandType.TUTORIAL:
206 Panel.onTutorial();
207 break;
193 } 208 }
194 }; 209 };
195 210
196 /** 211 /**
197 * Enable the ChromeVox Menus. 212 * Enable the ChromeVox Menus.
198 */ 213 */
199 Panel.onEnableMenus = function() { 214 Panel.onEnableMenus = function() {
200 Panel.menusEnabled_ = true; 215 Panel.menusEnabled_ = true;
201 $('menus_button').disabled = false; 216 $('menus_button').disabled = false;
202 $('triangle').style.display = ''; 217 $('triangle').style.display = '';
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 }; 478 };
464 479
465 /** 480 /**
466 * Called when the user releases the mouse button. If it's anywhere other 481 * Called when the user releases the mouse button. If it's anywhere other
467 * than on the menus button, close the menus and return focus to the page, 482 * than on the menus button, close the menus and return focus to the page,
468 * and if the mouse was released over a menu item, execute that item's 483 * and if the mouse was released over a menu item, execute that item's
469 * callback. 484 * callback.
470 * @param {Event} event The mouse event. 485 * @param {Event} event The mouse event.
471 */ 486 */
472 Panel.onMouseUp = function(event) { 487 Panel.onMouseUp = function(event) {
488 if (!Panel.activeMenu_)
489 return;
490
473 var target = event.target; 491 var target = event.target;
474 while (target && !target.classList.contains('menu-item')) { 492 while (target && !target.classList.contains('menu-item')) {
475 // Allow the user to click and release on the menu button and leave 493 // Allow the user to click and release on the menu button and leave
476 // the menu button. Otherwise releasing the mouse anywhere else will 494 // the menu button.
477 // close the menu.
478 if (target.id == 'menus_button') 495 if (target.id == 'menus_button')
479 return; 496 return;
480 497
481 target = target.parentElement; 498 target = target.parentElement;
482 } 499 }
483 500
484 if (target && Panel.activeMenu_) 501 if (target && Panel.activeMenu_)
485 Panel.pendingCallback_ = Panel.activeMenu_.getCallbackForElement(target); 502 Panel.pendingCallback_ = Panel.activeMenu_.getCallbackForElement(target);
486 Panel.closeMenusAndRestoreFocus(); 503 Panel.closeMenusAndRestoreFocus();
487 }; 504 };
488 505
489 /** 506 /**
490 * Called when a key is pressed. Handle arrow keys to navigate the menus, 507 * Called when a key is pressed. Handle arrow keys to navigate the menus,
491 * Esc to close, and Enter/Space to activate an item. 508 * Esc to close, and Enter/Space to activate an item.
492 * @param {Event} event The key event. 509 * @param {Event} event The key event.
493 */ 510 */
494 Panel.onKeyDown = function(event) { 511 Panel.onKeyDown = function(event) {
512 if (!Panel.activeMenu_)
513 return;
514
495 if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) 515 if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
496 return; 516 return;
497 517
498 switch (event.key) { 518 switch (event.key) {
499 case 'ArrowLeft': 519 case 'ArrowLeft':
500 Panel.advanceActiveMenuBy(-1); 520 Panel.advanceActiveMenuBy(-1);
501 break; 521 break;
502 case 'ArrowRight': 522 case 'ArrowRight':
503 Panel.advanceActiveMenuBy(1); 523 Panel.advanceActiveMenuBy(1);
504 break; 524 break;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 }; 588 };
569 589
570 /** 590 /**
571 * Close the menus and restore focus to the page. If a menu item's callback 591 * Close the menus and restore focus to the page. If a menu item's callback
572 * was queued, execute it once focus is restored. 592 * was queued, execute it once focus is restored.
573 */ 593 */
574 Panel.closeMenusAndRestoreFocus = function() { 594 Panel.closeMenusAndRestoreFocus = function() {
575 // Make sure we're not in full-screen mode. 595 // Make sure we're not in full-screen mode.
576 window.location = '#'; 596 window.location = '#';
577 597
598 this.activeMenu_ = null;
599
578 var bkgnd = 600 var bkgnd =
579 chrome.extension.getBackgroundPage()['ChromeVoxState']['instance']; 601 chrome.extension.getBackgroundPage()['ChromeVoxState']['instance'];
580 bkgnd['endExcursion'](Panel.pendingCallback_); 602 bkgnd['endExcursion'](Panel.pendingCallback_);
581 }; 603 };
582 604
605 /**
606 * Open the tutorial.
607 */
608 Panel.onTutorial = function() {
609 var bkgnd =
610 chrome.extension.getBackgroundPage()['ChromeVoxState']['instance'];
611 bkgnd['startExcursion']();
612
613 // Change the url fragment to 'fullscreen', which signals the native
614 // host code to make the window fullscreen, revealing the menus.
615 window.location = '#fullscreen';
616
617 $('main').style.display = 'none';
618 $('menus_background').style.display = 'none';
619 $('tutorial').style.display = 'block';
620
621 Panel.tutorial_.firstPage();
622 };
623
624 /**
625 * Move to the next page in the tutorial.
626 */
627 Panel.onTutorialNext = function() {
628 Panel.tutorial_.nextPage();
629 };
630
631 /**
632 * Move to the previous page in the tutorial.
633 */
634 Panel.onTutorialPrevious = function() {
635 Panel.tutorial_.previousPage();
636 };
637
638 /**
639 * Close the tutorial.
640 */
641 Panel.onCloseTutorial = function() {
642 $('main').style.display = 'block';
643 $('tutorial').style.display = 'none';
644 Panel.closeMenusAndRestoreFocus();
645 };
646
583 window.addEventListener('load', function() { 647 window.addEventListener('load', function() {
584 Panel.init(); 648 Panel.init();
585 }, false); 649 }, false);
586 650
587 window.addEventListener('hashchange', function() { 651 window.addEventListener('hashchange', function() {
588 if (location.hash == '#fullscreen' || location.hash == '#focus') { 652 if (location.hash == '#fullscreen' || location.hash == '#focus') {
589 this.originalStickyState_ = cvox.ChromeVox.isStickyPrefOn; 653 this.originalStickyState_ = cvox.ChromeVox.isStickyPrefOn;
590 cvox.ChromeVox.isStickyPrefOn = false; 654 cvox.ChromeVox.isStickyPrefOn = false;
591 } else { 655 } else {
592 cvox.ChromeVox.isStickyPrefOn = this.originalStickyState_; 656 cvox.ChromeVox.isStickyPrefOn = this.originalStickyState_;
593 } 657 }
594 }, false); 658 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698