| 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 Account picker screen implementation. | 6 * @fileoverview Account picker screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 login.createScreen('AccountPickerScreen', 'account-picker', function() { | 9 login.createScreen('AccountPickerScreen', 'account-picker', function() { |
| 10 /** | 10 /** |
| 11 * Maximum number of offline login failures before online login. | 11 * Maximum number of offline login failures before online login. |
| 12 * @type {number} | 12 * @type {number} |
| 13 * @const | 13 * @const |
| 14 */ | 14 */ |
| 15 var MAX_LOGIN_ATTEMPTS_IN_POD = 3; | 15 var MAX_LOGIN_ATTEMPTS_IN_POD = 3; |
| 16 | 16 |
| 17 /** |
| 18 * Distance between error bubble and user POD. |
| 19 * @type {number} |
| 20 * @const |
| 21 */ |
| 22 var BUBBLE_POD_OFFSET = 4; |
| 23 |
| 17 return { | 24 return { |
| 18 EXTERNAL_API: [ | 25 EXTERNAL_API: [ |
| 19 'loadUsers', | 26 'loadUsers', |
| 20 'runAppForTesting', | 27 'runAppForTesting', |
| 21 'setApps', | 28 'setApps', |
| 22 'setShouldShowApps', | 29 'setShouldShowApps', |
| 23 'showAppError', | 30 'showAppError', |
| 24 'updateUserImage', | 31 'updateUserImage', |
| 25 'setCapsLockState', | 32 'setCapsLockState', |
| 26 'forceLockedUserPodFocus', | 33 'forceLockedUserPodFocus', |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 chrome.send('maxIncorrectPasswordAttempts', | 179 chrome.send('maxIncorrectPasswordAttempts', |
| 173 [activatedPod.user.emailAddress]); | 180 [activatedPod.user.emailAddress]); |
| 174 activatedPod.showSigninUI(); | 181 activatedPod.showSigninUI(); |
| 175 } else { | 182 } else { |
| 176 if (loginAttempts == 1) { | 183 if (loginAttempts == 1) { |
| 177 chrome.send('firstIncorrectPasswordAttempt', | 184 chrome.send('firstIncorrectPasswordAttempt', |
| 178 [activatedPod.user.emailAddress]); | 185 [activatedPod.user.emailAddress]); |
| 179 } | 186 } |
| 180 // Update the pod row display if incorrect password. | 187 // Update the pod row display if incorrect password. |
| 181 $('pod-row').setFocusedPodErrorDisplay(true); | 188 $('pod-row').setFocusedPodErrorDisplay(true); |
| 182 // We want bubble's arrow to point to the first letter of input. | |
| 183 /** @const */ var BUBBLE_OFFSET = 7; | |
| 184 /** @const */ var BUBBLE_PADDING = 4; | |
| 185 | 189 |
| 186 // Anchor the bubble to the pod instead of the input if the pin keyboard | 190 /** @const */ var BUBBLE_OFFSET = 25; |
| 187 // is showing to avoid covering parts of the pin keyboard. | 191 // -8 = 4(BUBBLE_POD_OFFSET) - 2(bubble margin) |
| 192 // - 10(internal bubble adjustment) |
| 193 var bubblePositioningPadding = -8; |
| 194 |
| 188 var bubbleAnchor; | 195 var bubbleAnchor; |
| 189 if (activatedPod.pinContainer) | 196 var attachment; |
| 197 if (activatedPod.pinContainer) { |
| 198 // Anchor the bubble to the input field. |
| 199 bubbleAnchor = ( |
| 200 activatedPod.getElementsByClassName('auth-container'))[0]; |
| 201 if (!bubbleAnchor) { |
| 202 console.error('auth-container not found!'); |
| 203 bubbleAnchor = activatedPod.mainInput; |
| 204 } |
| 205 attachment = cr.ui.Bubble.Attachment.RIGHT; |
| 206 } else { |
| 207 // Anchor the bubble to the pod instead of the input. |
| 190 bubbleAnchor = activatedPod; | 208 bubbleAnchor = activatedPod; |
| 191 else | 209 attachment = cr.ui.Bubble.Attachment.BOTTOM; |
| 192 bubbleAnchor = activatedPod.mainInput; | 210 } |
| 193 | 211 |
| 194 // We want the bubble to point to where the input is after it is done | 212 var bubble = $('bubble'); |
| 195 // transitioning. | 213 |
| 196 var showBottomCallback = function() { | 214 // Cannot use cr.ui.LoginUITools.get* on bubble until it is attached to |
| 215 // the element. getMaxHeight/Width rely on the correct up/left element |
| 216 // side positioning that doesn't happen until bubble is attached. |
| 217 var maxHeight = |
| 218 cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping(bubbleAnchor) |
| 219 - bubbleAnchor.offsetHeight - BUBBLE_POD_OFFSET; |
| 220 var maxWidth = cr.ui.LoginUITools.getMaxWidthToFit(bubbleAnchor) |
| 221 - bubbleAnchor.offsetWidth - BUBBLE_POD_OFFSET; |
| 222 |
| 223 // Change bubble visibility temporary to calculate height. |
| 224 var bubbleVisibility = bubble.style.visibility; |
| 225 bubble.style.visibility = 'hidden'; |
| 226 bubble.hidden = false; |
| 227 // Now we need the bubble to have the new content before calculating |
| 228 // size. |
| 229 bubble.replaceContent(error); |
| 230 // Get bubble size. |
| 231 var bubbleOffsetHeight = parseInt(bubble.offsetHeight); |
| 232 var bubbleOffsetWidth = parseInt(bubble.offsetWidth); |
| 233 // Restore attributes. |
| 234 bubble.style.visibility = bubbleVisibility; |
| 235 bubble.hidden = true; |
| 236 |
| 237 if (attachment == cr.ui.Bubble.Attachment.BOTTOM) { |
| 238 // Move error bubble if it overlaps the shelf. |
| 239 if (maxHeight < bubbleOffsetHeight) |
| 240 attachment = cr.ui.Bubble.Attachment.TOP; |
| 241 } else { |
| 242 // Move error bubble if it doesn't fit screen. |
| 243 if (maxWidth < bubbleOffsetWidth) { |
| 244 bubblePositioningPadding = 2; |
| 245 attachment = cr.ui.Bubble.Attachment.LEFT; |
| 246 } |
| 247 } |
| 248 var showBubbleCallback = function() { |
| 197 activatedPod.removeEventListener("webkitTransitionEnd", | 249 activatedPod.removeEventListener("webkitTransitionEnd", |
| 198 showBottomCallback); | 250 showBubbleCallback); |
| 199 $('bubble').showContentForElement(bubbleAnchor, | 251 $('bubble').showContentForElement(bubbleAnchor, |
| 200 cr.ui.Bubble.Attachment.BOTTOM, | 252 attachment, |
| 201 error, | 253 error, |
| 202 BUBBLE_OFFSET, BUBBLE_PADDING); | 254 BUBBLE_OFFSET, |
| 255 bubblePositioningPadding, true); |
| 203 }; | 256 }; |
| 204 activatedPod.addEventListener("webkitTransitionEnd", | 257 activatedPod.addEventListener("webkitTransitionEnd", |
| 205 showBottomCallback); | 258 showBubbleCallback); |
| 206 ensureTransitionEndEvent(activatedPod); | 259 ensureTransitionEndEvent(activatedPod); |
| 207 | |
| 208 // Move error bubble up if it overlaps the shelf. | |
| 209 var maxHeight = | |
| 210 cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping($('bubble')); | |
| 211 if (maxHeight < $('bubble').offsetHeight) { | |
| 212 var showTopCallback = function() { | |
| 213 activatedPod.removeEventListener("webkitTransitionEnd", | |
| 214 showTopCallback); | |
| 215 $('bubble').showContentForElement(bubbleAnchor, | |
| 216 cr.ui.Bubble.Attachment.TOP, | |
| 217 error, | |
| 218 BUBBLE_OFFSET, BUBBLE_PADDING); | |
| 219 }; | |
| 220 activatedPod.addEventListener("webkitTransitionEnd", showTopCallback); | |
| 221 ensureTransitionEndEvent(activatedPod); | |
| 222 } | |
| 223 } | 260 } |
| 224 }, | 261 }, |
| 225 | 262 |
| 226 /** | 263 /** |
| 227 * Loads the PIN keyboard if any of the users can login with a PIN. Disables | 264 * Loads the PIN keyboard if any of the users can login with a PIN. Disables |
| 228 * the PIN keyboard for users who are not allowed to use PIN unlock. | 265 * the PIN keyboard for users who are not allowed to use PIN unlock. |
| 229 * @param {array} users Array of user instances. | 266 * @param {array} users Array of user instances. |
| 230 */ | 267 */ |
| 231 initializePinKeyboardStateForUsers_: function(users) { | 268 initializePinKeyboardStateForUsers_: function(users) { |
| 232 for (var i = 0; i < users.length; ++i) { | 269 for (var i = 0; i < users.length; ++i) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 * @param {string} userID The user ID of the public session | 465 * @param {string} userID The user ID of the public session |
| 429 * @param {string} locale The locale to which this list of keyboard layouts | 466 * @param {string} locale The locale to which this list of keyboard layouts |
| 430 * applies | 467 * applies |
| 431 * @param {!Object} list List of available keyboard layouts | 468 * @param {!Object} list List of available keyboard layouts |
| 432 */ | 469 */ |
| 433 setPublicSessionKeyboardLayouts: function(userID, locale, list) { | 470 setPublicSessionKeyboardLayouts: function(userID, locale, list) { |
| 434 $('pod-row').setPublicSessionKeyboardLayouts(userID, locale, list); | 471 $('pod-row').setPublicSessionKeyboardLayouts(userID, locale, list); |
| 435 } | 472 } |
| 436 }; | 473 }; |
| 437 }); | 474 }); |
| OLD | NEW |