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

Side by Side Diff: chrome/browser/resources/chromeos/login/user_pod_row.js

Issue 10207030: Asynchronously load wallpapers when user pod is selected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Pod width. 170px Pod + 10px padding + 10px margin on both sides. 10 /**
11 const POD_WIDTH = 170 + 2 * (10 + 10); 11 * Pod width. 170px Pod + 10px padding + 10px margin on both sides.
12 * @type {number}
13 * @const
14 */
15 var POD_WIDTH = 170 + 2 * (10 + 10);
16
17 /**
18 * Wallpaper load delay in milliseconds.
19 * @type {number}
20 * @const
21 */
22 var WALLPAPER_LOAD_DELAY_MS = 800;
12 23
13 /** 24 /**
14 * Oauth token status. These must match UserManager::OAuthTokenStatus. 25 * Oauth token status. These must match UserManager::OAuthTokenStatus.
15 * @enum {number} 26 * @enum {number}
27 * @const
16 */ 28 */
17 const OAuthTokenStatus = { 29 var OAuthTokenStatus = {
18 UNKNOWN: 0, 30 UNKNOWN: 0,
19 INVALID: 1, 31 INVALID: 1,
20 VALID: 2 32 VALID: 2
21 }; 33 };
22 34
23 /** 35 /**
24 * Tab order for user pods. Update these when adding new controls. 36 * Tab order for user pods. Update these when adding new controls.
25 * @enum {number} 37 * @enum {number}
38 * @const
26 */ 39 */
27 const UserPodTabOrder = { 40 var UserPodTabOrder = {
28 POD_INPUT: 1, // Password input fields (and whole pods themselves). 41 POD_INPUT: 1, // Password input fields (and whole pods themselves).
29 HEADER_BAR: 2, // Buttons on the header bar (Shutdown, Add User). 42 HEADER_BAR: 2, // Buttons on the header bar (Shutdown, Add User).
30 REMOVE_USER: 3 // Remove ('X') buttons. 43 REMOVE_USER: 3 // Remove ('X') buttons.
31 }; 44 };
32 45
33 // Focus and tab order are organized as follows: 46 // Focus and tab order are organized as follows:
34 // 47 //
35 // (1) all user pods have tab index 1 so they are traversed first; 48 // (1) all user pods have tab index 1 so they are traversed first;
36 // (2) when a user pod is activated, its tab index is set to -1 and its 49 // (2) when a user pod is activated, its tab index is set to -1 and its
37 // main input field gets focus and tab index 1; 50 // main input field gets focus and tab index 1;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Mousedown has to be used instead of click to be able to prevent 'focus' 85 // Mousedown has to be used instead of click to be able to prevent 'focus'
73 // event later. 86 // event later.
74 this.addEventListener('mousedown', 87 this.addEventListener('mousedown',
75 this.handleMouseDown_.bind(this)); 88 this.handleMouseDown_.bind(this));
76 89
77 this.enterButtonElement.addEventListener('click', 90 this.enterButtonElement.addEventListener('click',
78 this.activate.bind(this)); 91 this.activate.bind(this));
79 this.signinButtonElement.addEventListener('click', 92 this.signinButtonElement.addEventListener('click',
80 this.activate.bind(this)); 93 this.activate.bind(this));
81 94
82 this.removeUserButtonElement.addEventListener('mousedown', function (e) { 95 this.removeUserButtonElement.addEventListener('mousedown', function(e) {
83 // Prevent default so that we don't trigger a 'focus' event. 96 // Prevent default so that we don't trigger a 'focus' event.
84 e.preventDefault(); 97 e.preventDefault();
85 // Prevent the 'mousedown' event for the whole pod, which could result 98 // Prevent the 'mousedown' event for the whole pod, which could result
86 // in sign-in UI being shown. 99 // in sign-in UI being shown.
87 e.stopPropagation(); 100 e.stopPropagation();
88 }); 101 });
89 this.removeUserButtonElement.addEventListener('click', 102 this.removeUserButtonElement.addEventListener('click',
90 this.handleRemoveButtonClick_.bind(this)); 103 this.handleRemoveButtonClick_.bind(this));
91 this.removeUserButtonElement.addEventListener('mouseout', 104 this.removeUserButtonElement.addEventListener('mouseout',
92 this.handleRemoveButtonMouseOutOrBlur_.bind(this)); 105 this.handleRemoveButtonMouseOutOrBlur_.bind(this));
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 * Creates a new pod row element. 458 * Creates a new pod row element.
446 * @constructor 459 * @constructor
447 * @extends {HTMLDivElement} 460 * @extends {HTMLDivElement}
448 */ 461 */
449 var PodRow = cr.ui.define('podrow'); 462 var PodRow = cr.ui.define('podrow');
450 463
451 PodRow.prototype = { 464 PodRow.prototype = {
452 __proto__: HTMLDivElement.prototype, 465 __proto__: HTMLDivElement.prototype,
453 466
454 // Focused pod. 467 // Focused pod.
455 focusedPod_ : undefined, 468 focusedPod_: undefined,
456 469
457 // Activated pod, i.e. the pod of current login attempt. 470 // Activated pod, i.e. the pod of current login attempt.
458 activatedPod_: undefined, 471 activatedPod_: undefined,
459 472
473 // When moving through users quickly at login screen, set a timeout to
474 // prevent loading intermediate wallpapers.
475 loadWallpaperTimeout_: null,
476
460 // Pods whose initial images haven't been loaded yet. 477 // Pods whose initial images haven't been loaded yet.
461 podsWithPendingImages_: [], 478 podsWithPendingImages_: [],
462 479
463 /** @inheritDoc */ 480 /** @inheritDoc */
464 decorate: function() { 481 decorate: function() {
465 this.style.left = 0; 482 this.style.left = 0;
466 483
467 // Event listeners that are installed for the time period during which 484 // Event listeners that are installed for the time period during which
468 // the element is visible. 485 // the element is visible.
469 this.listeners_ = { 486 this.listeners_ = {
(...skipping 22 matching lines...) Expand all
492 if (pod.user.username == username) 509 if (pod.user.username == username)
493 return pod; 510 return pod;
494 } 511 }
495 return null; 512 return null;
496 }, 513 },
497 514
498 /** 515 /**
499 * True if the the pod row is disabled (handles no user interaction). 516 * True if the the pod row is disabled (handles no user interaction).
500 * @type {boolean} 517 * @type {boolean}
501 */ 518 */
502 disabled_ : false, 519 disabled_: false,
503 get disabled() { 520 get disabled() {
504 return this.disabled_; 521 return this.disabled_;
505 }, 522 },
506 set disabled(value) { 523 set disabled(value) {
507 this.disabled_ = value; 524 this.disabled_ = value;
508 var controls = this.querySelectorAll('button,input'); 525 var controls = this.querySelectorAll('button,input');
509 for (var i = 0, control; control = controls[i]; ++i) { 526 for (var i = 0, control; control = controls[i]; ++i) {
510 control.disabled = value; 527 control.disabled = value;
511 } 528 }
512 }, 529 },
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 /** 642 /**
626 * Focuses a given user pod or clear focus when given null. 643 * Focuses a given user pod or clear focus when given null.
627 * @param {UserPod=} podToFocus User pod to focus (undefined clears focus). 644 * @param {UserPod=} podToFocus User pod to focus (undefined clears focus).
628 * @param {boolean=} opt_force If true, forces focus update even when 645 * @param {boolean=} opt_force If true, forces focus update even when
629 * podToFocus is already focused. 646 * podToFocus is already focused.
630 */ 647 */
631 focusPod: function(podToFocus, opt_force) { 648 focusPod: function(podToFocus, opt_force) {
632 if (this.focusedPod_ == podToFocus && !opt_force) 649 if (this.focusedPod_ == podToFocus && !opt_force)
633 return; 650 return;
634 651
652 clearTimeout(this.loadWallpaperTimeout_);
635 for (var i = 0, pod; pod = this.pods[i]; ++i) { 653 for (var i = 0, pod; pod = this.pods[i]; ++i) {
636 pod.activeRemoveButton = false; 654 pod.activeRemoveButton = false;
637 if (pod != podToFocus) { 655 if (pod != podToFocus) {
638 pod.classList.remove('focused'); 656 pod.classList.remove('focused');
639 pod.classList.remove('faded'); 657 pod.classList.remove('faded');
640 pod.reset(false); 658 pod.reset(false);
641 } 659 }
642 } 660 }
643 661
644 this.focusedPod_ = podToFocus; 662 this.focusedPod_ = podToFocus;
645 if (podToFocus) { 663 if (podToFocus) {
646 podToFocus.classList.remove('faded'); 664 podToFocus.classList.remove('faded');
647 podToFocus.classList.add('focused'); 665 podToFocus.classList.add('focused');
648 podToFocus.reset(true); // Reset and give focus. 666 podToFocus.reset(true); // Reset and give focus.
649 this.scrollPodIntoView(podToFocus); 667 this.scrollPodIntoView(podToFocus);
668 this.loadWallpaperTimeout_ = window.setTimeout(function() {
669 chrome.send('userSelectedDelayed', [podToFocus.user.username]);
670 }, WALLPAPER_LOAD_DELAY_MS);
650 } 671 }
651 }, 672 },
652 673
653 /** 674 /**
654 * Returns the currently activated pod. 675 * Returns the currently activated pod.
655 * @type {UserPod} 676 * @type {UserPod}
656 */ 677 */
657 get activatedPod() { 678 get activatedPod() {
658 return this.activatedPod_; 679 return this.activatedPod_;
659 }, 680 },
(...skipping 29 matching lines...) Expand all
689 * @param {string} email Email for signin UI. 710 * @param {string} email Email for signin UI.
690 */ 711 */
691 showSigninUI: function(email) { 712 showSigninUI: function(email) {
692 this.disabled = true; 713 this.disabled = true;
693 Oobe.showSigninUI(email); 714 Oobe.showSigninUI(email);
694 }, 715 },
695 716
696 /** 717 /**
697 * Updates current image of a user. 718 * Updates current image of a user.
698 * @param {string} username User for which to update the image. 719 * @param {string} username User for which to update the image.
699 * @public
700 */ 720 */
701 updateUserImage: function(username) { 721 updateUserImage: function(username) {
702 var pod = this.getPodWithUsername_(username); 722 var pod = this.getPodWithUsername_(username);
703 if (pod) 723 if (pod)
704 pod.updateUserImage(); 724 pod.updateUserImage();
705 }, 725 },
706 726
707 /** 727 /**
708 * Resets OAuth token status (invalidates it). 728 * Resets OAuth token status (invalidates it).
709 * @param {string} username User for which to reset the status. 729 * @param {string} username User for which to reset the status.
710 * @public
711 */ 730 */
712 resetUserOAuthTokenStatus: function(username) { 731 resetUserOAuthTokenStatus: function(username) {
713 var pod = this.getPodWithUsername_(username); 732 var pod = this.getPodWithUsername_(username);
714 if (pod) { 733 if (pod) {
715 pod.user.oauthTokenStatus = OAuthTokenStatus.INVALID; 734 pod.user.oauthTokenStatus = OAuthTokenStatus.INVALID;
716 pod.update(); 735 pod.update();
717 } else { 736 } else {
718 console.log('Failed to update Gaia state for: ' + username); 737 console.log('Failed to update Gaia state for: ' + username);
719 } 738 }
720 }, 739 },
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 * @param {Event} e Blur Event object. 785 * @param {Event} e Blur Event object.
767 */ 786 */
768 handleBlur: function(e) { 787 handleBlur: function(e) {
769 // Clear focus when the pod input is blurred. 788 // Clear focus when the pod input is blurred.
770 this.focusPod(); 789 this.focusPod();
771 }, 790 },
772 791
773 /** 792 /**
774 * Handler of keydown event. 793 * Handler of keydown event.
775 * @param {Event} e KeyDown Event object. 794 * @param {Event} e KeyDown Event object.
776 * @public
777 */ 795 */
778 handleKeyDown: function(e) { 796 handleKeyDown: function(e) {
779 if (this.disabled) 797 if (this.disabled)
780 return; 798 return;
781 var editing = e.target.tagName == 'INPUT' && e.target.value; 799 var editing = e.target.tagName == 'INPUT' && e.target.value;
782 switch (e.keyIdentifier) { 800 switch (e.keyIdentifier) {
783 case 'Left': 801 case 'Left':
784 if (!editing) { 802 if (!editing) {
785 if (this.focusedPod_ && this.focusedPod_.previousElementSibling) 803 if (this.focusedPod_ && this.focusedPod_.previousElementSibling)
786 this.focusPod(this.focusedPod_.previousElementSibling); 804 this.focusPod(this.focusedPod_.previousElementSibling);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 if (this.podsWithPendingImages_.length == 0) { 865 if (this.podsWithPendingImages_.length == 0) {
848 chrome.send('userImagesLoaded'); 866 chrome.send('userImagesLoaded');
849 } 867 }
850 } 868 }
851 }; 869 };
852 870
853 return { 871 return {
854 PodRow: PodRow 872 PodRow: PodRow
855 }; 873 };
856 }); 874 });
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/webui_login_display.cc ('k') | chrome/browser/ui/views/ash/chrome_shell_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698