OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 * @enum {string} | 29 * @enum {string} |
30 */ | 30 */ |
31 Panel.Mode = { | 31 Panel.Mode = { |
32 COLLAPSED: 'collapsed', | 32 COLLAPSED: 'collapsed', |
33 FOCUSED: 'focused', | 33 FOCUSED: 'focused', |
34 FULLSCREEN_MENUS: 'menus', | 34 FULLSCREEN_MENUS: 'menus', |
35 FULLSCREEN_TUTORIAL: 'tutorial' | 35 FULLSCREEN_TUTORIAL: 'tutorial' |
36 }; | 36 }; |
37 | 37 |
38 /** | 38 /** |
| 39 * A callback function to be executed to perform the action from selecting |
| 40 * a menu item after the menu has been closed and focus has been restored |
| 41 * to the page or wherever it was previously. |
| 42 * @param {?Function} callback |
| 43 */ |
| 44 Panel.setPendingCallback = function(callback) { |
| 45 /** @type {?Function} @private */ |
| 46 Panel.pendingCallback_ = callback; |
| 47 }; |
| 48 |
| 49 /** |
39 * Initialize the panel. | 50 * Initialize the panel. |
40 */ | 51 */ |
41 Panel.init = function() { | 52 Panel.init = function() { |
42 /** @type {Element} @private */ | 53 /** @type {Element} @private */ |
43 this.speechContainer_ = $('speech-container'); | 54 this.speechContainer_ = $('speech-container'); |
44 | 55 |
45 /** @type {Element} @private */ | 56 /** @type {Element} @private */ |
46 this.speechElement_ = $('speech'); | 57 this.speechElement_ = $('speech'); |
47 | 58 |
48 /** @type {Element} @private */ | 59 /** @type {Element} @private */ |
(...skipping 28 matching lines...) Expand all Loading... |
77 | 88 |
78 /** | 89 /** |
79 * True if the menu button in the panel is enabled at all. It's disabled if | 90 * True if the menu button in the panel is enabled at all. It's disabled if |
80 * ChromeVox Next is not active. | 91 * ChromeVox Next is not active. |
81 * @type {boolean} | 92 * @type {boolean} |
82 * @private | 93 * @private |
83 */ | 94 */ |
84 this.menusEnabled_ = localStorage['useNext'] == 'true'; | 95 this.menusEnabled_ = localStorage['useNext'] == 'true'; |
85 | 96 |
86 /** | 97 /** |
87 * A callback function to be executed to perform the action from selecting | |
88 * a menu item after the menu has been closed and focus has been restored | |
89 * to the page or wherever it was previously. | |
90 * @type {?Function} | |
91 * @private | |
92 */ | |
93 this.pendingCallback_ = null; | |
94 | |
95 /** | |
96 * True if we're currently in incremental search mode. | 98 * True if we're currently in incremental search mode. |
97 * @type {boolean} | 99 * @type {boolean} |
98 * @private | 100 * @private |
99 */ | 101 */ |
100 this.searching_ = false; | 102 this.searching_ = false; |
101 | 103 |
102 /** | 104 /** |
103 * @type {Tutorial} | 105 * @type {Tutorial} |
104 * @private | 106 * @private |
105 */ | 107 */ |
106 this.tutorial_ = new Tutorial(); | 108 this.tutorial_ = new Tutorial(); |
107 | 109 |
| 110 Panel.setPendingCallback(null); |
108 Panel.updateFromPrefs(); | 111 Panel.updateFromPrefs(); |
109 | 112 |
110 Msgs.addTranslatedMessagesToDom(document); | 113 Msgs.addTranslatedMessagesToDom(document); |
111 | 114 |
112 window.addEventListener('storage', function(event) { | 115 window.addEventListener('storage', function(event) { |
113 if (event.key == 'brailleCaptions') { | 116 if (event.key == 'brailleCaptions') { |
114 Panel.updateFromPrefs(); | 117 Panel.updateFromPrefs(); |
115 } | 118 } |
116 }, false); | 119 }, false); |
117 | 120 |
(...skipping 12 matching lines...) Expand all Loading... |
130 $('close_tutorial').addEventListener('click', Panel.onCloseTutorial, false); | 133 $('close_tutorial').addEventListener('click', Panel.onCloseTutorial, false); |
131 | 134 |
132 document.addEventListener('keydown', Panel.onKeyDown, false); | 135 document.addEventListener('keydown', Panel.onKeyDown, false); |
133 document.addEventListener('mouseup', Panel.onMouseUp, false); | 136 document.addEventListener('mouseup', Panel.onMouseUp, false); |
134 window.addEventListener('blur', function(evt) { | 137 window.addEventListener('blur', function(evt) { |
135 if (evt.target != window || document.activeElement == document.body) | 138 if (evt.target != window || document.activeElement == document.body) |
136 return; | 139 return; |
137 | 140 |
138 Panel.closeMenusAndRestoreFocus(); | 141 Panel.closeMenusAndRestoreFocus(); |
139 }, false); | 142 }, false); |
140 | |
141 Panel.searchInput_.addEventListener('blur', Panel.onSearchInputBlur, false); | |
142 }; | 143 }; |
143 | 144 |
144 /** | 145 /** |
145 * Update the display based on prefs. | 146 * Update the display based on prefs. |
146 */ | 147 */ |
147 Panel.updateFromPrefs = function() { | 148 Panel.updateFromPrefs = function() { |
148 if (Panel.searching_) { | 149 if (Panel.searching_) { |
149 this.speechContainer_.hidden = true; | 150 this.speechContainer_.hidden = true; |
150 this.brailleContainer_.hidden = true; | 151 this.brailleContainer_.hidden = true; |
151 this.searchContainer_.hidden = false; | 152 this.searchContainer_.hidden = false; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 }; | 426 }; |
426 | 427 |
427 /** Open incremental search. */ | 428 /** Open incremental search. */ |
428 Panel.onSearch = function() { | 429 Panel.onSearch = function() { |
429 Panel.clearMenus(); | 430 Panel.clearMenus(); |
430 Panel.pendingCallback_ = null; | 431 Panel.pendingCallback_ = null; |
431 Panel.searching_ = true; | 432 Panel.searching_ = true; |
432 Panel.updateFromPrefs(); | 433 Panel.updateFromPrefs(); |
433 Panel.setMode(Panel.Mode.FOCUSED); | 434 Panel.setMode(Panel.Mode.FOCUSED); |
434 | 435 |
435 ISearchUI.get(Panel.searchInput_); | 436 ISearchUI.init(Panel.searchInput_); |
436 }; | 437 }; |
437 | 438 |
438 /** | 439 /** |
439 * Clear any previous menus. The menus are all regenerated each time the | 440 * Clear any previous menus. The menus are all regenerated each time the |
440 * menus are opened. | 441 * menus are opened. |
441 */ | 442 */ |
442 Panel.clearMenus = function() { | 443 Panel.clearMenus = function() { |
443 while (this.menus_.length) { | 444 while (this.menus_.length) { |
444 var menu = this.menus_.pop(); | 445 var menu = this.menus_.pop(); |
445 $('menu-bar').removeChild(menu.menuBarItemElement); | 446 $('menu-bar').removeChild(menu.menuBarItemElement); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 default: | 747 default: |
747 // Don't mark this event as handled. | 748 // Don't mark this event as handled. |
748 return; | 749 return; |
749 } | 750 } |
750 | 751 |
751 event.preventDefault(); | 752 event.preventDefault(); |
752 event.stopPropagation(); | 753 event.stopPropagation(); |
753 }; | 754 }; |
754 | 755 |
755 /** | 756 /** |
756 * Called when focus leaves the search input. | |
757 */ | |
758 Panel.onSearchInputBlur = function() { | |
759 if (Panel.searching_) { | |
760 if (document.activeElement != Panel.searchInput_ || !document.hasFocus()) { | |
761 Panel.searching_ = false; | |
762 Panel.setMode(Panel.Mode.COLLAPSED); | |
763 Panel.updateFromPrefs(); | |
764 Panel.searchInput_.value = ''; | |
765 } | |
766 } | |
767 }; | |
768 | |
769 /** | |
770 * Open the ChromeVox Options. | 757 * Open the ChromeVox Options. |
771 */ | 758 */ |
772 Panel.onOptions = function() { | 759 Panel.onOptions = function() { |
773 var bkgnd = | 760 var bkgnd = |
774 chrome.extension.getBackgroundPage()['ChromeVoxState']['instance']; | 761 chrome.extension.getBackgroundPage()['ChromeVoxState']['instance']; |
775 bkgnd['showOptionsPage'](); | 762 bkgnd['showOptionsPage'](); |
776 Panel.setMode(Panel.Mode.COLLAPSED); | 763 Panel.setMode(Panel.Mode.COLLAPSED); |
777 }; | 764 }; |
778 | 765 |
779 /** | 766 /** |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 }, false); | 865 }, false); |
879 | 866 |
880 window.addEventListener('hashchange', function() { | 867 window.addEventListener('hashchange', function() { |
881 if (location.hash == '#fullscreen' || location.hash == '#focus') { | 868 if (location.hash == '#fullscreen' || location.hash == '#focus') { |
882 this.originalStickyState_ = cvox.ChromeVox.isStickyPrefOn; | 869 this.originalStickyState_ = cvox.ChromeVox.isStickyPrefOn; |
883 cvox.ChromeVox.isStickyPrefOn = false; | 870 cvox.ChromeVox.isStickyPrefOn = false; |
884 } else { | 871 } else { |
885 cvox.ChromeVox.isStickyPrefOn = this.originalStickyState_; | 872 cvox.ChromeVox.isStickyPrefOn = this.originalStickyState_; |
886 } | 873 } |
887 }, false); | 874 }, false); |
OLD | NEW |