| 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 cr.exportPath('settings'); |
| 10 |
| 11 /** |
| 12 * @const {number} Millisecond delay that can be used when closing an action |
| 13 * menu to keep it briefly on-screen. |
| 14 */ |
| 15 settings.kMenuCloseDelay = 100; |
| 16 |
| 9 (function() { | 17 (function() { |
| 10 'use strict'; | 18 'use strict'; |
| 11 | 19 |
| 12 Polymer({ | 20 Polymer({ |
| 13 is: 'settings-languages-page', | 21 is: 'settings-languages-page', |
| 14 | 22 |
| 15 properties: { | 23 properties: { |
| 16 /** | 24 /** |
| 17 * Preferences state. | 25 * Preferences state. |
| 18 */ | 26 */ |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 * @param {!{target: !PaperCheckboxElement}} e | 167 * @param {!{target: !PaperCheckboxElement}} e |
| 160 * @private | 168 * @private |
| 161 */ | 169 */ |
| 162 onUILanguageChange_: function(e) { | 170 onUILanguageChange_: function(e) { |
| 163 // We don't support unchecking this checkbox. TODO(michaelpg): Ask for a | 171 // We don't support unchecking this checkbox. TODO(michaelpg): Ask for a |
| 164 // simpler widget. | 172 // simpler widget. |
| 165 assert(e.target.checked); | 173 assert(e.target.checked); |
| 166 this.languageHelper.setProspectiveUILanguage( | 174 this.languageHelper.setProspectiveUILanguage( |
| 167 this.detailLanguage_.language.code); | 175 this.detailLanguage_.language.code); |
| 168 | 176 |
| 169 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); | 177 this.closeMenuSoon_(); |
| 170 }, | 178 }, |
| 171 | 179 |
| 172 /** | 180 /** |
| 173 * @param {!chrome.languageSettingsPrivate.Language} language | 181 * @param {!chrome.languageSettingsPrivate.Language} language |
| 174 * @param {string} targetLanguageCode The default translate target language. | 182 * @param {string} targetLanguageCode The default translate target language. |
| 175 * @return {boolean} True if the translate checkbox should be disabled. | 183 * @return {boolean} True if the translate checkbox should be disabled. |
| 176 * @private | 184 * @private |
| 177 */ | 185 */ |
| 178 disableTranslateCheckbox_: function(language, targetLanguageCode) { | 186 disableTranslateCheckbox_: function(language, targetLanguageCode) { |
| 179 if (!language.supportsTranslate) | 187 if (!language.supportsTranslate) |
| 180 return true; | 188 return true; |
| 181 | 189 |
| 182 return this.languageHelper.convertLanguageCodeForTranslate(language.code) == | 190 return this.languageHelper.convertLanguageCodeForTranslate(language.code) == |
| 183 targetLanguageCode; | 191 targetLanguageCode; |
| 184 }, | 192 }, |
| 185 | 193 |
| 186 /** | 194 /** |
| 187 * Handler for changes to the translate checkbox. | 195 * Handler for changes to the translate checkbox. |
| 188 * @param {!{target: !PaperCheckboxElement}} e | 196 * @param {!{target: !PaperCheckboxElement}} e |
| 189 * @private | 197 * @private |
| 190 */ | 198 */ |
| 191 onTranslateCheckboxChange_: function(e) { | 199 onTranslateCheckboxChange_: function(e) { |
| 192 if (e.target.checked) { | 200 if (e.target.checked) { |
| 193 this.languageHelper.enableTranslateLanguage( | 201 this.languageHelper.enableTranslateLanguage( |
| 194 this.detailLanguage_.language.code); | 202 this.detailLanguage_.language.code); |
| 195 } else { | 203 } else { |
| 196 this.languageHelper.disableTranslateLanguage( | 204 this.languageHelper.disableTranslateLanguage( |
| 197 this.detailLanguage_.language.code); | 205 this.detailLanguage_.language.code); |
| 198 } | 206 } |
| 199 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); | 207 this.closeMenuSoon_(); |
| 200 }, | 208 }, |
| 201 | 209 |
| 202 /** | 210 /** |
| 203 * Returns "complex" if the menu includes checkboxes, which should change the | 211 * Returns "complex" if the menu includes checkboxes, which should change the |
| 204 * spacing of items and show a separator in the menu. | 212 * spacing of items and show a separator in the menu. |
| 205 * @param {boolean} translateEnabled | 213 * @param {boolean} translateEnabled |
| 206 * @return {string} | 214 * @return {string} |
| 207 */ | 215 */ |
| 208 getMenuClass_: function(translateEnabled) { | 216 getMenuClass_: function(translateEnabled) { |
| 209 if (translateEnabled || cr.isChromeOS || cr.isWindows) | 217 if (translateEnabled || cr.isChromeOS || cr.isWindows) |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 494 |
| 487 // The UI language choice doesn't persist for guests. | 495 // The UI language choice doesn't persist for guests. |
| 488 if (cr.isChromeOS && | 496 if (cr.isChromeOS && |
| 489 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || | 497 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || |
| 490 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { | 498 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { |
| 491 menu.querySelector('#uiLanguageItem').hidden = true; | 499 menu.querySelector('#uiLanguageItem').hidden = true; |
| 492 } | 500 } |
| 493 }, | 501 }, |
| 494 | 502 |
| 495 /** | 503 /** |
| 504 * Closes the shared action menu after a short delay, so when a checkbox is |
| 505 * tapped it can be seen to change state before disappearing. |
| 506 * @private |
| 507 */ |
| 508 closeMenuSoon_: function() { |
| 509 var menu = /** @type {!CrActionMenuElement} */(this.$.menu.get()); |
| 510 setTimeout(function() { |
| 511 if (menu.open) |
| 512 menu.close(); |
| 513 }, settings.kMenuCloseDelay); |
| 514 }, |
| 515 |
| 516 /** |
| 496 * Handler for the restart button. | 517 * Handler for the restart button. |
| 497 * @private | 518 * @private |
| 498 */ | 519 */ |
| 499 onRestartTap_: function() { | 520 onRestartTap_: function() { |
| 500 // <if expr="chromeos"> | 521 // <if expr="chromeos"> |
| 501 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); | 522 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); |
| 502 // </if> | 523 // </if> |
| 503 // <if expr="not chromeos"> | 524 // <if expr="not chromeos"> |
| 504 settings.LifetimeBrowserProxyImpl.getInstance().restart(); | 525 settings.LifetimeBrowserProxyImpl.getInstance().restart(); |
| 505 // </if> | 526 // </if> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 516 if (e.target.tagName == expandButtonTag) | 537 if (e.target.tagName == expandButtonTag) |
| 517 return; | 538 return; |
| 518 | 539 |
| 519 /** @type {!CrExpandButtonElement} */ | 540 /** @type {!CrExpandButtonElement} */ |
| 520 var expandButton = e.currentTarget.querySelector(expandButtonTag); | 541 var expandButton = e.currentTarget.querySelector(expandButtonTag); |
| 521 assert(expandButton); | 542 assert(expandButton); |
| 522 expandButton.expanded = !expandButton.expanded; | 543 expandButton.expanded = !expandButton.expanded; |
| 523 }, | 544 }, |
| 524 }); | 545 }); |
| 525 })(); | 546 })(); |
| OLD | NEW |