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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/languages_page/languages_page.js
diff --git a/chrome/browser/resources/settings/languages_page/languages_page.js b/chrome/browser/resources/settings/languages_page/languages_page.js
index d4d3198345f44cb065ee32300f4e37214b0b13f5..8bd513e26947af2ca69e027109b142165ec9d39e 100644
--- a/chrome/browser/resources/settings/languages_page/languages_page.js
+++ b/chrome/browser/resources/settings/languages_page/languages_page.js
@@ -125,6 +125,92 @@ Polymer({
},
/**
+ * @param {!LanguageState} languageState
+ * @param {string} prospectiveUILanguage The chosen UI language.
+ * @return {boolean} True if the given language cannot be set/unset as the
+ * prospective UI language by the user.
+ * @private
+ */
+ disableUILanguageCheckbox_: function(languageState, prospectiveUILanguage) {
+ // UI language setting belongs to the primary user.
+ if (this.isSecondaryUser_())
+ return true;
+
+ // UI language setting belongs to the primary user.
+ if (this.isSecondaryUser_())
+ return true;
stevenjb 2016/09/20 16:17:59 Dupe
michaelpg 2016/09/21 19:28:13 Done.
+
+ // If the language cannot be a UI language, we can't set/unset it as the
+ // prospective UI language.
+ if (!languageState.language.supportsUI)
+ return true;
+
+ // If the language already is the prospective UI language, it can't be unset
+ // if it is also the *actual* UI language, as we wouldn't know what other
+ // language to set as the prospective UI language.
+ if (languageState.language.code == navigator.language &&
+ (!prospectiveUILanguage ||
+ languageState.language.code == prospectiveUILanguage)) {
+ return true;
+ }
+
+ // 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.
+ return false;
+ },
+
+ /**
+ * @return {boolean} True for a secondary user in a multi-profile session.
+ * @private
+ */
+ isSecondaryUser_: function() {
+ return cr.isChromeOS && loadTimeData.getBoolean('isSecondaryUser');
+ },
+
+ /**
+ * Handler for changes to the UI language checkbox.
+ * @param {!{target: !PaperCheckboxElement}} e
+ * @private
+ */
+ onUILanguageChange_: function(e) {
+ if (e.target.checked) {
+ this.languageHelper.setUILanguage(this.detailLanguage_.language.code);
+ } else if (this.detailLanguage_.language.code ==
+ this.languageHelper.getProspectiveUILanguage()) {
+ // Reset the chosen UI language to the actual UI language.
+ this.languageHelper.resetUILanguage();
+ }
+ },
+
+ /**
+ * @param {!chrome.languageSettingsPrivate.Language} language
+ * @param {string} targetLanguageCode The default translate target language.
+ * @return {boolean} True if the translate checkbox should be disabled.
+ * @private
+ */
+ disableTranslateCheckbox_: function(language, targetLanguageCode) {
+ if (!language.supportsTranslate)
+ return true;
+
+ return this.languageHelper.convertLanguageCodeForTranslate(language.code) ==
+ targetLanguageCode;
+ },
+
+ /**
+ * Handler for changes to the translate checkbox.
+ * @param {!{target: !PaperCheckboxElement}} e
+ * @private
+ */
+ onTranslateCheckboxChange_: function(e) {
+ if (e.target.checked) {
+ this.languageHelper.enableTranslateLanguage(
+ this.detailLanguage_.language.code);
+ } else {
+ this.languageHelper.disableTranslateLanguage(
+ this.detailLanguage_.language.code);
+ }
+ },
+
+ /**
* Moves the language up in the list.
* @private
*/
@@ -152,15 +238,6 @@ Polymer({
},
/**
- * Opens the Language Detail page for the language.
- * @private
- */
- onShowLanguageDetailTap_: function() {
- this.menu_.closeMenu();
- settings.navigateTo(settings.Route.LANGUAGES_DETAIL);
- },
-
- /**
* Opens the Manage Input Methods page.
* @private
*/
@@ -247,8 +324,8 @@ Polymer({
/**
* Checks whether the prospective UI language (the pref that indicates what
- * language to use in Chrome) matches the current language. This pref is only
- * on Chrome OS and Windows; we don't control the UI language elsewhere.
+ * language to use in Chrome) matches the current language. This pref is used
+ * only on Chrome OS and Windows; we don't control the UI language elsewhere.
* @param {string} languageCode The language code identifying a language.
* @param {string} prospectiveUILanguage The prospective UI language.
* @return {boolean} True if the given language matches the prospective UI
@@ -282,17 +359,23 @@ Polymer({
*/
getLanguageItemClass_: function(languageCode, prospectiveUILanguage,
supportsUI) {
- var classes = [];
-
- if (cr.isChromeOS || cr.isWindows) {
- if (supportsUI && !loadTimeData.getBoolean('isGuest'))
- classes.push('list-button'); // Makes the item look "actionable".
-
- if (this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage))
- classes.push('selected');
+ if ((cr.isChromeOS || cr.isWindows) &&
+ this.isProspectiveUILanguage_(languageCode, prospectiveUILanguage)) {
+ return 'selected';
}
+ return '';
+ },
- return classes.join(' ');
+ /**
+ * @param {string} languageCode The language code identifying a language.
+ * @param {string} prospectiveUILanguage The prospective UI language.
+ * @return {boolean} True if the prospective UI language is set to
+ * |languageCode| but requires a restart to take effect.
+ * @private
+ */
+ isRestartRequired_: function(languageCode, prospectiveUILanguage) {
+ return prospectiveUILanguage == languageCode &&
+ navigator.language != languageCode;
},
/**
@@ -348,13 +431,47 @@ Polymer({
/** @type {!{model: !{item: !LanguageState}}} */(e).model.item;
// Ensure the template has been stamped.
- if (!this.menu_) {
- this.$.menuTemplate.if = true;
- this.$.menuTemplate.render();
- this.menu_ = /** @type {CrSharedMenuElement} */(
- this.$$('cr-shared-menu'));
- }
+ if (!this.menu_)
+ this.initializeMenu_();
+
this.menu_.toggleMenu(e.target);
},
+
+ /**
+ * Stamps the menu and applies Chrome OS session tweaks.
+ * @private
+ */
+ initializeMenu_: function() {
+ this.$.menuTemplate.if = true;
+ 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.
+ this.menu_ = /** @type {CrSharedMenuElement} */(
+ this.$$('cr-shared-menu'));
+
+ // In a CrOS multi-user session, the primary user controls the UI language.
+ // TODO(michaelpg): The language selection should not be hidden, but should
+ // show a policy indicator. crbug.com/648498
+ if (this.isSecondaryUser_())
+ this.menu_.querySelector('#uiLanguageItem').hidden = true;
+
+ // The UI language choice doesn't persist for guests.
+ if (cr.isChromeOS &&
+ (uiAccountTweaks.UIAccountTweaks.loggedInAsGuest() ||
+ uiAccountTweaks.UIAccountTweaks.loggedInAsPublicAccount())) {
+ this.menu_.querySelector('#uiLanguageItem').hidden = true;
+ }
+ },
+
+ /**
+ * Handler for the restart button.
+ * @private
+ */
+ onRestartTap_: function() {
+<if expr="chromeos">
+ settings.LifetimeBrowserProxyImpl.getInstance().logOutAndRestart();
+</if>
+<if expr="not chromeos">
+ settings.LifetimeBrowserProxyImpl.getInstance().restart();
+</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,
+ },
});
})();

Powered by Google App Engine
This is Rietveld 408576698