OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 // in sign-in UI being shown. | 99 // in sign-in UI being shown. |
100 e.stopPropagation(); | 100 e.stopPropagation(); |
101 }); | 101 }); |
102 this.removeUserButtonElement.addEventListener('click', | 102 this.removeUserButtonElement.addEventListener('click', |
103 this.handleRemoveButtonClick_.bind(this)); | 103 this.handleRemoveButtonClick_.bind(this)); |
104 this.removeUserButtonElement.addEventListener('mouseout', | 104 this.removeUserButtonElement.addEventListener('mouseout', |
105 this.handleRemoveButtonMouseOutOrBlur_.bind(this)); | 105 this.handleRemoveButtonMouseOutOrBlur_.bind(this)); |
106 // TODO(altimofeev): this will trigger when Gaia extension grabs focus. | 106 // TODO(altimofeev): this will trigger when Gaia extension grabs focus. |
107 this.removeUserButtonElement.addEventListener('blur', | 107 this.removeUserButtonElement.addEventListener('blur', |
108 this.handleRemoveButtonMouseOutOrBlur_.bind(this)); | 108 this.handleRemoveButtonMouseOutOrBlur_.bind(this)); |
109 | |
110 // |plainUserImage| and |animatedUserImage| are images for | |
111 // |non-animated and animated versions of user image. Used for | |
112 // |fast swapping between them (for instance, when user pod | |
Ivan Korotkov
2012/05/29 10:50:23
Stray |
Ivan Korotkov
2012/05/29 10:50:23
/swapping/switching/
ygorshenin1
2012/05/30 12:17:34
Done.
| |
113 // becomes active). | |
114 this.plainUserImage = new Image(); | |
115 this.animatedUserImage = new Image(); | |
116 // That flag is true, when we show animated (when possible) | |
117 // version of user image, and false otherwise. | |
118 this.userImageIsAnimated = false; | |
109 }, | 119 }, |
110 | 120 |
111 /** | 121 /** |
112 * Initializes the pod after its properties set and added to a pod row. | 122 * Initializes the pod after its properties set and added to a pod row. |
113 */ | 123 */ |
114 initialize: function() { | 124 initialize: function() { |
115 // TODO(flackr): Get rid of multiple blur listeners. We should be able to | 125 // TODO(flackr): Get rid of multiple blur listeners. We should be able to |
116 // use a single focusout listener on the pod or entire row but this is not | 126 // use a single focusout listener on the pod or entire row but this is not |
117 // being sent for some reason when you open the status area menus despite | 127 // being sent for some reason when you open the status area menus despite |
118 // blur being sent. | 128 // blur being sent. |
(...skipping 15 matching lines...) Expand all Loading... | |
134 this.imageElement.addEventListener('load', | 144 this.imageElement.addEventListener('load', |
135 this.parentNode.handlePodImageLoad.bind(this.parentNode, this)); | 145 this.parentNode.handlePodImageLoad.bind(this.parentNode, this)); |
136 }, | 146 }, |
137 | 147 |
138 /** | 148 /** |
139 * Resets tab order for pod elements to its initial state. | 149 * Resets tab order for pod elements to its initial state. |
140 */ | 150 */ |
141 resetTabOrder: function() { | 151 resetTabOrder: function() { |
142 this.tabIndex = UserPodTabOrder.POD_INPUT; | 152 this.tabIndex = UserPodTabOrder.POD_INPUT; |
143 this.mainInput.tabIndex = -1; | 153 this.mainInput.tabIndex = -1; |
154 | |
155 if (!this.isGuest) { | |
156 this.userImageIsAnimated = false; | |
157 this.updateUserImage_(); | |
158 } | |
144 }, | 159 }, |
145 | 160 |
146 /** | 161 /** |
147 * Handles keyup event on password input. | 162 * Handles keyup event on password input. |
148 * @param {Event} e Keyup Event object. | 163 * @param {Event} e Keyup Event object. |
149 * @private | 164 * @private |
150 */ | 165 */ |
151 handlePasswordKeyUp_: function(e) { | 166 handlePasswordKeyUp_: function(e) { |
152 this.passwordEmpty = !e.target.value; | 167 this.passwordEmpty = !e.target.value; |
153 }, | 168 }, |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 354 |
340 /** | 355 /** |
341 * Whether the password field is empty. | 356 * Whether the password field is empty. |
342 * @type {boolean} | 357 * @type {boolean} |
343 */ | 358 */ |
344 set passwordEmpty(empty) { | 359 set passwordEmpty(empty) { |
345 this.passwordElement.classList[empty ? 'add' : 'remove']('empty'); | 360 this.passwordElement.classList[empty ? 'add' : 'remove']('empty'); |
346 }, | 361 }, |
347 | 362 |
348 /** | 363 /** |
364 * Changes user image to animated or non-animated image from | |
365 * internal buffers. | |
366 */ | |
367 updateUserImage_: function() { | |
368 if (!this.isGuest) { | |
Ivan Korotkov
2012/05/29 10:50:23
Let's remove this function and move the code to "s
ygorshenin1
2012/05/30 12:17:34
In discussion for crbug.com/114083 it was decided
| |
369 this.imageElement.src = this.userImageIsAnimated ? | |
370 this.animatedUserImage.src : this.plainUserImage.src; | |
371 } | |
372 }, | |
373 | |
374 /** | |
349 * Updates the image element of the user. | 375 * Updates the image element of the user. |
350 */ | 376 */ |
351 updateUserImage: function() { | 377 updateUserImage: function() { |
352 this.imageElement.src = this.isGuest ? | 378 if (this.isGuest) { |
353 'chrome://theme/IDR_LOGIN_GUEST' : | 379 this.imageElement.src = 'chrome://theme/IDR_LOGIN_GUEST'; |
354 'chrome://userimage/' + this.user.username + | 380 } else { |
355 '?id=' + (new Date()).getTime(); | 381 var src = 'chrome://userimage/' + this.user.username + |
382 '?id=' + (new Date()).getTime(); | |
383 this.plainUserImage.src = src; | |
384 | |
385 src += '&animated=true'; | |
386 this.animatedUserImage.src = src; | |
387 | |
388 this.updateUserImage_(); | |
389 } | |
356 }, | 390 }, |
357 | 391 |
358 /** | 392 /** |
359 * Focuses on input element. | 393 * Focuses on input element. |
360 */ | 394 */ |
361 focusInput: function() { | 395 focusInput: function() { |
362 if (!this.isGuest) { | 396 if (!this.isGuest) { |
363 var needSignin = this.needGaiaSignin; | 397 var needSignin = this.needGaiaSignin; |
364 this.signinButtonElement.hidden = !needSignin; | 398 this.signinButtonElement.hidden = !needSignin; |
365 this.passwordElement.hidden = needSignin; | 399 this.passwordElement.hidden = needSignin; |
400 | |
401 if (!this.userImageIsAnimated) { | |
402 this.userImageIsAnimated = true; | |
403 this.updateUserImage_(); | |
404 } | |
366 } | 405 } |
367 // Move tabIndex from the whole pod to the main input. | 406 // Move tabIndex from the whole pod to the main input. |
368 this.tabIndex = -1; | 407 this.tabIndex = -1; |
369 this.mainInput.tabIndex = UserPodTabOrder.POD_INPUT; | 408 this.mainInput.tabIndex = UserPodTabOrder.POD_INPUT; |
370 this.mainInput.focus(); | 409 this.mainInput.focus(); |
371 }, | 410 }, |
372 | 411 |
373 /** | 412 /** |
374 * Activates the pod. | 413 * Activates the pod. |
375 * @return {boolean} True if activated successfully. | 414 * @return {boolean} True if activated successfully. |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 if (this.podsWithPendingImages_.length == 0) { | 906 if (this.podsWithPendingImages_.length == 0) { |
868 chrome.send('userImagesLoaded'); | 907 chrome.send('userImagesLoaded'); |
869 } | 908 } |
870 } | 909 } |
871 }; | 910 }; |
872 | 911 |
873 return { | 912 return { |
874 PodRow: PodRow | 913 PodRow: PodRow |
875 }; | 914 }; |
876 }); | 915 }); |
OLD | NEW |