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

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

Issue 1419033008: Extract language settings methods into a LanguageHelper interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@LanguagePage5InputMethodsAPI
Patch Set: cr.exportPath Created 5 years, 1 month 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 * @group Chrome Settings Elements 9 * @group Chrome Settings Elements
10 * @element settings-language-detail-page 10 * @element settings-language-detail-page
(...skipping 17 matching lines...) Expand all
28 */ 28 */
29 languages: Object, 29 languages: Object,
30 30
31 /** 31 /**
32 * The language to display the details for. 32 * The language to display the details for.
33 * @type {LanguageInfo|undefined} 33 * @type {LanguageInfo|undefined}
34 */ 34 */
35 detail: Object, 35 detail: Object,
36 }, 36 },
37 37
38 /** @private {LanguageSettingsHelper} */
39 languageHelper_: settings.LanguageHelper.getInstance(),
40
38 ready: function() { 41 ready: function() {
39 // In a CrOS multi-user session, the primary user controls the UI language. 42 // In a CrOS multi-user session, the primary user controls the UI language.
40 if (this.isSecondaryUser_()) { 43 if (this.isSecondaryUser_()) {
41 var indicator = this.$.policyIndicator; 44 var indicator = this.$.policyIndicator;
42 indicator.indicatorType = CrPolicyIndicatorType.PRIMARY_USER; 45 indicator.indicatorType = CrPolicyIndicatorType.PRIMARY_USER;
43 indicator.controllingUser = loadTimeData.getString('primaryUserEmail'); 46 indicator.controllingUser = loadTimeData.getString('primaryUserEmail');
44 } 47 }
45 48
46 // The UI language choice doesn't persist for guests. 49 // The UI language choice doesn't persist for guests.
47 if (cr.isChromeOS && 50 if (cr.isChromeOS &&
48 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() || 51 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() ||
49 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) { 52 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) {
50 this.$.languageSettings.hidden = true; 53 this.$.languageSettings.hidden = true;
51 } 54 }
52 }, 55 },
53 56
54 /** 57 /**
55 * @param {string} languageCode The language code identifying a language. 58 * @param {string} languageCode The language code identifying a language.
56 * @param {string} prospectiveUILanguage The chosen UI language. 59 * @param {string} prospectiveUILanguage The chosen UI language.
57 * @return {boolean} True if the given language matches the chosen UI language 60 * @return {boolean} True if the given language matches the chosen UI language
58 * (which may be different from the actual UI language). 61 * (which may be different from the actual UI language).
59 * @private 62 * @private
60 */ 63 */
61 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { 64 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) {
62 return languageCode == this.$.languages.getProspectiveUILanguage(); 65 return languageCode == this.languageHelper_.getProspectiveUILanguage();
63 }, 66 },
64 67
65 /** 68 /**
66 * @param {string} languageCode The language code identifying a language. 69 * @param {string} languageCode The language code identifying a language.
67 * @param {string} prospectiveUILanguage The prospective UI language. 70 * @param {string} prospectiveUILanguage The prospective UI language.
68 * @return {boolean} True if the the given language, the prospective UI 71 * @return {boolean} True if the the given language, the prospective UI
69 * language and the actual language all the same. 72 * language and the actual language all the same.
70 * @private 73 * @private
71 */ 74 */
72 isCurrentUILanguage_: function(languageCode, prospectiveUILanguage) { 75 isCurrentUILanguage_: function(languageCode, prospectiveUILanguage) {
73 return languageCode == prospectiveUILanguage && 76 return languageCode == prospectiveUILanguage &&
74 languageCode == navigator.language; 77 languageCode == navigator.language;
75 }, 78 },
76 79
77 /** 80 /**
78 * @param {string} languageCode The language code identifying a language. 81 * @param {string} languageCode The language code identifying a language.
79 * @param {string} targetLanguageCode The default translate target language. 82 * @param {string} targetLanguageCode The default translate target language.
80 * @return {boolean} True if the language code matches the target language. 83 * @return {boolean} True if the language code matches the target language.
81 * @private 84 * @private
82 */ 85 */
83 isTranslateDisabled_: function(languageCode, targetLanguageCode) { 86 isTranslateDisabled_: function(languageCode, targetLanguageCode) {
84 return this.$.languages.convertLanguageCodeForTranslate(languageCode) == 87 return this.languageHelper_.convertLanguageCodeForTranslate(languageCode) ==
85 targetLanguageCode; 88 targetLanguageCode;
86 }, 89 },
87 90
88 /** 91 /**
89 * @param {string} languageCode The language code identifying a language. 92 * @param {string} languageCode The language code identifying a language.
90 * @param {string} prospectiveUILanguage The prospective UI language. 93 * @param {string} prospectiveUILanguage The prospective UI language.
91 * @return {boolean} True if the prospective UI language is set to 94 * @return {boolean} True if the prospective UI language is set to
92 * |languageCode| but requires a restart to take effect. 95 * |languageCode| but requires a restart to take effect.
93 * @private 96 * @private
94 */ 97 */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return !translateEnabled || languageCode == 'zh'; 136 return !translateEnabled || languageCode == 'zh';
134 }, 137 },
135 138
136 /** 139 /**
137 * Handler for changes to the translate checkbox. 140 * Handler for changes to the translate checkbox.
138 * @param {!{target: !{checked: boolean}}} e 141 * @param {!{target: !{checked: boolean}}} e
139 * @private 142 * @private
140 */ 143 */
141 onTranslateEnabledChange_: function(e) { 144 onTranslateEnabledChange_: function(e) {
142 if (e.target.checked) 145 if (e.target.checked)
143 this.$.languages.enableTranslateLanguage(this.detail.language.code); 146 this.languageHelper_.enableTranslateLanguage(this.detail.language.code);
144 else 147 else
145 this.$.languages.disableTranslateLanguage(this.detail.language.code); 148 this.languageHelper_.disableTranslateLanguage(this.detail.language.code);
146 }, 149 },
147 150
148 /** 151 /**
149 * Handler for changes to the UI language toggle button. 152 * Handler for changes to the UI language toggle button.
150 * @param {!{target: !{checked: boolean}}} e 153 * @param {!{target: !{checked: boolean}}} e
151 * @private 154 * @private
152 */ 155 */
153 onUILanguageChange_: function(e) { 156 onUILanguageChange_: function(e) {
154 if (e.target.checked) { 157 if (e.target.checked) {
155 this.$.languages.setUILanguage(this.detail.language.code); 158 this.languageHelper_.setUILanguage(this.detail.language.code);
156 } else { 159 } else {
157 // Reset the chosen UI language to the actual UI language. 160 // Reset the chosen UI language to the actual UI language.
158 this.$.languages.resetUILanguage(); 161 this.languageHelper_.resetUILanguage();
159 } 162 }
160 }, 163 },
161 164
162 /** 165 /**
163 * Handler for the restart button. 166 * Handler for the restart button.
164 * @private 167 * @private
165 */ 168 */
166 onRestartTap_: function() { 169 onRestartTap_: function() {
167 chrome.send('restart'); 170 chrome.send('restart');
168 }, 171 },
169 }); 172 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698