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

Side by Side Diff: chrome/browser/resources/settings/languages_page/languages_page.js

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 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 'settings-languages-page' is the settings page 6 * @fileoverview 'settings-languages-page' is the settings page
7 * for language and input method settings. 7 * for language and input method settings.
8 */ 8 */
9 (function() { 9 (function() {
10 'use strict'; 10 'use strict';
11 11
12 Polymer({ 12 Polymer({
13 is: 'settings-languages-page', 13 is: 'settings-languages-page',
14 14
15 properties: { 15 properties: {
16 /** 16 /**
17 * Preferences state. 17 * Preferences state.
18 */ 18 */
19 prefs: { 19 prefs: {
20 type: Object, 20 type: Object,
21 notify: true, 21 notify: true,
22 }, 22 },
23 23
24 /** 24 /**
25 * Read-only reference to the languages model provided by the 25 * Read-only reference to the languages model provided by the
26 * 'settings-languages' instance. 26 * 'settings-languages' instance.
27 * @type {!LanguagesModel|undefined} 27 * @type {!LanguagesModel|undefined}
28 */ 28 */
29 languages: { 29 languages: {
30 type: Object, 30 type: Object,
31 notify: true, 31 notify: true,
32 }, 32 },
33 33
34 /** @type {!LanguageHelper} */ 34 /** @type {!LanguageHelper} */
35 languageHelper: Object, 35 languageHelper: Object,
36
37 /** @private */
38 spellCheckSecondaryText_: {
39 type: String,
40 value: '',
41 computed: 'getSpellCheckSecondaryText_(languages.enabled.*)',
42 },
43
44 /**
45 * The language to display the details for.
46 * @type {!LanguageState|undefined}
47 * @private
48 */
49 detailLanguage_: Object,
50
51 /** @private */
52 showAddLanguagesDialog_: Boolean,
53 },
54
55 /**
56 * Handler for enabling or disabling spell check.
57 * @param {!{target: Element, model: !{item: !LanguageState}}} e
58 */
59 onSpellCheckChange_: function(e) {
60 this.languageHelper.toggleSpellCheck(
61 e.model.item.language.code, e.target.checked);
62 },
36 63
37 /** @private */ 64 /** @private */
38 spellCheckSecondaryText_: { 65 onBackTap_: function() {
39 type: String, 66 this.$.pages.back();
40 value: '', 67 },
41 computed: 'getSpellCheckSecondaryText_(languages.enabled.*)', 68
42 }, 69 /**
43 70 * Stamps and opens the Add Languages dialog, registering a listener to
44 /** 71 * disable the dialog's dom-if again on close.
45 * The language to display the details for. 72 * @param {!Event} e
46 * @type {!LanguageState|undefined} 73 * @private
47 * @private 74 */
48 */ 75 onAddLanguagesTap_: function(e) {
49 detailLanguage_: Object, 76 e.preventDefault();
50 77 this.showAddLanguagesDialog_ = true;
51 /** @private */ 78 this.async(function() {
52 showAddLanguagesDialog_: Boolean, 79 var dialog = this.$$('settings-add-languages-dialog');
53 }, 80 dialog.addEventListener('close', function() {
54 81 this.showAddLanguagesDialog_ = false;
55 /** 82 }.bind(this));
56 * Handler for enabling or disabling spell check. 83 });
57 * @param {!{target: Element, model: !{item: !LanguageState}}} e 84 },
58 */ 85
59 onSpellCheckChange_: function(e) { 86 /**
60 this.languageHelper.toggleSpellCheck(e.model.item.language.code,
61 e.target.checked);
62 },
63
64 /** @private */
65 onBackTap_: function() {
66 this.$.pages.back();
67 },
68
69 /**
70 * Stamps and opens the Add Languages dialog, registering a listener to
71 * disable the dialog's dom-if again on close.
72 * @param {!Event} e
73 * @private
74 */
75 onAddLanguagesTap_: function(e) {
76 e.preventDefault();
77 this.showAddLanguagesDialog_ = true;
78 this.async(function() {
79 var dialog = this.$$('settings-add-languages-dialog');
80 dialog.addEventListener('close', function() {
81 this.showAddLanguagesDialog_ = false;
82 }.bind(this));
83 });
84 },
85
86 /**
87 * @param {!LanguageState} language 87 * @param {!LanguageState} language
88 * @return {boolean} True if |language| is first in the list of enabled 88 * @return {boolean} True if |language| is first in the list of enabled
89 * languages. Used to hide the "Move up" option. 89 * languages. Used to hide the "Move up" option.
90 * @private 90 * @private
91 */ 91 */
92 isFirstLanguage_: function(language) { 92 isFirstLanguage_: function(language) {
93 return language == this.languages.enabled[0]; 93 return language == this.languages.enabled[0];
94 }, 94 },
95 95
96 /** 96 /**
97 * @param {!LanguageState} language 97 * @param {!LanguageState} language
98 * @return {boolean} True if |language| is first or second in the list of 98 * @return {boolean} True if |language| is first or second in the list of
99 * enabled languages. Used to hide the "Move to top" option. 99 * enabled languages. Used to hide the "Move to top" option.
100 * @private 100 * @private
101 */ 101 */
102 isFirstOrSecondLanguage_: function(language) { 102 isFirstOrSecondLanguage_: function(language) {
103 return this.languages.enabled.slice(0, 2).includes(language); 103 return this.languages.enabled.slice(0, 2).includes(language);
104 }, 104 },
105 105
106 /** 106 /**
107 * @param {!LanguageState} language 107 * @param {!LanguageState} language
108 * @return {boolean} True if |language| is last in the list of enabled 108 * @return {boolean} True if |language| is last in the list of enabled
109 * languages. Used to hide the "Move down" option. 109 * languages. Used to hide the "Move down" option.
110 * @private 110 * @private
111 */ 111 */
112 isLastLanguage_: function(language) { 112 isLastLanguage_: function(language) {
113 return language == this.languages.enabled.slice(-1)[0]; 113 return language == this.languages.enabled.slice(-1)[0];
114 }, 114 },
115 115
116 /** 116 /**
117 * @param {!Object} change Polymer change object for languages.enabled.*. 117 * @param {!Object} change Polymer change object for languages.enabled.*.
118 * @return {boolean} True if there are less than 2 languages. 118 * @return {boolean} True if there are less than 2 languages.
119 */ 119 */
120 isHelpTextHidden_: function(change) { 120 isHelpTextHidden_: function(change) {
121 return this.languages.enabled.length <= 1; 121 return this.languages.enabled.length <= 1;
122 }, 122 },
123 123
124 /** 124 /**
125 * @param {!LanguageState} languageState 125 * @param {!LanguageState} languageState
126 * @param {string} prospectiveUILanguage The chosen UI language. 126 * @param {string} prospectiveUILanguage The chosen UI language.
127 * @return {boolean} True if the given language cannot be set as the 127 * @return {boolean} True if the given language cannot be set as the
128 * prospective UI language by the user. 128 * prospective UI language by the user.
129 * @private 129 * @private
130 */ 130 */
131 disableUILanguageCheckbox_: function(languageState, prospectiveUILanguage) { 131 disableUILanguageCheckbox_: function(languageState, prospectiveUILanguage) {
132 // UI language setting belongs to the primary user. 132 // UI language setting belongs to the primary user.
133 if (this.isSecondaryUser_()) 133 if (this.isSecondaryUser_())
134 return true; 134 return true;
135 135
136 // If the language cannot be a UI language, we can't set it as the 136 // If the language cannot be a UI language, we can't set it as the
137 // prospective UI language. 137 // prospective UI language.
138 if (!languageState.language.supportsUI) 138 if (!languageState.language.supportsUI)
139 return true; 139 return true;
140 140
141 // Unchecking the currently chosen language doesn't make much sense. 141 // Unchecking the currently chosen language doesn't make much sense.
142 if (languageState.language.code == prospectiveUILanguage) 142 if (languageState.language.code == prospectiveUILanguage)
143 return true; 143 return true;
144 144
145 // Otherwise, the prospective language can be changed to this language. 145 // Otherwise, the prospective language can be changed to this language.
146 return false; 146 return false;
147 }, 147 },
148 148
149 /** 149 /**
150 * @return {boolean} True for a secondary user in a multi-profile session. 150 * @return {boolean} True for a secondary user in a multi-profile session.
151 * @private 151 * @private
152 */ 152 */
153 isSecondaryUser_: function() { 153 isSecondaryUser_: function() {
154 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser'); 154 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser');
155 }, 155 },
156 156
157 /** 157 /**
158 * Handler for changes to the UI language checkbox. 158 * Handler for changes to the UI language checkbox.
159 * @param {!{target: !PaperCheckboxElement}} e 159 * @param {!{target: !PaperCheckboxElement}} e
160 * @private 160 * @private
161 */ 161 */
162 onUILanguageChange_: function(e) { 162 onUILanguageChange_: function(e) {
163 // We don't support unchecking this checkbox. TODO(michaelpg): Ask for a 163 // We don't support unchecking this checkbox. TODO(michaelpg): Ask for a
164 // simpler widget. 164 // simpler widget.
165 assert(e.target.checked); 165 assert(e.target.checked);
166 this.languageHelper.setProspectiveUILanguage( 166 this.languageHelper.setProspectiveUILanguage(
167 this.detailLanguage_.language.code); 167 this.detailLanguage_.language.code);
168 168
169 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); 169 /** @type {!CrActionMenuElement} */ (this.$.menu.get()).close();
170 }, 170 },
171 171
172 /** 172 /**
173 * @param {!chrome.languageSettingsPrivate.Language} language 173 * @param {!chrome.languageSettingsPrivate.Language} language
174 * @param {string} targetLanguageCode The default translate target language. 174 * @param {string} targetLanguageCode The default translate target language.
175 * @return {boolean} True if the translate checkbox should be disabled. 175 * @return {boolean} True if the translate checkbox should be disabled.
176 * @private 176 * @private
177 */ 177 */
178 disableTranslateCheckbox_: function(language, targetLanguageCode) { 178 disableTranslateCheckbox_: function(language, targetLanguageCode) {
179 if (!language.supportsTranslate) 179 if (!language.supportsTranslate)
180 return true; 180 return true;
181 181
182 return this.languageHelper.convertLanguageCodeForTranslate(language.code) == 182 return this.languageHelper.convertLanguageCodeForTranslate(
183 targetLanguageCode; 183 language.code) == targetLanguageCode;
184 }, 184 },
185 185
186 /** 186 /**
187 * Handler for changes to the translate checkbox. 187 * Handler for changes to the translate checkbox.
188 * @param {!{target: !PaperCheckboxElement}} e 188 * @param {!{target: !PaperCheckboxElement}} e
189 * @private 189 * @private
190 */ 190 */
191 onTranslateCheckboxChange_: function(e) { 191 onTranslateCheckboxChange_: function(e) {
192 if (e.target.checked) { 192 if (e.target.checked) {
193 this.languageHelper.enableTranslateLanguage( 193 this.languageHelper.enableTranslateLanguage(
194 this.detailLanguage_.language.code); 194 this.detailLanguage_.language.code);
195 } else { 195 } else {
196 this.languageHelper.disableTranslateLanguage( 196 this.languageHelper.disableTranslateLanguage(
197 this.detailLanguage_.language.code); 197 this.detailLanguage_.language.code);
198 } 198 }
199 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); 199 /** @type {!CrActionMenuElement} */ (this.$.menu.get()).close();
200 }, 200 },
201 201
202 /** 202 /**
203 * Returns "complex" if the menu includes checkboxes, which should change the 203 * Returns "complex" if the menu includes checkboxes, which should change the
204 * spacing of items and show a separator in the menu. 204 * spacing of items and show a separator in the menu.
205 * @param {boolean} translateEnabled 205 * @param {boolean} translateEnabled
206 * @return {string} 206 * @return {string}
207 */ 207 */
208 getMenuClass_: function(translateEnabled) { 208 getMenuClass_: function(translateEnabled) {
209 if (translateEnabled || cr.isChromeOS || cr.isWindows) 209 if (translateEnabled || cr.isChromeOS || cr.isWindows)
210 return 'complex'; 210 return 'complex';
211 return ''; 211 return '';
212 }, 212 },
213 213
214 /** 214 /**
215 * Moves the language to the top of the list. 215 * Moves the language to the top of the list.
216 * @private 216 * @private
217 */ 217 */
218 onMoveToTopTap_: function() { 218 onMoveToTopTap_: function() {
219 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); 219 /** @type {!CrActionMenuElement} */ (this.$.menu.get()).close();
220 this.languageHelper.moveLanguageToFront(this.detailLanguage_.language.code); 220 this.languageHelper.moveLanguageToFront(
221 }, 221 this.detailLanguage_.language.code);
222 222 },
223 /** 223
224 * Moves the language up in the list. 224 /**
225 * @private 225 * Moves the language up in the list.
226 */ 226 * @private
227 onMoveUpTap_: function() { 227 */
228 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); 228 onMoveUpTap_: function() {
229 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); 229 /** @type {!CrActionMenuElement} */ (this.$.menu.get()).close();
230 }, 230 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1);
231 231 },
232 /** 232
233 * Moves the language down in the list. 233 /**
234 * @private 234 * Moves the language down in the list.
235 */ 235 * @private
236 onMoveDownTap_: function() { 236 */
237 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); 237 onMoveDownTap_: function() {
238 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); 238 /** @type {!CrActionMenuElement} */ (this.$.menu.get()).close();
239 }, 239 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1);
240 240 },
241 /** 241
242 * Disables the language. 242 /**
243 * @private 243 * Disables the language.
244 */ 244 * @private
245 onRemoveLanguageTap_: function() { 245 */
246 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); 246 onRemoveLanguageTap_: function() {
247 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); 247 /** @type {!CrActionMenuElement} */ (this.$.menu.get()).close();
248 }, 248 this.languageHelper.disableLanguage(this.detailLanguage_.language.code);
249 249 },
250 /** 250
251 * Opens the Manage Input Methods page. 251 /**
252 * @private 252 * Opens the Manage Input Methods page.
253 */ 253 * @private
254 onManageInputMethodsTap_: function() { 254 */
255 assert(cr.isChromeOS); 255 onManageInputMethodsTap_: function() {
256 settings.navigateTo(settings.Route.INPUT_METHODS); 256 assert(cr.isChromeOS);
257 }, 257 settings.navigateTo(settings.Route.INPUT_METHODS);
258 258 },
259 /** 259
260 * Handler for tap and <Enter> events on an input method on the main page, 260 /**
261 * which sets it as the current input method. 261 * Handler for tap and <Enter> events on an input method on the main page,
262 * @param {!{model: !{item: !chrome.languageSettingsPrivate.InputMethod}, 262 * which sets it as the current input method.
263 * target: !{tagName: string}, 263 * @param {!{model: !{item: !chrome.languageSettingsPrivate.InputMethod},
264 * type: string, 264 * target: !{tagName: string},
265 * key: (string|undefined)}} e 265 * type: string,
266 */ 266 * key: (string|undefined)}} e
267 onInputMethodTap_: function(e) { 267 */
268 assert(cr.isChromeOS); 268 onInputMethodTap_: function(e) {
269 269 assert(cr.isChromeOS);
270 // Taps on the paper-icon-button are handled in onInputMethodOptionsTap_. 270
271 if (e.target.tagName == 'PAPER-ICON-BUTTON') 271 // Taps on the paper-icon-button are handled in onInputMethodOptionsTap_.
272 return; 272 if (e.target.tagName == 'PAPER-ICON-BUTTON')
273 273 return;
274 // Ignore key presses other than <Enter>. 274
275 if (e.type == 'keypress' && e.key != 'Enter') 275 // Ignore key presses other than <Enter>.
276 return; 276 if (e.type == 'keypress' && e.key != 'Enter')
277 277 return;
278 // Set the input method. 278
279 this.languageHelper.setCurrentInputMethod(e.model.item.id); 279 // Set the input method.
280 }, 280 this.languageHelper.setCurrentInputMethod(e.model.item.id);
281 281 },
282 /** 282
283 * Opens the input method extension's options page in a new tab (or focuses 283 /**
284 * an existing instance of the IME's options). 284 * Opens the input method extension's options page in a new tab (or focuses
285 * @param {!{model: !{item: chrome.languageSettingsPrivate.InputMethod}}} e 285 * an existing instance of the IME's options).
286 * @private 286 * @param {!{model: !{item: chrome.languageSettingsPrivate.InputMethod}}} e
287 */ 287 * @private
288 onInputMethodOptionsTap_: function(e) { 288 */
289 assert(cr.isChromeOS); 289 onInputMethodOptionsTap_: function(e) {
290 this.languageHelper.openInputMethodOptions(e.model.item.id); 290 assert(cr.isChromeOS);
291 }, 291 this.languageHelper.openInputMethodOptions(e.model.item.id);
292 292 },
293 /** 293
294 /**
294 * Returns the secondary text for the spell check subsection based on the 295 * Returns the secondary text for the spell check subsection based on the
295 * enabled spell check languages, listing at most 2 languages. 296 * enabled spell check languages, listing at most 2 languages.
296 * @return {string} 297 * @return {string}
297 * @private 298 * @private
298 */ 299 */
299 getSpellCheckSecondaryText_: function() { 300 getSpellCheckSecondaryText_: function() {
300 var enabledSpellCheckLanguages = 301 var enabledSpellCheckLanguages =
301 this.languages.enabled.filter(function(languageState) { 302 this.languages.enabled.filter(function(languageState) {
302 return languageState.spellCheckEnabled && 303 return languageState.spellCheckEnabled &&
303 languageState.language.supportsSpellcheck; 304 languageState.language.supportsSpellcheck;
304 }); 305 });
305 switch (enabledSpellCheckLanguages.length) { 306 switch (enabledSpellCheckLanguages.length) {
306 case 0: 307 case 0:
307 return ''; 308 return '';
308 case 1: 309 case 1:
309 return enabledSpellCheckLanguages[0].language.displayName; 310 return enabledSpellCheckLanguages[0].language.displayName;
310 case 2: 311 case 2:
311 return loadTimeData.getStringF( 312 return loadTimeData.getStringF(
312 'spellCheckSummaryTwoLanguages', 313 'spellCheckSummaryTwoLanguages',
313 enabledSpellCheckLanguages[0].language.displayName, 314 enabledSpellCheckLanguages[0].language.displayName,
314 enabledSpellCheckLanguages[1].language.displayName); 315 enabledSpellCheckLanguages[1].language.displayName);
315 case 3: 316 case 3:
316 // "foo, bar, and 1 other" 317 // "foo, bar, and 1 other"
317 return loadTimeData.getStringF( 318 return loadTimeData.getStringF(
318 'spellCheckSummaryThreeLanguages', 319 'spellCheckSummaryThreeLanguages',
319 enabledSpellCheckLanguages[0].language.displayName, 320 enabledSpellCheckLanguages[0].language.displayName,
320 enabledSpellCheckLanguages[1].language.displayName); 321 enabledSpellCheckLanguages[1].language.displayName);
321 default: 322 default:
322 // "foo, bar, and [N-2] others" 323 // "foo, bar, and [N-2] others"
323 return loadTimeData.getStringF( 324 return loadTimeData.getStringF(
324 'spellCheckSummaryMultipleLanguages', 325 'spellCheckSummaryMultipleLanguages',
325 enabledSpellCheckLanguages[0].language.displayName, 326 enabledSpellCheckLanguages[0].language.displayName,
326 enabledSpellCheckLanguages[1].language.displayName, 327 enabledSpellCheckLanguages[1].language.displayName,
327 (enabledSpellCheckLanguages.length - 2).toLocaleString()); 328 (enabledSpellCheckLanguages.length - 2).toLocaleString());
328 } 329 }
329 }, 330 },
330 331
331 /** 332 /**
332 * Opens the Custom Dictionary page. 333 * Opens the Custom Dictionary page.
333 * @private 334 * @private
334 */ 335 */
335 onEditDictionaryTap_: function() { 336 onEditDictionaryTap_: function() {
336 assert(!cr.isMac); 337 assert(!cr.isMac);
337 settings.navigateTo(settings.Route.EDIT_DICTIONARY); 338 settings.navigateTo(settings.Route.EDIT_DICTIONARY);
338 this.forceRenderList_('settings-edit-dictionary-page'); 339 this.forceRenderList_('settings-edit-dictionary-page');
339 }, 340 },
340 341
341 /** 342 /**
342 * Checks whether the prospective UI language (the pref that indicates what 343 * Checks whether the prospective UI language (the pref that indicates what
343 * language to use in Chrome) matches the current language. This pref is used 344 * language to use in Chrome) matches the current language. This pref is used
344 * only on Chrome OS and Windows; we don't control the UI language elsewhere. 345 * only on Chrome OS and Windows; we don't control the UI language elsewhere.
345 * @param {string} languageCode The language code identifying a language. 346 * @param {string} languageCode The language code identifying a language.
346 * @param {string} prospectiveUILanguage The prospective UI language. 347 * @param {string} prospectiveUILanguage The prospective UI language.
347 * @return {boolean} True if the given language matches the prospective UI 348 * @return {boolean} True if the given language matches the prospective UI
348 * pref (which may be different from the actual UI language). 349 * pref (which may be different from the actual UI language).
349 * @private 350 * @private
350 */ 351 */
351 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { 352 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) {
352 assert(cr.isChromeOS || cr.isWindows); 353 assert(cr.isChromeOS || cr.isWindows);
353 return languageCode == prospectiveUILanguage; 354 return languageCode == prospectiveUILanguage;
354 }, 355 },
355 356
356 <if expr="chromeos or is_win"> 357 /* <if expr="chromeos or is_win"> */
357 /** 358 /**
358 * @param {string} prospectiveUILanguage 359 * @param {string} prospectiveUILanguage
359 * @return {string} 360 * @return {string}
360 * @private 361 * @private
361 */ 362 */
362 getProspectiveUILanguageName_: function(prospectiveUILanguage) { 363 getProspectiveUILanguageName_: function(prospectiveUILanguage) {
363 return this.languageHelper.getLanguage(prospectiveUILanguage).displayName; 364 return this.languageHelper.getLanguage(prospectiveUILanguage).displayName;
364 }, 365 },
365 </if> 366 /* </if> */
366 367
367 /** 368 /**
368 * @return {string} 369 * @return {string}
369 * @private 370 * @private
370 */ 371 */
371 getLanguageListTwoLine_: function() { 372 getLanguageListTwoLine_: function() {
372 return cr.isChromeOS || cr.isWindows ? 'two-line' : ''; 373 return cr.isChromeOS || cr.isWindows ? 'two-line' : '';
373 }, 374 },
374 375
375 /** 376 /**
376 * @return {string} 377 * @return {string}
377 * @private 378 * @private
378 */ 379 */
379 getSpellCheckListTwoLine_: function() { 380 getSpellCheckListTwoLine_: function() {
380 return this.spellCheckSecondaryText_.length ? 'two-line' : ''; 381 return this.spellCheckSecondaryText_.length ? 'two-line' : '';
381 }, 382 },
382 383
383 /** 384 /**
384 * Returns either the "selected" class, if the language matches the 385 * Returns either the "selected" class, if the language matches the
385 * prospective UI language, or an empty string. Languages can only be 386 * prospective UI language, or an empty string. Languages can only be
386 * selected on Chrome OS and Windows. 387 * selected on Chrome OS and Windows.
387 * @param {string} languageCode The language code identifying a language. 388 * @param {string} languageCode The language code identifying a language.
388 * @param {string} prospectiveUILanguage The prospective UI language. 389 * @param {string} prospectiveUILanguage The prospective UI language.
389 * @return {string} The class name for the language item. 390 * @return {string} The class name for the language item.
390 * @private 391 * @private
391 */ 392 */
392 getLanguageItemClass_: function(languageCode, prospectiveUILanguage) { 393 getLanguageItemClass_: function(languageCode, prospectiveUILanguage) {
393 if ((cr.isChromeOS || cr.isWindows) && 394 if ((cr.isChromeOS || cr.isWindows) &&
394 languageCode == prospectiveUILanguage) { 395 languageCode == prospectiveUILanguage) {
395 return 'selected'; 396 return 'selected';
396 } 397 }
397 return ''; 398 return '';
398 }, 399 },
399 400
400 /** 401 /**
401 * @param {string} languageCode The language code identifying a language. 402 * @param {string} languageCode The language code identifying a language.
402 * @param {string} prospectiveUILanguage The prospective UI language. 403 * @param {string} prospectiveUILanguage The prospective UI language.
403 * @return {boolean} True if the prospective UI language is set to 404 * @return {boolean} True if the prospective UI language is set to
404 * |languageCode| but requires a restart to take effect. 405 * |languageCode| but requires a restart to take effect.
405 * @private 406 * @private
406 */ 407 */
407 isRestartRequired_: function(languageCode, prospectiveUILanguage) { 408 isRestartRequired_: function(languageCode, prospectiveUILanguage) {
408 return prospectiveUILanguage == languageCode && 409 return prospectiveUILanguage == languageCode &&
409 this.languageHelper.requiresRestart(); 410 this.languageHelper.requiresRestart();
410 }, 411 },
411 412
412 /** 413 /**
413 * @param {string} id The input method ID. 414 * @param {string} id The input method ID.
414 * @param {string} currentId The ID of the currently enabled input method. 415 * @param {string} currentId The ID of the currently enabled input method.
415 * @return {boolean} True if the IDs match. 416 * @return {boolean} True if the IDs match.
416 * @private 417 * @private
417 */ 418 */
418 isCurrentInputMethod_: function(id, currentId) { 419 isCurrentInputMethod_: function(id, currentId) {
419 assert(cr.isChromeOS); 420 assert(cr.isChromeOS);
420 return id == currentId; 421 return id == currentId;
421 }, 422 },
422 423
423 /** 424 /**
424 * @param {string} id The input method ID. 425 * @param {string} id The input method ID.
425 * @param {string} currentId The ID of the currently enabled input method. 426 * @param {string} currentId The ID of the currently enabled input method.
426 * @return {string} The class for the input method item. 427 * @return {string} The class for the input method item.
427 * @private 428 * @private
428 */ 429 */
429 getInputMethodItemClass_: function(id, currentId) { 430 getInputMethodItemClass_: function(id, currentId) {
430 assert(cr.isChromeOS); 431 assert(cr.isChromeOS);
431 return this.isCurrentInputMethod_(id, currentId) ? 'selected' : ''; 432 return this.isCurrentInputMethod_(id, currentId) ? 'selected' : '';
432 }, 433 },
433 434
434 getInputMethodName_: function(id) { 435 getInputMethodName_: function(id) {
435 assert(cr.isChromeOS); 436 assert(cr.isChromeOS);
436 var inputMethod = this.languages.inputMethods.enabled.find( 437 var inputMethod =
437 function(inputMethod) { 438 this.languages.inputMethods.enabled.find(function(inputMethod) {
438 return inputMethod.id == id; 439 return inputMethod.id == id;
439 }); 440 });
440 return inputMethod ? inputMethod.displayName : ''; 441 return inputMethod ? inputMethod.displayName : '';
441 }, 442 },
442 443
443 /** 444 /**
444 * HACK(michaelpg): This is necessary to show the list when navigating to 445 * HACK(michaelpg): This is necessary to show the list when navigating to
445 * the sub-page. Remove this function when PolymerElements/neon-animation#60 446 * the sub-page. Remove this function when PolymerElements/neon-animation#60
446 * is fixed. 447 * is fixed.
447 * @param {string} tagName Name of the element containing the <iron-list>. 448 * @param {string} tagName Name of the element containing the <iron-list>.
448 */ 449 */
449 forceRenderList_: function(tagName) { 450 forceRenderList_: function(tagName) {
450 this.$$(tagName).$$('iron-list').fire('iron-resize'); 451 this.$$(tagName).$$('iron-list').fire('iron-resize');
451 }, 452 },
452 453
453 /** 454 /**
454 * @param {!Event} e 455 * @param {!Event} e
455 * @private 456 * @private
456 */ 457 */
457 onDotsTap_: function(e) { 458 onDotsTap_: function(e) {
458 // Set a copy of the LanguageState object since it is not data-bound to the 459 // Set a copy of the LanguageState object since it is not data-bound to
459 // languages model directly. 460 // the
460 this.detailLanguage_ = /** @type {!LanguageState} */(Object.assign( 461 // languages model directly.
461 {}, 462 this.detailLanguage_ = /** @type {!LanguageState} */ (Object.assign(
462 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item)); 463 {},
464 /** @type {!{model: !{item: !LanguageState}}} */ (e).model.item));
463 465
464 // Ensure the template has been stamped. 466 // Ensure the template has been stamped.
465 var menu = /** @type {?CrActionMenuElement} */( 467 var menu =
466 this.$.menu.getIfExists()); 468 /** @type {?CrActionMenuElement} */ (this.$.menu.getIfExists());
467 if (!menu) { 469 if (!menu) {
468 menu = /** @type {!CrActionMenuElement} */(this.$.menu.get()); 470 menu = /** @type {!CrActionMenuElement} */ (this.$.menu.get());
469 this.initializeMenu_(menu); 471 this.initializeMenu_(menu);
470 } 472 }
471 473
472 menu.showAt(/** @type {!Element} */ (e.target)); 474 menu.showAt(/** @type {!Element} */ (e.target));
473 }, 475 },
474 476
475 /** 477 /**
476 * Applies Chrome OS session tweaks to the menu. 478 * Applies Chrome OS session tweaks to the menu.
477 * @param {!CrActionMenuElement} menu 479 * @param {!CrActionMenuElement} menu
478 * @private 480 * @private
479 */ 481 */
480 initializeMenu_: function(menu) { 482 initializeMenu_: function(menu) {
481 // In a CrOS multi-user session, the primary user controls the UI language. 483 // In a CrOS multi-user session, the primary user controls the UI
482 // TODO(michaelpg): The language selection should not be hidden, but should 484 // language.
483 // show a policy indicator. crbug.com/648498 485 // TODO(michaelpg): The language selection should not be hidden, but
484 if (this.isSecondaryUser_()) 486 // should
485 menu.querySelector('#uiLanguageItem').hidden = true; 487 // show a policy indicator. crbug.com/648498
488 if (this.isSecondaryUser_())
489 menu.querySelector('#uiLanguageItem').hidden = true;
486 490
487 // The UI language choice doesn't persist for guests. 491 // The UI language choice doesn't persist for guests.
488 if (cr.isChromeOS && 492 if (cr.isChromeOS &&
489 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || 493 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() ||
490 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { 494 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) {
491 menu.querySelector('#uiLanguageItem').hidden = true; 495 menu.querySelector('#uiLanguageItem').hidden = true;
492 } 496 }
493 }, 497 },
494 498
495 /** 499 /**
496 * Handler for the restart button. 500 * Handler for the restart button.
497 * @private 501 * @private
498 */ 502 */
499 onRestartTap_: function() { 503 onRestartTap_: function() {
500 <if expr="chromeos"> 504 /* <if expr="chromeos"> */
501 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); 505 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart();
502 </if> 506 /* </if> */
503 <if expr="not chromeos"> 507 /* <if expr="not chromeos"> */
504 settings.LifetimeBrowserProxyImpl.getInstance().restart(); 508 settings.LifetimeBrowserProxyImpl.getInstance().restart();
505 </if> 509 /* </if> */
506 }, 510 },
507 511
508 /** 512 /**
509 * Toggles the expand button within the element being listened to. 513 * Toggles the expand button within the element being listened to.
510 * @param {!Event} e 514 * @param {!Event} e
511 * @private 515 * @private
512 */ 516 */
513 toggleExpandButton_: function(e) { 517 toggleExpandButton_: function(e) {
514 // The expand button handles toggling itself. 518 // The expand button handles toggling itself.
515 var expandButtonTag = 'CR-EXPAND-BUTTON'; 519 var expandButtonTag = 'CR-EXPAND-BUTTON';
516 if (e.target.tagName == expandButtonTag) 520 if (e.target.tagName == expandButtonTag)
517 return; 521 return;
518 522
519 /** @type {!CrExpandButtonElement} */ 523 /** @type {!CrExpandButtonElement} */
520 var expandButton = e.currentTarget.querySelector(expandButtonTag); 524 var expandButton = e.currentTarget.querySelector(expandButtonTag);
521 assert(expandButton); 525 assert(expandButton);
522 expandButton.expanded = !expandButton.expanded; 526 expandButton.expanded = !expandButton.expanded;
523 }, 527 },
524 }); 528 });
525 })(); 529 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698