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

Unified Diff: ui/login/account_picker/user_pod_row.js

Issue 426063005: Allow recommended locales to be set for public sessions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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: ui/login/account_picker/user_pod_row.js
diff --git a/ui/login/account_picker/user_pod_row.js b/ui/login/account_picker/user_pod_row.js
index 494c58f389f5863c16945e62d8185aee218a1967..6772a1c46fd726abbb2a08fdf2a80c12c0af89f6 100644
--- a/ui/login/account_picker/user_pod_row.js
+++ b/ui/login/account_picker/user_pod_row.js
@@ -997,6 +997,11 @@ cr.define('login', function() {
this.resetTabOrder();
this.classList.toggle('expanded', expanded);
if (expanded) {
+ // Show the advanced expanded pod directly if there are at least two
+ // recommended locales. This will be the case in multilingual
+ // environments where users are likely to want to choose among locales.
+ if (this.querySelector('.language-select').multipleRecommendedLocales)
+ this.classList.add('advanced');
this.usualLeft = this.left;
this.makeSpaceForExpandedPod_();
} else if (typeof(this.usualLeft) != 'undefined') {
@@ -1059,11 +1064,17 @@ cr.define('login', function() {
var languageSelect = this.querySelector('.language-select');
languageSelect.tabIndex = UserPodTabOrder.POD_INPUT;
+ languageSelect.manuallyChanged = false;
languageSelect.addEventListener(
'change',
- this.getPublicSessionKeyboardLayouts_.bind(this));
- this.querySelector('.keyboard-select').tabIndex =
- UserPodTabOrder.POD_INPUT;
+ function() {
+ languageSelect.manuallyChanged = true;
+ this.getPublicSessionKeyboardLayouts_();
+ }.bind(this));
+
+ var keyboardSelect = this.querySelector('.keyboard-select');
+ keyboardSelect.tabIndex = UserPodTabOrder.POD_INPUT;
+ keyboardSelect.loadedLocale = null;
var languageAndInput = this.querySelector('.language-and-input');
languageAndInput.tabIndex = UserPodTabOrder.POD_INPUT;
@@ -1072,14 +1083,15 @@ cr.define('login', function() {
this.enterButtonElement.addEventListener('click', (function(e) {
this.enterButtonElement.disabled = true;
- var locale = "";
- var keyboardLayout = "";
- if (this.advanced) {
- // If the advanced pod is being shown, honor the selected UI language
- // and keyboard layout.
- locale = this.querySelector('.language-select').value;
- keyboardLayout = this.querySelector('.keyboard-select').value;
- }
+ var locale = this.querySelector('.language-select').value;
+ var keyboardSelect = this.querySelector('.keyboard-select');
+ // The contents of |keyboardSelect| is updated asynchronously. If its
+ // locale does not match |locale|, it has not updated yet and the
+ // currently selected keyboard layout may not be applicable to |locale|.
+ // Do not return any keyboard layout in this case and let the backend
+ // choose a suitable layout.
+ var keyboardLayout =
+ keyboardSelect.loadedLocale == locale ? keyboardSelect.value : "";
Nikita (slow) 2014/07/30 11:22:59 nit: ''
bartfab (slow) 2014/08/05 17:16:24 Done.
chrome.send('launchPublicSession',
[this.user.username, locale, keyboardLayout]);
}).bind(this));
@@ -1089,30 +1101,17 @@ cr.define('login', function() {
initialize: function() {
UserPod.prototype.initialize.call(this);
+ id = this.user.username + '-keyboard';
+ this.querySelector('.keyboard-select-label').htmlFor = id;
+ this.querySelector('.keyboard-select').setAttribute('id', id);
+
var id = this.user.username + '-language';
this.querySelector('.language-select-label').htmlFor = id;
var languageSelect = this.querySelector('.language-select');
languageSelect.setAttribute('id', id);
- var list = this.user.initialLocales;
- languageSelect.innerHTML = '';
- var group = languageSelect;
- for (var i = 0; i < list.length; ++i) {
- var item = list[i];
- if (item.optionGroupName) {
- group = document.createElement('optgroup');
- group.label = item.optionGroupName;
- languageSelect.appendChild(group);
- } else {
- group.appendChild(
- new Option(item.title, item.value, item.selected, item.selected));
- }
- }
-
- id = this.user.username + '-keyboard';
- this.querySelector('.keyboard-select-label').htmlFor = id;
- this.querySelector('.keyboard-select').setAttribute('id', id);
- this.populateKeyboardSelect_([this.user.initialKeyboardLayout]);
- this.getPublicSessionKeyboardLayouts_();
+ this.populateLanguageSelect(this.user.initialLocales,
+ this.user.initialLocale,
+ this.user.initialMultipleRecommendedLocales);
},
/** @override **/
@@ -1237,24 +1236,76 @@ cr.define('login', function() {
* selected locale.
*/
getPublicSessionKeyboardLayouts_: function() {
- var languageSelect = this.querySelector('.language-select');
- chrome.send('getPublicSessionKeyboardLayouts', [
- this.user.username,
- languageSelect.options[languageSelect.selectedIndex].value]);
+ var selectedLocale = this.querySelector('.language-select').value;
+ if (selectedLocale ==
+ this.querySelector('.keyboard-select').loadedLocale) {
+ // If the list of keyboard layouts was loaded for the currently selected
+ // locale, it is already up to date.
+ return;
+ }
+ chrome.send('getPublicSessionKeyboardLayouts',
+ [this.user.username, selectedLocale]);
},
/**
* Populates the keyboard layout "select" element with a list of layouts.
+ * @param {string} locale The locale to which this list of keyboard layouts
+ * applies
* @param {!Object} list List of available keyboard layouts
*/
- populateKeyboardSelect_: function(list) {
+ populateKeyboardSelect: function(locale, list) {
+ if (locale != this.querySelector('.language-select').value) {
+ // The selected locale has changed and the list of keyboard layouts is
+ // not applicable. This method will be called again when a list of
+ // keyboard layouts applicable to the selected locale is retrieved.
+ return;
+ }
+
var keyboardSelect = this.querySelector('.keyboard-select');
+ keyboardSelect.loadedLocale = locale;
keyboardSelect.innerHTML = '';
for (var i = 0; i < list.length; ++i) {
var item = list[i];
keyboardSelect.appendChild(
new Option(item.title, item.value, item.selected, item.selected));
}
+ },
+
+ /**
+ * Populates the language "select" element with a list of locales.
+ * @param {!Object} locales The list of available locales
+ * @param {string} defaultLocale The locale to select by default
+ * @param {boolean} multipleRecommendedLocales Whether |locales| contains
+ * two or more recommended locales
+ */
+ populateLanguageSelect: function(locales,
+ defaultLocale,
+ multipleRecommendedLocales) {
+ var languageSelect = this.querySelector('.language-select');
+ // If the user manually selected a locale, do not change the selection.
+ // Otherwise, select the new |defaultLocale|.
+ var selected =
+ languageSelect.manuallyChanged ? languageSelect.value : defaultLocale;
+ languageSelect.innerHTML = '';
+ var group = languageSelect;
+ for (var i = 0; i < locales.length; ++i) {
+ var item = locales[i];
+ if (item.optionGroupName) {
+ group = document.createElement('optgroup');
+ group.label = item.optionGroupName;
+ languageSelect.appendChild(group);
+ } else {
+ group.appendChild(new Option(item.title,
+ item.value,
+ item.value == selected,
+ item.value == selected));
+ }
+ }
+ languageSelect.multipleRecommendedLocales = multipleRecommendedLocales;
+
+ // Retrieve a list of keyboard layouts applicable to the locale that is
+ // now selected.
+ this.getPublicSessionKeyboardLayouts_();
}
};
@@ -1862,14 +1913,36 @@ cr.define('login', function() {
},
/**
+ * Updates the list of locales available for a public session.
+ * @param {string} userID The user ID of the public session
+ * @param {!Object} locales The list of available locales
+ * @param {string} defaultLocale The locale to select by default
+ * @param {boolean} multipleRecommendedLocales Whether |locales| contains
+ * two or more recommended locales
+ */
+ setPublicSessionLocales: function(userID,
+ locales,
+ defaultLocale,
+ multipleRecommendedLocales) {
+ var pod = this.getPodWithUsername_(userID);
+ if (pod != null) {
+ pod.populateLanguageSelect(locales,
+ defaultLocale,
+ multipleRecommendedLocales);
+ }
+ },
+
+ /**
* Updates the list of available keyboard layouts for a public session pod.
* @param {string} userID The user ID of the public session
+ * @param {string} locale The locale to which this list of keyboard layouts
+ * applies
* @param {!Object} list List of available keyboard layouts
*/
- setPublicSessionKeyboardLayouts: function(userID, list) {
+ setPublicSessionKeyboardLayouts: function(userID, locale, list) {
var pod = this.getPodWithUsername_(userID);
if (pod != null)
- pod.populateKeyboardSelect_(list);
+ pod.populateKeyboardSelect(locale, list);
},
/**

Powered by Google App Engine
This is Rietveld 408576698