Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1421)

Unified Diff: chrome/browser/resources/settings/languages_page/languages_page.js

Issue 1351623008: MD Settings: Languages model for language pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SingletonPrefs
Patch Set: stevenjb model feedback Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/languages_page/languages_page.js
diff --git a/chrome/browser/resources/settings/languages_page/languages_page.js b/chrome/browser/resources/settings/languages_page/languages_page.js
index a98cef445964dfbf86f3987ee922f59eac2d466d..3fa4525ea68247722b33c7c6863fe35f30db28c0 100644
--- a/chrome/browser/resources/settings/languages_page/languages_page.js
+++ b/chrome/browser/resources/settings/languages_page/languages_page.js
@@ -9,114 +9,88 @@
* @group Chrome Settings Elements
* @element cr-settings-languages-page
*/
+(function() {
+'use strict';
+
Polymer({
is: 'cr-settings-languages-page',
properties: {
/**
- * Preferences state.
+ * The current active route.
*/
- prefs: {
+ currentRoute: {
type: Object,
notify: true,
},
- dummyLanguages_: {
- type: Array,
- value: function() {
- return [{code: 'en', displayName: 'English', supportsSpellcheck: true},
- {code: 'es', displayName: 'Spanish', supportsSpellcheck: true},
- {code: 'ru', displayName: 'Russian', supportsSpellcheck: true},
- {code: 'ar', displayName: 'Arabic'}];
- },
- },
-
- dummyInputMethods_: {
- type: Array,
- value: function() {
- return [{id: 'us', name: 'US Keyboard'},
- {id: 'fr', name: 'French Keyboard'}];
- },
- },
-
- dummyAppLocale_: {
- type: String,
- value: 'en',
- },
-
- dummyCurrentInputMethod_: {
- type: String,
- value: 'us',
- },
-
- dummySpellcheckDictionaries_: {
- type: Array,
- value: function() {
- return ['en', 'es', 'ru'];
- },
- },
-
- route: String,
-
/**
- * Whether the page is a subpage.
+ * Preferences state.
*/
- subpage: {
- type: Boolean,
- value: false,
- readOnly: true
+ prefs: {
+ type: Object,
+ notify: true,
},
/**
- * ID of the page.
+ * 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.
+ * @type {(LanguagesModel|undefined)}
*/
- PAGE_ID: {
- type: String,
- value: 'languages',
- readOnly: true
+ 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).
+ type: Object,
+ 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
},
+ },
- /**
- * Title for the page header and navigation menu.
- */
- pageTitle: {
- type: String,
- value: function() {
- return loadTimeData.getString('languagesPageTitle');
- },
- },
+ /**
+ * Handler for clicking a language on the main page, which selects the
+ * language as the prospective UI language on Chrome OS and Windows.
+ * @param {!{model: !{item: !{language: !{code: string}}}}} e
+ */
+ onLanguageTap_: function(e) {
+ // Set the prospective UI language. This won't take effect until a restart.
+ 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)
+ this.$.languages.setUILanguage(e.model.item.language.code);
+ },
- /**
- * Name of the 'iron-icon' to be shown in the settings-page-header.
- */
- icon: {
- type: String,
- value: 'language',
- readOnly: true
- },
+ /**
+ * Handler for enabling or disabling spell check.
+ * @param {!{target: Element, model: !{item: !{language: !{code: string}}}}} e
+ */
+ onSpellCheckChange_: function(e) {
+ this.$.languages.toggleSpellCheck(e.model.item.language.code,
+ e.target.checked);
+ },
+
+ /** @private */
+ onBackTap_: function() {
+ this.$.pages.back();
},
/**
- * @param {!Array<!Language>} languages
- * @return {!Array<!Language>} The languages from |languages| which support
- * spell check.
+ * Opens the Manage Languages page.
* @private
*/
- getSpellcheckLanguages_: function(languages) {
- return languages.filter(function(language) {
- return language.supportsSpellcheck;
- });
+ onManageLanguagesTap_: function() {
+ this.$.pages.setSubpageChain(['manage-languages']);
+ // 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.
+ // the sub-page. Probably due to PolymerElements/neon-animation#60.
+ /** @type {{_render: function()}} */(this.$.manageLanguagesPage.$.list)
+ ._render();
},
/**
* @param {string} languageCode The language code identifying a language.
- * @param {string} dummyAppLocale A fake app locale.
+ * @param {string} appLocale The prospective UI language.
* @return {boolean} True if the given language matches the app locale pref
- * (which may be different from the actual app locale if it was changed).
+ * (which may be different from the actual app locale).
* @private
*/
- isUILanguage_: function(languageCode, dummyAppLocale) {
- return languageCode == dummyAppLocale;
+ isUILanguage_: function(languageCode, appLocale) {
+ // Check the current language if the locale pref hasn't been set.
+ if (!appLocale)
+ appLocale = navigator.language;
+ return languageCode == appLocale;
},
/**
@@ -129,15 +103,5 @@ Polymer({
assert(cr.isChromeOS);
return id == currentId;
},
-
- /**
- * @param {string} languageCode The language code identifying a language.
- * @param {!Array<string>} spellcheckDictionaries The list of languages
- * for which spell check is enabled.
- * @return {boolean} True if spell check is enabled for the language.
- * @private
- */
- isSpellcheckEnabled_: function(languageCode, spellcheckDictionaries) {
- return spellcheckDictionaries.indexOf(languageCode) != -1;
- },
});
+})();

Powered by Google App Engine
This is Rietveld 408576698