Chromium Code Reviews| 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 '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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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/unset 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 && | |
|
michaelpg
2016/12/13 05:33:09
Simplifying this because it leads to bugs and it's
| |
| 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/from 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 if (e.target.checked) { |
| 169 this.languageHelper.setUILanguage(this.detailLanguage_.language.code); | 164 this.languageHelper.setProspectiveUILanguage( |
| 165 this.detailLanguage_.language.code); | |
| 170 } else if (this.detailLanguage_.language.code == | 166 } else if (this.detailLanguage_.language.code == |
| 171 this.languageHelper.getProspectiveUILanguage()) { | 167 this.languages.prospectiveUILanguage) { |
| 172 // Reset the chosen UI language to the actual UI language. | 168 // Reset the chosen UI language to the actual UI language. |
| 173 this.languageHelper.resetUILanguage(); | 169 this.languageHelper.resetProspectiveUILanguage(); |
| 174 } | 170 } |
| 175 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); | 171 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); |
| 176 }, | 172 }, |
| 177 | 173 |
| 178 /** | 174 /** |
| 179 * @param {!chrome.languageSettingsPrivate.Language} language | 175 * @param {!chrome.languageSettingsPrivate.Language} language |
| 180 * @param {string} targetLanguageCode The default translate target language. | 176 * @param {string} targetLanguageCode The default translate target language. |
| 181 * @return {boolean} True if the translate checkbox should be disabled. | 177 * @return {boolean} True if the translate checkbox should be disabled. |
| 182 * @private | 178 * @private |
| 183 */ | 179 */ |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 * language to use in Chrome) matches the current language. This pref is used | 345 * 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. | 346 * only on Chrome OS and Windows; we don't control the UI language elsewhere. |
| 351 * @param {string} languageCode The language code identifying a language. | 347 * @param {string} languageCode The language code identifying a language. |
| 352 * @param {string} prospectiveUILanguage The prospective UI language. | 348 * @param {string} prospectiveUILanguage The prospective UI language. |
| 353 * @return {boolean} True if the given language matches the prospective UI | 349 * @return {boolean} True if the given language matches the prospective UI |
| 354 * pref (which may be different from the actual UI language). | 350 * pref (which may be different from the actual UI language). |
| 355 * @private | 351 * @private |
| 356 */ | 352 */ |
| 357 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { | 353 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { |
| 358 assert(cr.isChromeOS || cr.isWindows); | 354 assert(cr.isChromeOS || cr.isWindows); |
| 359 return languageCode == this.languageHelper.getProspectiveUILanguage(); | 355 return languageCode == prospectiveUILanguage; |
| 360 }, | 356 }, |
| 361 | 357 |
| 362 <if expr="chromeos or is_win"> | 358 <if expr="chromeos or is_win"> |
| 363 /** | 359 /** |
| 360 * @param {string} prospectiveUILanguage | |
| 364 * @return {string} | 361 * @return {string} |
| 365 * @private | 362 * @private |
| 366 */ | 363 */ |
| 367 getProspectiveUILanguageName_: function() { | 364 getProspectiveUILanguageName_: function(prospectiveUILanguage) { |
| 368 return this.languageHelper.getLanguage( | 365 return this.languageHelper.getLanguage(prospectiveUILanguage).displayName; |
| 369 this.languageHelper.getProspectiveUILanguage()).displayName; | |
| 370 }, | 366 }, |
| 371 </if> | 367 </if> |
| 372 | 368 |
| 373 /** | 369 /** |
| 374 * @return {string} | 370 * @return {string} |
| 375 * @private | 371 * @private |
| 376 */ | 372 */ |
| 377 getLanguageListTwoLine_: function() { | 373 getLanguageListTwoLine_: function() { |
| 378 return cr.isChromeOS || cr.isWindows ? 'two-line' : ''; | 374 return cr.isChromeOS || cr.isWindows ? 'two-line' : ''; |
| 379 }, | 375 }, |
| 380 | 376 |
| 381 /** | 377 /** |
| 382 * @return {string} | 378 * @return {string} |
| 383 * @private | 379 * @private |
| 384 */ | 380 */ |
| 385 getSpellCheckListTwoLine_: function() { | 381 getSpellCheckListTwoLine_: function() { |
| 386 return this.spellCheckSecondaryText_.length ? 'two-line' : ''; | 382 return this.spellCheckSecondaryText_.length ? 'two-line' : ''; |
| 387 }, | 383 }, |
| 388 | 384 |
| 389 /** | 385 /** |
| 390 * Returns either the "selected" class, if the language matches the | 386 * Returns either the "selected" class, if the language matches the |
| 391 * prospective UI language, or an empty string. Languages can only be | 387 * prospective UI language, or an empty string. Languages can only be |
| 392 * selected on Chrome OS and Windows. | 388 * selected on Chrome OS and Windows. |
| 393 * @param {string} languageCode The language code identifying a language. | 389 * @param {string} languageCode The language code identifying a language. |
| 394 * @param {string} prospectiveUILanguage The prospective UI language. | 390 * @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. | 391 * @return {string} The class name for the language item. |
| 398 * @private | 392 * @private |
| 399 */ | 393 */ |
| 400 getLanguageItemClass_: function(languageCode, prospectiveUILanguage, | 394 getLanguageItemClass_: function(languageCode, prospectiveUILanguage) { |
| 401 supportsUI) { | |
| 402 if ((cr.isChromeOS || cr.isWindows) && | 395 if ((cr.isChromeOS || cr.isWindows) && |
| 403 this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage)) { | 396 languageCode == prospectiveUILanguage) { |
| 404 return 'selected'; | 397 return 'selected'; |
| 405 } | 398 } |
| 406 return ''; | 399 return ''; |
| 407 }, | 400 }, |
| 408 | 401 |
| 409 /** | 402 /** |
| 410 * @param {string} languageCode The language code identifying a language. | 403 * @param {string} languageCode The language code identifying a language. |
| 411 * @param {string} prospectiveUILanguage The prospective UI language. | 404 * @param {string} prospectiveUILanguage The prospective UI language. |
| 412 * @return {boolean} True if the prospective UI language is set to | 405 * @return {boolean} True if the prospective UI language is set to |
| 413 * |languageCode| but requires a restart to take effect. | 406 * |languageCode| but requires a restart to take effect. |
| 414 * @private | 407 * @private |
| 415 */ | 408 */ |
| 416 isRestartRequired_: function(languageCode, prospectiveUILanguage) { | 409 isRestartRequired_: function(languageCode, prospectiveUILanguage) { |
| 417 return prospectiveUILanguage == languageCode && | 410 return prospectiveUILanguage == languageCode && |
| 418 navigator.language != languageCode; | 411 this.languageHelper.requiresRestart(); |
| 419 }, | 412 }, |
| 420 | 413 |
| 421 /** | 414 /** |
| 422 * @param {string} id The input method ID. | 415 * @param {string} id The input method ID. |
| 423 * @param {string} currentId The ID of the currently enabled input method. | 416 * @param {string} currentId The ID of the currently enabled input method. |
| 424 * @return {boolean} True if the IDs match. | 417 * @return {boolean} True if the IDs match. |
| 425 * @private | 418 * @private |
| 426 */ | 419 */ |
| 427 isCurrentInputMethod_: function(id, currentId) { | 420 isCurrentInputMethod_: function(id, currentId) { |
| 428 assert(cr.isChromeOS); | 421 assert(cr.isChromeOS); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 if (e.target.tagName == expandButtonTag) | 515 if (e.target.tagName == expandButtonTag) |
| 523 return; | 516 return; |
| 524 | 517 |
| 525 /** @type {!CrExpandButtonElement} */ | 518 /** @type {!CrExpandButtonElement} */ |
| 526 var expandButton = e.currentTarget.querySelector(expandButtonTag); | 519 var expandButton = e.currentTarget.querySelector(expandButtonTag); |
| 527 assert(expandButton); | 520 assert(expandButton); |
| 528 expandButton.expanded = !expandButton.expanded; | 521 expandButton.expanded = !expandButton.expanded; |
| 529 }, | 522 }, |
| 530 }); | 523 }); |
| 531 })(); | 524 })(); |
| OLD | NEW |