OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 /** | 72 /** |
73 * The time in milliseconds for most transitions. This should match what's | 73 * The time in milliseconds for most transitions. This should match what's |
74 * in new_tab.css. Unfortunately there's no better way to try to time | 74 * in new_tab.css. Unfortunately there's no better way to try to time |
75 * something to occur until after a transition has completed. | 75 * something to occur until after a transition has completed. |
76 * @type {number} | 76 * @type {number} |
77 * @const | 77 * @const |
78 */ | 78 */ |
79 var DEFAULT_TRANSITION_TIME = 500; | 79 var DEFAULT_TRANSITION_TIME = 500; |
80 | 80 |
81 /** | 81 /** |
82 * All the Grabber objects currently in use on the page | |
83 * @type {Array.<Grabber>} | |
84 */ | |
85 var grabbers = []; | |
86 | |
87 /** | |
88 * Invoked at startup once the DOM is available to initialize the app. | 82 * Invoked at startup once the DOM is available to initialize the app. |
89 */ | 83 */ |
90 function initialize() { | 84 function initialize() { |
91 // Load the current theme colors. | 85 // Load the current theme colors. |
92 themeChanged(); | 86 themeChanged(); |
93 | 87 |
94 dotList = getRequiredElement('dot-list'); | 88 dotList = getRequiredElement('dot-list'); |
95 pageList = getRequiredElement('page-list'); | 89 pageList = getRequiredElement('page-list'); |
96 trash = getRequiredElement('trash'); | 90 trash = getRequiredElement('trash'); |
97 trash.hidden = true; | 91 trash.hidden = true; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 /** | 204 /** |
211 * Callback invoked by chrome with the apps available. | 205 * Callback invoked by chrome with the apps available. |
212 * | 206 * |
213 * Note that calls to this function can occur at any time, not just in | 207 * Note that calls to this function can occur at any time, not just in |
214 * response to a getApps request. For example, when a user installs/uninstalls | 208 * response to a getApps request. For example, when a user installs/uninstalls |
215 * an app on another synchronized devices. | 209 * an app on another synchronized devices. |
216 * @param {Object} data An object with all the data on available | 210 * @param {Object} data An object with all the data on available |
217 * applications. | 211 * applications. |
218 */ | 212 */ |
219 function getAppsCallback(data) { | 213 function getAppsCallback(data) { |
220 // Clean up any existing grabber objects - cancelling any outstanding drag. | |
221 // Ideally an async app update wouldn't disrupt an active drag but | |
222 // that would require us to re-use existing elements and detect how the apps | |
223 // have changed, which would be a lot of work. | |
224 // Note that we have to explicitly clean up the grabber objects so they stop | |
225 // listening to events and break the DOM<->JS cycles necessary to enable | |
226 // collection of all these objects. | |
227 grabbers.forEach(function(g) { | |
228 // Note that this may raise DRAG_END/RELEASE events to clean up an | |
229 // oustanding drag. | |
230 g.dispose(); | |
231 }); | |
232 assert(!draggingAppContainer && !draggingAppOriginalPosition && | |
233 !draggingAppOriginalPage); | |
234 grabbers = []; | |
235 | |
236 // Clear any existing apps pages and dots. | 214 // Clear any existing apps pages and dots. |
237 // TODO(rbyers): It might be nice to preserve animation of dots after an | 215 // TODO(rbyers): It might be nice to preserve animation of dots after an |
238 // uninstall. Could we re-use the existing page and dot elements? It seems | 216 // uninstall. Could we re-use the existing page and dot elements? It seems |
239 // unfortunate to have Chrome send us the entire apps list after an | 217 // unfortunate to have Chrome send us the entire apps list after an |
240 // uninstall. | 218 // uninstall. |
241 for (var i = 0; i < appsPages.length; i++) { | 219 while (appsPages.length > 0) { |
242 var page = appsPages[i]; | 220 var page = appsPages[0]; |
243 var dot = page.navigationDot; | 221 var dot = page.navigationDot; |
244 | 222 |
245 page.tearDown(); | 223 page.tearDown(); |
246 page.parentNode.removeChild(page); | 224 page.parentNode.removeChild(page); |
247 dot.parentNode.removeChild(dot); | 225 dot.parentNode.removeChild(dot); |
248 } | 226 } |
249 | 227 |
250 // Get the array of apps and add any special synthesized entries | 228 // Get the array of apps and add any special synthesized entries |
251 var apps = data.apps; | 229 var apps = data.apps; |
252 | 230 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 * Appends a tile page (for apps or most visited). | 315 * Appends a tile page (for apps or most visited). |
338 * | 316 * |
339 * @param {TilePage} page The page element. | 317 * @param {TilePage} page The page element. |
340 * @param {boolean=} opt_animate If true, add the class 'new' to the created | 318 * @param {boolean=} opt_animate If true, add the class 'new' to the created |
341 * dot. | 319 * dot. |
342 */ | 320 */ |
343 function appendTilePage(page, opt_animate) { | 321 function appendTilePage(page, opt_animate) { |
344 pageList.appendChild(page); | 322 pageList.appendChild(page); |
345 | 323 |
346 // Make a deep copy of the dot template to add a new one. | 324 // Make a deep copy of the dot template to add a new one. |
347 var dotCount = dots.length; | |
348 var newDot = dotTemplate.cloneNode(true); | 325 var newDot = dotTemplate.cloneNode(true); |
349 newDot.querySelector('span').textContent = page.pageName; | 326 newDot.querySelector('span').textContent = page.pageName; |
350 if (opt_animate) | 327 if (opt_animate) |
351 newDot.classList.add('new'); | 328 newDot.classList.add('new'); |
352 dotList.appendChild(newDot); | 329 dotList.appendChild(newDot); |
353 page.navigationDot = newDot; | 330 page.navigationDot = newDot; |
354 | 331 |
355 newDot.showPage = function() { | 332 newDot.showPage = function() { |
356 cardSlider.selectCard(dotCount, true); | 333 cardSlider.selectCardByValue(page, true); |
357 }; | 334 }; |
358 function switchPage(e) { | 335 function switchPage(e) { |
359 newDot.showPage(); | 336 newDot.showPage(); |
360 e.stopPropagation(); | 337 e.stopPropagation(); |
361 } | 338 } |
362 // Add click handler to the dot to change the page. | 339 // Add click handler to the dot to change the page. |
363 // TODO(rbyers): Perhaps this should be TouchHandler.START_EVENT_ (so we | 340 // TODO(rbyers): Perhaps this should be TouchHandler.START_EVENT_ (so we |
364 // don't rely on synthesized click events, and the change takes effect | 341 // don't rely on synthesized click events, and the change takes effect |
365 // before releasing). However, click events seems to be synthesized for a | 342 // before releasing). However, click events seems to be synthesized for a |
366 // region outside the border, and a 10px box is too small to require touch | 343 // region outside the border, and a 10px box is too small to require touch |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 // TODO(estade): update the content handlers to use ntp namespace instead of | 711 // TODO(estade): update the content handlers to use ntp namespace instead of |
735 // making these global. | 712 // making these global. |
736 var assert = ntp4.assert; | 713 var assert = ntp4.assert; |
737 var getAppsCallback = ntp4.getAppsCallback; | 714 var getAppsCallback = ntp4.getAppsCallback; |
738 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 715 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
739 var themeChanged = ntp4.themeChanged; | 716 var themeChanged = ntp4.themeChanged; |
740 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 717 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
741 var setMostVisitedPages = ntp4.setMostVisitedPages; | 718 var setMostVisitedPages = ntp4.setMostVisitedPages; |
742 | 719 |
743 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 720 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
OLD | NEW |