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

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: 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-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',
11 11
12 properties: { 12 properties: {
13 /** 13 /**
14 * Preferences state. 14 * Preferences state.
15 */ 15 */
16 prefs: { 16 prefs: {
17 type: Object, 17 type: Object,
18 notify: true, 18 notify: true,
19 }, 19 },
20 20
21 /** 21 /**
22 * Read-only reference to the languages model provided by the 22 * Read-only reference to the languages model provided by the
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 /** @type {!LanguageHelper} */
29 languageHelper: Object,
30
28 /** 31 /**
29 * The language to display the details for. 32 * The language to display the details for.
30 * @type {!LanguageState|undefined} 33 * @type {!LanguageState|undefined}
31 */ 34 */
32 detail: Object, 35 detail: Object,
33
34 /** @private {!LanguageHelper} */
35 languageHelper_: Object,
36 }, 36 },
37 37
38 /** @override */ 38 /** @override */
39 created: function() {
40 this.languageHelper_ = LanguageHelperImpl.getInstance();
41 },
42
43 /** @override */
44 ready: function() { 39 ready: function() {
45 // In a CrOS multi-user session, the primary user controls the UI language. 40 // In a CrOS multi-user session, the primary user controls the UI language.
46 if (this.isSecondaryUser_()) { 41 if (this.isSecondaryUser_()) {
47 var indicator = this.$.policyIndicator; 42 var indicator = this.$.policyIndicator;
48 indicator.indicatorType = CrPolicyIndicatorType.PRIMARY_USER; 43 indicator.indicatorType = CrPolicyIndicatorType.PRIMARY_USER;
49 indicator.controllingUser = loadTimeData.getString('primaryUserEmail'); 44 indicator.controllingUser = loadTimeData.getString('primaryUserEmail');
50 } 45 }
51 46
52 // The UI language choice doesn't persist for guests. 47 // The UI language choice doesn't persist for guests.
53 if (cr.isChromeOS && 48 if (cr.isChromeOS &&
54 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || 49 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() ||
55 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { 50 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) {
56 this.$.languageSettings.hidden = true; 51 this.$.languageSettings.hidden = true;
57 } 52 }
58 }, 53 },
59 54
60 /** 55 /**
61 * Checks whether the prospective UI language (the pref that indicates what 56 * 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 57 * 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. 58 * on Chrome OS and Windows; we don't control the UI language elsewhere.
64 * @param {string} languageCode The language code identifying a language. 59 * @param {string} languageCode The language code identifying a language.
65 * @param {string} prospectiveUILanguage The prospective UI language. 60 * @param {string} prospectiveUILanguage The prospective UI language.
66 * @return {boolean} True if the given language matches the prospective UI 61 * @return {boolean} True if the given language matches the prospective UI
67 * pref (which may be different from the actual UI language). 62 * pref (which may be different from the actual UI language).
68 * @private 63 * @private
69 */ 64 */
70 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { 65 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) {
71 assert(cr.isChromeOS || cr.isWindows); 66 assert(cr.isChromeOS || cr.isWindows);
72 return languageCode == this.languageHelper_.getProspectiveUILanguage(); 67 return languageCode == this.languageHelper.getProspectiveUILanguage();
73 }, 68 },
74 69
75 /** 70 /**
76 * @param {string} languageCode The language code identifying a language. 71 * @param {string} languageCode The language code identifying a language.
77 * @param {string} prospectiveUILanguage The prospective UI language. 72 * @param {string} prospectiveUILanguage The prospective UI language.
78 * @return {boolean} True if the the given language, the prospective UI 73 * @return {boolean} True if the the given language, the prospective UI
79 * language and the actual language all the same. 74 * language and the actual language all the same.
80 * @private 75 * @private
81 */ 76 */
82 isCurrentUILanguage_: function(languageCode, prospectiveUILanguage) { 77 isCurrentUILanguage_: function(languageCode, prospectiveUILanguage) {
83 assert(cr.isChromeOS || cr.isWindows); 78 assert(cr.isChromeOS || cr.isWindows);
84 return languageCode == prospectiveUILanguage && 79 return languageCode == prospectiveUILanguage &&
85 languageCode == navigator.language; 80 languageCode == navigator.language;
86 }, 81 },
87 82
88 /** 83 /**
89 * @param {string} languageCode The language code identifying a language. 84 * @param {string} languageCode The language code identifying a language.
90 * @param {string} targetLanguageCode The default translate target language. 85 * @param {string} targetLanguageCode The default translate target language.
91 * @return {boolean} True if the language code matches the target language. 86 * @return {boolean} True if the language code matches the target language.
92 * @private 87 * @private
93 */ 88 */
94 isTranslateDisabled_: function(languageCode, targetLanguageCode) { 89 isTranslateDisabled_: function(languageCode, targetLanguageCode) {
95 return this.languageHelper_.convertLanguageCodeForTranslate(languageCode) == 90 return this.languageHelper.convertLanguageCodeForTranslate(languageCode) ==
96 targetLanguageCode; 91 targetLanguageCode;
97 }, 92 },
98 93
99 /** 94 /**
100 * @param {string} languageCode The language code identifying a language. 95 * @param {string} languageCode The language code identifying a language.
101 * @param {string} prospectiveUILanguage The prospective UI language. 96 * @param {string} prospectiveUILanguage The prospective UI language.
102 * @return {boolean} True if the prospective UI language is set to 97 * @return {boolean} True if the prospective UI language is set to
103 * |languageCode| but requires a restart to take effect. 98 * |languageCode| but requires a restart to take effect.
104 * @private 99 * @private
105 */ 100 */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return !translateEnabled || languageCode == 'zh'; 139 return !translateEnabled || languageCode == 'zh';
145 }, 140 },
146 141
147 /** 142 /**
148 * Handler for changes to the translate checkbox. 143 * Handler for changes to the translate checkbox.
149 * @param {!{target: !{checked: boolean}}} e 144 * @param {!{target: !{checked: boolean}}} e
150 * @private 145 * @private
151 */ 146 */
152 onTranslateEnabledChange_: function(e) { 147 onTranslateEnabledChange_: function(e) {
153 if (e.target.checked) 148 if (e.target.checked)
154 this.languageHelper_.enableTranslateLanguage(this.detail.language.code); 149 this.languageHelper.enableTranslateLanguage(this.detail.language.code);
155 else 150 else
156 this.languageHelper_.disableTranslateLanguage(this.detail.language.code); 151 this.languageHelper.disableTranslateLanguage(this.detail.language.code);
157 }, 152 },
158 153
159 /** 154 /**
160 * Handler for changes to the UI language toggle button. 155 * Handler for changes to the UI language toggle button.
161 * @param {!{target: !{checked: boolean}}} e 156 * @param {!{target: !{checked: boolean}}} e
162 * @private 157 * @private
163 */ 158 */
164 onUILanguageChange_: function(e) { 159 onUILanguageChange_: function(e) {
165 if (e.target.checked) { 160 if (e.target.checked) {
166 this.languageHelper_.setUILanguage(this.detail.language.code); 161 this.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 this.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