| 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'); | 9 cr.exportPath('settings'); |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 * @type {!LanguagesModel|undefined} | 35 * @type {!LanguagesModel|undefined} |
| 36 */ | 36 */ |
| 37 languages: { | 37 languages: { |
| 38 type: Object, | 38 type: Object, |
| 39 notify: true, | 39 notify: true, |
| 40 }, | 40 }, |
| 41 | 41 |
| 42 /** @type {!LanguageHelper} */ | 42 /** @type {!LanguageHelper} */ |
| 43 languageHelper: Object, | 43 languageHelper: Object, |
| 44 | 44 |
| 45 // <if expr="not is_macosx"> |
| 45 /** @private */ | 46 /** @private */ |
| 46 spellCheckSecondaryText_: { | 47 spellCheckSecondaryText_: { |
| 47 type: String, | 48 type: String, |
| 48 value: '', | 49 value: '', |
| 49 computed: 'getSpellCheckSecondaryText_(languages.enabled.*)', | 50 computed: 'getSpellCheckSecondaryText_(languages.enabled.*)', |
| 50 }, | 51 }, |
| 52 // </if> |
| 51 | 53 |
| 52 /** | 54 /** |
| 53 * The language to display the details for. | 55 * The language to display the details for. |
| 54 * @type {!LanguageState|undefined} | 56 * @type {!LanguageState|undefined} |
| 55 * @private | 57 * @private |
| 56 */ | 58 */ |
| 57 detailLanguage_: Object, | 59 detailLanguage_: Object, |
| 58 | 60 |
| 59 /** @private */ | 61 /** @private */ |
| 60 showAddLanguagesDialog_: Boolean, | 62 showAddLanguagesDialog_: Boolean, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 map.set( | 75 map.set( |
| 74 settings.Route.INPUT_METHODS.path, | 76 settings.Route.INPUT_METHODS.path, |
| 75 '#inputMethodsCollapse .subpage-arrow'); | 77 '#inputMethodsCollapse .subpage-arrow'); |
| 76 // </if> | 78 // </if> |
| 77 return map; | 79 return map; |
| 78 }, | 80 }, |
| 79 }, | 81 }, |
| 80 }, | 82 }, |
| 81 | 83 |
| 82 /** | 84 /** |
| 83 * Handler for enabling or disabling spell check. | |
| 84 * @param {!{target: Element, model: !{item: !LanguageState}}} e | |
| 85 */ | |
| 86 onSpellCheckChange_: function(e) { | |
| 87 var item = e.model.item; | |
| 88 if (!item.language.supportsSpellcheck) | |
| 89 return; | |
| 90 | |
| 91 this.languageHelper.toggleSpellCheck(item.language.code, | |
| 92 !item.spellCheckEnabled); | |
| 93 }, | |
| 94 | |
| 95 /** @private */ | |
| 96 onBackTap_: function() { | |
| 97 this.$.pages.back(); | |
| 98 }, | |
| 99 | |
| 100 /** | |
| 101 * Stamps and opens the Add Languages dialog, registering a listener to | 85 * Stamps and opens the Add Languages dialog, registering a listener to |
| 102 * disable the dialog's dom-if again on close. | 86 * disable the dialog's dom-if again on close. |
| 103 * @param {!Event} e | 87 * @param {!Event} e |
| 104 * @private | 88 * @private |
| 105 */ | 89 */ |
| 106 onAddLanguagesTap_: function(e) { | 90 onAddLanguagesTap_: function(e) { |
| 107 e.preventDefault(); | 91 e.preventDefault(); |
| 108 this.showAddLanguagesDialog_ = true; | 92 this.showAddLanguagesDialog_ = true; |
| 109 this.async(function() { | 93 this.async(function() { |
| 110 var dialog = this.$$('settings-add-languages-dialog'); | 94 var dialog = this.$$('settings-add-languages-dialog'); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 }, | 137 }, |
| 154 | 138 |
| 155 /** | 139 /** |
| 156 * @param {!Object} change Polymer change object for languages.enabled.*. | 140 * @param {!Object} change Polymer change object for languages.enabled.*. |
| 157 * @return {boolean} True if there are less than 2 languages. | 141 * @return {boolean} True if there are less than 2 languages. |
| 158 */ | 142 */ |
| 159 isHelpTextHidden_: function(change) { | 143 isHelpTextHidden_: function(change) { |
| 160 return this.languages.enabled.length <= 1; | 144 return this.languages.enabled.length <= 1; |
| 161 }, | 145 }, |
| 162 | 146 |
| 147 // <if expr="chromeos"> |
| 148 /** |
| 149 * Applies Chrome OS session tweaks to the menu. |
| 150 * @param {!CrActionMenuElement} menu |
| 151 * @private |
| 152 */ |
| 153 tweakMenuForCrOS_: function(menu) { |
| 154 // In a CrOS multi-user session, the primary user controls the UI language. |
| 155 // TODO(michaelpg): The language selection should not be hidden, but should |
| 156 // show a policy indicator. crbug.com/648498 |
| 157 if (this.isSecondaryUser_()) |
| 158 menu.querySelector('#uiLanguageItem').hidden = true; |
| 159 |
| 160 // The UI language choice doesn't persist for guests. |
| 161 if (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || |
| 162 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount()) { |
| 163 menu.querySelector('#uiLanguageItem').hidden = true; |
| 164 } |
| 165 }, |
| 166 |
| 167 /** |
| 168 * Opens the Manage Input Methods page. |
| 169 * @private |
| 170 */ |
| 171 onManageInputMethodsTap_: function() { |
| 172 settings.navigateTo(settings.Route.INPUT_METHODS); |
| 173 }, |
| 174 |
| 175 /** |
| 176 * Handler for tap and <Enter> events on an input method on the main page, |
| 177 * which sets it as the current input method. |
| 178 * @param {!{model: !{item: !chrome.languageSettingsPrivate.InputMethod}, |
| 179 * target: !{tagName: string}, |
| 180 * type: string, |
| 181 * key: (string|undefined)}} e |
| 182 */ |
| 183 onInputMethodTap_: function(e) { |
| 184 // Taps on the paper-icon-button are handled in onInputMethodOptionsTap_. |
| 185 if (e.target.tagName == 'PAPER-ICON-BUTTON') |
| 186 return; |
| 187 |
| 188 // Ignore key presses other than <Enter>. |
| 189 if (e.type == 'keypress' && e.key != 'Enter') |
| 190 return; |
| 191 |
| 192 // Set the input method. |
| 193 this.languageHelper.setCurrentInputMethod(e.model.item.id); |
| 194 }, |
| 195 |
| 196 /** |
| 197 * Opens the input method extension's options page in a new tab (or focuses |
| 198 * an existing instance of the IME's options). |
| 199 * @param {!{model: !{item: chrome.languageSettingsPrivate.InputMethod}}} e |
| 200 * @private |
| 201 */ |
| 202 onInputMethodOptionsTap_: function(e) { |
| 203 this.languageHelper.openInputMethodOptions(e.model.item.id); |
| 204 }, |
| 205 // </if> |
| 206 |
| 207 // <if expr="chromeos or is_win"> |
| 208 /** |
| 209 * @return {boolean} True for a secondary user in a multi-profile session. |
| 210 * @private |
| 211 */ |
| 212 isSecondaryUser_: function() { |
| 213 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser'); |
| 214 }, |
| 215 |
| 216 /** |
| 217 * @param {string} languageCode The language code identifying a language. |
| 218 * @param {string} prospectiveUILanguage The prospective UI language. |
| 219 * @return {boolean} True if the prospective UI language is set to |
| 220 * |languageCode| but requires a restart to take effect. |
| 221 * @private |
| 222 */ |
| 223 isRestartRequired_: function(languageCode, prospectiveUILanguage) { |
| 224 return prospectiveUILanguage == languageCode && |
| 225 this.languageHelper.requiresRestart(); |
| 226 }, |
| 227 |
| 163 /** | 228 /** |
| 164 * @param {!LanguageState} languageState | 229 * @param {!LanguageState} languageState |
| 165 * @param {string} prospectiveUILanguage The chosen UI language. | 230 * @param {string} prospectiveUILanguage The chosen UI language. |
| 166 * @return {boolean} True if the given language cannot be set as the | 231 * @return {boolean} True if the given language cannot be set as the |
| 167 * prospective UI language by the user. | 232 * prospective UI language by the user. |
| 168 * @private | 233 * @private |
| 169 */ | 234 */ |
| 170 disableUILanguageCheckbox_: function(languageState, prospectiveUILanguage) { | 235 disableUILanguageCheckbox_: function(languageState, prospectiveUILanguage) { |
| 171 // UI language setting belongs to the primary user. | 236 // UI language setting belongs to the primary user. |
| 172 if (this.isSecondaryUser_()) | 237 if (this.isSecondaryUser_()) |
| 173 return true; | 238 return true; |
| 174 | 239 |
| 175 // If the language cannot be a UI language, we can't set it as the | 240 // If the language cannot be a UI language, we can't set it as the |
| 176 // prospective UI language. | 241 // prospective UI language. |
| 177 if (!languageState.language.supportsUI) | 242 if (!languageState.language.supportsUI) |
| 178 return true; | 243 return true; |
| 179 | 244 |
| 180 // Unchecking the currently chosen language doesn't make much sense. | 245 // Unchecking the currently chosen language doesn't make much sense. |
| 181 if (languageState.language.code == prospectiveUILanguage) | 246 if (languageState.language.code == prospectiveUILanguage) |
| 182 return true; | 247 return true; |
| 183 | 248 |
| 184 // Otherwise, the prospective language can be changed to this language. | 249 // Otherwise, the prospective language can be changed to this language. |
| 185 return false; | 250 return false; |
| 186 }, | 251 }, |
| 187 | 252 |
| 188 /** | 253 /** |
| 189 * @return {boolean} True for a secondary user in a multi-profile session. | |
| 190 * @private | |
| 191 */ | |
| 192 isSecondaryUser_: function() { | |
| 193 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser'); | |
| 194 }, | |
| 195 | |
| 196 /** | |
| 197 * Handler for changes to the UI language checkbox. | 254 * Handler for changes to the UI language checkbox. |
| 198 * @param {!{target: !PaperCheckboxElement}} e | 255 * @param {!{target: !PaperCheckboxElement}} e |
| 199 * @private | 256 * @private |
| 200 */ | 257 */ |
| 201 onUILanguageChange_: function(e) { | 258 onUILanguageChange_: function(e) { |
| 202 // We don't support unchecking this checkbox. TODO(michaelpg): Ask for a | 259 // We don't support unchecking this checkbox. TODO(michaelpg): Ask for a |
| 203 // simpler widget. | 260 // simpler widget. |
| 204 assert(e.target.checked); | 261 assert(e.target.checked); |
| 205 this.languageHelper.setProspectiveUILanguage( | 262 this.languageHelper.setProspectiveUILanguage( |
| 206 this.detailLanguage_.language.code); | 263 this.detailLanguage_.language.code); |
| 207 | 264 |
| 208 this.closeMenuSoon_(); | 265 this.closeMenuSoon_(); |
| 209 }, | 266 }, |
| 267 // </if> |
| 210 | 268 |
| 211 /** | 269 /** |
| 212 * @param {!chrome.languageSettingsPrivate.Language} language | 270 * @param {!chrome.languageSettingsPrivate.Language} language |
| 213 * @param {string} targetLanguageCode The default translate target language. | 271 * @param {string} targetLanguageCode The default translate target language. |
| 214 * @return {boolean} True if the translate checkbox should be disabled. | 272 * @return {boolean} True if the translate checkbox should be disabled. |
| 215 * @private | 273 * @private |
| 216 */ | 274 */ |
| 217 disableTranslateCheckbox_: function(language, targetLanguageCode) { | 275 disableTranslateCheckbox_: function(language, targetLanguageCode) { |
| 218 if (!language.supportsTranslate) | 276 if (!language.supportsTranslate) |
| 219 return true; | 277 return true; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 337 |
| 280 /** | 338 /** |
| 281 * Disables the language. | 339 * Disables the language. |
| 282 * @private | 340 * @private |
| 283 */ | 341 */ |
| 284 onRemoveLanguageTap_: function() { | 342 onRemoveLanguageTap_: function() { |
| 285 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); | 343 /** @type {!CrActionMenuElement} */(this.$.menu.get()).close(); |
| 286 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); | 344 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); |
| 287 }, | 345 }, |
| 288 | 346 |
| 347 // <if expr="chromeos or is_win"> |
| 289 /** | 348 /** |
| 290 * Opens the Manage Input Methods page. | 349 * Checks whether the prospective UI language (the pref that indicates what |
| 350 * language to use in Chrome) matches the current language. This pref is used |
| 351 * only on Chrome OS and Windows; we don't control the UI language elsewhere. |
| 352 * @param {string} languageCode The language code identifying a language. |
| 353 * @param {string} prospectiveUILanguage The prospective UI language. |
| 354 * @return {boolean} True if the given language matches the prospective UI |
| 355 * pref (which may be different from the actual UI language). |
| 291 * @private | 356 * @private |
| 292 */ | 357 */ |
| 293 onManageInputMethodsTap_: function() { | 358 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { |
| 294 assert(cr.isChromeOS); | 359 return languageCode == prospectiveUILanguage; |
| 295 settings.navigateTo(settings.Route.INPUT_METHODS); | |
| 296 }, | 360 }, |
| 297 | 361 |
| 362 /** |
| 363 * @param {string} prospectiveUILanguage |
| 364 * @return {string} |
| 365 * @private |
| 366 */ |
| 367 getProspectiveUILanguageName_: function(prospectiveUILanguage) { |
| 368 return this.languageHelper.getLanguage(prospectiveUILanguage).displayName; |
| 369 }, |
| 370 // </if> |
| 371 |
| 298 /** | 372 /** |
| 299 * Handler for tap and <Enter> events on an input method on the main page, | 373 * @return {string} |
| 300 * which sets it as the current input method. | 374 * @private |
| 301 * @param {!{model: !{item: !chrome.languageSettingsPrivate.InputMethod}, | |
| 302 * target: !{tagName: string}, | |
| 303 * type: string, | |
| 304 * key: (string|undefined)}} e | |
| 305 */ | 375 */ |
| 306 onInputMethodTap_: function(e) { | 376 getLanguageListTwoLine_: function() { |
| 307 assert(cr.isChromeOS); | 377 return cr.isChromeOS || cr.isWindows ? 'two-line' : ''; |
| 308 | |
| 309 // Taps on the paper-icon-button are handled in onInputMethodOptionsTap_. | |
| 310 if (e.target.tagName == 'PAPER-ICON-BUTTON') | |
| 311 return; | |
| 312 | |
| 313 // Ignore key presses other than <Enter>. | |
| 314 if (e.type == 'keypress' && e.key != 'Enter') | |
| 315 return; | |
| 316 | |
| 317 // Set the input method. | |
| 318 this.languageHelper.setCurrentInputMethod(e.model.item.id); | |
| 319 }, | 378 }, |
| 320 | 379 |
| 321 /** | 380 // <if expr="not is_macosx"> |
| 322 * Opens the input method extension's options page in a new tab (or focuses | |
| 323 * an existing instance of the IME's options). | |
| 324 * @param {!{model: !{item: chrome.languageSettingsPrivate.InputMethod}}} e | |
| 325 * @private | |
| 326 */ | |
| 327 onInputMethodOptionsTap_: function(e) { | |
| 328 assert(cr.isChromeOS); | |
| 329 this.languageHelper.openInputMethodOptions(e.model.item.id); | |
| 330 }, | |
| 331 | |
| 332 /** | 381 /** |
| 333 * Returns the secondary text for the spell check subsection based on the | 382 * Returns the secondary text for the spell check subsection based on the |
| 334 * enabled spell check languages, listing at most 2 languages. | 383 * enabled spell check languages, listing at most 2 languages. |
| 335 * @return {string} | 384 * @return {string} |
| 336 * @private | 385 * @private |
| 337 */ | 386 */ |
| 338 getSpellCheckSecondaryText_: function() { | 387 getSpellCheckSecondaryText_: function() { |
| 339 var enabledSpellCheckLanguages = | 388 var enabledSpellCheckLanguages = |
| 340 this.languages.enabled.filter(function(languageState) { | 389 this.languages.enabled.filter(function(languageState) { |
| 341 return languageState.spellCheckEnabled && | 390 return languageState.spellCheckEnabled && |
| (...skipping 23 matching lines...) Expand all Loading... |
| 365 enabledSpellCheckLanguages[1].language.displayName, | 414 enabledSpellCheckLanguages[1].language.displayName, |
| 366 (enabledSpellCheckLanguages.length - 2).toLocaleString()); | 415 (enabledSpellCheckLanguages.length - 2).toLocaleString()); |
| 367 } | 416 } |
| 368 }, | 417 }, |
| 369 | 418 |
| 370 /** | 419 /** |
| 371 * Opens the Custom Dictionary page. | 420 * Opens the Custom Dictionary page. |
| 372 * @private | 421 * @private |
| 373 */ | 422 */ |
| 374 onEditDictionaryTap_: function() { | 423 onEditDictionaryTap_: function() { |
| 375 assert(!cr.isMac); | |
| 376 settings.navigateTo(settings.Route.EDIT_DICTIONARY); | 424 settings.navigateTo(settings.Route.EDIT_DICTIONARY); |
| 377 }, | 425 }, |
| 378 | 426 |
| 379 /** | 427 /** |
| 380 * Checks whether the prospective UI language (the pref that indicates what | 428 * Handler for enabling or disabling spell check. |
| 381 * language to use in Chrome) matches the current language. This pref is used | 429 * @param {!{target: Element, model: !{item: !LanguageState}}} e |
| 382 * only on Chrome OS and Windows; we don't control the UI language elsewhere. | |
| 383 * @param {string} languageCode The language code identifying a language. | |
| 384 * @param {string} prospectiveUILanguage The prospective UI language. | |
| 385 * @return {boolean} True if the given language matches the prospective UI | |
| 386 * pref (which may be different from the actual UI language). | |
| 387 * @private | |
| 388 */ | 430 */ |
| 389 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { | 431 onSpellCheckChange_: function(e) { |
| 390 assert(cr.isChromeOS || cr.isWindows); | 432 var item = e.model.item; |
| 391 return languageCode == prospectiveUILanguage; | 433 if (!item.language.supportsSpellcheck) |
| 392 }, | 434 return; |
| 393 | 435 |
| 394 // <if expr="chromeos or is_win"> | 436 this.languageHelper.toggleSpellCheck(item.language.code, |
| 395 /** | 437 !item.spellCheckEnabled); |
| 396 * @param {string} prospectiveUILanguage | |
| 397 * @return {string} | |
| 398 * @private | |
| 399 */ | |
| 400 getProspectiveUILanguageName_: function(prospectiveUILanguage) { | |
| 401 return this.languageHelper.getLanguage(prospectiveUILanguage).displayName; | |
| 402 }, | |
| 403 // </if> | |
| 404 | |
| 405 /** | |
| 406 * @return {string} | |
| 407 * @private | |
| 408 */ | |
| 409 getLanguageListTwoLine_: function() { | |
| 410 return cr.isChromeOS || cr.isWindows ? 'two-line' : ''; | |
| 411 }, | 438 }, |
| 412 | 439 |
| 413 /** | 440 /** |
| 414 * @return {string} | 441 * @return {string} |
| 415 * @private | 442 * @private |
| 416 */ | 443 */ |
| 417 getSpellCheckListTwoLine_: function() { | 444 getSpellCheckListTwoLine_: function() { |
| 418 return this.spellCheckSecondaryText_.length ? 'two-line' : ''; | 445 return this.spellCheckSecondaryText_.length ? 'two-line' : ''; |
| 419 }, | 446 }, |
| 447 // </if> |
| 420 | 448 |
| 421 /** | 449 /** |
| 422 * Returns either the "selected" class, if the language matches the | 450 * Returns either the "selected" class, if the language matches the |
| 423 * prospective UI language, or an empty string. Languages can only be | 451 * prospective UI language, or an empty string. Languages can only be |
| 424 * selected on Chrome OS and Windows. | 452 * selected on Chrome OS and Windows. |
| 425 * @param {string} languageCode The language code identifying a language. | 453 * @param {string} languageCode The language code identifying a language. |
| 426 * @param {string} prospectiveUILanguage The prospective UI language. | 454 * @param {string} prospectiveUILanguage The prospective UI language. |
| 427 * @return {string} The class name for the language item. | 455 * @return {string} The class name for the language item. |
| 428 * @private | 456 * @private |
| 429 */ | 457 */ |
| 430 getLanguageItemClass_: function(languageCode, prospectiveUILanguage) { | 458 getLanguageItemClass_: function(languageCode, prospectiveUILanguage) { |
| 431 if ((cr.isChromeOS || cr.isWindows) && | 459 if ((cr.isChromeOS || cr.isWindows) && |
| 432 languageCode == prospectiveUILanguage) { | 460 languageCode == prospectiveUILanguage) { |
| 433 return 'selected'; | 461 return 'selected'; |
| 434 } | 462 } |
| 435 return ''; | 463 return ''; |
| 436 }, | 464 }, |
| 437 | 465 |
| 438 /** | 466 // <if expr="chromeos"> |
| 439 * @param {string} languageCode The language code identifying a language. | |
| 440 * @param {string} prospectiveUILanguage The prospective UI language. | |
| 441 * @return {boolean} True if the prospective UI language is set to | |
| 442 * |languageCode| but requires a restart to take effect. | |
| 443 * @private | |
| 444 */ | |
| 445 isRestartRequired_: function(languageCode, prospectiveUILanguage) { | |
| 446 return prospectiveUILanguage == languageCode && | |
| 447 this.languageHelper.requiresRestart(); | |
| 448 }, | |
| 449 | |
| 450 /** | 467 /** |
| 451 * @param {string} id The input method ID. | 468 * @param {string} id The input method ID. |
| 452 * @param {string} currentId The ID of the currently enabled input method. | 469 * @param {string} currentId The ID of the currently enabled input method. |
| 453 * @return {boolean} True if the IDs match. | 470 * @return {boolean} True if the IDs match. |
| 454 * @private | 471 * @private |
| 455 */ | 472 */ |
| 456 isCurrentInputMethod_: function(id, currentId) { | 473 isCurrentInputMethod_: function(id, currentId) { |
| 457 assert(cr.isChromeOS); | 474 assert(cr.isChromeOS); |
| 458 return id == currentId; | 475 return id == currentId; |
| 459 }, | 476 }, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 470 }, | 487 }, |
| 471 | 488 |
| 472 getInputMethodName_: function(id) { | 489 getInputMethodName_: function(id) { |
| 473 assert(cr.isChromeOS); | 490 assert(cr.isChromeOS); |
| 474 var inputMethod = this.languages.inputMethods.enabled.find( | 491 var inputMethod = this.languages.inputMethods.enabled.find( |
| 475 function(inputMethod) { | 492 function(inputMethod) { |
| 476 return inputMethod.id == id; | 493 return inputMethod.id == id; |
| 477 }); | 494 }); |
| 478 return inputMethod ? inputMethod.displayName : ''; | 495 return inputMethod ? inputMethod.displayName : ''; |
| 479 }, | 496 }, |
| 497 // </if> |
| 480 | 498 |
| 481 /** | 499 /** |
| 482 * @param {!Event} e | 500 * @param {!Event} e |
| 483 * @private | 501 * @private |
| 484 */ | 502 */ |
| 485 onDotsTap_: function(e) { | 503 onDotsTap_: function(e) { |
| 486 // Set a copy of the LanguageState object since it is not data-bound to the | 504 // Set a copy of the LanguageState object since it is not data-bound to the |
| 487 // languages model directly. | 505 // languages model directly. |
| 488 this.detailLanguage_ = /** @type {!LanguageState} */(Object.assign( | 506 this.detailLanguage_ = /** @type {!LanguageState} */(Object.assign( |
| 489 {}, | 507 {}, |
| 490 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item)); | 508 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item)); |
| 491 | 509 |
| 492 // Ensure the template has been stamped. | 510 // Ensure the template has been stamped. |
| 493 var menu = /** @type {?CrActionMenuElement} */( | 511 var menu = /** @type {?CrActionMenuElement} */( |
| 494 this.$.menu.getIfExists()); | 512 this.$.menu.getIfExists()); |
| 495 if (!menu) { | 513 if (!menu) { |
| 496 menu = /** @type {!CrActionMenuElement} */(this.$.menu.get()); | 514 menu = /** @type {!CrActionMenuElement} */(this.$.menu.get()); |
| 497 this.initializeMenu_(menu); | 515 // <if expr="chromeos"> |
| 516 this.tweakMenuForCrOS_(menu); |
| 517 // </if> |
| 498 } | 518 } |
| 499 | 519 |
| 500 menu.showAt(/** @type {!Element} */ (e.target)); | 520 menu.showAt(/** @type {!Element} */ (e.target)); |
| 501 }, | 521 }, |
| 502 | 522 |
| 503 /** | 523 /** |
| 504 * Applies Chrome OS session tweaks to the menu. | |
| 505 * @param {!CrActionMenuElement} menu | |
| 506 * @private | |
| 507 */ | |
| 508 initializeMenu_: function(menu) { | |
| 509 // In a CrOS multi-user session, the primary user controls the UI language. | |
| 510 // TODO(michaelpg): The language selection should not be hidden, but should | |
| 511 // show a policy indicator. crbug.com/648498 | |
| 512 if (this.isSecondaryUser_()) | |
| 513 menu.querySelector('#uiLanguageItem').hidden = true; | |
| 514 | |
| 515 // The UI language choice doesn't persist for guests. | |
| 516 if (cr.isChromeOS && | |
| 517 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || | |
| 518 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { | |
| 519 menu.querySelector('#uiLanguageItem').hidden = true; | |
| 520 } | |
| 521 }, | |
| 522 | |
| 523 /** | |
| 524 * Closes the shared action menu after a short delay, so when a checkbox is | 524 * Closes the shared action menu after a short delay, so when a checkbox is |
| 525 * tapped it can be seen to change state before disappearing. | 525 * tapped it can be seen to change state before disappearing. |
| 526 * @private | 526 * @private |
| 527 */ | 527 */ |
| 528 closeMenuSoon_: function() { | 528 closeMenuSoon_: function() { |
| 529 var menu = /** @type {!CrActionMenuElement} */(this.$.menu.get()); | 529 var menu = /** @type {!CrActionMenuElement} */(this.$.menu.get()); |
| 530 setTimeout(function() { | 530 setTimeout(function() { |
| 531 if (menu.open) | 531 if (menu.open) |
| 532 menu.close(); | 532 menu.close(); |
| 533 }, settings.kMenuCloseDelay); | 533 }, settings.kMenuCloseDelay); |
| 534 }, | 534 }, |
| 535 | 535 |
| 536 // <if expr="chromeos or is_win"> |
| 536 /** | 537 /** |
| 537 * Handler for the restart button. | 538 * Handler for the restart button. |
| 538 * @private | 539 * @private |
| 539 */ | 540 */ |
| 540 onRestartTap_: function() { | 541 onRestartTap_: function() { |
| 541 // <if expr="chromeos"> | 542 // <if expr="chromeos"> |
| 542 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); | 543 settings.LifetimeBrowserProxyImpl.getInstance().signOutAndRestart(); |
| 543 // </if> | 544 // </if> |
| 544 // <if expr="not chromeos"> | 545 // <if expr="is_win"> |
| 545 settings.LifetimeBrowserProxyImpl.getInstance().restart(); | 546 settings.LifetimeBrowserProxyImpl.getInstance().restart(); |
| 546 // </if> | 547 // </if> |
| 547 }, | 548 }, |
| 549 // </if> |
| 548 | 550 |
| 549 /** | 551 /** |
| 550 * Toggles the expand button within the element being listened to. | 552 * Toggles the expand button within the element being listened to. |
| 551 * @param {!Event} e | 553 * @param {!Event} e |
| 552 * @private | 554 * @private |
| 553 */ | 555 */ |
| 554 toggleExpandButton_: function(e) { | 556 toggleExpandButton_: function(e) { |
| 555 // The expand button handles toggling itself. | 557 // The expand button handles toggling itself. |
| 556 var expandButtonTag = 'CR-EXPAND-BUTTON'; | 558 var expandButtonTag = 'CR-EXPAND-BUTTON'; |
| 557 if (e.target.tagName == expandButtonTag) | 559 if (e.target.tagName == expandButtonTag) |
| 558 return; | 560 return; |
| 559 | 561 |
| 560 /** @type {!CrExpandButtonElement} */ | 562 /** @type {!CrExpandButtonElement} */ |
| 561 var expandButton = e.currentTarget.querySelector(expandButtonTag); | 563 var expandButton = e.currentTarget.querySelector(expandButtonTag); |
| 562 assert(expandButton); | 564 assert(expandButton); |
| 563 expandButton.expanded = !expandButton.expanded; | 565 expandButton.expanded = !expandButton.expanded; |
| 564 }, | 566 }, |
| 565 }); | 567 }); |
| 566 })(); | 568 })(); |
| OLD | NEW |