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 used by touch-enabled Chrome | 7 * This is the main code for the new tab page used by touch-enabled Chrome |
| 8 * browsers. For now this is still a prototype. | 8 * browsers. For now this is still a prototype. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // Use an anonymous function to enable strict mode just for this file (which | 11 // Use an anonymous function to enable strict mode just for this file (which |
| 12 // will be concatenated with other files when embedded in Chrome | 12 // will be concatenated with other files when embedded in Chrome |
| 13 cr.define('ntp', function() { | 13 cr.define('ntp', function() { |
| 14 'use strict'; | 14 'use strict'; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * NewTabView instance. | 17 * NewTabView instance. |
| 18 * @type {!Object|undefined} | 18 * @type {!Object|undefined} |
| 19 */ | 19 */ |
| 20 var newTabView; | 20 var newTabView; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * If non-null, an info bubble for showing messages to the user. It points at | |
| 24 * the Most Visited label, and is used to draw more attention to the | |
| 25 * navigation dot UI. | |
| 26 * @type {!cr.ui.Bubble|undefined} | |
| 27 */ | |
| 28 var promoBubble; | |
| 29 | |
| 30 /** | |
| 31 * If non-null, an bubble confirming that the user has signed into sync. It | 23 * If non-null, an bubble confirming that the user has signed into sync. It |
| 32 * points at the login status at the top of the page. | 24 * points at the login status at the top of the page. |
| 33 * @type {!cr.ui.Bubble|undefined} | 25 * @type {!cr.ui.Bubble|undefined} |
| 34 */ | 26 */ |
| 35 var loginBubble; | 27 var loginBubble; |
| 36 | 28 |
| 37 /** | 29 /** |
| 38 * true if |loginBubble| should be shown. | 30 * true if |loginBubble| should be shown. |
| 39 * @type {boolean} | 31 * @type {boolean} |
| 40 */ | 32 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 pageSwitcherEnd = /** @type {!ntp.PageSwitcher} */( | 73 pageSwitcherEnd = /** @type {!ntp.PageSwitcher} */( |
| 82 getRequiredElement('page-switcher-end')); | 74 getRequiredElement('page-switcher-end')); |
| 83 } | 75 } |
| 84 this.initialize(getRequiredElement('page-list'), | 76 this.initialize(getRequiredElement('page-list'), |
| 85 getRequiredElement('dot-list'), | 77 getRequiredElement('dot-list'), |
| 86 getRequiredElement('card-slider-frame'), | 78 getRequiredElement('card-slider-frame'), |
| 87 getRequiredElement('trash'), | 79 getRequiredElement('trash'), |
| 88 pageSwitcherStart, pageSwitcherEnd); | 80 pageSwitcherStart, pageSwitcherEnd); |
| 89 } | 81 } |
| 90 | 82 |
| 91 NewTabView.prototype = { | 83 NewTabView.prototype = {__proto__: ntp.PageListView.prototype}; |
|
Dan Beam
2016/03/01 21:52:22
could I fix this silly single inheritance? yes, b
Evan Stade
2016/03/01 22:25:34
at least a TODO would be nice
Dan Beam
2016/03/01 22:36:06
Done.
| |
| 92 __proto__: ntp.PageListView.prototype, | |
| 93 | |
| 94 /** @override */ | |
| 95 appendTilePage: function(page, title, titleIsEditable, opt_refNode) { | |
| 96 ntp.PageListView.prototype.appendTilePage.apply(this, arguments); | |
| 97 | |
| 98 if (promoBubble) | |
| 99 window.setTimeout(promoBubble.reposition.bind(promoBubble), 0); | |
| 100 } | |
| 101 }; | |
| 102 | 84 |
| 103 /** | 85 /** |
| 104 * Invoked at startup once the DOM is available to initialize the app. | 86 * Invoked at startup once the DOM is available to initialize the app. |
| 105 */ | 87 */ |
| 106 function onLoad() { | 88 function onLoad() { |
| 107 sectionsToWaitFor = 0; | 89 sectionsToWaitFor = 0; |
| 108 if (loadTimeData.getBoolean('showApps')) { | 90 if (loadTimeData.getBoolean('showApps')) { |
| 109 sectionsToWaitFor++; | 91 sectionsToWaitFor++; |
| 110 if (loadTimeData.getBoolean('showAppLauncherPromo')) { | 92 if (loadTimeData.getBoolean('showAppLauncherPromo')) { |
| 111 $('app-launcher-promo-close-button').addEventListener('click', | 93 $('app-launcher-promo-close-button').addEventListener('click', |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 $('login-status-dismiss').onclick = loginBubble.hide.bind(loginBubble); | 135 $('login-status-dismiss').onclick = loginBubble.hide.bind(loginBubble); |
| 154 | 136 |
| 155 var bubbleContent = $('login-status-bubble-contents'); | 137 var bubbleContent = $('login-status-bubble-contents'); |
| 156 loginBubble.content = bubbleContent; | 138 loginBubble.content = bubbleContent; |
| 157 | 139 |
| 158 // The anchor node won't be updated until updateLogin is called so don't | 140 // The anchor node won't be updated until updateLogin is called so don't |
| 159 // show the bubble yet. | 141 // show the bubble yet. |
| 160 shouldShowLoginBubble = true; | 142 shouldShowLoginBubble = true; |
| 161 } | 143 } |
| 162 | 144 |
| 163 if (loadTimeData.valueExists('bubblePromoText')) { | |
| 164 promoBubble = new cr.ui.Bubble; | |
| 165 promoBubble.anchorNode = getRequiredElement('promo-bubble-anchor'); | |
| 166 promoBubble.arrowLocation = cr.ui.ArrowLocation.BOTTOM_START; | |
| 167 promoBubble.bubbleAlignment = cr.ui.BubbleAlignment.ENTIRELY_VISIBLE; | |
| 168 promoBubble.deactivateToDismissDelay = 2000; | |
| 169 promoBubble.content = parseHtmlSubset( | |
| 170 loadTimeData.getString('bubblePromoText'), ['BR']); | |
| 171 | |
| 172 var bubbleLink = promoBubble.querySelector('a'); | |
| 173 if (bubbleLink) { | |
| 174 bubbleLink.addEventListener('click', function(e) { | |
| 175 chrome.send('bubblePromoLinkClicked'); | |
| 176 }); | |
| 177 } | |
| 178 | |
| 179 promoBubble.handleCloseEvent = function() { | |
| 180 promoBubble.hide(); | |
| 181 chrome.send('bubblePromoClosed'); | |
| 182 }; | |
| 183 promoBubble.show(); | |
| 184 chrome.send('bubblePromoViewed'); | |
| 185 } | |
| 186 | |
| 187 $('login-container').addEventListener('click', showSyncLoginUI); | 145 $('login-container').addEventListener('click', showSyncLoginUI); |
| 188 if (loadTimeData.getBoolean('shouldShowSyncLogin')) | 146 if (loadTimeData.getBoolean('shouldShowSyncLogin')) |
| 189 chrome.send('initializeSyncLogin'); | 147 chrome.send('initializeSyncLogin'); |
| 190 | 148 |
| 191 doWhenAllSectionsReady(function() { | 149 doWhenAllSectionsReady(function() { |
| 192 // Tell the slider about the pages. | 150 // Tell the slider about the pages. |
| 193 newTabView.updateSliderCards(); | 151 newTabView.updateSliderCards(); |
| 194 // Mark the current page. | 152 // Mark the current page. |
| 195 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( | 153 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( |
| 196 'selected'); | 154 'selected'); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 setBookmarkBarAttached: setBookmarkBarAttached, | 455 setBookmarkBarAttached: setBookmarkBarAttached, |
| 498 setFaviconDominantColor: setFaviconDominantColor, | 456 setFaviconDominantColor: setFaviconDominantColor, |
| 499 themeChanged: themeChanged, | 457 themeChanged: themeChanged, |
| 500 updateLogin: updateLogin | 458 updateLogin: updateLogin |
| 501 }; | 459 }; |
| 502 }); | 460 }); |
| 503 | 461 |
| 504 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 462 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| 505 | 463 |
| 506 var toCssPx = cr.ui.toCssPx; | 464 var toCssPx = cr.ui.toCssPx; |
| OLD | NEW |