Chromium Code Reviews| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 * @type {number|undefined} | 129 * @type {number|undefined} |
| 130 * @private | 130 * @private |
| 131 */ | 131 */ |
| 132 var headerHeight; | 132 var headerHeight; |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * The height of the Bottom Panel Footer, in pixels. | 135 * The height of the Bottom Panel Footer, in pixels. |
| 136 * @type {number|undefined} | 136 * @type {number|undefined} |
| 137 * @private | 137 * @private |
| 138 */ | 138 */ |
| 139 var footerHeight; | 139 var footerHeight; |
|
Dan Beam
2012/12/14 03:44:42
remove this now that it can be a local, not a glob
pedro (no code reviews)
2012/12/14 05:06:33
Done.
| |
| 140 | 140 |
| 141 /** | 141 /** |
| 142 * 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 |
| 143 * 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 |
| 144 * something to occur until after a transition has completed. | 144 * something to occur until after a transition has completed. |
| 145 * @type {number} | 145 * @type {number} |
| 146 * @const | 146 * @const |
| 147 */ | 147 */ |
| 148 var DEFAULT_TRANSITION_TIME = 500; | 148 var DEFAULT_TRANSITION_TIME = 500; |
| 149 | 149 |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 if (width != this.contentWidth_) { | 728 if (width != this.contentWidth_) { |
| 729 this.contentWidth_ = width; | 729 this.contentWidth_ = width; |
| 730 $('bottom-panel-footer').style.width = width + 'px'; | 730 $('bottom-panel-footer').style.width = width + 'px'; |
| 731 } | 731 } |
| 732 | 732 |
| 733 // Finally, dispatch the layout method to the current page. | 733 // Finally, dispatch the layout method to the current page. |
| 734 var currentPage = opt_page || this.cardSlider.currentCardValue; | 734 var currentPage = opt_page || this.cardSlider.currentCardValue; |
| 735 | 735 |
| 736 var contentHeight = TILE_ROW_HEIGHT; | 736 var contentHeight = TILE_ROW_HEIGHT; |
| 737 if (!opt_page && currentPage.config.scrollable) { | 737 if (!opt_page && currentPage.config.scrollable) { |
| 738 footerHeight = $('bottom-panel-footer').offsetHeight; | |
|
Dan Beam
2012/12/14 03:44:42
nit: var footerHeight; (make a local)
pedro (no code reviews)
2012/12/14 05:06:33
I would normally create a variable, just for reada
| |
| 738 contentHeight = viewHeight - bottomPanelOffsetTop - | 739 contentHeight = viewHeight - bottomPanelOffsetTop - |
| 739 headerHeight - footerHeight; | 740 headerHeight - footerHeight; |
|
Dan Beam
2012/12/14 03:44:42
or just inline $('bottom-panel-footer').offsetHeig
pedro (no code reviews)
2012/12/14 05:06:33
Done.
| |
| 740 contentHeight = Math.max(TILE_ROW_HEIGHT, contentHeight); | 741 contentHeight = Math.max(TILE_ROW_HEIGHT, contentHeight); |
| 741 contentHeight = Math.min(2 * TILE_ROW_HEIGHT, contentHeight); | |
| 742 } | 742 } |
| 743 this.contentHeight_ = contentHeight; | 743 this.contentHeight_ = contentHeight; |
| 744 | 744 |
| 745 $('card-slider-frame').style.height = contentHeight + 'px'; | 745 $('card-slider-frame').style.height = contentHeight + 'px'; |
| 746 | 746 |
| 747 currentPage.layout(opt_animate); | 747 currentPage.layout(opt_animate); |
| 748 }, | 748 }, |
| 749 | 749 |
| 750 /** | 750 /** |
| 751 * @return {number} The height of the Bottom Panel's content. | 751 * @return {number} The height of the Bottom Panel's content. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 * Invoked at startup once the DOM is available to initialize the app. | 801 * Invoked at startup once the DOM is available to initialize the app. |
| 802 */ | 802 */ |
| 803 function onLoad() { | 803 function onLoad() { |
| 804 // Load the current theme colors. | 804 // Load the current theme colors. |
| 805 themeChanged(); | 805 themeChanged(); |
| 806 | 806 |
| 807 newTabView = new NewTabView(); | 807 newTabView = new NewTabView(); |
| 808 | 808 |
| 809 bottomPanelOffsetTop = $('bottom-panel').offsetTop; | 809 bottomPanelOffsetTop = $('bottom-panel').offsetTop; |
| 810 headerHeight = $('bottom-panel-header').offsetHeight; | 810 headerHeight = $('bottom-panel-header').offsetHeight; |
| 811 footerHeight = $('bottom-panel-footer').offsetHeight; | |
| 812 | 811 |
| 813 notificationContainer = getRequiredElement('notification-container'); | 812 notificationContainer = getRequiredElement('notification-container'); |
| 814 notificationContainer.addEventListener( | 813 notificationContainer.addEventListener( |
| 815 'webkitTransitionEnd', onNotificationTransitionEnd); | 814 'webkitTransitionEnd', onNotificationTransitionEnd); |
| 816 | 815 |
| 817 var mostVisited = new ntp.MostVisitedPage(); | 816 var mostVisited = new ntp.MostVisitedPage(); |
| 818 newTabView.appendTilePage(mostVisited, | 817 newTabView.appendTilePage(mostVisited, |
| 819 loadTimeData.getString('mostvisited')); | 818 loadTimeData.getString('mostvisited')); |
| 820 chrome.send('getMostVisited'); | 819 chrome.send('getMostVisited'); |
| 821 | 820 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 document.querySelector('#notification button').onclick = closeFunc; | 1004 document.querySelector('#notification button').onclick = closeFunc; |
| 1006 document.addEventListener('dragstart', closeFunc); | 1005 document.addEventListener('dragstart', closeFunc); |
| 1007 | 1006 |
| 1008 notificationContainer.hidden = false; | 1007 notificationContainer.hidden = false; |
| 1009 window.setTimeout(function() { | 1008 window.setTimeout(function() { |
| 1010 notificationContainer.classList.remove('inactive'); | 1009 notificationContainer.classList.remove('inactive'); |
| 1011 }, 0); | 1010 }, 0); |
| 1012 | 1011 |
| 1013 var timeout = opt_timeout || 10000; | 1012 var timeout = opt_timeout || 10000; |
| 1014 notificationTimeout = window.setTimeout(hideNotification, timeout); | 1013 notificationTimeout = window.setTimeout(hideNotification, timeout); |
| 1014 | |
| 1015 layout(); | |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1017 /** | 1018 /** |
| 1018 * Hide the notification bubble. | 1019 * Hide the notification bubble. |
| 1019 */ | 1020 */ |
| 1020 function hideNotification() { | 1021 function hideNotification() { |
| 1021 notificationContainer.classList.add('inactive'); | 1022 notificationContainer.classList.add('inactive'); |
| 1023 | |
| 1024 layout(); | |
| 1022 } | 1025 } |
| 1023 | 1026 |
| 1024 /** | 1027 /** |
| 1025 * When done fading out, set hidden to true so the notification can't be | 1028 * When done fading out, set hidden to true so the notification can't be |
| 1026 * tabbed to or clicked. | 1029 * tabbed to or clicked. |
| 1027 * @param {Event} e The webkitTransitionEnd event. | 1030 * @param {Event} e The webkitTransitionEnd event. |
| 1028 */ | 1031 */ |
| 1029 function onNotificationTransitionEnd(e) { | 1032 function onNotificationTransitionEnd(e) { |
| 1030 if (notificationContainer.classList.contains('inactive')) | 1033 if (notificationContainer.classList.contains('inactive')) |
| 1031 notificationContainer.hidden = true; | 1034 notificationContainer.hidden = true; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1097 } | 1100 } |
| 1098 | 1101 |
| 1099 function getCardSlider() { | 1102 function getCardSlider() { |
| 1100 return newTabView.cardSlider; | 1103 return newTabView.cardSlider; |
| 1101 } | 1104 } |
| 1102 | 1105 |
| 1103 function setAppToBeHighlighted(appId) { | 1106 function setAppToBeHighlighted(appId) { |
| 1104 newTabView.highlightAppId = appId; | 1107 newTabView.highlightAppId = appId; |
| 1105 } | 1108 } |
| 1106 | 1109 |
| 1107 function layout(opt_animate) { | 1110 function layout(opt_animate) { |
|
Dan Beam
2012/12/14 03:44:42
shouldn't this also take opt_page? why aren't use
Dan Beam
2012/12/14 03:45:02
why aren't you using**
pedro (no code reviews)
2012/12/14 05:06:33
Done.
pedro (no code reviews)
2012/12/14 05:06:33
Using the forwarding pattern now.
| |
| 1108 newTabView.layout(opt_animate); | 1111 newTabView.layout(opt_animate); |
| 1109 } | 1112 } |
| 1110 | 1113 |
| 1111 function getContentHeight() { | 1114 function getContentHeight() { |
| 1112 return newTabView.contentHeight; | 1115 return newTabView.contentHeight; |
| 1113 } | 1116 } |
| 1114 | 1117 |
| 1115 function getContentWidth() { | 1118 function getContentWidth() { |
| 1116 return newTabView.contentWidth; | 1119 return newTabView.contentWidth; |
| 1117 } | 1120 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1145 setRecentlyClosedTabs: noop, | 1148 setRecentlyClosedTabs: noop, |
| 1146 showNotification: showNotification, | 1149 showNotification: showNotification, |
| 1147 themeChanged: themeChanged, | 1150 themeChanged: themeChanged, |
| 1148 updateLogin: noop, | 1151 updateLogin: noop, |
| 1149 }; | 1152 }; |
| 1150 }); | 1153 }); |
| 1151 | 1154 |
| 1152 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 1155 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| 1153 | 1156 |
| 1154 var toCssPx = cr.ui.toCssPx; | 1157 var toCssPx = cr.ui.toCssPx; |
| OLD | NEW |