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 /** |
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 * Mapping between number of columns in pod-row and margin between user pods | 18 * Mapping between number of columns in pod-row and margin between user pods |
19 * for such layout. | 19 * for such layout. |
20 * @type {Array.<number>} | 20 * @type {Array.<number>} |
21 * @const | 21 * @const |
22 */ | 22 */ |
23 var MARGIN_BY_COLUMNS = [undefined, 40, 40, 40, 40, 40, 12]; | 23 var MARGIN_BY_COLUMNS = [undefined, 40, 40, 40, 40, 40, 12]; |
24 | 24 |
25 /** | 25 /** |
26 * Mapping between number of columns in the desktop pod-row and margin | |
27 * between user pods for such layout. | |
28 * @type {Array.<number>} | |
29 * @const | |
30 */ | |
31 var DESKTOP_MARGIN_BY_COLUMNS = [undefined, 32, 32, 32, 32, 32, 32]; | |
32 | |
33 /** | |
26 * Maximal number of columns currently supported by pod-row. | 34 * Maximal number of columns currently supported by pod-row. |
27 * @type {number} | 35 * @type {number} |
28 * @const | 36 * @const |
29 */ | 37 */ |
30 var MAX_NUMBER_OF_COLUMNS = 6; | 38 var MAX_NUMBER_OF_COLUMNS = 6; |
31 | 39 |
32 /** | 40 /** |
33 * Maximal number of rows if sign-in banner is displayed alonside. | 41 * Maximal number of rows if sign-in banner is displayed alonside. |
34 * @type {number} | 42 * @type {number} |
35 * @const | 43 * @const |
36 */ | 44 */ |
37 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; | 45 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; |
38 | 46 |
39 /** | 47 /** |
40 * Variables used for pod placement processing. Width and height should be | 48 * Variables used for pod placement processing. Width and height should be |
41 * synced with computed CSS sizes of pods. | 49 * synced with computed CSS sizes of pods. |
42 */ | 50 */ |
43 var POD_WIDTH = 180; | 51 var POD_WIDTH = 180; |
44 var PUBLIC_EXPANDED_WIDTH = 420; | 52 var PUBLIC_EXPANDED_WIDTH = 420; |
45 var CROS_POD_HEIGHT = 213; | 53 var CROS_POD_HEIGHT = 213; |
46 var DESKTOP_POD_HEIGHT = 216; | 54 var DESKTOP_POD_HEIGHT = 216; |
47 var POD_ROW_PADDING = 10; | 55 var POD_ROW_PADDING = 10; |
56 var DESKTOP_ROW_PADDING = 32; | |
48 | 57 |
49 /** | 58 /** |
50 * Minimal padding between user pod and virtual keyboard. | 59 * Minimal padding between user pod and virtual keyboard. |
51 * @type {number} | 60 * @type {number} |
52 * @const | 61 * @const |
53 */ | 62 */ |
54 var USER_POD_KEYBOARD_MIN_PADDING = 20; | 63 var USER_POD_KEYBOARD_MIN_PADDING = 20; |
55 | 64 |
56 /** | 65 /** |
57 * Whether to preselect the first pod automatically on login screen. | 66 * Whether to preselect the first pod automatically on login screen. |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 return height; | 980 return height; |
972 }, | 981 }, |
973 | 982 |
974 set expanded(expanded) { | 983 set expanded(expanded) { |
975 if (this.expanded == expanded) | 984 if (this.expanded == expanded) |
976 return; | 985 return; |
977 | 986 |
978 this.resetTabOrder(); | 987 this.resetTabOrder(); |
979 this.classList.toggle('expanded', expanded); | 988 this.classList.toggle('expanded', expanded); |
980 if (expanded) { | 989 if (expanded) { |
990 var isDesktopUserManager = Oobe.getInstance().displayType == | |
991 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | |
992 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : | |
993 POD_ROW_PADDING; | |
981 this.usualLeft = this.left; | 994 this.usualLeft = this.left; |
982 this.usualTop = this.top; | 995 this.usualTop = this.top; |
983 if (this.left + PUBLIC_EXPANDED_WIDTH > | 996 if (this.left + PUBLIC_EXPANDED_WIDTH > |
984 $('pod-row').offsetWidth - POD_ROW_PADDING) | 997 $('pod-row').offsetWidth - rowPadding) |
985 this.left = $('pod-row').offsetWidth - POD_ROW_PADDING - | 998 this.left = $('pod-row').offsetWidth - rowPadding - |
986 PUBLIC_EXPANDED_WIDTH; | 999 PUBLIC_EXPANDED_WIDTH; |
987 var expandedHeight = this.expandedHeight_; | 1000 var expandedHeight = this.expandedHeight_; |
988 if (this.top + expandedHeight > $('pod-row').offsetHeight) | 1001 if (this.top + expandedHeight > $('pod-row').offsetHeight) |
989 this.top = $('pod-row').offsetHeight - expandedHeight; | 1002 this.top = $('pod-row').offsetHeight - expandedHeight; |
990 } else { | 1003 } else { |
991 if (typeof(this.usualLeft) != 'undefined') | 1004 if (typeof(this.usualLeft) != 'undefined') |
992 this.left = this.usualLeft; | 1005 this.left = this.usualLeft; |
993 if (typeof(this.usualTop) != 'undefined') | 1006 if (typeof(this.usualTop) != 'undefined') |
994 this.top = this.usualTop; | 1007 this.top = this.usualTop; |
995 } | 1008 } |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 | 1813 |
1801 if (Oobe.getInstance().virtualKeyboardShown) | 1814 if (Oobe.getInstance().virtualKeyboardShown) |
1802 this.scrollFocusedPodIntoView(); | 1815 this.scrollFocusedPodIntoView(); |
1803 }, | 1816 }, |
1804 | 1817 |
1805 /** | 1818 /** |
1806 * Returns width of podrow having |columns| number of columns. | 1819 * Returns width of podrow having |columns| number of columns. |
1807 * @private | 1820 * @private |
1808 */ | 1821 */ |
1809 columnsToWidth_: function(columns) { | 1822 columnsToWidth_: function(columns) { |
1810 var margin = MARGIN_BY_COLUMNS[columns]; | 1823 var isDesktopUserManager = Oobe.getInstance().displayType == |
1811 return 2 * POD_ROW_PADDING + columns * | 1824 DISPLAY_TYPE.DESKTOP_USER_MANAGER; |
1812 this.userPodWidth_ + (columns - 1) * margin; | 1825 var margin = isDesktopUserManager ? DESKTOP_MARGIN_BY_COLUMNS[columns] : |
1826 MARGIN_BY_COLUMNS[columns]; | |
1827 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : | |
1828 POD_ROW_PADDING; | |
1829 return 2 * rowPadding + columns * this.userPodWidth_ + | |
1830 (columns - 1) * margin; | |
1813 }, | 1831 }, |
1814 | 1832 |
1815 /** | 1833 /** |
1816 * Returns height of podrow having |rows| number of rows. | 1834 * Returns height of podrow having |rows| number of rows. |
1817 * @private | 1835 * @private |
1818 */ | 1836 */ |
1819 rowsToHeight_: function(rows) { | 1837 rowsToHeight_: function(rows) { |
1820 return 2 * POD_ROW_PADDING + rows * this.userPodHeight_; | 1838 var isDesktopUserManager = Oobe.getInstance().displayType == |
1839 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | |
1840 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : | |
1841 POD_ROW_PADDING; | |
1842 return 2 * rowPadding + rows * this.userPodHeight_; | |
1821 }, | 1843 }, |
1822 | 1844 |
1823 /** | 1845 /** |
1824 * Calculates number of columns and rows that podrow should have in order to | 1846 * Calculates number of columns and rows that podrow should have in order to |
1825 * hold as much its pods as possible for current screen size. Also it tries | 1847 * hold as much its pods as possible for current screen size. Also it tries |
1826 * to choose layout that looks good. | 1848 * to choose layout that looks good. |
1827 * @return {{columns: number, rows: number}} | 1849 * @return {{columns: number, rows: number}} |
1828 */ | 1850 */ |
1829 calculateLayout_: function() { | 1851 calculateLayout_: function() { |
1830 var preferredColumns = this.pods.length < COLUMNS.length ? | 1852 var preferredColumns = this.pods.length < COLUMNS.length ? |
(...skipping 21 matching lines...) Expand all Loading... | |
1852 | 1874 |
1853 /** | 1875 /** |
1854 * Places pods onto their positions onto pod grid. | 1876 * Places pods onto their positions onto pod grid. |
1855 * @private | 1877 * @private |
1856 */ | 1878 */ |
1857 placePods_: function() { | 1879 placePods_: function() { |
1858 var layout = this.calculateLayout_(); | 1880 var layout = this.calculateLayout_(); |
1859 var columns = this.columns = layout.columns; | 1881 var columns = this.columns = layout.columns; |
1860 var rows = this.rows = layout.rows; | 1882 var rows = this.rows = layout.rows; |
1861 var maxPodsNumber = columns * rows; | 1883 var maxPodsNumber = columns * rows; |
1862 var margin = MARGIN_BY_COLUMNS[columns]; | 1884 var isDesktopUserManager = Oobe.getInstance().displayType == |
1885 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | |
1886 var margin = isDesktopUserManager ? DESKTOP_MARGIN_BY_COLUMNS[columns] : | |
1887 MARGIN_BY_COLUMNS[columns]; | |
1863 this.parentNode.setPreferredSize( | 1888 this.parentNode.setPreferredSize( |
1864 this.columnsToWidth_(columns), this.rowsToHeight_(rows)); | 1889 this.columnsToWidth_(columns), this.rowsToHeight_(rows)); |
1865 var height = this.userPodHeight_; | 1890 var height = this.userPodHeight_; |
1866 var width = this.userPodWidth_; | 1891 var width = this.userPodWidth_; |
1867 this.pods.forEach(function(pod, index) { | 1892 this.pods.forEach(function(pod, index) { |
1868 if (pod.offsetHeight != height) { | 1893 if (pod.offsetHeight != height) { |
1869 console.error('Pod offsetHeight (' + pod.offsetHeight + | 1894 console.error('Pod offsetHeight (' + pod.offsetHeight + |
1870 ') and POD_HEIGHT (' + height + ') are not equal.'); | 1895 ') and POD_HEIGHT (' + height + ') are not equal.'); |
1871 } | 1896 } |
1872 if (pod.offsetWidth != width) { | 1897 if (pod.offsetWidth != width) { |
1873 console.error('Pod offsetWidth (' + pod.offsetWidth + | 1898 console.error('Pod offsetWidth (' + pod.offsetWidth + |
1874 ') and POD_WIDTH (' + width + ') are not equal.'); | 1899 ') and POD_WIDTH (' + width + ') are not equal.'); |
1875 } | 1900 } |
1876 if (index >= maxPodsNumber) { | 1901 if (index >= maxPodsNumber) { |
1877 pod.hidden = true; | 1902 pod.hidden = true; |
1878 return; | 1903 return; |
1879 } | 1904 } |
1880 pod.hidden = false; | 1905 pod.hidden = false; |
1881 var column = index % columns; | 1906 var column = index % columns; |
1882 var row = Math.floor(index / columns); | 1907 var row = Math.floor(index / columns); |
1883 pod.left = POD_ROW_PADDING + column * (width + margin); | 1908 var rowPadding = isDesktopUserManager ? DESKTOP_ROW_PADDING : |
1884 pod.top = POD_ROW_PADDING + row * height; | 1909 POD_ROW_PADDING; |
1910 pod.left = rowPadding + column * (width + margin); | |
1911 pod.top = row * (height + rowPadding); | |
Nikita (slow)
2014/06/16 15:28:10
Should be
pod.top = rowPadding + row * height
noms (inactive)
2014/06/16 18:10:56
So I think on desktop we want the spacing to alway
| |
1885 }); | 1912 }); |
1886 Oobe.getInstance().updateScreenSize(this.parentNode); | 1913 Oobe.getInstance().updateScreenSize(this.parentNode); |
1887 }, | 1914 }, |
1888 | 1915 |
1889 /** | 1916 /** |
1890 * Number of columns. | 1917 * Number of columns. |
1891 * @type {?number} | 1918 * @type {?number} |
1892 */ | 1919 */ |
1893 set columns(columns) { | 1920 set columns(columns) { |
1894 // Cannot use 'columns' here. | 1921 // Cannot use 'columns' here. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1946 } | 1973 } |
1947 this.insideFocusPod_ = true; | 1974 this.insideFocusPod_ = true; |
1948 | 1975 |
1949 for (var i = 0, pod; pod = this.pods[i]; ++i) { | 1976 for (var i = 0, pod; pod = this.pods[i]; ++i) { |
1950 if (!this.alwaysFocusSinglePod) { | 1977 if (!this.alwaysFocusSinglePod) { |
1951 pod.isActionBoxMenuActive = false; | 1978 pod.isActionBoxMenuActive = false; |
1952 } | 1979 } |
1953 if (pod != podToFocus) { | 1980 if (pod != podToFocus) { |
1954 pod.isActionBoxMenuHovered = false; | 1981 pod.isActionBoxMenuHovered = false; |
1955 pod.classList.remove('focused'); | 1982 pod.classList.remove('focused'); |
1956 pod.classList.remove('faded'); | 1983 // On Desktop, the faded style is not set correctly, so we should |
1984 // manually fade out non-focused pods. | |
1985 if (pod.user.isDesktopUser) | |
1986 pod.classList.add('faded'); | |
1987 else | |
1988 pod.classList.remove('faded'); | |
1957 pod.reset(false); | 1989 pod.reset(false); |
1958 } | 1990 } |
1959 } | 1991 } |
1960 | 1992 |
1961 // Clear any error messages for previous pod. | 1993 // Clear any error messages for previous pod. |
1962 if (!this.isFocused(podToFocus)) | 1994 if (!this.isFocused(podToFocus)) |
1963 Oobe.clearErrors(); | 1995 Oobe.clearErrors(); |
1964 | 1996 |
1965 var hadFocus = !!this.focusedPod_; | 1997 var hadFocus = !!this.focusedPod_; |
1966 this.focusedPod_ = podToFocus; | 1998 this.focusedPod_ = podToFocus; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2307 if (this.podsWithPendingImages_.length == 0) { | 2339 if (this.podsWithPendingImages_.length == 0) { |
2308 this.classList.remove('images-loading'); | 2340 this.classList.remove('images-loading'); |
2309 } | 2341 } |
2310 } | 2342 } |
2311 }; | 2343 }; |
2312 | 2344 |
2313 return { | 2345 return { |
2314 PodRow: PodRow | 2346 PodRow: PodRow |
2315 }; | 2347 }; |
2316 }); | 2348 }); |
OLD | NEW |