| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * @param {!Object} change Polymer change object for languages.enabled.*. | 120 * @param {!Object} change Polymer change object for languages.enabled.*. |
| 121 * @return {boolean} True if there are less than 2 languages. | 121 * @return {boolean} True if there are less than 2 languages. |
| 122 */ | 122 */ |
| 123 isHelpTextHidden_: function(change) { | 123 isHelpTextHidden_: function(change) { |
| 124 return this.languages.enabled.length <= 1; | 124 return this.languages.enabled.length <= 1; |
| 125 }, | 125 }, |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * @param {!LanguageState} languageState |
| 129 * @param {string} prospectiveUILanguage The chosen UI language. |
| 130 * @return {boolean} True if the given language cannot be set/unset as the |
| 131 * prospective UI language by the user. |
| 132 * @private |
| 133 */ |
| 134 disableUILanguageCheckbox_: function(languageState, prospectiveUILanguage) { |
| 135 // UI language setting belongs to the primary user. |
| 136 if (this.isSecondaryUser_()) |
| 137 return true; |
| 138 |
| 139 // If the language cannot be a UI language, we can't set/unset it as the |
| 140 // prospective UI language. |
| 141 if (!languageState.language.supportsUI) |
| 142 return true; |
| 143 |
| 144 // If the language already is the prospective UI language, it can't be unset |
| 145 // if it is also the *actual* UI language, as we wouldn't know what other |
| 146 // language to set as the prospective UI language. |
| 147 if (languageState.language.code == navigator.language && |
| 148 (!prospectiveUILanguage || |
| 149 languageState.language.code == prospectiveUILanguage)) { |
| 150 return true; |
| 151 } |
| 152 |
| 153 // Otherwise, the prospective language can be changed to/from this language. |
| 154 return false; |
| 155 }, |
| 156 |
| 157 /** |
| 158 * @return {boolean} True for a secondary user in a multi-profile session. |
| 159 * @private |
| 160 */ |
| 161 isSecondaryUser_: function() { |
| 162 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser'); |
| 163 }, |
| 164 |
| 165 /** |
| 166 * Handler for changes to the UI language checkbox. |
| 167 * @param {!{target: !PaperCheckboxElement}} e |
| 168 * @private |
| 169 */ |
| 170 onUILanguageChange_: function(e) { |
| 171 if (e.target.checked) { |
| 172 this.languageHelper.setUILanguage(this.detailLanguage_.language.code); |
| 173 } else if (this.detailLanguage_.language.code == |
| 174 this.languageHelper.getProspectiveUILanguage()) { |
| 175 // Reset the chosen UI language to the actual UI language. |
| 176 this.languageHelper.resetUILanguage(); |
| 177 } |
| 178 }, |
| 179 |
| 180 /** |
| 181 * @param {!chrome.languageSettingsPrivate.Language} language |
| 182 * @param {string} targetLanguageCode The default translate target language. |
| 183 * @return {boolean} True if the translate checkbox should be disabled. |
| 184 * @private |
| 185 */ |
| 186 disableTranslateCheckbox_: function(language, targetLanguageCode) { |
| 187 if (!language.supportsTranslate) |
| 188 return true; |
| 189 |
| 190 return this.languageHelper.convertLanguageCodeForTranslate(language.code) == |
| 191 targetLanguageCode; |
| 192 }, |
| 193 |
| 194 /** |
| 195 * Handler for changes to the translate checkbox. |
| 196 * @param {!{target: !PaperCheckboxElement}} e |
| 197 * @private |
| 198 */ |
| 199 onTranslateCheckboxChange_: function(e) { |
| 200 if (e.target.checked) { |
| 201 this.languageHelper.enableTranslateLanguage( |
| 202 this.detailLanguage_.language.code); |
| 203 } else { |
| 204 this.languageHelper.disableTranslateLanguage( |
| 205 this.detailLanguage_.language.code); |
| 206 } |
| 207 }, |
| 208 |
| 209 /** |
| 128 * Moves the language up in the list. | 210 * Moves the language up in the list. |
| 129 * @private | 211 * @private |
| 130 */ | 212 */ |
| 131 onMoveUpTap_: function() { | 213 onMoveUpTap_: function() { |
| 132 this.menu_.closeMenu(); | 214 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); |
| 133 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); | 215 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); |
| 134 }, | 216 }, |
| 135 | 217 |
| 136 /** | 218 /** |
| 137 * Moves the language down in the list. | 219 * Moves the language down in the list. |
| 138 * @private | 220 * @private |
| 139 */ | 221 */ |
| 140 onMoveDownTap_: function() { | 222 onMoveDownTap_: function() { |
| 141 this.menu_.closeMenu(); | 223 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); |
| 142 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); | 224 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); |
| 143 }, | 225 }, |
| 144 | 226 |
| 145 /** | 227 /** |
| 146 * Disables the language. | 228 * Disables the language. |
| 147 * @private | 229 * @private |
| 148 */ | 230 */ |
| 149 onRemoveLanguageTap_: function() { | 231 onRemoveLanguageTap_: function() { |
| 150 this.menu_.closeMenu(); | 232 /** @type {!CrSharedMenuElement} */(this.$.menu.get()).closeMenu(); |
| 151 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); | 233 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); |
| 152 }, | 234 }, |
| 153 | 235 |
| 154 /** | 236 /** |
| 155 * Opens the Language Detail page for the language. | |
| 156 * @private | |
| 157 */ | |
| 158 onShowLanguageDetailTap_: function() { | |
| 159 this.menu_.closeMenu(); | |
| 160 settings.navigateTo(settings.Route.LANGUAGES_DETAIL); | |
| 161 }, | |
| 162 | |
| 163 /** | |
| 164 * Opens the Manage Input Methods page. | 237 * Opens the Manage Input Methods page. |
| 165 * @private | 238 * @private |
| 166 */ | 239 */ |
| 167 onManageInputMethodsTap_: function() { | 240 onManageInputMethodsTap_: function() { |
| 168 assert(cr.isChromeOS); | 241 assert(cr.isChromeOS); |
| 169 settings.navigateTo(settings.Route.INPUT_METHODS); | 242 settings.navigateTo(settings.Route.INPUT_METHODS); |
| 170 }, | 243 }, |
| 171 | 244 |
| 172 /** | 245 /** |
| 173 * Handler for clicking an input method on the main page, which sets it as | 246 * Handler for clicking an input method on the main page, which sets it as |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 * @private | 313 * @private |
| 241 */ | 314 */ |
| 242 onEditDictionaryTap_: function() { | 315 onEditDictionaryTap_: function() { |
| 243 assert(!cr.isMac); | 316 assert(!cr.isMac); |
| 244 settings.navigateTo(settings.Route.EDIT_DICTIONARY); | 317 settings.navigateTo(settings.Route.EDIT_DICTIONARY); |
| 245 this.forceRenderList_('settings-edit-dictionary-page'); | 318 this.forceRenderList_('settings-edit-dictionary-page'); |
| 246 }, | 319 }, |
| 247 | 320 |
| 248 /** | 321 /** |
| 249 * Checks whether the prospective UI language (the pref that indicates what | 322 * Checks whether the prospective UI language (the pref that indicates what |
| 250 * language to use in Chrome) matches the current language. This pref is only | 323 * language to use in Chrome) matches the current language. This pref is used |
| 251 * on Chrome OS and Windows; we don't control the UI language elsewhere. | 324 * only on Chrome OS and Windows; we don't control the UI language elsewhere. |
| 252 * @param {string} languageCode The language code identifying a language. | 325 * @param {string} languageCode The language code identifying a language. |
| 253 * @param {string} prospectiveUILanguage The prospective UI language. | 326 * @param {string} prospectiveUILanguage The prospective UI language. |
| 254 * @return {boolean} True if the given language matches the prospective UI | 327 * @return {boolean} True if the given language matches the prospective UI |
| 255 * pref (which may be different from the actual UI language). | 328 * pref (which may be different from the actual UI language). |
| 256 * @private | 329 * @private |
| 257 */ | 330 */ |
| 258 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { | 331 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { |
| 259 assert(cr.isChromeOS || cr.isWindows); | 332 assert(cr.isChromeOS || cr.isWindows); |
| 260 return languageCode == this.languageHelper.getProspectiveUILanguage(); | 333 return languageCode == this.languageHelper.getProspectiveUILanguage(); |
| 261 }, | 334 }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 275 * selected on Chrome OS and Windows. | 348 * selected on Chrome OS and Windows. |
| 276 * @param {string} languageCode The language code identifying a language. | 349 * @param {string} languageCode The language code identifying a language. |
| 277 * @param {string} prospectiveUILanguage The prospective UI language. | 350 * @param {string} prospectiveUILanguage The prospective UI language. |
| 278 * @param {boolean} supportsUI Whether Chrome's UI can be shown in this | 351 * @param {boolean} supportsUI Whether Chrome's UI can be shown in this |
| 279 * language. | 352 * language. |
| 280 * @return {string} The class name for the language item. | 353 * @return {string} The class name for the language item. |
| 281 * @private | 354 * @private |
| 282 */ | 355 */ |
| 283 getLanguageItemClass_: function(languageCode, prospectiveUILanguage, | 356 getLanguageItemClass_: function(languageCode, prospectiveUILanguage, |
| 284 supportsUI) { | 357 supportsUI) { |
| 285 var classes = []; | 358 if ((cr.isChromeOS || cr.isWindows) && |
| 359 this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage)) { |
| 360 return 'selected'; |
| 361 } |
| 362 return ''; |
| 363 }, |
| 286 | 364 |
| 287 if (cr.isChromeOS || cr.isWindows) { | 365 /** |
| 288 if (supportsUI && !loadTimeData.getBoolean('isGuest')) | 366 * @param {string} languageCode The language code identifying a language. |
| 289 classes.push('list-button'); // Makes the item look "actionable". | 367 * @param {string} prospectiveUILanguage The prospective UI language. |
| 290 | 368 * @return {boolean} True if the prospective UI language is set to |
| 291 if (this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage)) | 369 * |languageCode| but requires a restart to take effect. |
| 292 classes.push('selected'); | 370 * @private |
| 293 } | 371 */ |
| 294 | 372 isRestartRequired_: function(languageCode, prospectiveUILanguage) { |
| 295 return classes.join(' '); | 373 return prospectiveUILanguage == languageCode && |
| 374 navigator.language != languageCode; |
| 296 }, | 375 }, |
| 297 | 376 |
| 298 /** | 377 /** |
| 299 * @param {string} id The input method ID. | 378 * @param {string} id The input method ID. |
| 300 * @param {string} currentId The ID of the currently enabled input method. | 379 * @param {string} currentId The ID of the currently enabled input method. |
| 301 * @return {boolean} True if the IDs match. | 380 * @return {boolean} True if the IDs match. |
| 302 * @private | 381 * @private |
| 303 */ | 382 */ |
| 304 isCurrentInputMethod_: function(id, currentId) { | 383 isCurrentInputMethod_: function(id, currentId) { |
| 305 assert(cr.isChromeOS); | 384 assert(cr.isChromeOS); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 * @param {!Event} e | 420 * @param {!Event} e |
| 342 * @private | 421 * @private |
| 343 */ | 422 */ |
| 344 toggleMenu_: function(e) { | 423 toggleMenu_: function(e) { |
| 345 e.stopPropagation(); // Prevent the tap event from closing the menu. | 424 e.stopPropagation(); // Prevent the tap event from closing the menu. |
| 346 | 425 |
| 347 this.detailLanguage_ = | 426 this.detailLanguage_ = |
| 348 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item; | 427 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item; |
| 349 | 428 |
| 350 // Ensure the template has been stamped. | 429 // Ensure the template has been stamped. |
| 351 if (!this.menu_) { | 430 var menu = /** @type {?CrSharedMenuElement} */(this.$.menu.getIfExists()); |
| 352 this.$.menuTemplate.if = true; | 431 if (!menu) { |
| 353 this.$.menuTemplate.render(); | 432 menu = /** @type {!CrSharedMenuElement} */(this.$.menu.get()); |
| 354 this.menu_ = /** @type {CrSharedMenuElement} */( | 433 this.initializeMenu_(menu); |
| 355 this.$$('cr-shared-menu')); | |
| 356 } | 434 } |
| 357 this.menu_.toggleMenu(e.target); | 435 |
| 436 menu.toggleMenu(/** @type {!Element} */(e.target)); |
| 437 }, |
| 438 |
| 439 /** |
| 440 * Applies Chrome OS session tweaks to the menu. |
| 441 * @param {!CrSharedMenuElement} menu |
| 442 * @private |
| 443 */ |
| 444 initializeMenu_: function(menu) { |
| 445 // In a CrOS multi-user session, the primary user controls the UI language. |
| 446 // TODO(michaelpg): The language selection should not be hidden, but should |
| 447 // show a policy indicator. crbug.com/648498 |
| 448 if (this.isSecondaryUser_()) |
| 449 menu.querySelector('#uiLanguageItem').hidden = true; |
| 450 |
| 451 // The UI language choice doesn't persist for guests. |
| 452 if (cr.isChromeOS && |
| 453 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || |
| 454 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { |
| 455 menu.querySelector('#uiLanguageItem').hidden = true; |
| 456 } |
| 457 }, |
| 458 |
| 459 /** |
| 460 * Handler for the restart button. |
| 461 * @private |
| 462 */ |
| 463 onRestartTap_: function() { |
| 464 <if expr="chromeos"> |
| 465 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); |
| 466 </if> |
| 467 <if expr="not chromeos"> |
| 468 settings.LifetimeBrowserProxyImpl.getInstance().restart(); |
| 469 </if> |
| 358 }, | 470 }, |
| 359 }); | 471 }); |
| 360 })(); | 472 })(); |
| OLD | NEW |