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

Side by Side Diff: chrome/browser/resources/settings/languages_page/languages_page.js

Issue 2252323002: MD Settings: reduce complexity and overhead of Languages singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@RemoveLanguageInputMethods
Patch Set: Reduce diff Created 4 years, 4 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 '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 (function() { 9 (function() {
10 'use strict'; 10 'use strict';
(...skipping 13 matching lines...) Expand all
24 /** 24 /**
25 * Read-only reference to the languages model provided by the 25 * Read-only reference to the languages model provided by the
26 * 'settings-languages' instance. 26 * 'settings-languages' instance.
27 * @type {!LanguagesModel|undefined} 27 * @type {!LanguagesModel|undefined}
28 */ 28 */
29 languages: { 29 languages: {
30 type: Object, 30 type: Object,
31 notify: true, 31 notify: true,
32 }, 32 },
33 33
34 /** @type {!LanguageHelper} */
35 languageHelper: Object,
36
34 /** @private */ 37 /** @private */
35 spellCheckSecondary_: { 38 spellCheckSecondary_: {
36 type: String, 39 type: String,
37 value: 'Placeholder, e.g. English (United States)', 40 value: 'Placeholder, e.g. English (United States)',
38 }, 41 },
39 42
40 /** 43 /**
41 * The language to display the details for. 44 * The language to display the details for.
42 * @type {!LanguageState|undefined} 45 * @type {!LanguageState|undefined}
43 * @private 46 * @private
44 */ 47 */
45 detailLanguage_: Object, 48 detailLanguage_: Object,
46
47 /** @private {!LanguageHelper} */
48 languageHelper_: Object,
49 },
50
51 /** @override */
52 created: function() {
53 this.languageHelper_ = LanguageHelperImpl.getInstance();
54 }, 49 },
55 50
56 /** 51 /**
57 * Handler for clicking a language on the main page, which selects the 52 * Handler for clicking a language on the main page, which selects the
58 * language as the prospective UI language on Chrome OS and Windows. 53 * language as the prospective UI language on Chrome OS and Windows.
59 * @param {!Event} e The tap event. 54 * @param {!Event} e The tap event.
60 */ 55 */
61 onLanguageTap_: function(e) { 56 onLanguageTap_: function(e) {
62 // Only change the UI language on platforms that allow it. 57 // Only change the UI language on platforms that allow it.
63 if ((!cr.isChromeOS && !cr.isWindows) || loadTimeData.getBoolean('isGuest')) 58 if ((!cr.isChromeOS && !cr.isWindows) || loadTimeData.getBoolean('isGuest'))
64 return; 59 return;
65 60
66 // Set the prospective UI language. This won't take effect until a restart. 61 // Set the prospective UI language. This won't take effect until a restart.
67 var tapEvent = /** @type {!{model: !{item: !LanguageState}}} */(e); 62 var tapEvent = /** @type {!{model: !{item: !LanguageState}}} */(e);
68 if (tapEvent.model.item.language.supportsUI) 63 if (tapEvent.model.item.language.supportsUI)
69 this.languageHelper_.setUILanguage(tapEvent.model.item.language.code); 64 this.languageHelper.setUILanguage(tapEvent.model.item.language.code);
70 }, 65 },
71 66
72 /** 67 /**
73 * Stops tap events on the language options menu, its trigger, or its items 68 * Stops tap events on the language options menu, its trigger, or its items
74 * from bubbling up to the language itself. Tap events on the language are 69 * from bubbling up to the language itself. Tap events on the language are
75 * handled in onLanguageTap_. 70 * handled in onLanguageTap_.
76 * @param {!Event} e The tap event. 71 * @param {!Event} e The tap event.
77 */ 72 */
78 stopPropagationHandler_: function(e) { 73 stopPropagationHandler_: function(e) {
79 e.stopPropagation(); 74 e.stopPropagation();
80 }, 75 },
81 76
82 /** 77 /**
83 * Handler for enabling or disabling spell check. 78 * Handler for enabling or disabling spell check.
84 * @param {!{target: Element, model: !{item: !LanguageState}}} e 79 * @param {!{target: Element, model: !{item: !LanguageState}}} e
85 */ 80 */
86 onSpellCheckChange_: function(e) { 81 onSpellCheckChange_: function(e) {
87 this.languageHelper_.toggleSpellCheck(e.model.item.language.code, 82 this.languageHelper.toggleSpellCheck(e.model.item.language.code,
88 e.target.checked); 83 e.target.checked);
89 }, 84 },
90 85
91 /** @private */ 86 /** @private */
92 onBackTap_: function() { 87 onBackTap_: function() {
93 this.$.pages.back(); 88 this.$.pages.back();
94 }, 89 },
95 90
96 /** 91 /**
97 * Opens the Manage Languages page. 92 * Opens the Manage Languages page.
98 * @private 93 * @private
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 isHelpTextHidden_: function(change) { 126 isHelpTextHidden_: function(change) {
132 return this.languages.enabled.length <= 1; 127 return this.languages.enabled.length <= 1;
133 }, 128 },
134 129
135 /** 130 /**
136 * Moves the language up in the list. 131 * Moves the language up in the list.
137 * @param {!{model: !{item: !LanguageState}}} e 132 * @param {!{model: !{item: !LanguageState}}} e
138 * @private 133 * @private
139 */ 134 */
140 onMoveUpTap_: function(e) { 135 onMoveUpTap_: function(e) {
141 this.languageHelper_.moveLanguage(e.model.item.language.code, -1); 136 this.languageHelper.moveLanguage(e.model.item.language.code, -1);
142 }, 137 },
143 138
144 /** 139 /**
145 * Moves the language down in the list. 140 * Moves the language down in the list.
146 * @param {!{model: !{item: !LanguageState}}} e 141 * @param {!{model: !{item: !LanguageState}}} e
147 * @private 142 * @private
148 */ 143 */
149 onMoveDownTap_: function(e) { 144 onMoveDownTap_: function(e) {
150 this.languageHelper_.moveLanguage(e.model.item.language.code, 1); 145 this.languageHelper.moveLanguage(e.model.item.language.code, 1);
151 }, 146 },
152 147
153 /** 148 /**
154 * Opens the Language Detail page for the language. 149 * Opens the Language Detail page for the language.
155 * @param {!{model: !{item: !LanguageState}}} e 150 * @param {!{model: !{item: !LanguageState}}} e
156 * @private 151 * @private
157 */ 152 */
158 onShowLanguageDetailTap_: function(e) { 153 onShowLanguageDetailTap_: function(e) {
159 this.detailLanguage_ = e.model.item; 154 this.detailLanguage_ = e.model.item;
160 settings.navigateTo(settings.Route.LANGUAGES_DETAIL); 155 settings.navigateTo(settings.Route.LANGUAGES_DETAIL);
(...skipping 15 matching lines...) Expand all
176 * target: !{tagName: string}}} e 171 * target: !{tagName: string}}} e
177 */ 172 */
178 onInputMethodTap_: function(e) { 173 onInputMethodTap_: function(e) {
179 assert(cr.isChromeOS); 174 assert(cr.isChromeOS);
180 175
181 // Taps on the paper-icon-button are handled in onInputMethodOptionsTap_. 176 // Taps on the paper-icon-button are handled in onInputMethodOptionsTap_.
182 if (e.target.tagName == 'PAPER-ICON-BUTTON') 177 if (e.target.tagName == 'PAPER-ICON-BUTTON')
183 return; 178 return;
184 179
185 // Set the input method. 180 // Set the input method.
186 this.languageHelper_.setCurrentInputMethod(e.model.item.id); 181 this.languageHelper.setCurrentInputMethod(e.model.item.id);
187 }, 182 },
188 183
189 /** 184 /**
190 * Opens the input method extension's options page in a new tab (or focuses 185 * Opens the input method extension's options page in a new tab (or focuses
191 * an existing instance of the IME's options). 186 * an existing instance of the IME's options).
192 * @param {!{model: !{item: chrome.languageSettingsPrivate.InputMethod}}} e 187 * @param {!{model: !{item: chrome.languageSettingsPrivate.InputMethod}}} e
193 * @private 188 * @private
194 */ 189 */
195 onInputMethodOptionsTap_: function(e) { 190 onInputMethodOptionsTap_: function(e) {
196 assert(cr.isChromeOS); 191 assert(cr.isChromeOS);
197 this.languageHelper_.openInputMethodOptions(e.model.item.id); 192 this.languageHelper.openInputMethodOptions(e.model.item.id);
198 }, 193 },
199 194
200 /** 195 /**
201 * Returns the secondary text for the spell check subsection based on the 196 * Returns the secondary text for the spell check subsection based on the
202 * enabled spell check languages, listing at most 2 languages. 197 * enabled spell check languages, listing at most 2 languages.
203 * @return {string} 198 * @return {string}
204 * @private 199 * @private
205 */ 200 */
206 getSpellCheckSecondaryText_: function() { 201 getSpellCheckSecondaryText_: function() {
207 var enabledSpellCheckLanguages = 202 var enabledSpellCheckLanguages =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 * language to use in Chrome) matches the current language. This pref is only 245 * language to use in Chrome) matches the current language. This pref is only
251 * on Chrome OS and Windows; we don't control the UI language elsewhere. 246 * on Chrome OS and Windows; we don't control the UI language elsewhere.
252 * @param {string} languageCode The language code identifying a language. 247 * @param {string} languageCode The language code identifying a language.
253 * @param {string} prospectiveUILanguage The prospective UI language. 248 * @param {string} prospectiveUILanguage The prospective UI language.
254 * @return {boolean} True if the given language matches the prospective UI 249 * @return {boolean} True if the given language matches the prospective UI
255 * pref (which may be different from the actual UI language). 250 * pref (which may be different from the actual UI language).
256 * @private 251 * @private
257 */ 252 */
258 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { 253 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) {
259 assert(cr.isChromeOS || cr.isWindows); 254 assert(cr.isChromeOS || cr.isWindows);
260 return languageCode == this.languageHelper_.getProspectiveUILanguage(); 255 return languageCode == this.languageHelper.getProspectiveUILanguage();
261 }, 256 },
262 257
263 /** 258 /**
264 * @return {string} 259 * @return {string}
265 * @private 260 * @private
266 */ 261 */
267 getProspectiveUILanguageName_: function() { 262 getProspectiveUILanguageName_: function() {
268 return this.languageHelper_.getLanguage( 263 return this.languageHelper.getLanguage(
269 this.languageHelper_.getProspectiveUILanguage()).displayName; 264 this.languageHelper.getProspectiveUILanguage()).displayName;
270 }, 265 },
271 266
272 /** 267 /**
273 * Returns either the "selected" class, if the language matches the 268 * Returns either the "selected" class, if the language matches the
274 * prospective UI language, or an empty string. Languages can only be 269 * prospective UI language, or an empty string. Languages can only be
275 * selected on Chrome OS and Windows. 270 * selected on Chrome OS and Windows.
276 * @param {string} languageCode The language code identifying a language. 271 * @param {string} languageCode The language code identifying a language.
277 * @param {string} prospectiveUILanguage The prospective UI language. 272 * @param {string} prospectiveUILanguage The prospective UI language.
278 * @param {boolean} supportsUI Whether Chrome's UI can be shown in this 273 * @param {boolean} supportsUI Whether Chrome's UI can be shown in this
279 * language. 274 * language.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 * HACK(michaelpg): This is necessary to show the list when navigating to 325 * HACK(michaelpg): This is necessary to show the list when navigating to
331 * the sub-page. Remove this function when PolymerElements/neon-animation#60 326 * the sub-page. Remove this function when PolymerElements/neon-animation#60
332 * is fixed. 327 * is fixed.
333 * @param {string} tagName Name of the element containing the <iron-list>. 328 * @param {string} tagName Name of the element containing the <iron-list>.
334 */ 329 */
335 forceRenderList_: function(tagName) { 330 forceRenderList_: function(tagName) {
336 this.$$(tagName).$$('iron-list').fire('iron-resize'); 331 this.$$(tagName).$$('iron-list').fire('iron-resize');
337 }, 332 },
338 }); 333 });
339 })(); 334 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698