| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 * @private | 178 * @private |
| 179 */ | 179 */ |
| 180 onUILanguageChange_: function(e) { | 180 onUILanguageChange_: function(e) { |
| 181 if (e.target.checked) { | 181 if (e.target.checked) { |
| 182 this.languageHelper.setUILanguage(this.detailLanguage_.language.code); | 182 this.languageHelper.setUILanguage(this.detailLanguage_.language.code); |
| 183 } else if (this.detailLanguage_.language.code == | 183 } else if (this.detailLanguage_.language.code == |
| 184 this.languageHelper.getProspectiveUILanguage()) { | 184 this.languageHelper.getProspectiveUILanguage()) { |
| 185 // Reset the chosen UI language to the actual UI language. | 185 // Reset the chosen UI language to the actual UI language. |
| 186 this.languageHelper.resetUILanguage(); | 186 this.languageHelper.resetUILanguage(); |
| 187 } | 187 } |
| 188 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); | 188 /** @type {!SettingsActionMenuElement} */(this.$.menu.get()).close(); |
| 189 }, | 189 }, |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * @param {!chrome.languageSettingsPrivate.Language} language | 192 * @param {!chrome.languageSettingsPrivate.Language} language |
| 193 * @param {string} targetLanguageCode The default translate target language. | 193 * @param {string} targetLanguageCode The default translate target language. |
| 194 * @return {boolean} True if the translate checkbox should be disabled. | 194 * @return {boolean} True if the translate checkbox should be disabled. |
| 195 * @private | 195 * @private |
| 196 */ | 196 */ |
| 197 disableTranslateCheckbox_: function(language, targetLanguageCode) { | 197 disableTranslateCheckbox_: function(language, targetLanguageCode) { |
| 198 if (!language.supportsTranslate) | 198 if (!language.supportsTranslate) |
| 199 return true; | 199 return true; |
| 200 | 200 |
| 201 return this.languageHelper.convertLanguageCodeForTranslate(language.code) == | 201 return this.languageHelper.convertLanguageCodeForTranslate(language.code) == |
| 202 targetLanguageCode; | 202 targetLanguageCode; |
| 203 }, | 203 }, |
| 204 | 204 |
| 205 /** | 205 /** |
| 206 * Handler for changes to the translate checkbox. | 206 * Handler for changes to the translate checkbox. |
| 207 * @param {!{target: !PaperCheckboxElement}} e | 207 * @param {!{target: !PaperCheckboxElement}} e |
| 208 * @private | 208 * @private |
| 209 */ | 209 */ |
| 210 onTranslateCheckboxChange_: function(e) { | 210 onTranslateCheckboxChange_: function(e) { |
| 211 if (e.target.checked) { | 211 if (e.target.checked) { |
| 212 this.languageHelper.enableTranslateLanguage( | 212 this.languageHelper.enableTranslateLanguage( |
| 213 this.detailLanguage_.language.code); | 213 this.detailLanguage_.language.code); |
| 214 } else { | 214 } else { |
| 215 this.languageHelper.disableTranslateLanguage( | 215 this.languageHelper.disableTranslateLanguage( |
| 216 this.detailLanguage_.language.code); | 216 this.detailLanguage_.language.code); |
| 217 } | 217 } |
| 218 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); | 218 /** @type {!SettingsActionMenuElement} */(this.$.menu.get()).close(); |
| 219 }, | 219 }, |
| 220 | 220 |
| 221 /** | 221 /** |
| 222 * Returns "complex" if the menu includes checkboxes, which should change the | 222 * Returns "complex" if the menu includes checkboxes, which should change the |
| 223 * spacing of items and show a separator in the menu. | 223 * spacing of items and show a separator in the menu. |
| 224 * @param {boolean} translateEnabled | 224 * @param {boolean} translateEnabled |
| 225 * @return {string} | 225 * @return {string} |
| 226 */ | 226 */ |
| 227 getMenuClass_: function(translateEnabled) { | 227 getMenuClass_: function(translateEnabled) { |
| 228 if (translateEnabled || cr.isChromeOS || cr.isWindows) | 228 if (translateEnabled || cr.isChromeOS || cr.isWindows) |
| 229 return 'complex'; | 229 return 'complex'; |
| 230 return ''; | 230 return ''; |
| 231 }, | 231 }, |
| 232 | 232 |
| 233 /** | 233 /** |
| 234 * Moves the language to the top of the list. | 234 * Moves the language to the top of the list. |
| 235 * @private | 235 * @private |
| 236 */ | 236 */ |
| 237 onMoveToTopTap_: function() { | 237 onMoveToTopTap_: function() { |
| 238 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); | 238 /** @type {!SettingsActionMenuElement} */(this.$.menu.get()).close(); |
| 239 this.languageHelper.moveLanguageToFront(this.detailLanguage_.language.code); | 239 this.languageHelper.moveLanguageToFront(this.detailLanguage_.language.code); |
| 240 }, | 240 }, |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * Moves the language up in the list. | 243 * Moves the language up in the list. |
| 244 * @private | 244 * @private |
| 245 */ | 245 */ |
| 246 onMoveUpTap_: function() { | 246 onMoveUpTap_: function() { |
| 247 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); | 247 /** @type {!SettingsActionMenuElement} */(this.$.menu.get()).close(); |
| 248 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); | 248 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); |
| 249 }, | 249 }, |
| 250 | 250 |
| 251 /** | 251 /** |
| 252 * Moves the language down in the list. | 252 * Moves the language down in the list. |
| 253 * @private | 253 * @private |
| 254 */ | 254 */ |
| 255 onMoveDownTap_: function() { | 255 onMoveDownTap_: function() { |
| 256 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); | 256 /** @type {!SettingsActionMenuElement} */(this.$.menu.get()).close(); |
| 257 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); | 257 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); |
| 258 }, | 258 }, |
| 259 | 259 |
| 260 /** | 260 /** |
| 261 * Disables the language. | 261 * Disables the language. |
| 262 * @private | 262 * @private |
| 263 */ | 263 */ |
| 264 onRemoveLanguageTap_: function() { | 264 onRemoveLanguageTap_: function() { |
| 265 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); | 265 /** @type {!SettingsActionMenuElement} */(this.$.menu.get()).close(); |
| 266 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); | 266 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); |
| 267 }, | 267 }, |
| 268 | 268 |
| 269 /** | 269 /** |
| 270 * Opens the Manage Input Methods page. | 270 * Opens the Manage Input Methods page. |
| 271 * @private | 271 * @private |
| 272 */ | 272 */ |
| 273 onManageInputMethodsTap_: function() { | 273 onManageInputMethodsTap_: function() { |
| 274 assert(cr.isChromeOS); | 274 assert(cr.isChromeOS); |
| 275 settings.navigateTo(settings.Route.INPUT_METHODS); | 275 settings.navigateTo(settings.Route.INPUT_METHODS); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 * HACK(michaelpg): This is necessary to show the list when navigating to | 442 * HACK(michaelpg): This is necessary to show the list when navigating to |
| 443 * the sub-page. Remove this function when PolymerElements/neon-animation#60 | 443 * the sub-page. Remove this function when PolymerElements/neon-animation#60 |
| 444 * is fixed. | 444 * is fixed. |
| 445 * @param {string} tagName Name of the element containing the <iron-list>. | 445 * @param {string} tagName Name of the element containing the <iron-list>. |
| 446 */ | 446 */ |
| 447 forceRenderList_: function(tagName) { | 447 forceRenderList_: function(tagName) { |
| 448 this.$$(tagName).$$('iron-list').fire('iron-resize'); | 448 this.$$(tagName).$$('iron-list').fire('iron-resize'); |
| 449 }, | 449 }, |
| 450 | 450 |
| 451 /** | 451 /** |
| 452 * Opens or closes the shared menu at the location of the tapped item. | |
| 453 * @param {!Event} e | 452 * @param {!Event} e |
| 454 * @private | 453 * @private |
| 455 */ | 454 */ |
| 456 toggleMenu_: function(e) { | 455 onDotsTap_: function(e) { |
| 457 e.stopPropagation(); // Prevent the tap event from closing the menu. | |
| 458 | |
| 459 this.detailLanguage_ = | 456 this.detailLanguage_ = |
| 460 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item; | 457 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item; |
| 461 | 458 |
| 462 // Ensure the template has been stamped. | 459 // Ensure the template has been stamped. |
| 463 var menu = /** @type {?CrSharedMenuElement} */(this.$.menu.getIfExists()); | 460 var menu = /** @type {?SettingsActionMenuElement} */( |
| 461 this.$.menu.getIfExists()); |
| 464 if (!menu) { | 462 if (!menu) { |
| 465 menu = /** @type {!CrSharedMenuElement} */(this.$.menu.get()); | 463 menu = /** @type {!SettingsActionMenuElement} */(this.$.menu.get()); |
| 466 this.initializeMenu_(menu); | 464 this.initializeMenu_(menu); |
| 467 } | 465 } |
| 468 | 466 |
| 469 menu.toggleMenu(/** @type {!Element} */(e.target)); | 467 menu.showAt(/** @type {!Element} */ (e.target)); |
| 470 }, | 468 }, |
| 471 | 469 |
| 472 /** | 470 /** |
| 473 * Applies Chrome OS session tweaks to the menu. | 471 * Applies Chrome OS session tweaks to the menu. |
| 474 * @param {!CrSharedMenuElement} menu | 472 * @param {!SettingsActionMenuElement} menu |
| 475 * @private | 473 * @private |
| 476 */ | 474 */ |
| 477 initializeMenu_: function(menu) { | 475 initializeMenu_: function(menu) { |
| 478 // In a CrOS multi-user session, the primary user controls the UI language. | 476 // In a CrOS multi-user session, the primary user controls the UI language. |
| 479 // TODO(michaelpg): The language selection should not be hidden, but should | 477 // TODO(michaelpg): The language selection should not be hidden, but should |
| 480 // show a policy indicator. crbug.com/648498 | 478 // show a policy indicator. crbug.com/648498 |
| 481 if (this.isSecondaryUser_()) | 479 if (this.isSecondaryUser_()) |
| 482 menu.querySelector('#uiLanguageItem').hidden = true; | 480 menu.querySelector('#uiLanguageItem').hidden = true; |
| 483 | 481 |
| 484 // The UI language choice doesn't persist for guests. | 482 // The UI language choice doesn't persist for guests. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 496 onRestartTap_: function() { | 494 onRestartTap_: function() { |
| 497 <if expr="chromeos"> | 495 <if expr="chromeos"> |
| 498 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); | 496 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); |
| 499 </if> | 497 </if> |
| 500 <if expr="not chromeos"> | 498 <if expr="not chromeos"> |
| 501 settings.LifetimeBrowserProxyImpl.getInstance().restart(); | 499 settings.LifetimeBrowserProxyImpl.getInstance().restart(); |
| 502 </if> | 500 </if> |
| 503 }, | 501 }, |
| 504 }); | 502 }); |
| 505 })(); | 503 })(); |
| OLD | NEW |