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

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

Issue 9358073: First version of the time slicing on the urls. Not ready for review yet. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added relative time to time slicing Created 8 years, 9 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
OLDNEW
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 PageListView implementation. 6 * @fileoverview PageListView implementation.
7 * PageListView manages page list, dot list, switcher buttons and handles apps 7 * PageListView manages page list, dot list, switcher buttons and handles apps
8 * pages callbacks from backend. 8 * pages callbacks from backend.
9 * 9 *
10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. 10 * Note that you need to have AppLauncherHandler in your WebUI to use this code.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 */ 52 */
53 tilePages: undefined, 53 tilePages: undefined,
54 54
55 /** 55 /**
56 * A list of all 'apps-page' elements. 56 * A list of all 'apps-page' elements.
57 * @type {!NodeList|undefined} 57 * @type {!NodeList|undefined}
58 */ 58 */
59 appsPages: undefined, 59 appsPages: undefined,
60 60
61 /** 61 /**
62 * The Suggestions page.
63 * @type {!Element|undefined}
64 */
65 suggestionsPage: undefined,
66
67 /**
62 * The Most Visited page. 68 * The Most Visited page.
63 * @type {!Element|undefined} 69 * @type {!Element|undefined}
64 */ 70 */
65 mostVisitedPage: undefined, 71 mostVisitedPage: undefined,
66 72
67 /** 73 /**
68 * The 'dots-list' element. 74 * The 'dots-list' element.
69 * @type {!Element|undefined} 75 * @type {!Element|undefined}
70 */ 76 */
71 dotList: undefined, 77 dotList: undefined,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 * @param {string} title The title of the tile page. 198 * @param {string} title The title of the tile page.
193 * @param {bool} titleIsEditable If true, the title can be changed. 199 * @param {bool} titleIsEditable If true, the title can be changed.
194 * @param {TilePage} opt_refNode Optional reference node to insert in front 200 * @param {TilePage} opt_refNode Optional reference node to insert in front
195 * of. 201 * of.
196 * When opt_refNode is falsey, |page| will just be appended to the end of 202 * When opt_refNode is falsey, |page| will just be appended to the end of
197 * the page list. 203 * the page list.
198 */ 204 */
199 appendTilePage: function(page, title, titleIsEditable, opt_refNode) { 205 appendTilePage: function(page, title, titleIsEditable, opt_refNode) {
200 if (opt_refNode) { 206 if (opt_refNode) {
201 var refIndex = this.getTilePageIndex(opt_refNode); 207 var refIndex = this.getTilePageIndex(opt_refNode);
202 this.cardSlider.insertCardAtIndex(page, refIndex); 208 this.cardSlider.addCardAtIndex(page, refIndex);
203 } else { 209 } else {
204 this.cardSlider.appendCard(page); 210 this.cardSlider.appendCard(page);
205 } 211 }
206 212
207 // Remember special MostVisitedPage. 213 // Remember special MostVisitedPage.
208 if (typeof ntp.MostVisitedPage != 'undefined' && 214 if (typeof ntp.MostVisitedPage != 'undefined' &&
209 page instanceof ntp.MostVisitedPage) { 215 page instanceof ntp.MostVisitedPage) {
210 assert(this.tilePages.length == 1, 216 assert(this.tilePages.length == 1,
211 'MostVisitedPage should be added as first tile page'); 217 'MostVisitedPage should be added as first tile page');
212 this.mostVisitedPage = page; 218 this.mostVisitedPage = page;
213 } 219 }
214 220
221 if (typeof ntp.SuggestionsPage != 'undefined' &&
222 page instanceof ntp.SuggestionsPage) {
223 this.suggestionsPage = page;
224 }
225
215 // If we're appending an AppsPage and it's a temporary page, animate it. 226 // If we're appending an AppsPage and it's a temporary page, animate it.
216 var animate = page instanceof ntp.AppsPage && 227 var animate = page instanceof ntp.AppsPage &&
217 page.classList.contains('temporary'); 228 page.classList.contains('temporary');
218 // Make a deep copy of the dot template to add a new one. 229 // Make a deep copy of the dot template to add a new one.
219 var newDot = new ntp.NavDot(page, title, titleIsEditable, animate); 230 var newDot = new ntp.NavDot(page, title, titleIsEditable, animate);
220 page.navigationDot = newDot; 231 page.navigationDot = newDot;
221 this.dotList.insertBefore(newDot, 232 this.dotList.insertBefore(newDot,
222 opt_refNode ? opt_refNode.navigationDot : null); 233 opt_refNode ? opt_refNode.navigationDot : null);
223 // Set a tab index on the first dot. 234 // Set a tab index on the first dot.
224 if (this.dotList.dots.length == 1) 235 if (this.dotList.dots.length == 1)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 323
313 // Sort by launch ordinal 324 // Sort by launch ordinal
314 apps.sort(function(a, b) { 325 apps.sort(function(a, b) {
315 return a.app_launch_ordinal > b.app_launch_ordinal ? 1 : 326 return a.app_launch_ordinal > b.app_launch_ordinal ? 1 :
316 a.app_launch_ordinal < b.app_launch_ordinal ? -1 : 0; 327 a.app_launch_ordinal < b.app_launch_ordinal ? -1 : 0;
317 }); 328 });
318 329
319 // An app to animate (in case it was just installed). 330 // An app to animate (in case it was just installed).
320 var highlightApp; 331 var highlightApp;
321 332
333 // If there are any pages after the apps, add new pages before them.
334 var lastAppsPage = (this.appsPages.length > 0) ?
335 this.appsPages[this.appsPages.length - 1] : null;
336 var lastAppsPageIndex = (lastAppsPage != null) ?
337 Array.prototype.indexOf.call(this.tilePages, lastAppsPage) : -1;
338 var nextPageAfterApps = lastAppsPageIndex != -1 ?
339 this.tilePages[lastAppsPageIndex + 1] : null;
340
322 // Add the apps, creating pages as necessary 341 // Add the apps, creating pages as necessary
323 for (var i = 0; i < apps.length; i++) { 342 for (var i = 0; i < apps.length; i++) {
324 var app = apps[i]; 343 var app = apps[i];
325 var pageIndex = app.page_index || 0; 344 var pageIndex = app.page_index || 0;
326 while (pageIndex >= this.appsPages.length) { 345 while (pageIndex >= this.appsPages.length) {
327 var pageName = localStrings.getString('appDefaultPageName'); 346 var pageName = localStrings.getString('appDefaultPageName');
328 if (this.appsPages.length < pageNames.length) 347 if (this.appsPages.length < pageNames.length)
329 pageName = pageNames[this.appsPages.length]; 348 pageName = pageNames[this.appsPages.length];
330 349
331 var origPageCount = this.appsPages.length; 350 var origPageCount = this.appsPages.length;
332 this.appendTilePage(new ntp.AppsPage(), pageName, true); 351 this.appendTilePage(new ntp.AppsPage(), pageName, true,
352 nextPageAfterApps);
333 // Confirm that appsPages is a live object, updated when a new page is 353 // Confirm that appsPages is a live object, updated when a new page is
334 // added (otherwise we'd have an infinite loop) 354 // added (otherwise we'd have an infinite loop)
335 assert(this.appsPages.length == origPageCount + 1, 355 assert(this.appsPages.length == origPageCount + 1,
336 'expected new page'); 356 'expected new page');
337 } 357 }
338 358
339 if (app.id == this.highlightAppId) 359 if (app.id == this.highlightAppId)
340 highlightApp = app; 360 highlightApp = app;
341 else 361 else
342 this.appsPages[pageIndex].appendApp(app, false); 362 this.appsPages[pageIndex].appendApp(app, false);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 switch (this.shownPage) { 442 switch (this.shownPage) {
423 case templateData['apps_page_id']: 443 case templateData['apps_page_id']:
424 this.cardSlider.selectCardByValue( 444 this.cardSlider.selectCardByValue(
425 this.appsPages[Math.min(this.shownPageIndex, 445 this.appsPages[Math.min(this.shownPageIndex,
426 this.appsPages.length - 1)]); 446 this.appsPages.length - 1)]);
427 break; 447 break;
428 case templateData['most_visited_page_id']: 448 case templateData['most_visited_page_id']:
429 if (this.mostVisitedPage) 449 if (this.mostVisitedPage)
430 this.cardSlider.selectCardByValue(this.mostVisitedPage); 450 this.cardSlider.selectCardByValue(this.mostVisitedPage);
431 break; 451 break;
452 case templateData['suggestions_page_id']:
453 if (this.suggestionsPage)
454 this.cardSlider.selectCardByValue(this.suggestionsPage);
455 break;
432 } 456 }
433 }, 457 },
434 458
435 /** 459 /**
436 * Called whenever tiles should be re-arranging themselves out of the way 460 * Called whenever tiles should be re-arranging themselves out of the way
437 * of a moving or insert tile. 461 * of a moving or insert tile.
438 */ 462 */
439 enterRearrangeMode: function() { 463 enterRearrangeMode: function() {
440 var tempPage = new ntp.AppsPage(); 464 var tempPage = new ntp.AppsPage();
441 tempPage.classList.add('temporary'); 465 tempPage.classList.add('temporary');
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 560
537 // Don't change shownPage until startup is done (and page changes actually 561 // Don't change shownPage until startup is done (and page changes actually
538 // reflect user actions). 562 // reflect user actions).
539 if (!this.isStartingUp_()) { 563 if (!this.isStartingUp_()) {
540 if (page.classList.contains('apps-page')) { 564 if (page.classList.contains('apps-page')) {
541 this.shownPage = templateData.apps_page_id; 565 this.shownPage = templateData.apps_page_id;
542 this.shownPageIndex = this.getAppsPageIndex(page); 566 this.shownPageIndex = this.getAppsPageIndex(page);
543 } else if (page.classList.contains('most-visited-page')) { 567 } else if (page.classList.contains('most-visited-page')) {
544 this.shownPage = templateData.most_visited_page_id; 568 this.shownPage = templateData.most_visited_page_id;
545 this.shownPageIndex = 0; 569 this.shownPageIndex = 0;
570 } else if (page.classList.contains('suggestions-page')) {
571 this.shownPage = templateData.suggestions_page_id;
572 this.shownPageIndex = 0;
546 } else { 573 } else {
547 console.error('unknown page selected'); 574 console.error('unknown page selected');
548 } 575 }
549 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); 576 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]);
550 } 577 }
551 578
552 // Update the active dot 579 // Update the active dot
553 var curDot = this.dotList.getElementsByClassName('selected')[0]; 580 var curDot = this.dotList.getElementsByClassName('selected')[0];
554 if (curDot) 581 if (curDot)
555 curDot.classList.remove('selected'); 582 curDot.classList.remove('selected');
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 if (page.navigationDot) 689 if (page.navigationDot)
663 page.navigationDot.remove(opt_animate); 690 page.navigationDot.remove(opt_animate);
664 this.cardSlider.removeCard(page); 691 this.cardSlider.removeCard(page);
665 }, 692 },
666 }; 693 };
667 694
668 return { 695 return {
669 PageListView: PageListView 696 PageListView: PageListView
670 }; 697 };
671 }); 698 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.js ('k') | chrome/browser/resources/ntp4/suggestions_page.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698