Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/resources/ntp4/new_tab.js

Issue 7577002: ntp4: new app animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/app_launcher_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 */ 95 */
96 var eventTracker = new EventTracker; 96 var eventTracker = new EventTracker;
97 97
98 /** 98 /**
99 * Object for accessing localized strings. 99 * Object for accessing localized strings.
100 * @type {!LocalStrings} 100 * @type {!LocalStrings}
101 */ 101 */
102 var localStrings = new LocalStrings; 102 var localStrings = new LocalStrings;
103 103
104 /** 104 /**
105 * If non-null, this is the ID of the app to highlight to the user the next
106 * time getAppsCallback runs. "Highlight" in this case means to switch to
107 * the page and run the new tile animation.
108 * @type {String}
109 */
110 var highlightAppId = null;
111
112 /**
105 * The time in milliseconds for most transitions. This should match what's 113 * The time in milliseconds for most transitions. This should match what's
106 * in new_tab.css. Unfortunately there's no better way to try to time 114 * in new_tab.css. Unfortunately there's no better way to try to time
107 * something to occur until after a transition has completed. 115 * something to occur until after a transition has completed.
108 * @type {number} 116 * @type {number}
109 * @const 117 * @const
110 */ 118 */
111 var DEFAULT_TRANSITION_TIME = 500; 119 var DEFAULT_TRANSITION_TIME = 500;
112 120
113 /** 121 /**
114 * Invoked at startup once the DOM is available to initialize the app. 122 * Invoked at startup once the DOM is available to initialize the app.
115 */ 123 */
116 function initialize() { 124 function initialize() {
117 cr.enablePlatformSpecificCSSRules(); 125 cr.enablePlatformSpecificCSSRules();
118 126
119 // Load the current theme colors. 127 // Load the current theme colors.
120 themeChanged(); 128 themeChanged();
121 129
122 dotList = getRequiredElement('dot-list'); 130 dotList = getRequiredElement('dot-list');
123 pageList = getRequiredElement('page-list'); 131 pageList = getRequiredElement('page-list');
124 trash = getRequiredElement('trash'); 132 trash = getRequiredElement('trash');
125 new ntp4.Trash(trash); 133 new ntp4.Trash(trash);
126 134
127 shownPage = templateData['shown_page_type']; 135 shownPage = templateData['shown_page_type'];
128 shownPageIndex = templateData['shown_page_index']; 136 shownPageIndex = templateData['shown_page_index'];
129 137
138 // When a new app has been installed, we will be opened with a hash value
139 // that corresponds to the new app ID.
140 var hash = location.hash;
141 if (hash && hash.indexOf('#app-id=') == 0)
142 highlightAppId = hash.split('=')[1];
143
130 document.querySelector('#notification button').onclick = function(e) { 144 document.querySelector('#notification button').onclick = function(e) {
131 hideNotification(); 145 hideNotification();
132 }; 146 };
133 147
134 // Request data on the apps so we can fill them in. 148 // Request data on the apps so we can fill them in.
135 // Note that this is kicked off asynchronously. 'getAppsCallback' will be 149 // Note that this is kicked off asynchronously. 'getAppsCallback' will be
136 // invoked at some point after this function returns. 150 // invoked at some point after this function returns.
137 chrome.send('getApps'); 151 chrome.send('getApps');
138 152
139 // Prevent touch events from triggering any sort of native scrolling 153 // Prevent touch events from triggering any sort of native scrolling
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 264 }
251 265
252 if (!pageNames || stringListIsEmpty(pageNames)) 266 if (!pageNames || stringListIsEmpty(pageNames))
253 pageNames = [localStrings.getString('appDefaultPageName')]; 267 pageNames = [localStrings.getString('appDefaultPageName')];
254 268
255 // Sort by launch index 269 // Sort by launch index
256 apps.sort(function(a, b) { 270 apps.sort(function(a, b) {
257 return a.app_launch_index - b.app_launch_index; 271 return a.app_launch_index - b.app_launch_index;
258 }); 272 });
259 273
274 // An app to animate (in case it was just installed).
275 var highlightApp;
276
260 // Add the apps, creating pages as necessary 277 // Add the apps, creating pages as necessary
261 for (var i = 0; i < apps.length; i++) { 278 for (var i = 0; i < apps.length; i++) {
262 var app = apps[i]; 279 var app = apps[i];
263 var pageIndex = (app.page_index || 0); 280 var pageIndex = (app.page_index || 0);
264 while (pageIndex >= appsPages.length) { 281 while (pageIndex >= appsPages.length) {
265 var pageName = ''; 282 var pageName = '';
266 if (appsPages.length < pageNames.length) 283 if (appsPages.length < pageNames.length)
267 pageName = pageNames[appsPages.length]; 284 pageName = pageNames[appsPages.length];
268 285
269 var origPageCount = appsPages.length; 286 var origPageCount = appsPages.length;
270 appendAppsPage(new ntp4.AppsPage(), pageName); 287 appendAppsPage(new ntp4.AppsPage(), pageName);
271 // Confirm that appsPages is a live object, updated when a new page is 288 // Confirm that appsPages is a live object, updated when a new page is
272 // added (otherwise we'd have an infinite loop) 289 // added (otherwise we'd have an infinite loop)
273 assert(appsPages.length == origPageCount + 1, 'expected new page'); 290 assert(appsPages.length == origPageCount + 1, 'expected new page');
274 } 291 }
275 292
276 appsPages[pageIndex].appendApp(app); 293 if (app.id == highlightAppId) {
294 highlightApp = app;
295 highlightAppId = null;
296 } else {
297 appsPages[pageIndex].appendApp(app);
298 }
277 } 299 }
278 300
279 ntp4.AppsPage.setPromo(data.showPromo ? data : null); 301 ntp4.AppsPage.setPromo(data.showPromo ? data : null);
280 302
281 // Tell the slider about the pages 303 // Tell the slider about the pages
282 updateSliderCards(); 304 updateSliderCards();
283 305
306 if (highlightApp)
307 appAdded(highlightApp);
Rick Byers 2011/08/04 13:21:58 Is there some reason you can't just do this call t
Evan Stade 2011/08/04 16:35:02 All the cards have to be present and correct.
Rick Byers 2011/08/04 16:54:19 Yeah, I think that's good enough. Thanks.
308
284 // Mark the current page 309 // Mark the current page
285 dots[cardSlider.currentCard].classList.add('selected'); 310 dots[cardSlider.currentCard].classList.add('selected');
286 logEvent('apps.layout: ' + (Date.now() - startTime)); 311 logEvent('apps.layout: ' + (Date.now() - startTime));
287 } 312 }
288 313
289 /** 314 /**
290 * Called by chrome when a new app has been added to chrome. 315 * Called by chrome when a new app has been added to chrome.
291 * @param {Object} app A data structure full of relevant information for the 316 * @param {Object} app A data structure full of relevant information for the
292 * app. 317 * app.
293 */ 318 */
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // TODO(estade): update the content handlers to use ntp namespace instead of 706 // TODO(estade): update the content handlers to use ntp namespace instead of
682 // making these global. 707 // making these global.
683 var assert = ntp4.assert; 708 var assert = ntp4.assert;
684 var getAppsCallback = ntp4.getAppsCallback; 709 var getAppsCallback = ntp4.getAppsCallback;
685 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; 710 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback;
686 var themeChanged = ntp4.themeChanged; 711 var themeChanged = ntp4.themeChanged;
687 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; 712 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs;
688 var setMostVisitedPages = ntp4.setMostVisitedPages; 713 var setMostVisitedPages = ntp4.setMostVisitedPages;
689 714
690 document.addEventListener('DOMContentLoaded', ntp4.initialize); 715 document.addEventListener('DOMContentLoaded', ntp4.initialize);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/app_launcher_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698