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

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

Issue 2573643005: Language settings: Fix Restart and Remove buttons shown at wrong times (Closed)
Patch Set: feedback Created 4 years 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';
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/unset 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/unset 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 // If the language already is the prospective UI language, it can't be unset 141 // Unchecking the currently chosen language doesn't make much sense.
142 // if it is also the *actual* UI language, as we wouldn't know what other 142 if (languageState.language.code == prospectiveUILanguage)
143 // language to set as the prospective UI language.
144 if (languageState.language.code == navigator.language &&
145 (!prospectiveUILanguage ||
146 languageState.language.code == prospectiveUILanguage)) {
147 return true; 143 return true;
148 }
149 144
150 // Otherwise, the prospective language can be changed to/from this language. 145 // Otherwise, the prospective language can be changed to this language.
151 return false; 146 return false;
152 }, 147 },
153 148
154 /** 149 /**
155 * @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.
156 * @private 151 * @private
157 */ 152 */
158 isSecondaryUser_: function() { 153 isSecondaryUser_: function() {
159 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser'); 154 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser');
160 }, 155 },
161 156
162 /** 157 /**
163 * Handler for changes to the UI language checkbox. 158 * Handler for changes to the UI language checkbox.
164 * @param {!{target: !PaperCheckboxElement}} e 159 * @param {!{target: !PaperCheckboxElement}} e
165 * @private 160 * @private
166 */ 161 */
167 onUILanguageChange_: function(e) { 162 onUILanguageChange_: function(e) {
168 if (e.target.checked) { 163 // We don't support unchecking this checkbox. TODO(michaelpg): Ask for a
169 this.languageHelper.setUILanguage(this.detailLanguage_.language.code); 164 // simpler widget.
170 } else if (this.detailLanguage_.language.code == 165 assert(e.target.checked);
171 this.languageHelper.getProspectiveUILanguage()) { 166 this.languageHelper.setProspectiveUILanguage(
172 // Reset the chosen UI language to the actual UI language. 167 this.detailLanguage_.language.code);
173 this.languageHelper.resetUILanguage(); 168
174 }
175 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); 169 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close();
176 }, 170 },
177 171
178 /** 172 /**
179 * @param {!chrome.languageSettingsPrivate.Language} language 173 * @param {!chrome.languageSettingsPrivate.Language} language
180 * @param {string} targetLanguageCode The default translate target language. 174 * @param {string} targetLanguageCode The default translate target language.
181 * @return {boolean} True if the translate checkbox should be disabled. 175 * @return {boolean} True if the translate checkbox should be disabled.
182 * @private 176 * @private
183 */ 177 */
184 disableTranslateCheckbox_: function(language, targetLanguageCode) { 178 disableTranslateCheckbox_: function(language, targetLanguageCode) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 * language to use in Chrome) matches the current language. This pref is used 343 * language to use in Chrome) matches the current language. This pref is used
350 * only on Chrome OS and Windows; we don't control the UI language elsewhere. 344 * only on Chrome OS and Windows; we don't control the UI language elsewhere.
351 * @param {string} languageCode The language code identifying a language. 345 * @param {string} languageCode The language code identifying a language.
352 * @param {string} prospectiveUILanguage The prospective UI language. 346 * @param {string} prospectiveUILanguage The prospective UI language.
353 * @return {boolean} True if the given language matches the prospective UI 347 * @return {boolean} True if the given language matches the prospective UI
354 * pref (which may be different from the actual UI language). 348 * pref (which may be different from the actual UI language).
355 * @private 349 * @private
356 */ 350 */
357 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { 351 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) {
358 assert(cr.isChromeOS || cr.isWindows); 352 assert(cr.isChromeOS || cr.isWindows);
359 return languageCode == this.languageHelper.getProspectiveUILanguage(); 353 return languageCode == prospectiveUILanguage;
360 }, 354 },
361 355
362 <if expr="chromeos or is_win"> 356 <if expr="chromeos or is_win">
363 /** 357 /**
358 * @param {string} prospectiveUILanguage
364 * @return {string} 359 * @return {string}
365 * @private 360 * @private
366 */ 361 */
367 getProspectiveUILanguageName_: function() { 362 getProspectiveUILanguageName_: function(prospectiveUILanguage) {
368 return this.languageHelper.getLanguage( 363 return this.languageHelper.getLanguage(prospectiveUILanguage).displayName;
369 this.languageHelper.getProspectiveUILanguage()).displayName;
370 }, 364 },
371 </if> 365 </if>
372 366
373 /** 367 /**
374 * @return {string} 368 * @return {string}
375 * @private 369 * @private
376 */ 370 */
377 getLanguageListTwoLine_: function() { 371 getLanguageListTwoLine_: function() {
378 return cr.isChromeOS || cr.isWindows ? 'two-line' : ''; 372 return cr.isChromeOS || cr.isWindows ? 'two-line' : '';
379 }, 373 },
380 374
381 /** 375 /**
382 * @return {string} 376 * @return {string}
383 * @private 377 * @private
384 */ 378 */
385 getSpellCheckListTwoLine_: function() { 379 getSpellCheckListTwoLine_: function() {
386 return this.spellCheckSecondaryText_.length ? 'two-line' : ''; 380 return this.spellCheckSecondaryText_.length ? 'two-line' : '';
387 }, 381 },
388 382
389 /** 383 /**
390 * Returns either the "selected" class, if the language matches the 384 * Returns either the "selected" class, if the language matches the
391 * prospective UI language, or an empty string. Languages can only be 385 * prospective UI language, or an empty string. Languages can only be
392 * selected on Chrome OS and Windows. 386 * selected on Chrome OS and Windows.
393 * @param {string} languageCode The language code identifying a language. 387 * @param {string} languageCode The language code identifying a language.
394 * @param {string} prospectiveUILanguage The prospective UI language. 388 * @param {string} prospectiveUILanguage The prospective UI language.
395 * @param {boolean} supportsUI Whether Chrome's UI can be shown in this
396 * language.
397 * @return {string} The class name for the language item. 389 * @return {string} The class name for the language item.
398 * @private 390 * @private
399 */ 391 */
400 getLanguageItemClass_: function(languageCode, prospectiveUILanguage, 392 getLanguageItemClass_: function(languageCode, prospectiveUILanguage) {
401 supportsUI) {
402 if ((cr.isChromeOS || cr.isWindows) && 393 if ((cr.isChromeOS || cr.isWindows) &&
403 this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage)) { 394 languageCode == prospectiveUILanguage) {
404 return 'selected'; 395 return 'selected';
405 } 396 }
406 return ''; 397 return '';
407 }, 398 },
408 399
409 /** 400 /**
410 * @param {string} languageCode The language code identifying a language. 401 * @param {string} languageCode The language code identifying a language.
411 * @param {string} prospectiveUILanguage The prospective UI language. 402 * @param {string} prospectiveUILanguage The prospective UI language.
412 * @return {boolean} True if the prospective UI language is set to 403 * @return {boolean} True if the prospective UI language is set to
413 * |languageCode| but requires a restart to take effect. 404 * |languageCode| but requires a restart to take effect.
414 * @private 405 * @private
415 */ 406 */
416 isRestartRequired_: function(languageCode, prospectiveUILanguage) { 407 isRestartRequired_: function(languageCode, prospectiveUILanguage) {
417 return prospectiveUILanguage == languageCode && 408 return prospectiveUILanguage == languageCode &&
418 navigator.language != languageCode; 409 this.languageHelper.requiresRestart();
419 }, 410 },
420 411
421 /** 412 /**
422 * @param {string} id The input method ID. 413 * @param {string} id The input method ID.
423 * @param {string} currentId The ID of the currently enabled input method. 414 * @param {string} currentId The ID of the currently enabled input method.
424 * @return {boolean} True if the IDs match. 415 * @return {boolean} True if the IDs match.
425 * @private 416 * @private
426 */ 417 */
427 isCurrentInputMethod_: function(id, currentId) { 418 isCurrentInputMethod_: function(id, currentId) {
428 assert(cr.isChromeOS); 419 assert(cr.isChromeOS);
(...skipping 28 matching lines...) Expand all
457 */ 448 */
458 forceRenderList_: function(tagName) { 449 forceRenderList_: function(tagName) {
459 this.$$(tagName).$$('iron-list').fire('iron-resize'); 450 this.$$(tagName).$$('iron-list').fire('iron-resize');
460 }, 451 },
461 452
462 /** 453 /**
463 * @param {!Event} e 454 * @param {!Event} e
464 * @private 455 * @private
465 */ 456 */
466 onDotsTap_: function(e) { 457 onDotsTap_: function(e) {
467 this.detailLanguage_ = 458 // Set a copy of the LanguageState object since it is not data-bound to the
468 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item; 459 // languages model directly.
460 this.detailLanguage_ = /** @type {!LanguageState} */(Object.assign(
461 {},
462 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item));
469 463
470 // Ensure the template has been stamped. 464 // Ensure the template has been stamped.
471 var menu = /** @type {?CrActionMenuElement} */( 465 var menu = /** @type {?CrActionMenuElement} */(
472 this.$.menu.getIfExists()); 466 this.$.menu.getIfExists());
473 if (!menu) { 467 if (!menu) {
474 menu = /** @type {!CrActionMenuElement} */(this.$.menu.get()); 468 menu = /** @type {!CrActionMenuElement} */(this.$.menu.get());
475 this.initializeMenu_(menu); 469 this.initializeMenu_(menu);
476 } 470 }
477 471
478 menu.showAt(/** @type {!Element} */ (e.target)); 472 menu.showAt(/** @type {!Element} */ (e.target));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (e.target.tagName == expandButtonTag) 516 if (e.target.tagName == expandButtonTag)
523 return; 517 return;
524 518
525 /** @type {!CrExpandButtonElement} */ 519 /** @type {!CrExpandButtonElement} */
526 var expandButton = e.currentTarget.querySelector(expandButtonTag); 520 var expandButton = e.currentTarget.querySelector(expandButtonTag);
527 assert(expandButton); 521 assert(expandButton);
528 expandButton.expanded = !expandButton.expanded; 522 expandButton.expanded = !expandButton.expanded;
529 }, 523 },
530 }); 524 });
531 })(); 525 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698