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 /** |
11 * Number of displayed columns depending on user pod count. | 11 * Number of displayed columns depending on user pod count. |
12 * @type {Array.<number>} | 12 * @type {Array.<number>} |
13 * @const | 13 * @const |
14 */ | 14 */ |
15 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]; |
16 | 16 |
17 /** | 17 /** |
18 * Whether to preselect the first pod automatically on login screen. | 18 * Whether to preselect the first pod automatically on login screen. |
19 * @type {boolean} | 19 * @type {boolean} |
20 * @const | 20 * @const |
21 */ | 21 */ |
22 var PRESELECT_FIRST_POD = true; | 22 var PRESELECT_FIRST_POD = true; |
23 | 23 |
24 /** | 24 /** |
25 * Wallpaper load delay in milliseconds. | 25 * Minimum wallpaper load delay in milliseconds. |
26 * @type {number} | 26 * @type {number} |
27 * @const | 27 * @const |
28 */ | 28 */ |
29 var WALLPAPER_LOAD_DELAY_MS = 500; | 29 var WALLPAPER_LOAD_MIN_DELAY_MS = 100; |
30 | 30 |
31 /** | 31 /** |
32 * Wallpaper load delay in milliseconds. TODO(nkostylev): Tune this constant. | 32 * If last walpaper load time cannot be calculated, assume this value. |
33 * @type {number} | 33 * @type {number} |
34 * @const | 34 * @const |
35 */ | 35 */ |
36 var WALLPAPER_BOOT_LOAD_DELAY_MS = 100; | 36 var WALLPAPER_DEFAULT_LOAD_TIME_MS = 200; |
37 | |
38 /** | |
39 * Min and Max average wallpaper load time. | |
40 * Delay to next wallpaper load is 2 * <average load time>. | |
41 * @type {number} | |
42 * @const | |
43 */ | |
44 var WALLPAPER_MIN_LOAD_TIME_MS = 50; | |
45 var WALLPAPER_MAX_LOAD_TIME_MS = 2000; | |
46 | |
47 /** | |
48 * Number last wallpaper load times to remember. | |
49 * @type {number} | |
50 * @const | |
51 */ | |
52 var WALLPAPER_LOAD_STATS_MAX_LENGTH = 4; | |
37 | 53 |
38 /** | 54 /** |
39 * Maximum time for which the pod row remains hidden until all user images | 55 * Maximum time for which the pod row remains hidden until all user images |
40 * have been loaded. | 56 * have been loaded. |
41 * @type {number} | 57 * @type {number} |
42 * @const | 58 * @const |
43 */ | 59 */ |
44 var POD_ROW_IMAGES_LOAD_TIMEOUT_MS = 3000; | 60 var POD_ROW_IMAGES_LOAD_TIMEOUT_MS = 3000; |
45 | 61 |
46 /** | 62 /** |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 * @extends {HTMLDivElement} | 933 * @extends {HTMLDivElement} |
918 */ | 934 */ |
919 var PodRow = cr.ui.define('podrow'); | 935 var PodRow = cr.ui.define('podrow'); |
920 | 936 |
921 PodRow.prototype = { | 937 PodRow.prototype = { |
922 __proto__: HTMLDivElement.prototype, | 938 __proto__: HTMLDivElement.prototype, |
923 | 939 |
924 // Whether this user pod row is shown for the first time. | 940 // Whether this user pod row is shown for the first time. |
925 firstShown_: true, | 941 firstShown_: true, |
926 | 942 |
927 // Whether the initial wallpaper load after boot has been requested. Used | |
928 // only if |Oobe.getInstance().shouldLoadWallpaperOnBoot()| is true. | |
929 bootWallpaperLoaded_: false, | |
930 | |
931 // True if inside focusPod(). | 943 // True if inside focusPod(). |
932 insideFocusPod_: false, | 944 insideFocusPod_: false, |
933 | 945 |
934 // True if user pod has been activated with keyboard. | 946 // True if user pod has been activated with keyboard. |
935 // In case of activation with keyboard we delay wallpaper change. | 947 // In case of activation with keyboard we delay wallpaper change. |
936 keyboardActivated_: false, | 948 keyboardActivated_: false, |
dzhioev (left Google)
2013/09/26 17:46:41
keyboardActivated_ is not used anymore and can be
Alexander Alekseev
2013/10/01 15:47:49
Done.
| |
937 | 949 |
938 // Focused pod. | 950 // Focused pod. |
939 focusedPod_: undefined, | 951 focusedPod_: undefined, |
940 | 952 |
941 // Activated pod, i.e. the pod of current login attempt. | 953 // Activated pod, i.e. the pod of current login attempt. |
942 activatedPod_: undefined, | 954 activatedPod_: undefined, |
943 | 955 |
944 // Pod that was most recently focused, if any. | 956 // Pod that was most recently focused, if any. |
945 lastFocusedPod_: undefined, | 957 lastFocusedPod_: undefined, |
946 | 958 |
947 // When moving through users quickly at login screen, set a timeout to | 959 // When moving through users quickly at login screen, set a timeout to |
948 // prevent loading intermediate wallpapers. | 960 // prevent loading intermediate wallpapers. |
949 loadWallpaperTimeout_: null, | 961 loadWallpaperTimeout_: null, |
950 | 962 |
963 // When waiting for wallpaper load, remember load start time. | |
964 // This is actually associative array with key = username and value = | |
965 // start time. | |
966 wallpaperLoadInProgress: {}, | |
dzhioev (left Google)
2013/09/26 17:46:41
Please respect convention about naming private mem
Alexander Alekseev
2013/10/01 15:47:49
Done.
| |
967 | |
968 // Wait a delay and then load this wallpaper. Value = username. | |
969 wallpaperLoadPending: undefined, | |
970 | |
971 // Wait untill this Date before loading next wallpaper. | |
972 wallpaperLoadTryNextAfter: undefined, | |
973 | |
974 // Username, owner of current wallpaper. | |
975 wallpaperCurrent: '', | |
976 | |
977 wallpaperLoadStats: { | |
978 // Array of times (in milliseconds) of last wallpaper load attempts. | |
979 // Length is limited by WALLPAPER_LOAD_STATS_MAX_LENGTH. | |
980 history: [], | |
981 // sum(history) | |
982 totalTimeMs: 0 | |
dzhioev (left Google)
2013/09/27 09:04:39
Are you sure that it is needed? I think it is prem
Alexander Alekseev
2013/10/16 17:20:27
Done.
| |
983 }, | |
984 | |
951 // Pods whose initial images haven't been loaded yet. | 985 // Pods whose initial images haven't been loaded yet. |
952 podsWithPendingImages_: [], | 986 podsWithPendingImages_: [], |
953 | 987 |
954 /** @override */ | 988 /** @override */ |
955 decorate: function() { | 989 decorate: function() { |
956 this.style.left = 0; | 990 this.style.left = 0; |
957 | 991 |
958 // Event listeners that are installed for the time period during which | 992 // Event listeners that are installed for the time period during which |
959 // the element is visible. | 993 // the element is visible. |
960 this.listeners_ = { | 994 this.listeners_ = { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1182 /** | 1216 /** |
1183 * Whether the pod is currently focused. | 1217 * Whether the pod is currently focused. |
1184 * @param {UserPod} pod Pod to check for focus. | 1218 * @param {UserPod} pod Pod to check for focus. |
1185 * @return {boolean} Pod focus status. | 1219 * @return {boolean} Pod focus status. |
1186 */ | 1220 */ |
1187 isFocused: function(pod) { | 1221 isFocused: function(pod) { |
1188 return this.focusedPod_ == pod; | 1222 return this.focusedPod_ == pod; |
1189 }, | 1223 }, |
1190 | 1224 |
1191 /** | 1225 /** |
1226 * Schedules wallpaper load. | |
1227 */ | |
1228 scheduleLoadWallpaper: function(email) { | |
1229 if (this.wallpaperLoadPending && this.wallpaperLoadPending == email) | |
1230 return; | |
1231 this.wallpaperLoadPending = email; | |
1232 if (this.wallpaperLoadInProgress.hasOwnProperty(email)) { | |
1233 clearTimeout(this.loadWallpaperTimeout_); | |
1234 delete this.wallpaperLoadPending; | |
1235 return; | |
1236 } | |
1237 if ((Object.getOwnPropertyNames(this.wallpaperLoadInProgress).length == | |
1238 0) && (this.wallpaperCurrent == email)) { | |
1239 delete this.wallpaperLoadPending; | |
1240 return; | |
1241 } | |
1242 if (this.loadWallpaperTimeout_) { | |
1243 clearTimeout(this.loadWallpaperTimeout_); | |
1244 } | |
1245 var now = new Date(); | |
1246 var timeout = WALLPAPER_LOAD_MIN_DELAY_MS; | |
1247 if (this.wallpaperLoadTryNextAfter && | |
1248 (now < this.wallpaperLoadTryNextAfter) && | |
1249 (this.wallpaperLoadTryNextAfter.getUTCMilliseconds() - | |
1250 now.getUTCMilliseconds() > WALLPAPER_LOAD_MIN_DELAY_MS)) | |
1251 timeout = this.wallpaperLoadTryNextAfter.getUTCMilliseconds() - | |
1252 now.getUTCMilliseconds(); | |
1253 | |
1254 this.loadWallpaperTimeout_ = window.setTimeout( | |
1255 this.loadWallpaper_.bind(this), timeout); | |
1256 }, | |
1257 | |
1258 /** | |
1192 * Focuses a given user pod or clear focus when given null. | 1259 * Focuses a given user pod or clear focus when given null. |
1193 * @param {UserPod=} podToFocus User pod to focus (undefined clears focus). | 1260 * @param {UserPod=} podToFocus User pod to focus (undefined clears focus). |
1194 * @param {boolean=} opt_force If true, forces focus update even when | 1261 * @param {boolean=} opt_force If true, forces focus update even when |
1195 * podToFocus is already focused. | 1262 * podToFocus is already focused. |
1196 */ | 1263 */ |
1197 focusPod: function(podToFocus, opt_force) { | 1264 focusPod: function(podToFocus, opt_force) { |
1198 if (this.isFocused(podToFocus) && !opt_force) { | 1265 if (this.isFocused(podToFocus) && !opt_force) { |
1199 this.keyboardActivated_ = false; | 1266 this.keyboardActivated_ = false; |
1200 return; | 1267 return; |
1201 } | 1268 } |
(...skipping 22 matching lines...) Expand all Loading... | |
1224 if (!this.isFocused(podToFocus)) | 1291 if (!this.isFocused(podToFocus)) |
1225 Oobe.clearErrors(); | 1292 Oobe.clearErrors(); |
1226 | 1293 |
1227 var hadFocus = !!this.focusedPod_; | 1294 var hadFocus = !!this.focusedPod_; |
1228 this.focusedPod_ = podToFocus; | 1295 this.focusedPod_ = podToFocus; |
1229 if (podToFocus) { | 1296 if (podToFocus) { |
1230 podToFocus.classList.remove('faded'); | 1297 podToFocus.classList.remove('faded'); |
1231 podToFocus.classList.add('focused'); | 1298 podToFocus.classList.add('focused'); |
1232 podToFocus.reset(true); // Reset and give focus. | 1299 podToFocus.reset(true); // Reset and give focus. |
1233 chrome.send('focusPod', [podToFocus.user.emailAddress]); | 1300 chrome.send('focusPod', [podToFocus.user.emailAddress]); |
1234 if (hadFocus && this.keyboardActivated_) { | 1301 |
1235 // Delay wallpaper loading to let user tab through pods without lag. | 1302 this.scheduleLoadWallpaper(podToFocus.user.emailAddress); |
1236 this.loadWallpaperTimeout_ = window.setTimeout( | |
1237 this.loadWallpaper_.bind(this), WALLPAPER_LOAD_DELAY_MS); | |
1238 } else if (!this.firstShown_) { | |
1239 // Load wallpaper immediately if there no pod was focused | |
1240 // previously, and it is not a boot into user pod list case. | |
1241 this.loadWallpaper_(); | |
1242 } | |
1243 this.firstShown_ = false; | 1303 this.firstShown_ = false; |
1244 this.lastFocusedPod_ = podToFocus; | 1304 this.lastFocusedPod_ = podToFocus; |
1245 } | 1305 } |
1246 this.insideFocusPod_ = false; | 1306 this.insideFocusPod_ = false; |
1247 this.keyboardActivated_ = false; | 1307 this.keyboardActivated_ = false; |
1248 }, | 1308 }, |
1249 | 1309 |
1250 /** | 1310 /** |
1251 * Loads wallpaper for the active user pod, if any. | 1311 * Loads pending wallpaper, if any. |
1252 * @private | 1312 * @private |
1253 */ | 1313 */ |
1254 loadWallpaper_: function() { | 1314 loadWallpaper_: function() { |
1255 if (this.focusedPod_) | 1315 if (this.wallpaperLoadPending) { |
1256 chrome.send('loadWallpaper', [this.focusedPod_.user.username]); | 1316 var email = this.wallpaperLoadPending; |
1317 delete this.wallpaperLoadPending; | |
1318 if (email == this.wallpaperCurrent) | |
1319 return; | |
1320 if (this.wallpaperLoadInProgress[email]) | |
1321 return; | |
1322 this.wallpaperLoadInProgress[email] = new Date(); | |
1323 chrome.send('loadWallpaper', [email]); | |
1324 } | |
1257 }, | 1325 }, |
1258 | 1326 |
1259 /** | 1327 /** |
1260 * Resets wallpaper to the last active user's wallpaper, if any. | 1328 * Resets wallpaper to the last active user's wallpaper, if any. |
1261 */ | 1329 */ |
1262 loadLastWallpaper: function() { | 1330 loadLastWallpaper: function() { |
1263 if (this.lastFocusedPod_) | 1331 if (this.lastFocusedPod_) |
1264 chrome.send('loadWallpaper', [this.lastFocusedPod_.user.username]); | 1332 this.scheduleLoadWallpaper(this.lastFocusedPod_.user.username); |
1265 }, | 1333 }, |
1266 | 1334 |
1267 /** | 1335 /** |
1336 * Calculates average wallpaper load time. | |
1337 */ | |
1338 wallpaperLoadAvg: function() { | |
dzhioev (left Google)
2013/09/27 09:04:39
get*_
Alexander Alekseev
2013/10/01 15:47:49
Done.
| |
1339 var avg = WALLPAPER_DEFAULT_LOAD_TIME_MS; | |
1340 if (this.wallpaperLoadStats.history.length) { | |
1341 avg = this.wallpaperLoadStats.totalTimeMs / | |
1342 this.wallpaperLoadStats.history.length; | |
1343 if (avg < WALLPAPER_MIN_LOAD_TIME_MS) { | |
1344 avg = WALLPAPER_MIN_LOAD_TIME_MS; | |
1345 } | |
1346 if (avg > WALLPAPER_MAX_LOAD_TIME_MS) { | |
1347 avg = WALLPAPER_MAX_LOAD_TIME_MS; | |
1348 } | |
1349 } | |
1350 return avg; | |
1351 }, | |
1352 | |
1353 /** | |
1354 * Handles 'wallpaperLoaded' event. Recalculates statistics and | |
1355 * [re]schedules next wallpaper load. | |
1356 */ | |
1357 wallpaperLoaded: function(email) { | |
1358 this.wallpaperCurrent = email; | |
1359 var started = this.wallpaperLoadInProgress[email]; | |
1360 delete this.wallpaperLoadInProgress[email]; | |
1361 var finished = new Date(); | |
1362 var elapsed = (started ? | |
dzhioev (left Google)
2013/09/27 09:04:39
Brackets are excess here.
Alexander Alekseev
2013/10/16 17:20:27
Done.
| |
1363 finished.getUTCMilliseconds() - started.getUTCMilliseconds() : | |
dzhioev (left Google)
2013/09/27 09:04:39
I believe that getUTCMilliseconds is not what you
Alexander Alekseev
2013/10/01 15:47:49
Done.
| |
1364 WALLPAPER_DEFAULT_LOAD_TIME_MS); | |
1365 this.wallpaperLoadStats.history.push(elapsed); | |
1366 this.wallpaperLoadStats.totalTimeMs += elapsed; | |
1367 if (this.wallpaperLoadStats.history.length > | |
1368 WALLPAPER_LOAD_STATS_MAX_LENGTH) { | |
1369 var tt = this.wallpaperLoadStats.history.shift(); | |
1370 this.wallpaperLoadStats.totalTimeMs -= tt; | |
1371 } | |
1372 var nextAfter = new Date; | |
dzhioev (left Google)
2013/09/27 09:04:39
You use "new Date" and "new Date()". Choose one fo
Alexander Alekseev
2013/10/01 15:47:49
Done.
| |
1373 nextAfter.setUTCMilliseconds(nextAfter.getUTCMilliseconds() + | |
1374 2 * this.wallpaperLoadAvg()); | |
1375 this.wallpaperLoadTryNextAfter = nextAfter; | |
1376 if (this.wallpaperLoadPending) { | |
1377 if (this.wallpaperLoadPending == email) { | |
1378 delete this.wallpaperLoadPending; | |
1379 clearTimeout(this.loadWallpaperTimeout_); | |
1380 } else { | |
1381 this.scheduleLoadWallpaper(this.wallpaperLoadPending); | |
dzhioev (left Google)
2013/09/27 09:04:39
This call is useless because scheduleLoadWallpaper
Alexander Alekseev
2013/10/01 15:47:49
Done.
| |
1382 } | |
1383 } | |
1384 }, | |
1385 | |
1386 /** | |
1268 * Returns the currently activated pod. | 1387 * Returns the currently activated pod. |
1269 * @type {UserPod} | 1388 * @type {UserPod} |
1270 */ | 1389 */ |
1271 get activatedPod() { | 1390 get activatedPod() { |
1272 return this.activatedPod_; | 1391 return this.activatedPod_; |
1273 }, | 1392 }, |
1274 set activatedPod(pod) { | 1393 set activatedPod(pod) { |
1275 if (pod && pod.activate()) | 1394 if (pod && pod.activate()) |
1276 this.activatedPod_ = pod; | 1395 this.activatedPod_ = pod; |
1277 }, | 1396 }, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1518 if (this.focusedPod_) { | 1637 if (this.focusedPod_) { |
1519 var focusedPod = this.focusedPod_; | 1638 var focusedPod = this.focusedPod_; |
1520 var screen = this.parentNode; | 1639 var screen = this.parentNode; |
1521 var self = this; | 1640 var self = this; |
1522 focusedPod.addEventListener('webkitTransitionEnd', function f(e) { | 1641 focusedPod.addEventListener('webkitTransitionEnd', function f(e) { |
1523 if (e.target == focusedPod) { | 1642 if (e.target == focusedPod) { |
1524 focusedPod.removeEventListener('webkitTransitionEnd', f); | 1643 focusedPod.removeEventListener('webkitTransitionEnd', f); |
1525 focusedPod.reset(true); | 1644 focusedPod.reset(true); |
1526 // Notify screen that it is ready. | 1645 // Notify screen that it is ready. |
1527 screen.onShow(); | 1646 screen.onShow(); |
1528 // Boot transition: load wallpaper. | 1647 self.scheduleLoadWallpaper(focusedPod.user.username); |
1529 if (!self.bootWallpaperLoaded_ && | |
1530 Oobe.getInstance().shouldLoadWallpaperOnBoot()) { | |
1531 self.loadWallpaperTimeout_ = window.setTimeout( | |
1532 self.loadWallpaper_.bind(self), WALLPAPER_BOOT_LOAD_DELAY_MS); | |
1533 self.bootWallpaperLoaded_ = true; | |
1534 } | |
1535 } | 1648 } |
1536 }); | 1649 }); |
1537 } | 1650 } |
1538 }, | 1651 }, |
1539 | 1652 |
1540 /** | 1653 /** |
1541 * Called right before the pod row is shown. | 1654 * Called right before the pod row is shown. |
1542 */ | 1655 */ |
1543 handleBeforeShow: function() { | 1656 handleBeforeShow: function() { |
1544 for (var event in this.listeners_) { | 1657 for (var event in this.listeners_) { |
(...skipping 27 matching lines...) Expand all Loading... | |
1572 if (this.podsWithPendingImages_.length == 0) { | 1685 if (this.podsWithPendingImages_.length == 0) { |
1573 this.classList.remove('images-loading'); | 1686 this.classList.remove('images-loading'); |
1574 } | 1687 } |
1575 } | 1688 } |
1576 }; | 1689 }; |
1577 | 1690 |
1578 return { | 1691 return { |
1579 PodRow: PodRow | 1692 PodRow: PodRow |
1580 }; | 1693 }; |
1581 }); | 1694 }); |
OLD | NEW |