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

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

Issue 12985002: Add a new App launcher promo to the apps page / NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OWNERS review round 4. Created 7 years, 8 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 this.updateOfflineEnabledApps_.bind(this)); 211 this.updateOfflineEnabledApps_.bind(this));
212 window.addEventListener('offline', 212 window.addEventListener('offline',
213 this.updateOfflineEnabledApps_.bind(this)); 213 this.updateOfflineEnabledApps_.bind(this));
214 }, 214 },
215 215
216 /** 216 /**
217 * Appends a tile page. 217 * Appends a tile page.
218 * 218 *
219 * @param {TilePage} page The page element. 219 * @param {TilePage} page The page element.
220 * @param {string} title The title of the tile page. 220 * @param {string} title The title of the tile page.
221 * @param {bool} titleIsEditable If true, the title can be changed. 221 * @param {boolean} titleIsEditable If true, the title can be changed.
222 * @param {TilePage} opt_refNode Optional reference node to insert in front 222 * @param {TilePage} opt_refNode Optional reference node to insert in front
223 * of. 223 * of.
224 * When opt_refNode is falsey, |page| will just be appended to the end of 224 * When opt_refNode is falsey, |page| will just be appended to the end of
225 * the page list. 225 * the page list.
226 */ 226 */
227 appendTilePage: function(page, title, titleIsEditable, opt_refNode) { 227 appendTilePage: function(page, title, titleIsEditable, opt_refNode) {
228 if (opt_refNode) { 228 if (opt_refNode) {
229 var refIndex = this.getTilePageIndex(opt_refNode); 229 var refIndex = this.getTilePageIndex(opt_refNode);
230 this.cardSlider.addCardAtIndex(page, refIndex); 230 this.cardSlider.addCardAtIndex(page, refIndex);
231 } else { 231 } else {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 logEvent('apps.layout: ' + (Date.now() - startTime)); 405 logEvent('apps.layout: ' + (Date.now() - startTime));
406 406
407 // Tell the slider about the pages and mark the current page. 407 // Tell the slider about the pages and mark the current page.
408 this.updateSliderCards(); 408 this.updateSliderCards();
409 this.cardSlider.currentCardValue.navigationDot.classList.add('selected'); 409 this.cardSlider.currentCardValue.navigationDot.classList.add('selected');
410 410
411 if (!this.appsLoaded_) { 411 if (!this.appsLoaded_) {
412 this.appsLoaded_ = true; 412 this.appsLoaded_ = true;
413 cr.dispatchSimpleEvent(document, 'sectionready', true, true); 413 cr.dispatchSimpleEvent(document, 'sectionready', true, true);
414 } 414 }
415 this.updateAppLauncherPromoHiddenState_();
415 }, 416 },
416 417
417 /** 418 /**
418 * Called by chrome when a new app has been added to chrome or has been 419 * Called by chrome when a new app has been added to chrome or has been
419 * enabled if previously disabled. 420 * enabled if previously disabled.
420 * @param {Object} appData A data structure full of relevant information for 421 * @param {Object} appData A data structure full of relevant information for
421 * the app. 422 * the app.
422 * @param {boolean=} opt_highlight Whether the app about to be added should 423 * @param {boolean=} opt_highlight Whether the app about to be added should
423 * be highlighted. 424 * be highlighted.
424 */ 425 */
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 469
469 // Set the App dot names. Skip the first dot (Most Visited). 470 // Set the App dot names. Skip the first dot (Most Visited).
470 var dots = this.dotList.getElementsByClassName('dot'); 471 var dots = this.dotList.getElementsByClassName('dot');
471 var start = this.mostVisitedPage ? 1 : 0; 472 var start = this.mostVisitedPage ? 1 : 0;
472 for (var i = start; i < dots.length; ++i) { 473 for (var i = start; i < dots.length; ++i) {
473 dots[i].displayTitle = data.appPageNames[i - start] || ''; 474 dots[i].displayTitle = data.appPageNames[i - start] || '';
474 } 475 }
475 }, 476 },
476 477
477 /** 478 /**
479 * Callback invoked by chrome whenever the app launcher promo pref changes.
480 * @param {boolean} show Identifies if we should show or hide the promo.
481 */
482 appLauncherPromoPrefChangeCallback: function(show) {
483 loadTimeData.overrideValues({showAppLauncherPromo: show});
484 this.updateAppLauncherPromoHiddenState_();
485 },
486
487 /**
488 * Updates the hidden state of the app launcher promo based on the page
489 * shown and load data content.
490 */
491 updateAppLauncherPromoHiddenState_: function() {
492 $('app-launcher-promo').hidden =
493 !loadTimeData.getBoolean('showAppLauncherPromo') ||
494 this.shownPage != loadTimeData.getInteger('apps_page_id');
495 },
496
497 /**
478 * Invoked whenever the pages in apps-page-list have changed so that 498 * Invoked whenever the pages in apps-page-list have changed so that
479 * the Slider knows about the new elements. 499 * the Slider knows about the new elements.
480 */ 500 */
481 updateSliderCards: function() { 501 updateSliderCards: function() {
482 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, 502 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard,
483 this.tilePages.length - 1)); 503 this.tilePages.length - 1));
484 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), 504 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages),
485 pageNo); 505 pageNo);
486 switch (this.shownPage) { 506 // The shownPage property was potentially saved from a previous webui that
487 case loadTimeData.getInteger('apps_page_id'): 507 // didn't have the same set of pages as the current one. So we cascade
488 this.cardSlider.selectCardByValue( 508 // from suggestions, to most visited and then to apps because we can have
489 this.appsPages[Math.min(this.shownPageIndex, 509 // an page with apps only (e.g., chrome://apps) or one with only the most
490 this.appsPages.length - 1)]); 510 // visited, but not one with only suggestions. And we alwayd default to
491 break; 511 // most visited first when previously shown page is not availabel anymore.
492 case loadTimeData.getInteger('most_visited_page_id'): 512 // If most visited isn't there either, we go to apps.
493 if (this.mostVisitedPage) 513 if (this.shownPage == loadTimeData.getInteger('suggestions_page_id')) {
494 this.cardSlider.selectCardByValue(this.mostVisitedPage); 514 if (this.suggestionsPage)
495 break; 515 this.cardSlider.selectCardByValue(this.suggestionsPage);
496 case loadTimeData.getInteger('suggestions_page_id'): 516 else
497 if (this.suggestionsPage) 517 this.shownPage = loadTimeData.getInteger('most_visited_page_id');
498 this.cardSlider.selectCardByValue(this.suggestionsPage); 518 }
499 break; 519 if (this.shownPage == loadTimeData.getInteger('most_visited_page_id')) {
520 if (this.mostVisitedPage)
521 this.cardSlider.selectCardByValue(this.mostVisitedPage);
522 else
523 this.shownPage = loadTimeData.getInteger('apps_page_id');
524 }
525 if (this.shownPage == loadTimeData.getInteger('apps_page_id') &&
526 loadTimeData.getBoolean('showApps')) {
527 this.cardSlider.selectCardByValue(
528 this.appsPages[Math.min(this.shownPageIndex,
529 this.appsPages.length - 1)]);
530 } else if (this.mostVisitedPage) {
531 this.shownPage = loadTimeData.getInteger('most_visited_page_id');
532 this.cardSlider.selectCardByValue(this.mostVisitedPage);
500 } 533 }
501 }, 534 },
502 535
503 /** 536 /**
504 * Called whenever tiles should be re-arranging themselves out of the way 537 * Called whenever tiles should be re-arranging themselves out of the way
505 * of a moving or insert tile. 538 * of a moving or insert tile.
506 */ 539 */
507 enterRearrangeMode: function() { 540 enterRearrangeMode: function() {
508 if (loadTimeData.getBoolean('showApps')) { 541 if (loadTimeData.getBoolean('showApps')) {
509 var tempPage = new ntp.AppsPage(); 542 var tempPage = new ntp.AppsPage();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 * Saves/updates the newly selected page to open when first loading the NTP. 677 * Saves/updates the newly selected page to open when first loading the NTP.
645 * @type {number} shownPage The new shown page type. 678 * @type {number} shownPage The new shown page type.
646 * @type {number} shownPageIndex The new shown page index. 679 * @type {number} shownPageIndex The new shown page index.
647 * @private 680 * @private
648 */ 681 */
649 setShownPage_: function(shownPage, shownPageIndex) { 682 setShownPage_: function(shownPage, shownPageIndex) {
650 assert(shownPageIndex >= 0); 683 assert(shownPageIndex >= 0);
651 this.shownPage = shownPage; 684 this.shownPage = shownPage;
652 this.shownPageIndex = shownPageIndex; 685 this.shownPageIndex = shownPageIndex;
653 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); 686 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]);
687 this.updateAppLauncherPromoHiddenState_();
654 }, 688 },
655 689
656 /** 690 /**
657 * Listen for card additions to update the page switchers or the current 691 * Listen for card additions to update the page switchers or the current
658 * card accordingly. 692 * card accordingly.
659 * @param {Event} e A card removed or added event. 693 * @param {Event} e A card removed or added event.
660 */ 694 */
661 onCardAdded_: function(e) { 695 onCardAdded_: function(e) {
662 // When the second arg passed to insertBefore is falsey, it acts just like 696 // When the second arg passed to insertBefore is falsey, it acts just like
663 // appendChild. 697 // appendChild.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 if (page.navigationDot) 803 if (page.navigationDot)
770 page.navigationDot.remove(opt_animate); 804 page.navigationDot.remove(opt_animate);
771 this.cardSlider.removeCard(page); 805 this.cardSlider.removeCard(page);
772 }, 806 },
773 }; 807 };
774 808
775 return { 809 return {
776 PageListView: PageListView 810 PageListView: PageListView
777 }; 811 };
778 }); 812 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.js ('k') | chrome/browser/ui/webui/ntp/app_launcher_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698