| 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 <include src="wallpaper_loader.js"></include> | |
| 6 | |
| 7 /** | 5 /** |
| 8 * @fileoverview User pod row implementation. | 6 * @fileoverview User pod row implementation. |
| 9 */ | 7 */ |
| 10 | 8 |
| 11 cr.define('login', function() { | 9 cr.define('login', function() { |
| 12 /** | 10 /** |
| 13 * Number of displayed columns depending on user pod count. | 11 * Number of displayed columns depending on user pod count. |
| 14 * @type {Array.<number>} | 12 * @type {Array.<number>} |
| 15 * @const | 13 * @const |
| 16 */ | 14 */ |
| 17 var COLUMNS = [0, 1, 2, 3, 4, 5, 4, 4, 4, 5, 5, 6, 6, 5, 5, 6, 6, 6, 6]; | 15 var COLUMNS = [0, 1, 2, 3, 4, 5, 4, 4, 4, 5, 5, 6, 6, 5, 5, 6, 6, 6, 6]; |
| 18 | 16 |
| 19 /** | 17 /** |
| 20 * Whether to preselect the first pod automatically on login screen. | 18 * Whether to preselect the first pod automatically on login screen. |
| 21 * @type {boolean} | 19 * @type {boolean} |
| 22 * @const | 20 * @const |
| 23 */ | 21 */ |
| 24 var PRESELECT_FIRST_POD = true; | 22 var PRESELECT_FIRST_POD = true; |
| 25 | 23 |
| 26 /** | 24 /** |
| 25 * Wallpaper load delay in milliseconds. |
| 26 * @type {number} |
| 27 * @const |
| 28 */ |
| 29 var WALLPAPER_LOAD_DELAY_MS = 500; |
| 30 |
| 31 /** |
| 32 * Wallpaper load delay in milliseconds. TODO(nkostylev): Tune this constant. |
| 33 * @type {number} |
| 34 * @const |
| 35 */ |
| 36 var WALLPAPER_BOOT_LOAD_DELAY_MS = 100; |
| 37 |
| 38 /** |
| 27 * Maximum time for which the pod row remains hidden until all user images | 39 * Maximum time for which the pod row remains hidden until all user images |
| 28 * have been loaded. | 40 * have been loaded. |
| 29 * @type {number} | 41 * @type {number} |
| 30 * @const | 42 * @const |
| 31 */ | 43 */ |
| 32 var POD_ROW_IMAGES_LOAD_TIMEOUT_MS = 3000; | 44 var POD_ROW_IMAGES_LOAD_TIMEOUT_MS = 3000; |
| 33 | 45 |
| 34 /** | 46 /** |
| 35 * Public session help topic identifier. | 47 * Public session help topic identifier. |
| 36 * @type {number} | 48 * @type {number} |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 * @extends {HTMLDivElement} | 952 * @extends {HTMLDivElement} |
| 941 */ | 953 */ |
| 942 var PodRow = cr.ui.define('podrow'); | 954 var PodRow = cr.ui.define('podrow'); |
| 943 | 955 |
| 944 PodRow.prototype = { | 956 PodRow.prototype = { |
| 945 __proto__: HTMLDivElement.prototype, | 957 __proto__: HTMLDivElement.prototype, |
| 946 | 958 |
| 947 // Whether this user pod row is shown for the first time. | 959 // Whether this user pod row is shown for the first time. |
| 948 firstShown_: true, | 960 firstShown_: true, |
| 949 | 961 |
| 962 // Whether the initial wallpaper load after boot has been requested. Used |
| 963 // only if |Oobe.getInstance().shouldLoadWallpaperOnBoot()| is true. |
| 964 bootWallpaperLoaded_: false, |
| 965 |
| 950 // True if inside focusPod(). | 966 // True if inside focusPod(). |
| 951 insideFocusPod_: false, | 967 insideFocusPod_: false, |
| 952 | 968 |
| 969 // True if user pod has been activated with keyboard. |
| 970 // In case of activation with keyboard we delay wallpaper change. |
| 971 keyboardActivated_: false, |
| 972 |
| 953 // Focused pod. | 973 // Focused pod. |
| 954 focusedPod_: undefined, | 974 focusedPod_: undefined, |
| 955 | 975 |
| 956 // Activated pod, i.e. the pod of current login attempt. | 976 // Activated pod, i.e. the pod of current login attempt. |
| 957 activatedPod_: undefined, | 977 activatedPod_: undefined, |
| 958 | 978 |
| 959 // Pod that was most recently focused, if any. | 979 // Pod that was most recently focused, if any. |
| 960 lastFocusedPod_: undefined, | 980 lastFocusedPod_: undefined, |
| 961 | 981 |
| 962 // Note: created only in decorate() ! | 982 // When moving through users quickly at login screen, set a timeout to |
| 963 wallpaperLoader_: undefined, | 983 // prevent loading intermediate wallpapers. |
| 984 loadWallpaperTimeout_: null, |
| 964 | 985 |
| 965 // Pods whose initial images haven't been loaded yet. | 986 // Pods whose initial images haven't been loaded yet. |
| 966 podsWithPendingImages_: [], | 987 podsWithPendingImages_: [], |
| 967 | 988 |
| 968 /** @override */ | 989 /** @override */ |
| 969 decorate: function() { | 990 decorate: function() { |
| 970 this.style.left = 0; | 991 this.style.left = 0; |
| 971 | 992 |
| 972 // Event listeners that are installed for the time period during which | 993 // Event listeners that are installed for the time period during which |
| 973 // the element is visible. | 994 // the element is visible. |
| 974 this.listeners_ = { | 995 this.listeners_ = { |
| 975 focus: [this.handleFocus_.bind(this), true /* useCapture */], | 996 focus: [this.handleFocus_.bind(this), true /* useCapture */], |
| 976 click: [this.handleClick_.bind(this), true], | 997 click: [this.handleClick_.bind(this), true], |
| 977 mousemove: [this.handleMouseMove_.bind(this), false], | 998 mousemove: [this.handleMouseMove_.bind(this), false], |
| 978 keydown: [this.handleKeyDown.bind(this), false] | 999 keydown: [this.handleKeyDown.bind(this), false] |
| 979 }; | 1000 }; |
| 980 this.wallpaperLoader_ = new login.WallpaperLoader(); | |
| 981 }, | 1001 }, |
| 982 | 1002 |
| 983 /** | 1003 /** |
| 984 * Returns all the pods in this pod row. | 1004 * Returns all the pods in this pod row. |
| 985 * @type {NodeList} | 1005 * @type {NodeList} |
| 986 */ | 1006 */ |
| 987 get pods() { | 1007 get pods() { |
| 988 return this.children; | 1008 return this.children; |
| 989 }, | 1009 }, |
| 990 | 1010 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 return; | 1235 return; |
| 1216 } | 1236 } |
| 1217 | 1237 |
| 1218 // Make sure there's only one focusPod operation happening at a time. | 1238 // Make sure there's only one focusPod operation happening at a time. |
| 1219 if (this.insideFocusPod_) { | 1239 if (this.insideFocusPod_) { |
| 1220 this.keyboardActivated_ = false; | 1240 this.keyboardActivated_ = false; |
| 1221 return; | 1241 return; |
| 1222 } | 1242 } |
| 1223 this.insideFocusPod_ = true; | 1243 this.insideFocusPod_ = true; |
| 1224 | 1244 |
| 1225 this.wallpaperLoader_.reset(); | 1245 clearTimeout(this.loadWallpaperTimeout_); |
| 1226 for (var i = 0, pod; pod = this.pods[i]; ++i) { | 1246 for (var i = 0, pod; pod = this.pods[i]; ++i) { |
| 1227 if (!this.isSinglePod) { | 1247 if (!this.isSinglePod) { |
| 1228 pod.isActionBoxMenuActive = false; | 1248 pod.isActionBoxMenuActive = false; |
| 1229 } | 1249 } |
| 1230 if (pod != podToFocus) { | 1250 if (pod != podToFocus) { |
| 1231 pod.isActionBoxMenuHovered = false; | 1251 pod.isActionBoxMenuHovered = false; |
| 1232 pod.classList.remove('focused'); | 1252 pod.classList.remove('focused'); |
| 1233 pod.classList.remove('faded'); | 1253 pod.classList.remove('faded'); |
| 1234 pod.reset(false); | 1254 pod.reset(false); |
| 1235 } | 1255 } |
| 1236 } | 1256 } |
| 1237 | 1257 |
| 1238 // Clear any error messages for previous pod. | 1258 // Clear any error messages for previous pod. |
| 1239 if (!this.isFocused(podToFocus)) | 1259 if (!this.isFocused(podToFocus)) |
| 1240 Oobe.clearErrors(); | 1260 Oobe.clearErrors(); |
| 1241 | 1261 |
| 1242 var hadFocus = !!this.focusedPod_; | 1262 var hadFocus = !!this.focusedPod_; |
| 1243 this.focusedPod_ = podToFocus; | 1263 this.focusedPod_ = podToFocus; |
| 1244 if (podToFocus) { | 1264 if (podToFocus) { |
| 1245 podToFocus.classList.remove('faded'); | 1265 podToFocus.classList.remove('faded'); |
| 1246 podToFocus.classList.add('focused'); | 1266 podToFocus.classList.add('focused'); |
| 1247 podToFocus.reset(true); // Reset and give focus. | 1267 podToFocus.reset(true); // Reset and give focus. |
| 1248 chrome.send('focusPod', [podToFocus.user.emailAddress]); | 1268 chrome.send('focusPod', [podToFocus.user.emailAddress]); |
| 1249 | 1269 if (hadFocus && this.keyboardActivated_) { |
| 1250 this.wallpaperLoader_.scheduleLoad(podToFocus.user.emailAddress); | 1270 // Delay wallpaper loading to let user tab through pods without lag. |
| 1271 this.loadWallpaperTimeout_ = window.setTimeout( |
| 1272 this.loadWallpaper_.bind(this), WALLPAPER_LOAD_DELAY_MS); |
| 1273 } else if (!this.firstShown_) { |
| 1274 // Load wallpaper immediately if there no pod was focused |
| 1275 // previously, and it is not a boot into user pod list case. |
| 1276 this.loadWallpaper_(); |
| 1277 } |
| 1251 this.firstShown_ = false; | 1278 this.firstShown_ = false; |
| 1252 this.lastFocusedPod_ = podToFocus; | 1279 this.lastFocusedPod_ = podToFocus; |
| 1253 } | 1280 } |
| 1254 this.insideFocusPod_ = false; | 1281 this.insideFocusPod_ = false; |
| 1255 this.keyboardActivated_ = false; | 1282 this.keyboardActivated_ = false; |
| 1256 }, | 1283 }, |
| 1257 | 1284 |
| 1258 /** | 1285 /** |
| 1286 * Loads wallpaper for the active user pod, if any. |
| 1287 * @private |
| 1288 */ |
| 1289 loadWallpaper_: function() { |
| 1290 if (this.focusedPod_) |
| 1291 chrome.send('loadWallpaper', [this.focusedPod_.user.username]); |
| 1292 }, |
| 1293 |
| 1294 /** |
| 1259 * Resets wallpaper to the last active user's wallpaper, if any. | 1295 * Resets wallpaper to the last active user's wallpaper, if any. |
| 1260 */ | 1296 */ |
| 1261 loadLastWallpaper: function() { | 1297 loadLastWallpaper: function() { |
| 1262 if (this.lastFocusedPod_) | 1298 if (this.lastFocusedPod_) |
| 1263 this.wallpaperLoader_.scheduleLoad(this.lastFocusedPod_.user.username); | 1299 chrome.send('loadWallpaper', [this.lastFocusedPod_.user.username]); |
| 1264 }, | 1300 }, |
| 1265 | 1301 |
| 1266 /** | 1302 /** |
| 1267 * Handles 'onWallpaperLoaded' event. Recalculates statistics and | |
| 1268 * [re]schedules next wallpaper load. | |
| 1269 */ | |
| 1270 onWallpaperLoaded: function(email) { | |
| 1271 this.wallpaperLoader_.onWallpaperLoaded(email); | |
| 1272 }, | |
| 1273 | |
| 1274 /** | |
| 1275 * Returns the currently activated pod. | 1303 * Returns the currently activated pod. |
| 1276 * @type {UserPod} | 1304 * @type {UserPod} |
| 1277 */ | 1305 */ |
| 1278 get activatedPod() { | 1306 get activatedPod() { |
| 1279 return this.activatedPod_; | 1307 return this.activatedPod_; |
| 1280 }, | 1308 }, |
| 1281 set activatedPod(pod) { | 1309 set activatedPod(pod) { |
| 1282 if (pod && pod.activate()) | 1310 if (pod && pod.activate()) |
| 1283 this.activatedPod_ = pod; | 1311 this.activatedPod_ = pod; |
| 1284 }, | 1312 }, |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 if (this.focusedPod_) { | 1553 if (this.focusedPod_) { |
| 1526 var focusedPod = this.focusedPod_; | 1554 var focusedPod = this.focusedPod_; |
| 1527 var screen = this.parentNode; | 1555 var screen = this.parentNode; |
| 1528 var self = this; | 1556 var self = this; |
| 1529 focusedPod.addEventListener('webkitTransitionEnd', function f(e) { | 1557 focusedPod.addEventListener('webkitTransitionEnd', function f(e) { |
| 1530 if (e.target == focusedPod) { | 1558 if (e.target == focusedPod) { |
| 1531 focusedPod.removeEventListener('webkitTransitionEnd', f); | 1559 focusedPod.removeEventListener('webkitTransitionEnd', f); |
| 1532 focusedPod.reset(true); | 1560 focusedPod.reset(true); |
| 1533 // Notify screen that it is ready. | 1561 // Notify screen that it is ready. |
| 1534 screen.onShow(); | 1562 screen.onShow(); |
| 1535 self.wallpaperLoader_.scheduleLoad(focusedPod.user.username); | 1563 // Boot transition: load wallpaper. |
| 1564 if (!self.bootWallpaperLoaded_ && |
| 1565 Oobe.getInstance().shouldLoadWallpaperOnBoot()) { |
| 1566 self.loadWallpaperTimeout_ = window.setTimeout( |
| 1567 self.loadWallpaper_.bind(self), WALLPAPER_BOOT_LOAD_DELAY_MS); |
| 1568 self.bootWallpaperLoaded_ = true; |
| 1569 } |
| 1536 } | 1570 } |
| 1537 }); | 1571 }); |
| 1538 // Guard timer for 1 second -- it would conver all possible animations. | 1572 // Guard timer for 1 second -- it would conver all possible animations. |
| 1539 ensureTransitionEndEvent(focusedPod, 1000); | 1573 ensureTransitionEndEvent(focusedPod, 1000); |
| 1540 } | 1574 } |
| 1541 }, | 1575 }, |
| 1542 | 1576 |
| 1543 /** | 1577 /** |
| 1544 * Called right before the pod row is shown. | 1578 * Called right before the pod row is shown. |
| 1545 */ | 1579 */ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1575 if (this.podsWithPendingImages_.length == 0) { | 1609 if (this.podsWithPendingImages_.length == 0) { |
| 1576 this.classList.remove('images-loading'); | 1610 this.classList.remove('images-loading'); |
| 1577 } | 1611 } |
| 1578 } | 1612 } |
| 1579 }; | 1613 }; |
| 1580 | 1614 |
| 1581 return { | 1615 return { |
| 1582 PodRow: PodRow | 1616 PodRow: PodRow |
| 1583 }; | 1617 }; |
| 1584 }); | 1618 }); |
| OLD | NEW |