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 29 matching lines...) Expand all Loading... |
40 * Variables used for pod placement processing. Width and height should be | 40 * Variables used for pod placement processing. Width and height should be |
41 * synced with computed CSS sizes of pods. | 41 * synced with computed CSS sizes of pods. |
42 */ | 42 */ |
43 var POD_WIDTH = 180; | 43 var POD_WIDTH = 180; |
44 var PUBLIC_EXPANDED_WIDTH = 420; | 44 var PUBLIC_EXPANDED_WIDTH = 420; |
45 var CROS_POD_HEIGHT = 213; | 45 var CROS_POD_HEIGHT = 213; |
46 var DESKTOP_POD_HEIGHT = 216; | 46 var DESKTOP_POD_HEIGHT = 216; |
47 var POD_ROW_PADDING = 10; | 47 var POD_ROW_PADDING = 10; |
48 | 48 |
49 /** | 49 /** |
| 50 * Minimal padding between user pod and virtual keyboard. |
| 51 * @type {number} |
| 52 * @const |
| 53 */ |
| 54 var USER_POD_KEYBOARD_MIN_PADDING = 20; |
| 55 |
| 56 /** |
50 * Whether to preselect the first pod automatically on login screen. | 57 * Whether to preselect the first pod automatically on login screen. |
51 * @type {boolean} | 58 * @type {boolean} |
52 * @const | 59 * @const |
53 */ | 60 */ |
54 var PRESELECT_FIRST_POD = true; | 61 var PRESELECT_FIRST_POD = true; |
55 | 62 |
56 /** | 63 /** |
57 * Maximum time for which the pod row remains hidden until all user images | 64 * Maximum time for which the pod row remains hidden until all user images |
58 * have been loaded. | 65 * have been loaded. |
59 * @type {number} | 66 * @type {number} |
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 * @param {boolean} animated Whether to use init animation. | 1560 * @param {boolean} animated Whether to use init animation. |
1554 */ | 1561 */ |
1555 loadPods: function(users, animated) { | 1562 loadPods: function(users, animated) { |
1556 this.users_ = users; | 1563 this.users_ = users; |
1557 this.userAddIsAnimated_ = animated; | 1564 this.userAddIsAnimated_ = animated; |
1558 | 1565 |
1559 this.rebuildPods(); | 1566 this.rebuildPods(); |
1560 }, | 1567 }, |
1561 | 1568 |
1562 /** | 1569 /** |
| 1570 * Scrolls focused user pod into view. |
| 1571 */ |
| 1572 scrollFocusedPodIntoView: function() { |
| 1573 var pod = this.focusedPod_; |
| 1574 if (!pod) |
| 1575 return; |
| 1576 |
| 1577 // First check whether focused pod is already fully visible. |
| 1578 var visibleArea = $('scroll-container'); |
| 1579 var scrollTop = visibleArea.scrollTop; |
| 1580 var clientHeight = visibleArea.clientHeight; |
| 1581 var podTop = $('oobe').offsetTop + pod.offsetTop; |
| 1582 var padding = USER_POD_KEYBOARD_MIN_PADDING; |
| 1583 if (podTop + pod.height + padding <= scrollTop + clientHeight && |
| 1584 podTop - padding >= scrollTop) { |
| 1585 return; |
| 1586 } |
| 1587 |
| 1588 // Scroll so that user pod is as centered as possible. |
| 1589 visibleArea.scrollTop = podTop - (clientHeight - pod.offsetHeight) / 2; |
| 1590 }, |
| 1591 |
| 1592 /** |
1563 * Rebuilds pod row using users_ and apps_ that were previously set or | 1593 * Rebuilds pod row using users_ and apps_ that were previously set or |
1564 * updated. | 1594 * updated. |
1565 */ | 1595 */ |
1566 rebuildPods: function() { | 1596 rebuildPods: function() { |
1567 var emptyPodRow = this.pods.length == 0; | 1597 var emptyPodRow = this.pods.length == 0; |
1568 | 1598 |
1569 // Clear existing pods. | 1599 // Clear existing pods. |
1570 this.innerHTML = ''; | 1600 this.innerHTML = ''; |
1571 this.focusedPod_ = undefined; | 1601 this.focusedPod_ = undefined; |
1572 this.activatedPod_ = undefined; | 1602 this.activatedPod_ = undefined; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1727 BUBBLE_PADDING); | 1757 BUBBLE_PADDING); |
1728 }, | 1758 }, |
1729 | 1759 |
1730 /** | 1760 /** |
1731 * Called when window was resized. | 1761 * Called when window was resized. |
1732 */ | 1762 */ |
1733 onWindowResize: function() { | 1763 onWindowResize: function() { |
1734 var layout = this.calculateLayout_(); | 1764 var layout = this.calculateLayout_(); |
1735 if (layout.columns != this.columns || layout.rows != this.rows) | 1765 if (layout.columns != this.columns || layout.rows != this.rows) |
1736 this.placePods_(); | 1766 this.placePods_(); |
| 1767 |
| 1768 if (Oobe.getInstance().virtualKeyboardShown) |
| 1769 this.scrollFocusedPodIntoView(); |
1737 }, | 1770 }, |
1738 | 1771 |
1739 /** | 1772 /** |
1740 * Returns width of podrow having |columns| number of columns. | 1773 * Returns width of podrow having |columns| number of columns. |
1741 * @private | 1774 * @private |
1742 */ | 1775 */ |
1743 columnsToWidth_: function(columns) { | 1776 columnsToWidth_: function(columns) { |
1744 var margin = MARGIN_BY_COLUMNS[columns]; | 1777 var margin = MARGIN_BY_COLUMNS[columns]; |
1745 return 2 * POD_ROW_PADDING + columns * | 1778 return 2 * POD_ROW_PADDING + columns * |
1746 this.userPodWidth_ + (columns - 1) * margin; | 1779 this.userPodWidth_ + (columns - 1) * margin; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 | 1855 |
1823 /** | 1856 /** |
1824 * Number of columns. | 1857 * Number of columns. |
1825 * @type {?number} | 1858 * @type {?number} |
1826 */ | 1859 */ |
1827 set columns(columns) { | 1860 set columns(columns) { |
1828 // Cannot use 'columns' here. | 1861 // Cannot use 'columns' here. |
1829 this.setAttribute('ncolumns', columns); | 1862 this.setAttribute('ncolumns', columns); |
1830 }, | 1863 }, |
1831 get columns() { | 1864 get columns() { |
1832 return this.getAttribute('ncolumns'); | 1865 return parseInt(this.getAttribute('ncolumns')); |
1833 }, | 1866 }, |
1834 | 1867 |
1835 /** | 1868 /** |
1836 * Number of rows. | 1869 * Number of rows. |
1837 * @type {?number} | 1870 * @type {?number} |
1838 */ | 1871 */ |
1839 set rows(rows) { | 1872 set rows(rows) { |
1840 // Cannot use 'rows' here. | 1873 // Cannot use 'rows' here. |
1841 this.setAttribute('nrows', rows); | 1874 this.setAttribute('nrows', rows); |
1842 }, | 1875 }, |
1843 get rows() { | 1876 get rows() { |
1844 return this.getAttribute('nrows'); | 1877 return parseInt(this.getAttribute('nrows')); |
1845 }, | 1878 }, |
1846 | 1879 |
1847 /** | 1880 /** |
1848 * Whether the pod is currently focused. | 1881 * Whether the pod is currently focused. |
1849 * @param {UserPod} pod Pod to check for focus. | 1882 * @param {UserPod} pod Pod to check for focus. |
1850 * @return {boolean} Pod focus status. | 1883 * @return {boolean} Pod focus status. |
1851 */ | 1884 */ |
1852 isFocused: function(pod) { | 1885 isFocused: function(pod) { |
1853 return this.focusedPod_ == pod; | 1886 return this.focusedPod_ == pod; |
1854 }, | 1887 }, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 this.focusedPod_ = podToFocus; | 1933 this.focusedPod_ = podToFocus; |
1901 if (podToFocus) { | 1934 if (podToFocus) { |
1902 podToFocus.classList.remove('faded'); | 1935 podToFocus.classList.remove('faded'); |
1903 podToFocus.classList.add('focused'); | 1936 podToFocus.classList.add('focused'); |
1904 podToFocus.reset(true); // Reset and give focus. | 1937 podToFocus.reset(true); // Reset and give focus. |
1905 // focusPod() automatically loads wallpaper | 1938 // focusPod() automatically loads wallpaper |
1906 if (!podToFocus.user.isApp) | 1939 if (!podToFocus.user.isApp) |
1907 chrome.send('focusPod', [podToFocus.user.username]); | 1940 chrome.send('focusPod', [podToFocus.user.username]); |
1908 this.firstShown_ = false; | 1941 this.firstShown_ = false; |
1909 this.lastFocusedPod_ = podToFocus; | 1942 this.lastFocusedPod_ = podToFocus; |
| 1943 |
| 1944 if (Oobe.getInstance().virtualKeyboardShown) |
| 1945 this.scrollFocusedPodIntoView(); |
1910 } | 1946 } |
1911 this.insideFocusPod_ = false; | 1947 this.insideFocusPod_ = false; |
1912 this.keyboardActivated_ = false; | 1948 this.keyboardActivated_ = false; |
1913 }, | 1949 }, |
1914 | 1950 |
1915 /** | 1951 /** |
1916 * Focuses a given user pod by index or clear focus when given null. | 1952 * Focuses a given user pod by index or clear focus when given null. |
1917 * @param {int=} podToFocus index of User pod to focus. | 1953 * @param {int=} podToFocus index of User pod to focus. |
1918 * @param {boolean=} opt_force If true, forces focus update even when | 1954 * @param {boolean=} opt_force If true, forces focus update even when |
1919 * podToFocus is already focused. | 1955 * podToFocus is already focused. |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 if (this.podsWithPendingImages_.length == 0) { | 2274 if (this.podsWithPendingImages_.length == 0) { |
2239 this.classList.remove('images-loading'); | 2275 this.classList.remove('images-loading'); |
2240 } | 2276 } |
2241 } | 2277 } |
2242 }; | 2278 }; |
2243 | 2279 |
2244 return { | 2280 return { |
2245 PodRow: PodRow | 2281 PodRow: PodRow |
2246 }; | 2282 }; |
2247 }); | 2283 }); |
OLD | NEW |