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

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: 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..8aad5fd1edcbdd0afcbb253cece7fd3b0b78686a 100644
--- a/chrome/browser/resources/settings/languages_page/languages_page.js
+++ b/chrome/browser/resources/settings/languages_page/languages_page.js
@@ -9,114 +9,89 @@
* @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.
+ * Read-only reference to the languages model provided by the
+ * 'cr-settings-languages' instance.
+ * @type {LanguagesModel|undefined}
*/
- PAGE_ID: {
- type: String,
- value: 'languages',
- readOnly: true
+ languages: {
+ type: Object,
+ notify: true,
},
+ },
- /**
- * 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: !LanguageInfo}}} e
+ */
+ onLanguageTap_: function(e) {
+ // Set the prospective UI language. This won't take effect until a restart.
+ if (e.model.item.language.supportsUI)
+ 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: !LanguageInfo}}} 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']);
+ // HACK(michaelpg): This is necessary to show the list when navigating to
+ // the sub-page. Remove when PolymerElements/neon-animation#60 is fixed.
+ /** @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 +104,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