Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 var DESKTOP_POD_WIDTH = 180; | 52 var DESKTOP_POD_WIDTH = 180; |
| 53 var MD_DESKTOP_POD_WIDTH = 160; | 53 var MD_DESKTOP_POD_WIDTH = 160; |
| 54 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; | 54 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; |
| 55 var PUBLIC_EXPANDED_ADVANCED_WIDTH = 610; | 55 var PUBLIC_EXPANDED_ADVANCED_WIDTH = 610; |
| 56 var CROS_POD_HEIGHT = 213; | 56 var CROS_POD_HEIGHT = 213; |
| 57 var DESKTOP_POD_HEIGHT = 226; | 57 var DESKTOP_POD_HEIGHT = 226; |
| 58 var MD_DESKTOP_POD_HEIGHT = 200; | 58 var MD_DESKTOP_POD_HEIGHT = 200; |
| 59 var POD_ROW_PADDING = 10; | 59 var POD_ROW_PADDING = 10; |
| 60 var DESKTOP_ROW_PADDING = 32; | 60 var DESKTOP_ROW_PADDING = 32; |
| 61 var CUSTOM_ICON_CONTAINER_SIZE = 40; | 61 var CUSTOM_ICON_CONTAINER_SIZE = 40; |
| 62 var CROS_PIN_POD_WIDTH = 270; | |
| 63 var CROS_PIN_POD_HEIGHT = 594; | |
| 64 var PIN_EXTRA_WIDTH = 90; | |
| 62 | 65 |
| 63 /** | 66 /** |
| 64 * Minimal padding between user pod and virtual keyboard. | 67 * Minimal padding between user pod and virtual keyboard. |
| 65 * @type {number} | 68 * @type {number} |
| 66 * @const | 69 * @const |
| 67 */ | 70 */ |
| 68 var USER_POD_KEYBOARD_MIN_PADDING = 20; | 71 var USER_POD_KEYBOARD_MIN_PADDING = 20; |
| 69 | 72 |
| 70 /** | 73 /** |
| 71 * Maximum time for which the pod row remains hidden until all user images | 74 * Maximum time for which the pod row remains hidden until all user images |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 828 }, | 831 }, |
| 829 | 832 |
| 830 /** | 833 /** |
| 831 * Height number of pixels. | 834 * Height number of pixels. |
| 832 */ | 835 */ |
| 833 get height() { | 836 get height() { |
| 834 return this.offsetHeight; | 837 return this.offsetHeight; |
| 835 }, | 838 }, |
| 836 | 839 |
| 837 /** | 840 /** |
| 838 * Gets the authorization element of the pod. | |
| 839 * @type {!HTMLDivElement} | |
| 840 */ | |
| 841 get authElement() { | |
| 842 return this.querySelector('.auth-container'); | |
| 843 }, | |
| 844 | |
| 845 /** | |
| 846 * Gets image pane element. | |
| 847 * @type {!HTMLDivElement} | |
| 848 */ | |
| 849 get imagePaneElement() { | |
| 850 return this.querySelector('.user-image-pane'); | |
| 851 }, | |
| 852 | |
| 853 /** | |
| 854 * Gets image element. | 841 * Gets image element. |
| 855 * @type {!HTMLImageElement} | 842 * @type {!HTMLImageElement} |
| 856 */ | 843 */ |
| 857 get imageElement() { | 844 get imageElement() { |
| 858 return this.querySelector('.user-image'); | 845 return this.querySelector('.user-image'); |
| 859 }, | 846 }, |
| 860 | 847 |
| 861 /** | 848 /** |
| 862 * Gets name element. | 849 * Gets name element. |
| 863 * @type {!HTMLDivElement} | 850 * @type {!HTMLDivElement} |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 893 /** | 880 /** |
| 894 * Gets the password label, which is used to show a message where the | 881 * Gets the password label, which is used to show a message where the |
| 895 * password field is normally. | 882 * password field is normally. |
| 896 * @type {!HTMLInputElement} | 883 * @type {!HTMLInputElement} |
| 897 */ | 884 */ |
| 898 get passwordLabelElement() { | 885 get passwordLabelElement() { |
| 899 return this.querySelector('.password-label'); | 886 return this.querySelector('.password-label'); |
| 900 }, | 887 }, |
| 901 | 888 |
| 902 /** | 889 /** |
| 903 * Gets the pin-container of the pod. | |
| 904 * @type {!HTMLDivElement} | |
| 905 */ | |
| 906 get pinContainer() { | |
| 907 return this.querySelector('.pin-container'); | |
| 908 }, | |
| 909 | |
| 910 /** | |
| 911 * Gets the pin-keyboard of the pod. | 890 * Gets the pin-keyboard of the pod. |
| 912 * @type {!HTMLElement} | 891 * @type {!HTMLElement} |
| 913 */ | 892 */ |
| 914 get pinKeyboard() { | 893 get pinKeyboard() { |
| 915 return this.querySelector('pin-keyboard'); | 894 return this.querySelector('pin-keyboard'); |
| 916 }, | 895 }, |
| 917 | 896 |
| 918 /** | 897 /** |
| 919 * Gets user online sign in hint element. | 898 * Gets user online sign in hint element. |
| 920 * @type {!HTMLDivElement} | 899 * @type {!HTMLDivElement} |
| 921 */ | 900 */ |
| 922 get reauthWarningElement() { | 901 get reauthWarningElement() { |
| 923 return this.querySelector('.reauth-hint-container'); | 902 return this.querySelector('.reauth-hint-container'); |
| 924 }, | 903 }, |
| 925 | 904 |
| 926 /** | 905 /** |
| 927 * Gets the signed in indicator of the pod. | |
| 928 * @type {!HTMLDivElement} | |
| 929 */ | |
| 930 get signInElement() { | |
| 931 return this.querySelector('.signed-in-indicator'); | |
| 932 }, | |
| 933 | |
| 934 /** | |
| 935 * Gets the container holding the launch app button. | 906 * Gets the container holding the launch app button. |
| 936 * @type {!HTMLButtonElement} | 907 * @type {!HTMLButtonElement} |
| 937 */ | 908 */ |
| 938 get launchAppButtonContainerElement() { | 909 get launchAppButtonContainerElement() { |
| 939 return this.querySelector('.launch-app-button-container'); | 910 return this.querySelector('.launch-app-button-container'); |
| 940 }, | 911 }, |
| 941 | 912 |
| 942 /** | 913 /** |
| 943 * Gets launch app button. | 914 * Gets launch app button. |
| 944 * @type {!HTMLButtonElement} | 915 * @type {!HTMLButtonElement} |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1130 } else if (this.user_.isApp) { | 1101 } else if (this.user_.isApp) { |
| 1131 this.setUserPodIconType('app'); | 1102 this.setUserPodIconType('app'); |
| 1132 } | 1103 } |
| 1133 }, | 1104 }, |
| 1134 | 1105 |
| 1135 toggleTransitions: function(enable) { | 1106 toggleTransitions: function(enable) { |
| 1136 this.classList.toggle('flying-pin-pod', enable); | 1107 this.classList.toggle('flying-pin-pod', enable); |
| 1137 }, | 1108 }, |
| 1138 | 1109 |
| 1139 setPinVisibility: function(visible) { | 1110 setPinVisibility: function(visible) { |
| 1140 var elements = [this, this.authElement, this.imagePaneElement, | 1111 var elements = this.getElementsByClassName('pin-tag'); |
| 1141 this.imageElement, this.pinContainer]; | 1112 var elements_array = Array.prototype.slice.call(elements); |
| 1113 elements_array.push(this); | |
| 1142 | 1114 |
| 1143 for (var idx = 0; idx < elements.length; idx++) { | 1115 for (var idx = 0; idx < elements_array.length; idx++) { |
| 1144 var currentElement = elements[idx]; | 1116 var currentElement = elements_array[idx]; |
| 1145 currentElement.classList.toggle('pin-enabled', visible); | 1117 currentElement.classList.toggle('pin-enabled', visible); |
| 1146 currentElement.classList.toggle('pin-disabled', !visible); | 1118 currentElement.classList.toggle('pin-disabled', !visible); |
| 1147 } | 1119 } |
| 1148 | 1120 |
| 1149 // Set the focus to the input element after showing/hiding pin keyboard. | 1121 // Set the focus to the input element after showing/hiding pin keyboard. |
| 1150 if (visible) | 1122 if (visible) |
| 1151 this.pinKeyboard.focus(); | 1123 this.pinKeyboard.focus(); |
| 1152 else | 1124 else |
| 1153 this.mainInput.focus(); | 1125 this.mainInput.focus(); |
| 1154 }, | 1126 }, |
| 1155 | 1127 |
| 1128 isPinShown: function() { | |
| 1129 return this.classList.contains('pin-enabled'); | |
| 1130 }, | |
| 1131 | |
| 1156 setUserPodIconType: function(userTypeClass) { | 1132 setUserPodIconType: function(userTypeClass) { |
| 1157 this.userTypeIconAreaElement.classList.add(userTypeClass); | 1133 this.userTypeIconAreaElement.classList.add(userTypeClass); |
| 1158 this.userTypeIconAreaElement.hidden = false; | 1134 this.userTypeIconAreaElement.hidden = false; |
| 1159 }, | 1135 }, |
| 1160 | 1136 |
| 1161 /** | 1137 /** |
| 1162 * The user that this pod represents. | 1138 * The user that this pod represents. |
| 1163 * @type {!Object} | 1139 * @type {!Object} |
| 1164 */ | 1140 */ |
| 1165 user_: undefined, | 1141 user_: undefined, |
| (...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2572 togglePinTransitions: function(enable) { | 2548 togglePinTransitions: function(enable) { |
| 2573 for (var i = 0; i < this.pods.length; ++i) | 2549 for (var i = 0; i < this.pods.length; ++i) |
| 2574 this.pods[i].toggleTransitions(enable); | 2550 this.pods[i].toggleTransitions(enable); |
| 2575 }, | 2551 }, |
| 2576 | 2552 |
| 2577 setFocusedPodPinVisibility: function(visible) { | 2553 setFocusedPodPinVisibility: function(visible) { |
| 2578 if (this.focusedPod_ && this.focusedPod_.user.showPin) | 2554 if (this.focusedPod_ && this.focusedPod_.user.showPin) |
| 2579 this.focusedPod_.setPinVisibility(visible); | 2555 this.focusedPod_.setPinVisibility(visible); |
| 2580 }, | 2556 }, |
| 2581 | 2557 |
| 2558 isAnyPinShown_: function() { | |
| 2559 for (var i = 0; i < this.pods.length; ++i) { | |
| 2560 if (this.pods[i].isPinShown()) | |
| 2561 return true; | |
| 2562 } | |
| 2563 return false; | |
| 2564 }, | |
| 2565 | |
| 2582 /** | 2566 /** |
| 2583 * Runs app with a given id from the list of loaded apps. | 2567 * Runs app with a given id from the list of loaded apps. |
| 2584 * @param {!string} app_id of an app to run. | 2568 * @param {!string} app_id of an app to run. |
| 2585 * @param {boolean=} opt_diagnosticMode Whether to run the app in | 2569 * @param {boolean=} opt_diagnosticMode Whether to run the app in |
| 2586 * diagnostic mode. Default is false. | 2570 * diagnostic mode. Default is false. |
| 2587 */ | 2571 */ |
| 2588 findAndRunAppForTesting: function(app_id, opt_diagnosticMode) { | 2572 findAndRunAppForTesting: function(app_id, opt_diagnosticMode) { |
| 2589 var app = this.getPodWithAppId_(app_id); | 2573 var app = this.getPodWithAppId_(app_id); |
| 2590 if (app) { | 2574 if (app) { |
| 2591 var activationEvent = cr.doc.createEvent('MouseEvents'); | 2575 var activationEvent = cr.doc.createEvent('MouseEvents'); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3002 var layout = this.calculateLayout_(); | 2986 var layout = this.calculateLayout_(); |
| 3003 var columns = this.columns = layout.columns; | 2987 var columns = this.columns = layout.columns; |
| 3004 var rows = this.rows = layout.rows; | 2988 var rows = this.rows = layout.rows; |
| 3005 var maxPodsNumber = columns * rows; | 2989 var maxPodsNumber = columns * rows; |
| 3006 var margin = isDesktopUserManager ? DESKTOP_MARGIN_BY_COLUMNS[columns] : | 2990 var margin = isDesktopUserManager ? DESKTOP_MARGIN_BY_COLUMNS[columns] : |
| 3007 MARGIN_BY_COLUMNS[columns]; | 2991 MARGIN_BY_COLUMNS[columns]; |
| 3008 this.parentNode.setPreferredSize( | 2992 this.parentNode.setPreferredSize( |
| 3009 this.columnsToWidth_(columns), this.rowsToHeight_(rows)); | 2993 this.columnsToWidth_(columns), this.rowsToHeight_(rows)); |
| 3010 var height = this.userPodHeight_; | 2994 var height = this.userPodHeight_; |
| 3011 var width = this.userPodWidth_; | 2995 var width = this.userPodWidth_; |
| 2996 | |
| 2997 var pinShownRow = maxPodsNumber + 1; | |
| 2998 var pinShownColumn = maxPodsNumber + 1; | |
| 2999 var podWithPin = this.focusedPod_; | |
| 3000 | |
| 3001 if (this.isAnyPinShown_()) { | |
|
jdufault
2016/07/12 23:37:47
This logic is a bit confusing.
1. isAnyPinShown_
| |
| 3002 this.pods.forEach(function(pod, index) { | |
| 3003 var column = index % columns; | |
| 3004 var row = Math.floor(index / columns); | |
| 3005 if (pod == podWithPin) { | |
| 3006 pinShownRow = row; | |
| 3007 pinShownColumn = column; | |
| 3008 } | |
| 3009 }); | |
| 3010 } | |
| 3011 | |
| 3012 this.pods.forEach(function(pod, index) { | 3012 this.pods.forEach(function(pod, index) { |
| 3013 if (index >= maxPodsNumber) { | 3013 if (index >= maxPodsNumber) { |
| 3014 pod.hidden = true; | 3014 pod.hidden = true; |
| 3015 return; | 3015 return; |
| 3016 } | 3016 } |
| 3017 pod.hidden = false; | 3017 pod.hidden = false; |
| 3018 if (pod.offsetHeight != height) { | 3018 if (pod.offsetHeight != height && |
| 3019 pod.offsetHeight != CROS_PIN_POD_HEIGHT) { | |
| 3019 console.error('Pod offsetHeight (' + pod.offsetHeight + | 3020 console.error('Pod offsetHeight (' + pod.offsetHeight + |
| 3020 ') and POD_HEIGHT (' + height + ') are not equal.'); | 3021 ') and POD_HEIGHT (' + height + ') are not equal.'); |
| 3021 } | 3022 } |
| 3022 if (pod.offsetWidth != width) { | 3023 if (pod.offsetWidth != width && |
| 3024 pod.offsetWidth != CROS_PIN_POD_WIDTH) { | |
| 3023 console.error('Pod offsetWidth (' + pod.offsetWidth + | 3025 console.error('Pod offsetWidth (' + pod.offsetWidth + |
| 3024 ') and POD_WIDTH (' + width + ') are not equal.'); | 3026 ') and POD_WIDTH (' + width + ') are not equal.'); |
| 3025 } | 3027 } |
| 3026 var column = index % columns; | 3028 var column = index % columns; |
| 3027 var row = Math.floor(index / columns); | 3029 var row = Math.floor(index / columns); |
| 3030 var offsetFromPin = 0; | |
| 3031 if (row == pinShownRow) { | |
| 3032 offsetFromPin = PIN_EXTRA_WIDTH / 2; | |
| 3033 if (column <= pinShownColumn) | |
| 3034 offsetFromPin *= -1; | |
| 3035 } | |
| 3036 | |
| 3028 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : | 3037 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : |
| 3029 POD_ROW_PADDING; | 3038 POD_ROW_PADDING; |
| 3030 pod.left = rowPadding + column * (width + margin); | 3039 pod.left = rowPadding + column * (width + margin) + offsetFromPin; |
| 3031 | 3040 |
| 3032 // On desktop, we want the rows to always be equally spaced. | 3041 // On desktop, we want the rows to always be equally spaced. |
| 3033 pod.top = isDesktopUserManager ? row * (height + rowPadding) : | 3042 pod.top = isDesktopUserManager ? row * (height + rowPadding) : |
| 3034 row * height + rowPadding; | 3043 row * height + rowPadding; |
| 3035 }); | 3044 }); |
| 3036 Oobe.getInstance().updateScreenSize(this.parentNode); | 3045 Oobe.getInstance().updateScreenSize(this.parentNode); |
| 3037 }, | 3046 }, |
| 3038 | 3047 |
| 3039 /** | 3048 /** |
| 3040 * Number of columns. | 3049 * Number of columns. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3091 } | 3100 } |
| 3092 this.insideFocusPod_ = true; | 3101 this.insideFocusPod_ = true; |
| 3093 | 3102 |
| 3094 for (var i = 0, pod; pod = this.pods[i]; ++i) { | 3103 for (var i = 0, pod; pod = this.pods[i]; ++i) { |
| 3095 if (!this.alwaysFocusSinglePod) { | 3104 if (!this.alwaysFocusSinglePod) { |
| 3096 pod.isActionBoxMenuActive = false; | 3105 pod.isActionBoxMenuActive = false; |
| 3097 } | 3106 } |
| 3098 if (pod != podToFocus) { | 3107 if (pod != podToFocus) { |
| 3099 pod.isActionBoxMenuHovered = false; | 3108 pod.isActionBoxMenuHovered = false; |
| 3100 pod.classList.remove('focused'); | 3109 pod.classList.remove('focused'); |
| 3110 pod.setPinVisibility(false); | |
| 3101 // On Desktop, the faded style is not set correctly, so we should | 3111 // On Desktop, the faded style is not set correctly, so we should |
| 3102 // manually fade out non-focused pods if there is a focused pod. | 3112 // manually fade out non-focused pods if there is a focused pod. |
| 3103 if (pod.user.isDesktopUser && podToFocus) | 3113 if (pod.user.isDesktopUser && podToFocus) |
| 3104 pod.classList.add('faded'); | 3114 pod.classList.add('faded'); |
| 3105 else | 3115 else |
| 3106 pod.classList.remove('faded'); | 3116 pod.classList.remove('faded'); |
| 3107 pod.reset(false); | 3117 pod.reset(false); |
| 3108 } | 3118 } |
| 3109 } | 3119 } |
| 3110 | 3120 |
| 3111 // Clear any error messages for previous pod. | 3121 // Clear any error messages for previous pod. |
| 3112 if (!this.isFocused(podToFocus)) | 3122 if (!this.isFocused(podToFocus)) |
| 3113 Oobe.clearErrors(); | 3123 Oobe.clearErrors(); |
| 3114 | 3124 |
| 3115 var hadFocus = !!this.focusedPod_; | 3125 var hadFocus = !!this.focusedPod_; |
| 3116 this.focusedPod_ = podToFocus; | 3126 this.focusedPod_ = podToFocus; |
| 3117 if (podToFocus) { | 3127 if (podToFocus) { |
| 3128 this.setFocusedPodPinVisibility(true); | |
| 3118 podToFocus.classList.remove('faded'); | 3129 podToFocus.classList.remove('faded'); |
| 3119 podToFocus.classList.add('focused'); | 3130 podToFocus.classList.add('focused'); |
| 3120 if (!podToFocus.multiProfilesPolicyApplied) { | 3131 if (!podToFocus.multiProfilesPolicyApplied) { |
| 3121 podToFocus.classList.toggle('signing-in', false); | 3132 podToFocus.classList.toggle('signing-in', false); |
| 3122 if (!opt_skipInputFocus) | 3133 if (!opt_skipInputFocus) |
| 3123 podToFocus.focusInput(); | 3134 podToFocus.focusInput(); |
| 3124 } else { | 3135 } else { |
| 3125 podToFocus.userTypeBubbleElement.classList.add('bubble-shown'); | 3136 podToFocus.userTypeBubbleElement.classList.add('bubble-shown'); |
| 3126 // Note it is not necessary to skip this focus request when | 3137 // Note it is not necessary to skip this focus request when |
| 3127 // |opt_skipInputFocus| is true. When |multiProfilesPolicyApplied| | 3138 // |opt_skipInputFocus| is true. When |multiProfilesPolicyApplied| |
| 3128 // is false, it doesn't focus on the password input box by default. | 3139 // is false, it doesn't focus on the password input box by default. |
| 3129 podToFocus.focus(); | 3140 podToFocus.focus(); |
| 3130 } | 3141 } |
| 3131 | 3142 |
| 3132 // focusPod() automatically loads wallpaper | 3143 // focusPod() automatically loads wallpaper |
| 3133 if (!podToFocus.user.isApp) | 3144 if (!podToFocus.user.isApp) |
| 3134 chrome.send('focusPod', [podToFocus.user.username]); | 3145 chrome.send('focusPod', [podToFocus.user.username]); |
| 3135 this.firstShown_ = false; | 3146 this.firstShown_ = false; |
| 3136 this.lastFocusedPod_ = podToFocus; | 3147 this.lastFocusedPod_ = podToFocus; |
| 3137 this.scrollFocusedPodIntoView(); | 3148 this.scrollFocusedPodIntoView(); |
| 3138 } | 3149 } |
| 3139 this.insideFocusPod_ = false; | 3150 this.insideFocusPod_ = false; |
| 3151 this.placePods_(); | |
| 3140 }, | 3152 }, |
| 3141 | 3153 |
| 3142 /** | 3154 /** |
| 3143 * Resets wallpaper to the last active user's wallpaper, if any. | 3155 * Resets wallpaper to the last active user's wallpaper, if any. |
| 3144 */ | 3156 */ |
| 3145 loadLastWallpaper: function() { | 3157 loadLastWallpaper: function() { |
| 3146 if (this.lastFocusedPod_ && !this.lastFocusedPod_.user.isApp) | 3158 if (this.lastFocusedPod_ && !this.lastFocusedPod_.user.isApp) |
| 3147 chrome.send('loadWallpaper', [this.lastFocusedPod_.user.username]); | 3159 chrome.send('loadWallpaper', [this.lastFocusedPod_.user.username]); |
| 3148 }, | 3160 }, |
| 3149 | 3161 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3511 if (pod && pod.multiProfilesPolicyApplied) { | 3523 if (pod && pod.multiProfilesPolicyApplied) { |
| 3512 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 3524 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
| 3513 } | 3525 } |
| 3514 } | 3526 } |
| 3515 }; | 3527 }; |
| 3516 | 3528 |
| 3517 return { | 3529 return { |
| 3518 PodRow: PodRow | 3530 PodRow: PodRow |
| 3519 }; | 3531 }; |
| 3520 }); | 3532 }); |
| OLD | NEW |