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

Side by Side Diff: chrome/browser/resources/ntp_search/apps_page.js

Issue 11412214: NTP5: Fine tuning of Apps implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Dan's comments Created 8 years 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 cr.define('ntp', function() { 5 cr.define('ntp', function() {
6 'use strict'; 6 'use strict';
7 7
8 var Tile = ntp.Tile; 8 var Tile = ntp.Tile;
9 var TilePage = ntp.TilePage; 9 var TilePage = ntp.TilePage;
10 var APP_LAUNCH = ntp.APP_LAUNCH; 10 var APP_LAUNCH = ntp.APP_LAUNCH;
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 * Reference to the Tile subclass that will be used to create the tiles. 569 * Reference to the Tile subclass that will be used to create the tiles.
570 * @constructor 570 * @constructor
571 * @extends {Tile} 571 * @extends {Tile}
572 */ 572 */
573 TileClass: App, 573 TileClass: App,
574 574
575 // The config object should be defined by a TilePage subclass if it 575 // The config object should be defined by a TilePage subclass if it
576 // wants the non-default behavior. 576 // wants the non-default behavior.
577 config: { 577 config: {
578 // The width of a cell. 578 // The width of a cell.
579 cellWidth: 77, 579 cellWidth: 70,
580 // The start margin of a cell (left or right according to text direction). 580 // The start margin of a cell (left or right according to text direction).
581 cellMarginStart: 12, 581 cellMarginStart: 12,
582 // The maximum number of Tiles to be displayed. 582 // The maximum number of Tiles to be displayed.
583 maxTileCount: 20 583 maxTileCount: 20,
584 // Whether the TilePage content will be scrollable.
585 scrollable: true,
584 }, 586 },
585 587
586 initialize: function() { 588 initialize: function() {
589 TilePage.prototype.initialize.apply(this, arguments);
590
587 this.classList.add('apps-page'); 591 this.classList.add('apps-page');
588 592
589 this.addEventListener('cardselected', this.onCardSelected_); 593 this.addEventListener('cardselected', this.onCardSelected_);
590 // Add event listeners for two events, so we can temporarily suppress 594 // Add event listeners for two events, so we can temporarily suppress
591 // the app notification bubbles when the app card slides in and out of 595 // the app notification bubbles when the app card slides in and out of
592 // view. 596 // view.
593 this.addEventListener('carddeselected', this.onCardDeselected_); 597 this.addEventListener('carddeselected', this.onCardDeselected_);
594 this.addEventListener('cardSlider:card_change_ended', 598 this.addEventListener('cardSlider:card_change_ended',
595 this.onCardChangeEnded_); 599 this.onCardChangeEnded_);
596 600
597 this.addEventListener('tilePage:tile_added', this.onTileAdded_); 601 this.addEventListener('tilePage:tile_added', this.onTileAdded_);
598
599 this.content_.addEventListener('scroll', this.onScroll_.bind(this));
600 }, 602 },
601 603
602 /** 604 /**
603 * Highlight a newly installed app as it's added to the NTP. 605 * Highlight a newly installed app as it's added to the NTP.
604 * @param {Object} appData The data object that describes the app. 606 * @param {Object} appData The data object that describes the app.
605 */ 607 */
606 insertAndHighlightApp: function(appData) { 608 insertAndHighlightApp: function(appData) {
607 ntp.getCardSlider().selectCardByValue(this); 609 ntp.getCardSlider().selectCardByValue(this);
608 this.content_.scrollTop = this.content_.scrollHeight; 610 var app = this.insertApp(appData, true);
609 this.insertApp(appData, true); 611 this.content_.scrollTop = app.tileCell.offsetTop;
610 }, 612 },
611 613
612 /** 614 /**
613 * Similar to appendApp, but it respects the app_launch_ordinal field of 615 * Inserts an App into the TilePage, preserving the alphabetical order.
614 * |appData|.
615 * @param {Object} appData The data that describes the app. 616 * @param {Object} appData The data that describes the app.
616 * @param {boolean} animate Whether to animate the insertion. 617 * @param {boolean} animate Whether to animate the insertion.
Evan Stade 2012/12/03 18:41:46 @return
pedro (no code reviews) 2012/12/03 19:55:15 The added App was being returned to we can scroll
617 */ 618 */
618 insertApp: function(appData, animate) { 619 insertApp: function(appData, animate) {
619 var index = this.tiles_.length; 620 var index = this.tiles_.length;
620 for (var i = 0; i < this.tiles_.length; i++) { 621 for (var i = 0; i < this.tiles_.length; i++) {
621 if (appData.app_launch_ordinal < 622 if (appData.title.toLocaleLowerCase() <
622 this.tiles_[i].appData.app_launch_ordinal) { 623 this.tiles_[i].appData.title.toLocaleLowerCase()) {
623 index = i; 624 index = i;
624 break; 625 break;
625 } 626 }
626 } 627 }
627 628
628 this.addTileAt(new App(appData), index); 629 var app = new App(appData);
630 this.addTileAt(app, index);
629 this.renderGrid_(); 631 this.renderGrid_();
632
633 return app;
630 }, 634 },
631 635
632 /** 636 /**
633 * Handler for 'cardselected' event, fired when |this| is selected. The 637 * Handler for 'cardselected' event, fired when |this| is selected. The
634 * first time this is called, we load all the app icons. 638 * first time this is called, we load all the app icons.
635 * @private 639 * @private
636 */ 640 */
637 onCardSelected_: function(e) { 641 onCardSelected_: function(e) {
638 var apps = this.querySelectorAll('.app.icon-loading'); 642 var apps = this.querySelectorAll('.app.icon-loading');
639 for (var i = 0; i < apps.length; i++) { 643 for (var i = 0; i < apps.length; i++) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 */ 681 */
678 onCardDeselected_: function(e) { 682 onCardDeselected_: function(e) {
679 for (var i = 0; i < this.tiles_.length; i++) { 683 for (var i = 0; i < this.tiles_.length; i++) {
680 var app = this.tiles_[i]; 684 var app = this.tiles_[i];
681 assert(app instanceof App); 685 assert(app instanceof App);
682 if (app.currentBubbleShowing_) 686 if (app.currentBubbleShowing_)
683 app.currentBubbleShowing_.suppressed = true; 687 app.currentBubbleShowing_.suppressed = true;
684 } 688 }
685 }, 689 },
686 690
687 /** 691 /** @override */
688 * A handler for when the apps page is scrolled (then we need to reposition 692 onScroll: function() {
689 * the bubbles. 693 TilePage.prototype.onScroll.apply(this, arguments);
690 * @private 694
691 */
692 onScroll_: function(e) {
693 if (!this.selected)
694 return;
695 for (var i = 0; i < this.tiles_.length; i++) { 695 for (var i = 0; i < this.tiles_.length; i++) {
696 var app = this.tiles_[i]; 696 var app = this.tiles_[i];
697 assert(app instanceof App); 697 assert(app instanceof App);
698 if (app.currentBubbleShowing_) 698 if (app.currentBubbleShowing_)
699 app.currentBubbleShowing_.resizeAndReposition(); 699 app.currentBubbleShowing_.resizeAndReposition();
700 } 700 }
701 }, 701 },
702 702
703 /** @override */ 703 /** @override */
704 doDragOver: function(e) { 704 doDragOver: function(e) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 if (app && !app.appData.notifications_disabled) 840 if (app && !app.appData.notifications_disabled)
841 app.setupNotification_(notification); 841 app.setupNotification_(notification);
842 } 842 }
843 843
844 return { 844 return {
845 appNotificationChanged: appNotificationChanged, 845 appNotificationChanged: appNotificationChanged,
846 AppsPage: AppsPage, 846 AppsPage: AppsPage,
847 launchAppAfterEnable: launchAppAfterEnable, 847 launchAppAfterEnable: launchAppAfterEnable,
848 }; 848 };
849 }); 849 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp_search/apps_page.css ('k') | chrome/browser/resources/ntp_search/mock/debug.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698