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

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

Powered by Google App Engine
This is Rietveld 408576698