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

Side by Side Diff: chrome/browser/resources/settings/languages_page/language_detail_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-language-detail-page' is a sub-page for editing 6 * @fileoverview 'settings-language-detail-page' is a sub-page for editing
7 * an individual language's settings. 7 * an individual language's settings.
8 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'settings-language-detail-page', 10 is: 'settings-language-detail-page',
(...skipping 12 matching lines...) Expand all
23 * 'settings-languages' instance. 23 * 'settings-languages' instance.
24 * @type {!LanguagesModel|undefined} 24 * @type {!LanguagesModel|undefined}
25 */ 25 */
26 languages: Object, 26 languages: Object,
27 27
28 /** 28 /**
29 * The language to display the details for. 29 * The language to display the details for.
30 * @type {!LanguageState|undefined} 30 * @type {!LanguageState|undefined}
31 */ 31 */
32 detail: Object, 32 detail: Object,
33
34 /** @private {!LanguageHelper} */
35 languageHelper_: Object,
36 }, 33 },
37 34
38 /** @override */ 35 /** @override */
39 created: function() {
40 this.languageHelper_ = LanguageHelperImpl.getInstance();
stevenjb 2016/08/18 16:22:02 QQ: These changes seem fine, but any particular re
michaelpg 2016/08/18 22:32:27 Changed to a data-bound member. The instance wasn
41 },
42
43 /** @override */
44 ready: function() { 36 ready: function() {
45 // In a CrOS multi-user session, the primary user controls the UI language. 37 // In a CrOS multi-user session, the primary user controls the UI language.
46 if (this.isSecondaryUser_()) { 38 if (this.isSecondaryUser_()) {
47 var indicator = this.$.policyIndicator; 39 var indicator = this.$.policyIndicator;
48 indicator.indicatorType = CrPolicyIndicatorType.PRIMARY_USER; 40 indicator.indicatorType = CrPolicyIndicatorType.PRIMARY_USER;
49 indicator.controllingUser = loadTimeData.getString('primaryUserEmail'); 41 indicator.controllingUser = loadTimeData.getString('primaryUserEmail');
50 } 42 }
51 43
52 // The UI language choice doesn't persist for guests. 44 // The UI language choice doesn't persist for guests.
53 if (cr.isChromeOS && 45 if (cr.isChromeOS &&
54 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || 46 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() ||
55 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { 47 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) {
56 this.$.languageSettings.hidden = true; 48 this.$.languageSettings.hidden = true;
57 } 49 }
58 }, 50 },
59 51
60 /** 52 /**
61 * Checks whether the prospective UI language (the pref that indicates what 53 * Checks whether the prospective UI language (the pref that indicates what
62 * language to use in Chrome) matches the current language. This pref is only 54 * language to use in Chrome) matches the current language. This pref is only
63 * on Chrome OS and Windows; we don't control the UI language elsewhere. 55 * on Chrome OS and Windows; we don't control the UI language elsewhere.
64 * @param {string} languageCode The language code identifying a language. 56 * @param {string} languageCode The language code identifying a language.
65 * @param {string} prospectiveUILanguage The prospective UI language. 57 * @param {string} prospectiveUILanguage The prospective UI language.
66 * @return {boolean} True if the given language matches the prospective UI 58 * @return {boolean} True if the given language matches the prospective UI
67 * pref (which may be different from the actual UI language). 59 * pref (which may be different from the actual UI language).
68 * @private 60 * @private
69 */ 61 */
70 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { 62 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) {
71 assert(cr.isChromeOS || cr.isWindows); 63 assert(cr.isChromeOS || cr.isWindows);
72 return languageCode == this.languageHelper_.getProspectiveUILanguage(); 64 return languageCode ==
65 settings.LanguageHelperImpl.getInstance().getProspectiveUILanguage();
stevenjb 2016/08/18 16:22:02 nit: In C++ we would make getInstance() part of th
michaelpg 2016/08/18 22:32:27 Changed to a data-bound member.
73 }, 66 },
74 67
75 /** 68 /**
76 * @param {string} languageCode The language code identifying a language. 69 * @param {string} languageCode The language code identifying a language.
77 * @param {string} prospectiveUILanguage The prospective UI language. 70 * @param {string} prospectiveUILanguage The prospective UI language.
78 * @return {boolean} True if the the given language, the prospective UI 71 * @return {boolean} True if the the given language, the prospective UI
79 * language and the actual language all the same. 72 * language and the actual language all the same.
80 * @private 73 * @private
81 */ 74 */
82 isCurrentUILanguage_: function(languageCode, prospectiveUILanguage) { 75 isCurrentUILanguage_: function(languageCode, prospectiveUILanguage) {
83 assert(cr.isChromeOS || cr.isWindows); 76 assert(cr.isChromeOS || cr.isWindows);
84 return languageCode == prospectiveUILanguage && 77 return languageCode == prospectiveUILanguage &&
85 languageCode == navigator.language; 78 languageCode == navigator.language;
86 }, 79 },
87 80
88 /** 81 /**
89 * @param {string} languageCode The language code identifying a language. 82 * @param {string} languageCode The language code identifying a language.
90 * @param {string} targetLanguageCode The default translate target language. 83 * @param {string} targetLanguageCode The default translate target language.
91 * @return {boolean} True if the language code matches the target language. 84 * @return {boolean} True if the language code matches the target language.
92 * @private 85 * @private
93 */ 86 */
94 isTranslateDisabled_: function(languageCode, targetLanguageCode) { 87 isTranslateDisabled_: function(languageCode, targetLanguageCode) {
95 return this.languageHelper_.convertLanguageCodeForTranslate(languageCode) == 88 return settings.LanguageHelperImpl.getInstance()
96 targetLanguageCode; 89 .convertLanguageCodeForTranslate(languageCode) == targetLanguageCode;
97 }, 90 },
98 91
99 /** 92 /**
100 * @param {string} languageCode The language code identifying a language. 93 * @param {string} languageCode The language code identifying a language.
101 * @param {string} prospectiveUILanguage The prospective UI language. 94 * @param {string} prospectiveUILanguage The prospective UI language.
102 * @return {boolean} True if the prospective UI language is set to 95 * @return {boolean} True if the prospective UI language is set to
103 * |languageCode| but requires a restart to take effect. 96 * |languageCode| but requires a restart to take effect.
104 * @private 97 * @private
105 */ 98 */
106 isRestartRequired_: function(languageCode, prospectiveUILanguage) { 99 isRestartRequired_: function(languageCode, prospectiveUILanguage) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // checkbox when general Chinese is selected. 136 // checkbox when general Chinese is selected.
144 return !translateEnabled || languageCode == 'zh'; 137 return !translateEnabled || languageCode == 'zh';
145 }, 138 },
146 139
147 /** 140 /**
148 * Handler for changes to the translate checkbox. 141 * Handler for changes to the translate checkbox.
149 * @param {!{target: !{checked: boolean}}} e 142 * @param {!{target: !{checked: boolean}}} e
150 * @private 143 * @private
151 */ 144 */
152 onTranslateEnabledChange_: function(e) { 145 onTranslateEnabledChange_: function(e) {
146 var languageHelper = settings.LanguageHelperImpl.getInstance();
153 if (e.target.checked) 147 if (e.target.checked)
154 this.languageHelper_.enableTranslateLanguage(this.detail.language.code); 148 languageHelper.enableTranslateLanguage(this.detail.language.code);
155 else 149 else
156 this.languageHelper_.disableTranslateLanguage(this.detail.language.code); 150 languageHelper.disableTranslateLanguage(this.detail.language.code);
157 }, 151 },
158 152
159 /** 153 /**
160 * Handler for changes to the UI language toggle button. 154 * Handler for changes to the UI language toggle button.
161 * @param {!{target: !{checked: boolean}}} e 155 * @param {!{target: !{checked: boolean}}} e
162 * @private 156 * @private
163 */ 157 */
164 onUILanguageChange_: function(e) { 158 onUILanguageChange_: function(e) {
159 var languageHelper = settings.LanguageHelperImpl.getInstance();
165 if (e.target.checked) { 160 if (e.target.checked) {
166 this.languageHelper_.setUILanguage(this.detail.language.code); 161 languageHelper.setUILanguage(this.detail.language.code);
167 } else { 162 } else {
168 // Reset the chosen UI language to the actual UI language. 163 // Reset the chosen UI language to the actual UI language.
169 this.languageHelper_.resetUILanguage(); 164 languageHelper.resetUILanguage();
170 } 165 }
171 }, 166 },
172 167
173 /** 168 /**
174 * Handler for the restart button. 169 * Handler for the restart button.
175 * @private 170 * @private
176 */ 171 */
177 onRestartTap_: function() { 172 onRestartTap_: function() {
178 <if expr="chromeos"> 173 <if expr="chromeos">
179 settings.LifetimeBrowserProxyImpl.getInstance().logOutAndRestart(); 174 settings.LifetimeBrowserProxyImpl.getInstance().logOutAndRestart();
180 </if> 175 </if>
181 <if expr="not chromeos"> 176 <if expr="not chromeos">
182 settings.LifetimeBrowserProxyImpl.getInstance().restart(); 177 settings.LifetimeBrowserProxyImpl.getInstance().restart();
183 </if> 178 </if>
184 }, 179 },
185 }); 180 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698