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 New tab page | 6 * @fileoverview New tab page |
7 * This is the main code for the new tab page. NewTabView manages page list, | 7 * This is the main code for the new tab page. NewTabView manages page list, |
8 * dot list and handles apps pages callbacks from backend. It also handles | 8 * dot list and handles apps pages callbacks from backend. It also handles |
9 * the layout of the Bottom Panel and the global UI states of the New Tab Page. | 9 * the layout of the Bottom Panel and the global UI states of the New Tab Page. |
10 */ | 10 */ |
(...skipping 19 matching lines...) Expand all Loading... |
30 * @type {number} | 30 * @type {number} |
31 * @const | 31 * @const |
32 */ | 32 */ |
33 var BOTTOM_PANEL_HORIZONTAL_MARGIN = 100; | 33 var BOTTOM_PANEL_HORIZONTAL_MARGIN = 100; |
34 | 34 |
35 /** | 35 /** |
36 * The height required to show the Bottom Panel. | 36 * The height required to show the Bottom Panel. |
37 * @type {number} | 37 * @type {number} |
38 * @const | 38 * @const |
39 */ | 39 */ |
40 var HEIGHT_FOR_BOTTOM_PANEL = 558; | 40 var HEIGHT_FOR_BOTTOM_PANEL = 531; |
41 | 41 |
42 /** | 42 /** |
43 * The Bottom Panel width required to show 6 cols of Tiles, which is used | 43 * The Bottom Panel width required to show 6 cols of Tiles, which is used |
44 * in the width computation. | 44 * in the width computation. |
45 * @type {number} | 45 * @type {number} |
46 * @const | 46 * @const |
47 */ | 47 */ |
48 var MAX_BOTTOM_PANEL_WIDTH = 920; | 48 var MAX_BOTTOM_PANEL_WIDTH = 920; |
49 | 49 |
50 /** | 50 /** |
(...skipping 17 matching lines...) Expand all Loading... |
68 * equal to this value, then the width of the Bottom Panel's content will be | 68 * equal to this value, then the width of the Bottom Panel's content will be |
69 * the available width minus side margin. If the available width is smaller | 69 * the available width minus side margin. If the available width is smaller |
70 * than this value, then the width of the Bottom Panel's content will be an | 70 * than this value, then the width of the Bottom Panel's content will be an |
71 * interpolation between the normal width, and the minimum width defined by | 71 * interpolation between the normal width, and the minimum width defined by |
72 * the constant MIN_BOTTOM_PANEL_CONTENT_WIDTH. | 72 * the constant MIN_BOTTOM_PANEL_CONTENT_WIDTH. |
73 * @type {number} | 73 * @type {number} |
74 * @const | 74 * @const |
75 */ | 75 */ |
76 var NORMAL_BOTTOM_PANEL_WIDTH = 500; | 76 var NORMAL_BOTTOM_PANEL_WIDTH = 500; |
77 | 77 |
| 78 /** |
| 79 * @type {number} |
| 80 * @const |
| 81 */ |
| 82 var TILE_ROW_HEIGHT = 100; |
| 83 |
78 //---------------------------------------------------------------------------- | 84 //---------------------------------------------------------------------------- |
79 | 85 |
80 /** | 86 /** |
81 * NewTabView instance. | 87 * NewTabView instance. |
82 * @type {!Object|undefined} | 88 * @type {!Object|undefined} |
83 */ | 89 */ |
84 var newTabView; | 90 var newTabView; |
85 | 91 |
86 /** | 92 /** |
87 * The 'notification-container' element. | 93 * The 'notification-container' element. |
(...skipping 17 matching lines...) Expand all Loading... |
105 var hoveredThumbnailCount = 0; | 111 var hoveredThumbnailCount = 0; |
106 | 112 |
107 /** | 113 /** |
108 * The time when all sections are ready. | 114 * The time when all sections are ready. |
109 * @type {number|undefined} | 115 * @type {number|undefined} |
110 * @private | 116 * @private |
111 */ | 117 */ |
112 var startTime; | 118 var startTime; |
113 | 119 |
114 /** | 120 /** |
| 121 * The top position of the Bottom Panel. |
| 122 * @type {number|undefined} |
| 123 * @private |
| 124 */ |
| 125 var bottomPanelOffsetTop; |
| 126 |
| 127 /** |
| 128 * The height of the Bottom Panel Header, in pixels. |
| 129 * @type {number|undefined} |
| 130 * @private |
| 131 */ |
| 132 var headerHeight; |
| 133 |
| 134 /** |
| 135 * The height of the Bottom Panel Footer, in pixels. |
| 136 * @type {number|undefined} |
| 137 * @private |
| 138 */ |
| 139 var footerHeight; |
| 140 |
| 141 /** |
115 * The time in milliseconds for most transitions. This should match what's | 142 * The time in milliseconds for most transitions. This should match what's |
116 * in new_tab.css. Unfortunately there's no better way to try to time | 143 * in new_tab.css. Unfortunately there's no better way to try to time |
117 * something to occur until after a transition has completed. | 144 * something to occur until after a transition has completed. |
118 * @type {number} | 145 * @type {number} |
119 * @const | 146 * @const |
120 */ | 147 */ |
121 var DEFAULT_TRANSITION_TIME = 500; | 148 var DEFAULT_TRANSITION_TIME = 500; |
122 | 149 |
123 /** | 150 /** |
124 * See description for these values in ntp_stats.h. | 151 * See description for these values in ntp_stats.h. |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 733 |
707 // Calculates the width of the Bottom Panel's Content. | 734 // Calculates the width of the Bottom Panel's Content. |
708 var width = this.calculateContentWidth_(); | 735 var width = this.calculateContentWidth_(); |
709 if (width != this.contentWidth_) { | 736 if (width != this.contentWidth_) { |
710 this.contentWidth_ = width; | 737 this.contentWidth_ = width; |
711 $('bottom-panel-footer').style.width = width + 'px'; | 738 $('bottom-panel-footer').style.width = width + 'px'; |
712 } | 739 } |
713 | 740 |
714 // Finally, dispatch the layout method to the current page. | 741 // Finally, dispatch the layout method to the current page. |
715 var currentPage = opt_page || this.cardSlider.currentCardValue; | 742 var currentPage = opt_page || this.cardSlider.currentCardValue; |
| 743 |
| 744 var contentHeight = TILE_ROW_HEIGHT; |
| 745 if (!opt_page && currentPage.config.scrollable) { |
| 746 contentHeight = viewHeight - bottomPanelOffsetTop - |
| 747 headerHeight - footerHeight; |
| 748 contentHeight = Math.max(TILE_ROW_HEIGHT, contentHeight); |
| 749 contentHeight = Math.min(2 * TILE_ROW_HEIGHT, contentHeight); |
| 750 } |
| 751 this.contentHeight_ = contentHeight; |
| 752 |
| 753 $('card-slider-frame').style.height = contentHeight + 'px'; |
| 754 |
716 currentPage.layout(opt_animate); | 755 currentPage.layout(opt_animate); |
717 }, | 756 }, |
718 | 757 |
719 /** | 758 /** |
| 759 * @return {number} The height of the Bottom Panel's content. |
| 760 */ |
| 761 get contentHeight() { |
| 762 return this.contentHeight_; |
| 763 }, |
| 764 |
| 765 /** |
720 * @return {number} The width of the Bottom Panel's content. | 766 * @return {number} The width of the Bottom Panel's content. |
721 */ | 767 */ |
722 get contentWidth() { | 768 get contentWidth() { |
723 return this.contentWidth_; | 769 return this.contentWidth_; |
724 }, | 770 }, |
725 | 771 |
726 /** | 772 /** |
727 * @return {number} The width of the Bottom Panel's content. | 773 * @return {number} The width of the Bottom Panel's content. |
728 * @private | 774 * @private |
729 */ | 775 */ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 807 |
762 /** | 808 /** |
763 * Invoked at startup once the DOM is available to initialize the app. | 809 * Invoked at startup once the DOM is available to initialize the app. |
764 */ | 810 */ |
765 function onLoad() { | 811 function onLoad() { |
766 // Load the current theme colors. | 812 // Load the current theme colors. |
767 themeChanged(); | 813 themeChanged(); |
768 | 814 |
769 newTabView = new NewTabView(); | 815 newTabView = new NewTabView(); |
770 | 816 |
| 817 bottomPanelOffsetTop = $('bottom-panel').offsetTop; |
| 818 headerHeight = $('bottom-panel-header').offsetHeight; |
| 819 footerHeight = $('bottom-panel-footer').offsetHeight; |
| 820 |
771 notificationContainer = getRequiredElement('notification-container'); | 821 notificationContainer = getRequiredElement('notification-container'); |
772 notificationContainer.addEventListener( | 822 notificationContainer.addEventListener( |
773 'webkitTransitionEnd', onNotificationTransitionEnd); | 823 'webkitTransitionEnd', onNotificationTransitionEnd); |
774 | 824 |
775 var mostVisited = new ntp.MostVisitedPage(); | 825 var mostVisited = new ntp.MostVisitedPage(); |
776 newTabView.appendTilePage(mostVisited, | 826 newTabView.appendTilePage(mostVisited, |
777 loadTimeData.getString('mostvisited')); | 827 loadTimeData.getString('mostvisited')); |
778 chrome.send('getMostVisited'); | 828 chrome.send('getMostVisited'); |
779 | 829 |
780 if (loadTimeData.valueExists('bubblePromoText')) { | 830 if (loadTimeData.valueExists('bubblePromoText')) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 } | 1117 } |
1068 | 1118 |
1069 function setAppToBeHighlighted(appId) { | 1119 function setAppToBeHighlighted(appId) { |
1070 newTabView.highlightAppId = appId; | 1120 newTabView.highlightAppId = appId; |
1071 } | 1121 } |
1072 | 1122 |
1073 function layout(opt_animate) { | 1123 function layout(opt_animate) { |
1074 newTabView.layout(opt_animate); | 1124 newTabView.layout(opt_animate); |
1075 } | 1125 } |
1076 | 1126 |
| 1127 function getContentHeight() { |
| 1128 return newTabView.contentHeight; |
| 1129 } |
| 1130 |
1077 function getContentWidth() { | 1131 function getContentWidth() { |
1078 return newTabView.contentWidth; | 1132 return newTabView.contentWidth; |
1079 } | 1133 } |
1080 | 1134 |
1081 // Return an object with all the exports | 1135 // Return an object with all the exports |
1082 return { | 1136 return { |
1083 APP_LAUNCH: APP_LAUNCH, | 1137 APP_LAUNCH: APP_LAUNCH, |
| 1138 TILE_ROW_HEIGHT: TILE_ROW_HEIGHT, |
1084 appAdded: appAdded, | 1139 appAdded: appAdded, |
1085 appMoved: appMoved, | 1140 appMoved: appMoved, |
1086 appRemoved: appRemoved, | 1141 appRemoved: appRemoved, |
1087 appsPrefChangeCallback: appsPrefChangeCallback, | 1142 appsPrefChangeCallback: appsPrefChangeCallback, |
1088 getAppsCallback: getAppsCallback, | 1143 getAppsCallback: getAppsCallback, |
1089 getCardSlider: getCardSlider, | 1144 getCardSlider: getCardSlider, |
| 1145 getContentHeight: getContentHeight, |
1090 getContentWidth: getContentWidth, | 1146 getContentWidth: getContentWidth, |
1091 getThumbnailUrl: getThumbnailUrl, | 1147 getThumbnailUrl: getThumbnailUrl, |
1092 incrementHoveredThumbnailCount: incrementHoveredThumbnailCount, | 1148 incrementHoveredThumbnailCount: incrementHoveredThumbnailCount, |
1093 layout: layout, | 1149 layout: layout, |
1094 logTimeToClickAndHoverCount: logTimeToClickAndHoverCount, | 1150 logTimeToClickAndHoverCount: logTimeToClickAndHoverCount, |
1095 NtpFollowAction: NtpFollowAction, | 1151 NtpFollowAction: NtpFollowAction, |
1096 onLoad: onLoad, | 1152 onLoad: onLoad, |
1097 setAppToBeHighlighted: setAppToBeHighlighted, | 1153 setAppToBeHighlighted: setAppToBeHighlighted, |
1098 setBookmarkBarAttached: setBookmarkBarAttached, | 1154 setBookmarkBarAttached: setBookmarkBarAttached, |
1099 setForeignSessions: setForeignSessions, | 1155 setForeignSessions: setForeignSessions, |
1100 setMostVisitedPages: setMostVisitedPages, | 1156 setMostVisitedPages: setMostVisitedPages, |
1101 setRecentlyClosedTabs: setRecentlyClosedTabs, | 1157 setRecentlyClosedTabs: setRecentlyClosedTabs, |
1102 showNotification: showNotification, | 1158 showNotification: showNotification, |
1103 themeChanged: themeChanged, | 1159 themeChanged: themeChanged, |
1104 }; | 1160 }; |
1105 }); | 1161 }); |
1106 | 1162 |
1107 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 1163 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
1108 | 1164 |
1109 var toCssPx = cr.ui.toCssPx; | 1165 var toCssPx = cr.ui.toCssPx; |
OLD | NEW |