OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 User pod row implementation. | 6 * @fileoverview User pod row implementation. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('login', function() { | 9 cr.define('login', function() { |
10 /** | 10 /** |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 * @const | 43 * @const |
44 */ | 44 */ |
45 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; | 45 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; |
46 | 46 |
47 /** | 47 /** |
48 * Variables used for pod placement processing. Width and height should be | 48 * Variables used for pod placement processing. Width and height should be |
49 * synced with computed CSS sizes of pods. | 49 * synced with computed CSS sizes of pods. |
50 */ | 50 */ |
51 var POD_WIDTH = 180; | 51 var POD_WIDTH = 180; |
52 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; | 52 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; |
| 53 var PUBLIC_EXPANDED_ADVANCED_WIDTH = 610; |
53 var CROS_POD_HEIGHT = 213; | 54 var CROS_POD_HEIGHT = 213; |
54 var DESKTOP_POD_HEIGHT = 226; | 55 var DESKTOP_POD_HEIGHT = 226; |
55 var POD_ROW_PADDING = 10; | 56 var POD_ROW_PADDING = 10; |
56 var DESKTOP_ROW_PADDING = 15; | 57 var DESKTOP_ROW_PADDING = 15; |
57 | 58 |
58 /** | 59 /** |
59 * Minimal padding between user pod and virtual keyboard. | 60 * Minimal padding between user pod and virtual keyboard. |
60 * @type {number} | 61 * @type {number} |
61 * @const | 62 * @const |
62 */ | 63 */ |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 return this.classList.contains('expanded'); | 990 return this.classList.contains('expanded'); |
990 }, | 991 }, |
991 | 992 |
992 set expanded(expanded) { | 993 set expanded(expanded) { |
993 if (this.expanded == expanded) | 994 if (this.expanded == expanded) |
994 return; | 995 return; |
995 | 996 |
996 this.resetTabOrder(); | 997 this.resetTabOrder(); |
997 this.classList.toggle('expanded', expanded); | 998 this.classList.toggle('expanded', expanded); |
998 if (expanded) { | 999 if (expanded) { |
999 var isDesktopUserManager = Oobe.getInstance().displayType == | |
1000 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | |
1001 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : | |
1002 POD_ROW_PADDING; | |
1003 this.usualLeft = this.left; | 1000 this.usualLeft = this.left; |
1004 this.usualTop = this.top; | 1001 this.makeSpaceForExpandedPod_(); |
1005 if (this.left + PUBLIC_EXPANDED_BASIC_WIDTH > | 1002 } else if (typeof(this.usualLeft) != 'undefined') { |
1006 $('pod-row').offsetWidth - rowPadding) | 1003 this.left = this.usualLeft; |
1007 this.left = $('pod-row').offsetWidth - rowPadding - | |
1008 PUBLIC_EXPANDED_BASIC_WIDTH; | |
1009 } else { | |
1010 if (typeof(this.usualLeft) != 'undefined') | |
1011 this.left = this.usualLeft; | |
1012 if (typeof(this.usualTop) != 'undefined') | |
1013 this.top = this.usualTop; | |
1014 } | 1004 } |
1015 | 1005 |
1016 var self = this; | 1006 var self = this; |
1017 this.classList.add('animating'); | 1007 this.classList.add('animating'); |
1018 this.addEventListener('webkitTransitionEnd', function f(e) { | 1008 this.addEventListener('webkitTransitionEnd', function f(e) { |
1019 self.removeEventListener('webkitTransitionEnd', f); | 1009 self.removeEventListener('webkitTransitionEnd', f); |
1020 self.classList.remove('animating'); | 1010 self.classList.remove('animating'); |
1021 | 1011 |
1022 // Accessibility focus indicator does not move with the focused | 1012 // Accessibility focus indicator does not move with the focused |
1023 // element. Sends a 'focus' event on the currently focused element | 1013 // element. Sends a 'focus' event on the currently focused element |
1024 // so that accessibility focus indicator updates its location. | 1014 // so that accessibility focus indicator updates its location. |
1025 if (document.activeElement) | 1015 if (document.activeElement) |
1026 document.activeElement.dispatchEvent(new Event('focus')); | 1016 document.activeElement.dispatchEvent(new Event('focus')); |
1027 }); | 1017 }); |
| 1018 // Guard timer set to animation duration + 20ms. |
| 1019 ensureTransitionEndEvent(this, 200); |
1028 }, | 1020 }, |
1029 | 1021 |
1030 /** @override */ | 1022 /** @override */ |
1031 get mainInput() { | 1023 get mainInput() { |
1032 if (this.expanded) | 1024 if (this.expanded) |
1033 return this.enterButtonElement; | 1025 return this.enterButtonElement; |
1034 else | 1026 else |
1035 return this.nameElement; | 1027 return this.nameElement; |
1036 }, | 1028 }, |
1037 | 1029 |
(...skipping 16 matching lines...) Expand all Loading... |
1054 | 1046 |
1055 var learnMore = this.querySelector('.learn-more'); | 1047 var learnMore = this.querySelector('.learn-more'); |
1056 learnMore.addEventListener('mousedown', stopEventPropagation); | 1048 learnMore.addEventListener('mousedown', stopEventPropagation); |
1057 learnMore.addEventListener('click', this.handleLearnMoreEvent); | 1049 learnMore.addEventListener('click', this.handleLearnMoreEvent); |
1058 learnMore.addEventListener('keydown', this.handleLearnMoreEvent); | 1050 learnMore.addEventListener('keydown', this.handleLearnMoreEvent); |
1059 | 1051 |
1060 learnMore = this.querySelector('.expanded-pane-learn-more'); | 1052 learnMore = this.querySelector('.expanded-pane-learn-more'); |
1061 learnMore.addEventListener('click', this.handleLearnMoreEvent); | 1053 learnMore.addEventListener('click', this.handleLearnMoreEvent); |
1062 learnMore.addEventListener('keydown', this.handleLearnMoreEvent); | 1054 learnMore.addEventListener('keydown', this.handleLearnMoreEvent); |
1063 | 1055 |
| 1056 var languageSelect = this.querySelector('.language-select'); |
| 1057 languageSelect.tabIndex = UserPodTabOrder.POD_INPUT; |
| 1058 languageSelect.addEventListener('change', function() { |
| 1059 chrome.send('getPublicSessionKeyboardLayouts', [ |
| 1060 this.user.username, |
| 1061 languageSelect.options[languageSelect.selectedIndex].value]); |
| 1062 }.bind(this)); |
| 1063 |
| 1064 this.querySelector('.keyboard-select').tabIndex = |
| 1065 UserPodTabOrder.POD_INPUT; |
| 1066 |
| 1067 var languageAndInput = this.querySelector('.language-and-input'); |
| 1068 languageAndInput.tabIndex = UserPodTabOrder.POD_INPUT; |
| 1069 languageAndInput.addEventListener('click', |
| 1070 this.transitionToAdvanced_.bind(this)); |
| 1071 |
1064 this.enterButtonElement.addEventListener('click', (function(e) { | 1072 this.enterButtonElement.addEventListener('click', (function(e) { |
1065 this.enterButtonElement.disabled = true; | 1073 this.enterButtonElement.disabled = true; |
1066 chrome.send('launchPublicAccount', [this.user.username]); | 1074 chrome.send('launchPublicAccount', [this.user.username]); |
1067 }).bind(this)); | 1075 }).bind(this)); |
1068 }, | 1076 }, |
1069 | 1077 |
1070 /** @override **/ | 1078 /** @override **/ |
| 1079 initialize: function() { |
| 1080 UserPod.prototype.initialize.call(this); |
| 1081 |
| 1082 var id = this.user.username + '-language'; |
| 1083 this.querySelector('.language-select-label').htmlFor = id; |
| 1084 var languageSelect = this.querySelector('.language-select'); |
| 1085 languageSelect.setAttribute('id', id); |
| 1086 var list = this.user.initialLocales; |
| 1087 languageSelect.innerHTML = ''; |
| 1088 var group = languageSelect; |
| 1089 for (var i = 0; i < list.length; ++i) { |
| 1090 var item = list[i]; |
| 1091 if (item.optionGroupName) { |
| 1092 group = document.createElement('optgroup'); |
| 1093 group.label = item.optionGroupName; |
| 1094 languageSelect.appendChild(group); |
| 1095 } else { |
| 1096 group.appendChild( |
| 1097 new Option(item.title, item.value, item.selected, item.selected)); |
| 1098 } |
| 1099 } |
| 1100 |
| 1101 id = this.user.username + '-keyboard'; |
| 1102 this.querySelector('.keyboard-select-label').htmlFor = id; |
| 1103 this.querySelector('.keyboard-select').setAttribute('id', id); |
| 1104 this.populateKeyboardSelect_(this.user.initialKeyboardLayouts); |
| 1105 }, |
| 1106 |
| 1107 /** @override **/ |
1071 update: function() { | 1108 update: function() { |
1072 UserPod.prototype.update.call(this); | 1109 UserPod.prototype.update.call(this); |
1073 this.querySelector('.expanded-pane-name').textContent = | 1110 this.querySelector('.expanded-pane-name').textContent = |
1074 this.user_.displayName; | 1111 this.user_.displayName; |
1075 this.querySelector('.info').textContent = | 1112 this.querySelector('.info').textContent = |
1076 loadTimeData.getStringF('publicAccountInfoFormat', | 1113 loadTimeData.getStringF('publicAccountInfoFormat', |
1077 this.user_.enterpriseDomain); | 1114 this.user_.enterpriseDomain); |
1078 }, | 1115 }, |
1079 | 1116 |
1080 /** @override */ | 1117 /** @override */ |
1081 focusInput: function() { | 1118 focusInput: function() { |
1082 // Move tabIndex from the whole pod to the main input. | 1119 // Move tabIndex from the whole pod to the main input. |
1083 this.tabIndex = -1; | 1120 this.tabIndex = -1; |
1084 this.mainInput.tabIndex = UserPodTabOrder.POD_INPUT; | 1121 this.mainInput.tabIndex = UserPodTabOrder.POD_INPUT; |
1085 this.mainInput.focus(); | 1122 this.mainInput.focus(); |
1086 }, | 1123 }, |
1087 | 1124 |
1088 /** @override */ | 1125 /** @override */ |
1089 reset: function(takeFocus) { | 1126 reset: function(takeFocus) { |
1090 if (!takeFocus) | 1127 if (!takeFocus) |
1091 this.expanded = false; | 1128 this.expanded = false; |
1092 this.enterButtonElement.disabled = false; | 1129 this.enterButtonElement.disabled = false; |
1093 UserPod.prototype.reset.call(this, takeFocus); | 1130 UserPod.prototype.reset.call(this, takeFocus); |
1094 }, | 1131 }, |
1095 | 1132 |
1096 /** @override */ | 1133 /** @override */ |
1097 activate: function(e) { | 1134 activate: function(e) { |
1098 this.expanded = true; | 1135 if (!this.expanded) { |
1099 this.focusInput(); | 1136 this.expanded = true; |
| 1137 this.focusInput(); |
| 1138 } |
1100 return true; | 1139 return true; |
1101 }, | 1140 }, |
1102 | 1141 |
1103 /** @override */ | 1142 /** @override */ |
1104 handleClickOnPod_: function(e) { | 1143 handleClickOnPod_: function(e) { |
1105 if (this.parentNode.disabled) | 1144 if (this.parentNode.disabled) |
1106 return; | 1145 return; |
1107 | 1146 |
1108 this.parentNode.focusPod(this); | 1147 this.parentNode.focusPod(this); |
1109 this.parentNode.setActivatedPod(this, e); | 1148 this.parentNode.setActivatedPod(this, e); |
(...skipping 21 matching lines...) Expand all Loading... |
1131 case 32: // Space. | 1170 case 32: // Space. |
1132 break; | 1171 break; |
1133 default: | 1172 default: |
1134 return; | 1173 return; |
1135 } | 1174 } |
1136 break; | 1175 break; |
1137 } | 1176 } |
1138 chrome.send('launchHelpApp', [HELP_TOPIC_PUBLIC_SESSION]); | 1177 chrome.send('launchHelpApp', [HELP_TOPIC_PUBLIC_SESSION]); |
1139 stopEventPropagation(event); | 1178 stopEventPropagation(event); |
1140 }, | 1179 }, |
| 1180 |
| 1181 makeSpaceForExpandedPod_: function() { |
| 1182 var width = this.classList.contains('advanced') ? |
| 1183 PUBLIC_EXPANDED_ADVANCED_WIDTH : PUBLIC_EXPANDED_BASIC_WIDTH; |
| 1184 var isDesktopUserManager = Oobe.getInstance().displayType == |
| 1185 DISPLAY_TYPE.DESKTOP_USER_MANAGER; |
| 1186 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : |
| 1187 POD_ROW_PADDING; |
| 1188 if (this.left + width > $('pod-row').offsetWidth - rowPadding) |
| 1189 this.left = $('pod-row').offsetWidth - rowPadding - width; |
| 1190 }, |
| 1191 |
| 1192 /** |
| 1193 * Transition the expanded pod from the basic to the advanced view. |
| 1194 */ |
| 1195 transitionToAdvanced_: function() { |
| 1196 var pod = this; |
| 1197 var languageAndInputSection = |
| 1198 this.querySelector('.language-and-input-section'); |
| 1199 this.classList.add('transitioning-to-advanced'); |
| 1200 setTimeout(function() { |
| 1201 pod.classList.add('advanced'); |
| 1202 pod.makeSpaceForExpandedPod_(); |
| 1203 languageAndInputSection.addEventListener('webkitTransitionEnd', |
| 1204 function observer() { |
| 1205 languageAndInputSection.removeEventListener('webkitTransitionEnd', |
| 1206 observer); |
| 1207 pod.classList.remove('transitioning-to-advanced'); |
| 1208 pod.querySelector('.language-select').focus(); |
| 1209 }); |
| 1210 // Guard timer set to animation duration + 20ms. |
| 1211 ensureTransitionEndEvent(languageAndInputSection, 380); |
| 1212 }, 0); |
| 1213 }, |
| 1214 |
| 1215 /** |
| 1216 * Populates the keyboard layout "select" element with a list of layouts. |
| 1217 * @param {!Object} list List of available keyboard layouts |
| 1218 */ |
| 1219 populateKeyboardSelect_: function(list) { |
| 1220 var keyboardSelect = this.querySelector('.keyboard-select'); |
| 1221 keyboardSelect.innerHTML = ''; |
| 1222 for (var i = 0; i < list.length; ++i) { |
| 1223 var item = list[i]; |
| 1224 keyboardSelect.appendChild( |
| 1225 new Option(item.title, item.value, item.selected, item.selected)); |
| 1226 } |
| 1227 } |
1141 }; | 1228 }; |
1142 | 1229 |
1143 /** | 1230 /** |
1144 * Creates a user pod to be used only in desktop chrome. | 1231 * Creates a user pod to be used only in desktop chrome. |
1145 * @constructor | 1232 * @constructor |
1146 * @extends {UserPod} | 1233 * @extends {UserPod} |
1147 */ | 1234 */ |
1148 var DesktopUserPod = cr.ui.define(function() { | 1235 var DesktopUserPod = cr.ui.define(function() { |
1149 // Don't just instantiate a UserPod(), as this will call decorate() on the | 1236 // Don't just instantiate a UserPod(), as this will call decorate() on the |
1150 // parent object, and add duplicate event listeners. | 1237 // parent object, and add duplicate event listeners. |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 /** @const */ var BUBBLE_OFFSET = 20; | 1813 /** @const */ var BUBBLE_OFFSET = 20; |
1727 /** @const */ var BUBBLE_PADDING = 8; | 1814 /** @const */ var BUBBLE_PADDING = 8; |
1728 $('bubble').showContentForElement(attachElement, | 1815 $('bubble').showContentForElement(attachElement, |
1729 cr.ui.Bubble.Attachment.RIGHT, | 1816 cr.ui.Bubble.Attachment.RIGHT, |
1730 bubbleContent, | 1817 bubbleContent, |
1731 BUBBLE_OFFSET, | 1818 BUBBLE_OFFSET, |
1732 BUBBLE_PADDING); | 1819 BUBBLE_PADDING); |
1733 }, | 1820 }, |
1734 | 1821 |
1735 /** | 1822 /** |
| 1823 * Updates the list of available keyboard layouts for a public session pod. |
| 1824 * @param {string} userID The user ID of the public session |
| 1825 * @param {!Object} list List of available keyboard layouts |
| 1826 */ |
| 1827 setPublicSessionKeyboardLayouts: function(userID, list) { |
| 1828 var pod = this.getPodWithUsername_(userID); |
| 1829 if (pod != null) |
| 1830 pod.populateKeyboardSelect_(list); |
| 1831 }, |
| 1832 |
| 1833 /** |
1736 * Called when window was resized. | 1834 * Called when window was resized. |
1737 */ | 1835 */ |
1738 onWindowResize: function() { | 1836 onWindowResize: function() { |
1739 var layout = this.calculateLayout_(); | 1837 var layout = this.calculateLayout_(); |
1740 if (layout.columns != this.columns || layout.rows != this.rows) | 1838 if (layout.columns != this.columns || layout.rows != this.rows) |
1741 this.placePods_(); | 1839 this.placePods_(); |
1742 | 1840 |
1743 if (Oobe.getInstance().virtualKeyboardShown) | 1841 if (Oobe.getInstance().virtualKeyboardShown) |
1744 this.scrollFocusedPodIntoView(); | 1842 this.scrollFocusedPodIntoView(); |
1745 }, | 1843 }, |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2080 // Clears focus if not clicked on a pod and if there's more than one pod. | 2178 // Clears focus if not clicked on a pod and if there's more than one pod. |
2081 var pod = findAncestorByClass(e.target, 'pod'); | 2179 var pod = findAncestorByClass(e.target, 'pod'); |
2082 if ((!pod || pod.parentNode != this) && !this.alwaysFocusSinglePod) { | 2180 if ((!pod || pod.parentNode != this) && !this.alwaysFocusSinglePod) { |
2083 this.focusPod(); | 2181 this.focusPod(); |
2084 } | 2182 } |
2085 | 2183 |
2086 if (pod) | 2184 if (pod) |
2087 pod.isActionBoxMenuHovered = true; | 2185 pod.isActionBoxMenuHovered = true; |
2088 | 2186 |
2089 // Return focus back to single pod. | 2187 // Return focus back to single pod. |
2090 if (this.alwaysFocusSinglePod) { | 2188 if (this.alwaysFocusSinglePod && !pod) { |
2091 this.focusPod(this.focusedPod_, true /* force */); | 2189 this.focusPod(this.focusedPod_, true /* force */); |
2092 this.focusedPod_.userTypeBubbleElement.classList.remove('bubble-shown'); | 2190 this.focusedPod_.userTypeBubbleElement.classList.remove('bubble-shown'); |
2093 if (!pod) | 2191 this.focusedPod_.isActionBoxMenuHovered = false; |
2094 this.focusedPod_.isActionBoxMenuHovered = false; | |
2095 } | 2192 } |
2096 }, | 2193 }, |
2097 | 2194 |
2098 /** | 2195 /** |
2099 * Handler of mouse move event. | 2196 * Handler of mouse move event. |
2100 * @param {Event} e Click Event object. | 2197 * @param {Event} e Click Event object. |
2101 * @private | 2198 * @private |
2102 */ | 2199 */ |
2103 handleMouseMove_: function(e) { | 2200 handleMouseMove_: function(e) { |
2104 if (this.disabled) | 2201 if (this.disabled) |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2293 if (this.podsWithPendingImages_.length == 0) { | 2390 if (this.podsWithPendingImages_.length == 0) { |
2294 this.classList.remove('images-loading'); | 2391 this.classList.remove('images-loading'); |
2295 } | 2392 } |
2296 } | 2393 } |
2297 }; | 2394 }; |
2298 | 2395 |
2299 return { | 2396 return { |
2300 PodRow: PodRow | 2397 PodRow: PodRow |
2301 }; | 2398 }; |
2302 }); | 2399 }); |
OLD | NEW |