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 'cr-settings-languages-page' is the settings page | 6 * @fileoverview 'cr-settings-languages-page' is the settings page |
| 7 * for language and input method settings. | 7 * for language and input method settings. |
| 8 * | 8 * |
| 9 * @group Chrome Settings Elements | 9 * @group Chrome Settings Elements |
| 10 * @element cr-settings-languages-page | 10 * @element cr-settings-languages-page |
| 11 */ | 11 */ |
| 12 (function() { | |
| 13 'use strict'; | |
| 14 | |
| 12 Polymer({ | 15 Polymer({ |
| 13 is: 'cr-settings-languages-page', | 16 is: 'cr-settings-languages-page', |
| 14 | 17 |
| 15 properties: { | 18 properties: { |
| 16 /** | 19 /** |
| 20 * The current active route. | |
| 21 */ | |
| 22 currentRoute: { | |
| 23 type: Object, | |
| 24 notify: true, | |
| 25 }, | |
| 26 | |
| 27 /** | |
| 17 * Preferences state. | 28 * Preferences state. |
| 18 */ | 29 */ |
| 19 prefs: { | 30 prefs: { |
| 20 type: Object, | 31 type: Object, |
| 21 notify: true, | 32 notify: true, |
| 22 }, | 33 }, |
| 23 | 34 |
| 24 dummyLanguages_: { | |
| 25 type: Array, | |
| 26 value: function() { | |
| 27 return [{code: 'en', displayName: 'English', supportsSpellcheck: true}, | |
| 28 {code: 'es', displayName: 'Spanish', supportsSpellcheck: true}, | |
| 29 {code: 'ru', displayName: 'Russian', supportsSpellcheck: true}, | |
| 30 {code: 'ar', displayName: 'Arabic'}]; | |
| 31 }, | |
| 32 }, | |
| 33 | |
| 34 dummyInputMethods_: { | |
| 35 type: Array, | |
| 36 value: function() { | |
| 37 return [{id: 'us', name: 'US Keyboard'}, | |
| 38 {id: 'fr', name: 'French Keyboard'}]; | |
| 39 }, | |
| 40 }, | |
| 41 | |
| 42 dummyAppLocale_: { | |
| 43 type: String, | |
| 44 value: 'en', | |
| 45 }, | |
| 46 | |
| 47 dummyCurrentInputMethod_: { | |
| 48 type: String, | |
| 49 value: 'us', | |
| 50 }, | |
| 51 | |
| 52 dummySpellcheckDictionaries_: { | |
| 53 type: Array, | |
| 54 value: function() { | |
| 55 return ['en', 'es', 'ru']; | |
| 56 }, | |
| 57 }, | |
| 58 | |
| 59 route: String, | |
| 60 | |
| 61 /** | 35 /** |
| 62 * Whether the page is a subpage. | 36 * Languages model. |
|
stevenjb
2015/09/22 16:47:33
I think a bit more of a comment would be useful he
michaelpg
2015/09/23 21:27:27
Done.
| |
| 37 * @type {(LanguagesModel|undefined)} | |
| 63 */ | 38 */ |
| 64 subpage: { | 39 model: { |
|
stevenjb
2015/09/22 16:47:34
I think it would clarify things a little for me if
michaelpg
2015/09/23 21:27:27
Done (model -> languages).
| |
| 65 type: Boolean, | 40 type: Object, |
| 66 value: false, | 41 notify: true, |
|
stevenjb
2015/09/22 16:47:34
can we make this readOnly?
michaelpg
2015/09/23 21:27:27
no, readOnly would prevent it from being updatable
| |
| 67 readOnly: true | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * ID of the page. | |
| 72 */ | |
| 73 PAGE_ID: { | |
| 74 type: String, | |
| 75 value: 'languages', | |
| 76 readOnly: true | |
| 77 }, | |
| 78 | |
| 79 /** | |
| 80 * Title for the page header and navigation menu. | |
| 81 */ | |
| 82 pageTitle: { | |
| 83 type: String, | |
| 84 value: function() { | |
| 85 return loadTimeData.getString('languagesPageTitle'); | |
| 86 }, | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * Name of the 'iron-icon' to be shown in the settings-page-header. | |
| 91 */ | |
| 92 icon: { | |
| 93 type: String, | |
| 94 value: 'language', | |
| 95 readOnly: true | |
| 96 }, | 42 }, |
| 97 }, | 43 }, |
| 98 | 44 |
| 99 /** | 45 /** |
| 100 * @param {!Array<!Language>} languages | 46 * Handler for clicking a language on the main page, which selects the |
| 101 * @return {!Array<!Language>} The languages from |languages| which support | 47 * language as the prospective UI language on Chrome OS and Windows. |
| 102 * spell check. | 48 * @param {!{model: !{item: !{language: !{code: string}}}}} e |
| 49 */ | |
| 50 onLanguageTap_: function(e) { | |
| 51 // Set the prospective UI language. This won't take effect until a restart. | |
| 52 if (cr.isChromeOS || cr.isWindows) | |
|
stevenjb
2015/09/22 16:47:33
I think this if() would be better in setUILanguage
michaelpg
2015/09/23 21:27:27
The UI (a list of languages on the advanced page)
| |
| 53 this.$.languages.setUILanguage(e.model.item.language.code); | |
| 54 }, | |
| 55 | |
| 56 /** | |
| 57 * Handler for enabling or disabling spell check. | |
| 58 * @param {!{target: Element, model: !{item: !{language: !{code: string}}}}} e | |
| 59 */ | |
| 60 onSpellCheckChange_: function(e) { | |
| 61 this.$.languages.toggleSpellCheck(e.model.item.language.code, | |
| 62 e.target.checked); | |
| 63 }, | |
| 64 | |
| 65 /** @private */ | |
| 66 onBackTap_: function() { | |
| 67 this.$.pages.back(); | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * Opens the Manage Languages page. | |
| 103 * @private | 72 * @private |
| 104 */ | 73 */ |
| 105 getSpellcheckLanguages_: function(languages) { | 74 onManageLanguagesTap_: function() { |
| 106 return languages.filter(function(language) { | 75 this.$.pages.setSubpageChain(['manage-languages']); |
| 107 return language.supportsSpellcheck; | 76 // TODO(michaelpg): This is necessary to show the list when navigating to |
|
stevenjb
2015/09/22 16:47:33
nit: TODO(): Remove... (?)
michaelpg
2015/09/23 21:27:27
Done.
| |
| 108 }); | 77 // the sub-page. Probably due to PolymerElements/neon-animation#60. |
| 78 /** @type {{_render: function()}} */(this.$.manageLanguagesPage.$.list) | |
| 79 ._render(); | |
| 109 }, | 80 }, |
| 110 | 81 |
| 111 /** | 82 /** |
| 112 * @param {string} languageCode The language code identifying a language. | 83 * @param {string} languageCode The language code identifying a language. |
| 113 * @param {string} dummyAppLocale A fake app locale. | 84 * @param {string} appLocale The prospective UI language. |
| 114 * @return {boolean} True if the given language matches the app locale pref | 85 * @return {boolean} True if the given language matches the app locale pref |
| 115 * (which may be different from the actual app locale if it was changed). | 86 * (which may be different from the actual app locale). |
| 116 * @private | 87 * @private |
| 117 */ | 88 */ |
| 118 isUILanguage_: function(languageCode, dummyAppLocale) { | 89 isUILanguage_: function(languageCode, appLocale) { |
| 119 return languageCode == dummyAppLocale; | 90 // Check the current language if the locale pref hasn't been set. |
| 91 if (!appLocale) | |
| 92 appLocale = navigator.language; | |
| 93 return languageCode == appLocale; | |
| 120 }, | 94 }, |
| 121 | 95 |
| 122 /** | 96 /** |
| 123 * @param {string} id The input method ID. | 97 * @param {string} id The input method ID. |
| 124 * @param {string} currentId The ID of the currently enabled input method. | 98 * @param {string} currentId The ID of the currently enabled input method. |
| 125 * @return {boolean} True if the IDs match. | 99 * @return {boolean} True if the IDs match. |
| 126 * @private | 100 * @private |
| 127 */ | 101 */ |
| 128 isCurrentInputMethod_: function(id, currentId) { | 102 isCurrentInputMethod_: function(id, currentId) { |
| 129 assert(cr.isChromeOS); | 103 assert(cr.isChromeOS); |
| 130 return id == currentId; | 104 return id == currentId; |
| 131 }, | 105 }, |
| 132 | |
| 133 /** | |
| 134 * @param {string} languageCode The language code identifying a language. | |
| 135 * @param {!Array<string>} spellcheckDictionaries The list of languages | |
| 136 * for which spell check is enabled. | |
| 137 * @return {boolean} True if spell check is enabled for the language. | |
| 138 * @private | |
| 139 */ | |
| 140 isSpellcheckEnabled_: function(languageCode, spellcheckDictionaries) { | |
| 141 return spellcheckDictionaries.indexOf(languageCode) != -1; | |
| 142 }, | |
| 143 }); | 106 }); |
| 107 })(); | |
| OLD | NEW |