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

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

Issue 2351963003: MD Settings: Replace language detail page with dropdown menu items (Closed)
Patch Set: . Created 4 years, 3 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 /** 119 /**
120 * @param {!Object} change Polymer change object for languages.enabled.*. 120 * @param {!Object} change Polymer change object for languages.enabled.*.
121 * @return {boolean} True if there are less than 2 languages. 121 * @return {boolean} True if there are less than 2 languages.
122 */ 122 */
123 isHelpTextHidden_: function(change) { 123 isHelpTextHidden_: function(change) {
124 return this.languages.enabled.length <= 1; 124 return this.languages.enabled.length <= 1;
125 }, 125 },
126 126
127 /** 127 /**
128 * @param {!LanguageState} languageState
129 * @param {string} prospectiveUILanguage The chosen UI language.
130 * @return {boolean} True if the given language cannot be set/unset as the
131 * prospective UI language by the user.
132 * @private
133 */
134 disableUILanguageCheckbox_: function(languageState, prospectiveUILanguage) {
135 // UI language setting belongs to the primary user.
136 if (this.isSecondaryUser_())
137 return true;
138
139 // UI language setting belongs to the primary user.
140 if (this.isSecondaryUser_())
141 return true;
stevenjb 2016/09/20 16:17:59 Dupe
michaelpg 2016/09/21 19:28:13 Done.
142
143 // If the language cannot be a UI language, we can't set/unset it as the
144 // prospective UI language.
145 if (!languageState.language.supportsUI)
146 return true;
147
148 // If the language already is the prospective UI language, it can't be unset
149 // if it is also the *actual* UI language, as we wouldn't know what other
150 // language to set as the prospective UI language.
151 if (languageState.language.code == navigator.language &&
152 (!prospectiveUILanguage ||
153 languageState.language.code == prospectiveUILanguage)) {
154 return true;
155 }
156
157 // Otherwise, the prospective language can changed to/from this language.
stevenjb 2016/09/20 16:17:59 can be changed
michaelpg 2016/09/21 19:28:13 Done.
158 return false;
159 },
160
161 /**
162 * @return {boolean} True for a secondary user in a multi-profile session.
163 * @private
164 */
165 isSecondaryUser_: function() {
166 return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser');
167 },
168
169 /**
170 * Handler for changes to the UI language checkbox.
171 * @param {!{target: !PaperCheckboxElement}} e
172 * @private
173 */
174 onUILanguageChange_: function(e) {
175 if (e.target.checked) {
176 this.languageHelper.setUILanguage(this.detailLanguage_.language.code);
177 } else if (this.detailLanguage_.language.code ==
178 this.languageHelper.getProspectiveUILanguage()) {
179 // Reset the chosen UI language to the actual UI language.
180 this.languageHelper.resetUILanguage();
181 }
182 },
183
184 /**
185 * @param {!chrome.languageSettingsPrivate.Language} language
186 * @param {string} targetLanguageCode The default translate target language.
187 * @return {boolean} True if the translate checkbox should be disabled.
188 * @private
189 */
190 disableTranslateCheckbox_: function(language, targetLanguageCode) {
191 if (!language.supportsTranslate)
192 return true;
193
194 return this.languageHelper.convertLanguageCodeForTranslate(language.code) ==
195 targetLanguageCode;
196 },
197
198 /**
199 * Handler for changes to the translate checkbox.
200 * @param {!{target: !PaperCheckboxElement}} e
201 * @private
202 */
203 onTranslateCheckboxChange_: function(e) {
204 if (e.target.checked) {
205 this.languageHelper.enableTranslateLanguage(
206 this.detailLanguage_.language.code);
207 } else {
208 this.languageHelper.disableTranslateLanguage(
209 this.detailLanguage_.language.code);
210 }
211 },
212
213 /**
128 * Moves the language up in the list. 214 * Moves the language up in the list.
129 * @private 215 * @private
130 */ 216 */
131 onMoveUpTap_: function() { 217 onMoveUpTap_: function() {
132 this.menu_.closeMenu(); 218 this.menu_.closeMenu();
133 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1); 219 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, -1);
134 }, 220 },
135 221
136 /** 222 /**
137 * Moves the language down in the list. 223 * Moves the language down in the list.
138 * @private 224 * @private
139 */ 225 */
140 onMoveDownTap_: function() { 226 onMoveDownTap_: function() {
141 this.menu_.closeMenu(); 227 this.menu_.closeMenu();
142 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1); 228 this.languageHelper.moveLanguage(this.detailLanguage_.language.code, 1);
143 }, 229 },
144 230
145 /** 231 /**
146 * Disables the language. 232 * Disables the language.
147 * @private 233 * @private
148 */ 234 */
149 onRemoveLanguageTap_: function() { 235 onRemoveLanguageTap_: function() {
150 this.menu_.closeMenu(); 236 this.menu_.closeMenu();
151 this.languageHelper.disableLanguage(this.detailLanguage_.language.code); 237 this.languageHelper.disableLanguage(this.detailLanguage_.language.code);
152 }, 238 },
153 239
154 /** 240 /**
155 * Opens the Language Detail page for the language.
156 * @private
157 */
158 onShowLanguageDetailTap_: function() {
159 this.menu_.closeMenu();
160 settings.navigateTo(settings.Route.LANGUAGES_DETAIL);
161 },
162
163 /**
164 * Opens the Manage Input Methods page. 241 * Opens the Manage Input Methods page.
165 * @private 242 * @private
166 */ 243 */
167 onManageInputMethodsTap_: function() { 244 onManageInputMethodsTap_: function() {
168 assert(cr.isChromeOS); 245 assert(cr.isChromeOS);
169 settings.navigateTo(settings.Route.INPUT_METHODS); 246 settings.navigateTo(settings.Route.INPUT_METHODS);
170 }, 247 },
171 248
172 /** 249 /**
173 * Handler for clicking an input method on the main page, which sets it as 250 * Handler for clicking an input method on the main page, which sets it as
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 * @private 317 * @private
241 */ 318 */
242 onEditDictionaryTap_: function() { 319 onEditDictionaryTap_: function() {
243 assert(!cr.isMac); 320 assert(!cr.isMac);
244 settings.navigateTo(settings.Route.EDIT_DICTIONARY); 321 settings.navigateTo(settings.Route.EDIT_DICTIONARY);
245 this.forceRenderList_('settings-edit-dictionary-page'); 322 this.forceRenderList_('settings-edit-dictionary-page');
246 }, 323 },
247 324
248 /** 325 /**
249 * Checks whether the prospective UI language (the pref that indicates what 326 * Checks whether the prospective UI language (the pref that indicates what
250 * language to use in Chrome) matches the current language. This pref is only 327 * language to use in Chrome) matches the current language. This pref is used
251 * on Chrome OS and Windows; we don't control the UI language elsewhere. 328 * only on Chrome OS and Windows; we don't control the UI language elsewhere.
252 * @param {string} languageCode The language code identifying a language. 329 * @param {string} languageCode The language code identifying a language.
253 * @param {string} prospectiveUILanguage The prospective UI language. 330 * @param {string} prospectiveUILanguage The prospective UI language.
254 * @return {boolean} True if the given language matches the prospective UI 331 * @return {boolean} True if the given language matches the prospective UI
255 * pref (which may be different from the actual UI language). 332 * pref (which may be different from the actual UI language).
256 * @private 333 * @private
257 */ 334 */
258 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) { 335 isProspectiveUILanguage_: function(languageCode, prospectiveUILanguage) {
259 assert(cr.isChromeOS || cr.isWindows); 336 assert(cr.isChromeOS || cr.isWindows);
260 return languageCode == this.languageHelper.getProspectiveUILanguage(); 337 return languageCode == this.languageHelper.getProspectiveUILanguage();
261 }, 338 },
(...skipping 13 matching lines...) Expand all
275 * selected on Chrome OS and Windows. 352 * selected on Chrome OS and Windows.
276 * @param {string} languageCode The language code identifying a language. 353 * @param {string} languageCode The language code identifying a language.
277 * @param {string} prospectiveUILanguage The prospective UI language. 354 * @param {string} prospectiveUILanguage The prospective UI language.
278 * @param {boolean} supportsUI Whether Chrome's UI can be shown in this 355 * @param {boolean} supportsUI Whether Chrome's UI can be shown in this
279 * language. 356 * language.
280 * @return {string} The class name for the language item. 357 * @return {string} The class name for the language item.
281 * @private 358 * @private
282 */ 359 */
283 getLanguageItemClass_: function(languageCode, prospectiveUILanguage, 360 getLanguageItemClass_: function(languageCode, prospectiveUILanguage,
284 supportsUI) { 361 supportsUI) {
285 var classes = []; 362 if ((cr.isChromeOS || cr.isWindows) &&
363 this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage)) {
364 return 'selected';
365 }
366 return '';
367 },
286 368
287 if (cr.isChromeOS || cr.isWindows) { 369 /**
288 if (supportsUI && !loadTimeData.getBoolean('isGuest')) 370 * @param {string} languageCode The language code identifying a language.
289 classes.push('list-button'); // Makes the item look "actionable". 371 * @param {string} prospectiveUILanguage The prospective UI language.
290 372 * @return {boolean} True if the prospective UI language is set to
291 if (this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage)) 373 * |languageCode| but requires a restart to take effect.
292 classes.push('selected'); 374 * @private
293 } 375 */
294 376 isRestartRequired_: function(languageCode, prospectiveUILanguage) {
295 return classes.join(' '); 377 return prospectiveUILanguage == languageCode &&
378 navigator.language != languageCode;
296 }, 379 },
297 380
298 /** 381 /**
299 * @param {string} id The input method ID. 382 * @param {string} id The input method ID.
300 * @param {string} currentId The ID of the currently enabled input method. 383 * @param {string} currentId The ID of the currently enabled input method.
301 * @return {boolean} True if the IDs match. 384 * @return {boolean} True if the IDs match.
302 * @private 385 * @private
303 */ 386 */
304 isCurrentInputMethod_: function(id, currentId) { 387 isCurrentInputMethod_: function(id, currentId) {
305 assert(cr.isChromeOS); 388 assert(cr.isChromeOS);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 * @param {!Event} e 424 * @param {!Event} e
342 * @private 425 * @private
343 */ 426 */
344 toggleMenu_: function(e) { 427 toggleMenu_: function(e) {
345 e.stopPropagation(); // Prevent the tap event from closing the menu. 428 e.stopPropagation(); // Prevent the tap event from closing the menu.
346 429
347 this.detailLanguage_ = 430 this.detailLanguage_ =
348 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item; 431 /** @type {!{model: !{item: !LanguageState}}} */(e).model.item;
349 432
350 // Ensure the template has been stamped. 433 // Ensure the template has been stamped.
351 if (!this.menu_) { 434 if (!this.menu_)
352 this.$.menuTemplate.if = true; 435 this.initializeMenu_();
353 this.$.menuTemplate.render(); 436
354 this.menu_ = /** @type {CrSharedMenuElement} */( 437 this.menu_.toggleMenu(e.target);
355 this.$$('cr-shared-menu')); 438 },
439
440 /**
441 * Stamps the menu and applies Chrome OS session tweaks.
442 * @private
443 */
444 initializeMenu_: function() {
445 this.$.menuTemplate.if = true;
446 this.$.menuTemplate.render();
stevenjb 2016/09/20 16:17:59 This is interesting. Can you point me to the docum
michaelpg 2016/09/21 19:28:13 Changed this to use history's cr-lazy-render. But
stevenjb 2016/09/21 19:45:56 Ah, I missed that, thanks.
447 this.menu_ = /** @type {CrSharedMenuElement} */(
448 this.$$('cr-shared-menu'));
449
450 // In a CrOS multi-user session, the primary user controls the UI language.
451 // TODO(michaelpg): The language selection should not be hidden, but should
452 // show a policy indicator. crbug.com/648498
453 if (this.isSecondaryUser_())
454 this.menu_.querySelector('#uiLanguageItem').hidden = true;
455
456 // The UI language choice doesn't persist for guests.
457 if (cr.isChromeOS &&
458 (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() ||
459 uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) {
460 this.menu_.querySelector('#uiLanguageItem').hidden = true;
356 } 461 }
357 this.menu_.toggleMenu(e.target); 462 },
463
464 /**
465 * Handler for the restart button.
466 * @private
467 */
468 onRestartTap_: function() {
469 <if expr="chromeos">
470 settings.LifetimeBrowserProxyImpl.getInstance().logOutAndRestart();
471 </if>
472 <if expr="not chromeos">
473 settings.LifetimeBrowserProxyImpl.getInstance().restart();
474 </if>
stevenjb 2016/09/20 16:17:59 Ugh. It would be nice if we could make logOutAndRe
michaelpg 2016/09/21 19:28:13 CrOS can also "restart" without the logOut, e.g. w
stevenjb 2016/09/21 19:45:56 signOutAndRestart I think is correct on Chrome OS,
358 }, 475 },
359 }); 476 });
360 })(); 477 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698