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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
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 * Read-only reference to the languages model provided by the
37 * 'cr-settings-languages' instance.
38 * @type {LanguagesModel|undefined}
63 */ 39 */
64 subpage: { 40 languages: {
65 type: Boolean, 41 type: Object,
66 value: false, 42 notify: true,
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 }, 43 },
97 }, 44 },
98 45
99 /** 46 /**
100 * @param {!Array<!Language>} languages 47 * Handler for clicking a language on the main page, which selects the
101 * @return {!Array<!Language>} The languages from |languages| which support 48 * language as the prospective UI language on Chrome OS and Windows.
102 * spell check. 49 * @param {!{model: !{item: !LanguageInfo}}} e
50 */
51 onLanguageTap_: function(e) {
52 // Set the prospective UI language. This won't take effect until a restart.
53 if (e.model.item.language.supportsUI)
54 this.$.languages.setUILanguage(e.model.item.language.code);
55 },
56
57 /**
58 * Handler for enabling or disabling spell check.
59 * @param {!{target: Element, model: !{item: !LanguageInfo}}} e
60 */
61 onSpellCheckChange_: function(e) {
62 this.$.languages.toggleSpellCheck(e.model.item.language.code,
63 e.target.checked);
64 },
65
66 /** @private */
67 onBackTap_: function() {
68 this.$.pages.back();
69 },
70
71 /**
72 * Opens the Manage Languages page.
103 * @private 73 * @private
104 */ 74 */
105 getSpellcheckLanguages_: function(languages) { 75 onManageLanguagesTap_: function() {
106 return languages.filter(function(language) { 76 this.$.pages.setSubpageChain(['manage-languages']);
107 return language.supportsSpellcheck; 77 // HACK(michaelpg): This is necessary to show the list when navigating to
108 }); 78 // the sub-page. Remove when PolymerElements/neon-animation#60 is fixed.
79 /** @type {{_render: function()}} */(this.$.manageLanguagesPage.$.list)
80 ._render();
109 }, 81 },
110 82
111 /** 83 /**
112 * @param {string} languageCode The language code identifying a language. 84 * @param {string} languageCode The language code identifying a language.
113 * @param {string} dummyAppLocale A fake app locale. 85 * @param {string} appLocale The prospective UI language.
114 * @return {boolean} True if the given language matches the app locale pref 86 * @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). 87 * (which may be different from the actual app locale).
116 * @private 88 * @private
117 */ 89 */
118 isUILanguage_: function(languageCode, dummyAppLocale) { 90 isUILanguage_: function(languageCode, appLocale) {
119 return languageCode == dummyAppLocale; 91 // Check the current language if the locale pref hasn't been set.
92 if (!appLocale)
93 appLocale = navigator.language;
94 return languageCode == appLocale;
120 }, 95 },
121 96
122 /** 97 /**
123 * @param {string} id The input method ID. 98 * @param {string} id The input method ID.
124 * @param {string} currentId The ID of the currently enabled input method. 99 * @param {string} currentId The ID of the currently enabled input method.
125 * @return {boolean} True if the IDs match. 100 * @return {boolean} True if the IDs match.
126 * @private 101 * @private
127 */ 102 */
128 isCurrentInputMethod_: function(id, currentId) { 103 isCurrentInputMethod_: function(id, currentId) {
129 assert(cr.isChromeOS); 104 assert(cr.isChromeOS);
130 return id == currentId; 105 return id == currentId;
131 }, 106 },
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 }); 107 });
108 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698