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

Side by Side Diff: remoting/webapp/app_remoting/js/keyboard_layouts_menu.js

Issue 917093003: Shorten Closure template notation from Array.<*> to Array<*>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove cvox Created 5 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 6 * @fileoverview
7 * Class managing the host's available keyboard layouts, allowing the user to 7 * Class managing the host's available keyboard layouts, allowing the user to
8 * select one that matches the local layout, or auto-selecting based on the 8 * select one that matches the local layout, or auto-selecting based on the
9 * current locale. 9 * current locale.
10 */ 10 */
(...skipping 24 matching lines...) Expand all
35 /** 35 /**
36 * @type {string} 36 * @type {string}
37 * @private 37 * @private
38 */ 38 */
39 this.currentLayout_ = ''; 39 this.currentLayout_ = '';
40 40
41 adapter.addListener(this.onContextMenu_.bind(this)); 41 adapter.addListener(this.onContextMenu_.bind(this));
42 }; 42 };
43 43
44 /** 44 /**
45 * @param {Array.<string>} layouts The keyboard layouts available on the host, 45 * @param {Array<string>} layouts The keyboard layouts available on the host,
46 * for example en-US, de-DE 46 * for example en-US, de-DE
47 * @param {string} currentLayout The layout currently active on the host. 47 * @param {string} currentLayout The layout currently active on the host.
48 */ 48 */
49 remoting.KeyboardLayoutsMenu.prototype.setLayouts = 49 remoting.KeyboardLayoutsMenu.prototype.setLayouts =
50 function(layouts, currentLayout) { 50 function(layouts, currentLayout) {
51 this.submenuManager_.removeAll(); 51 this.submenuManager_.removeAll();
52 this.currentLayout_ = ''; 52 this.currentLayout_ = '';
53 for (var i = 0; i < layouts.length; ++i) { 53 for (var i = 0; i < layouts.length; ++i) {
54 this.submenuManager_.add(this.makeMenuId_(layouts[i]), layouts[i]); 54 this.submenuManager_.add(this.makeMenuId_(layouts[i]), layouts[i]);
55 } 55 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 * algorithm: 91 * algorithm:
92 * - Search local storage by for a preferred keyboard layout for the app; 92 * - Search local storage by for a preferred keyboard layout for the app;
93 * if it is found, prefer it over the current locale, falling back on the 93 * if it is found, prefer it over the current locale, falling back on the
94 * latter only if no match is found. 94 * latter only if no match is found.
95 * - If the candidate layout matches one of the supported layouts, use it. 95 * - If the candidate layout matches one of the supported layouts, use it.
96 * - Otherwise, if the language portion of the candidate matches that of 96 * - Otherwise, if the language portion of the candidate matches that of
97 * any of the supported layouts, use the first such layout (e.g, en-AU 97 * any of the supported layouts, use the first such layout (e.g, en-AU
98 * will match either en-US or en-GB, whichever appears first). 98 * will match either en-US or en-GB, whichever appears first).
99 * - Otherwise, use the host's current layout. 99 * - Otherwise, use the host's current layout.
100 * 100 *
101 * @param {Array.<string>} layouts 101 * @param {Array<string>} layouts
102 * @param {string} currentHostLayout 102 * @param {string} currentHostLayout
103 * @param {function(string):void} onDone 103 * @param {function(string):void} onDone
104 * @private 104 * @private
105 */ 105 */
106 remoting.KeyboardLayoutsMenu.prototype.getBestLayout_ = 106 remoting.KeyboardLayoutsMenu.prototype.getBestLayout_ =
107 function(layouts, currentHostLayout, onDone) { 107 function(layouts, currentHostLayout, onDone) {
108 /** 108 /**
109 * Extract the language id from a string that is either "language" (e.g. 109 * Extract the language id from a string that is either "language" (e.g.
110 * "de") or "language-region" (e.g. "en-US"). 110 * "de") or "language-region" (e.g. "en-US").
111 * 111 *
112 * @param {string} layout 112 * @param {string} layout
113 * @return {string} 113 * @return {string}
114 */ 114 */
115 var getLanguage = function(layout) { 115 var getLanguage = function(layout) {
116 var languageAndRegion = layout.split('-'); 116 var languageAndRegion = layout.split('-');
117 switch (languageAndRegion.length) { 117 switch (languageAndRegion.length) {
118 case 1: 118 case 1:
119 case 2: 119 case 2:
120 return languageAndRegion[0]; 120 return languageAndRegion[0];
121 default: 121 default:
122 return ''; 122 return '';
123 } 123 }
124 }; 124 };
125 125
126 /** @param {Object.<string>} storage */ 126 /** @param {Object<string>} storage */
127 var chooseLayout = function(storage) { 127 var chooseLayout = function(storage) {
128 var configuredLayout = storage[remoting.KeyboardLayoutsMenu.KEY_]; 128 var configuredLayout = storage[remoting.KeyboardLayoutsMenu.KEY_];
129 var tryLayouts = [ chrome.i18n.getUILanguage() ]; 129 var tryLayouts = [ chrome.i18n.getUILanguage() ];
130 if (configuredLayout && typeof(configuredLayout) == 'string') { 130 if (configuredLayout && typeof(configuredLayout) == 'string') {
131 tryLayouts.unshift(configuredLayout); 131 tryLayouts.unshift(configuredLayout);
132 } 132 }
133 for (var i = 0; i < tryLayouts.length; ++i) { 133 for (var i = 0; i < tryLayouts.length; ++i) {
134 if (layouts.indexOf(tryLayouts[i]) != -1) { 134 if (layouts.indexOf(tryLayouts[i]) != -1) {
135 onDone(tryLayouts[i]); 135 onDone(tryLayouts[i]);
136 return; 136 return;
(...skipping 26 matching lines...) Expand all
163 return 'layout@' + layout; 163 return 'layout@' + layout;
164 }; 164 };
165 165
166 /** 166 /**
167 * Handle a click on the application's context menu. 167 * Handle a click on the application's context menu.
168 * 168 *
169 * @param {OnClickData=} info 169 * @param {OnClickData=} info
170 * @private 170 * @private
171 */ 171 */
172 remoting.KeyboardLayoutsMenu.prototype.onContextMenu_ = function(info) { 172 remoting.KeyboardLayoutsMenu.prototype.onContextMenu_ = function(info) {
173 /** @type {Array.<string>} */ 173 /** @type {Array<string>} */
174 var components = info.menuItemId.split('@'); 174 var components = info.menuItemId.split('@');
175 if (components.length == 2 && 175 if (components.length == 2 &&
176 this.makeMenuId_(components[1]) == info.menuItemId) { 176 this.makeMenuId_(components[1]) == info.menuItemId) {
177 this.setLayout_(true, components[1]); 177 this.setLayout_(true, components[1]);
178 } 178 }
179 }; 179 };
180 180
181 /** 181 /**
182 * @type {string} 182 * @type {string}
183 * @private 183 * @private
184 */ 184 */
185 remoting.KeyboardLayoutsMenu.KEY_ = 'preferred-keyboard-layout'; 185 remoting.KeyboardLayoutsMenu.KEY_ = 'preferred-keyboard-layout';
OLDNEW
« no previous file with comments | « remoting/webapp/app_remoting/js/idle_detector.js ('k') | remoting/webapp/app_remoting/js/window_activation_menu.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698