Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
|
Dan Beam
2012/11/29 04:59:55
nit: hanging "," IMO
pedro (no code reviews)
2012/11/29 08:02:37
Done.
| |
| 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 this.content_.scrollTop = this.content_.scrollHeight; |
| 609 this.insertApp(appData, true); | 611 this.insertApp(appData, true); |
| 610 }, | 612 }, |
| 611 | 613 |
| 612 /** | 614 /** |
| 613 * Similar to appendApp, but it respects the app_launch_ordinal field of | 615 * Similar to appendApp, but it respects the app_launch_ordinal field of |
|
Dan Beam
2012/11/29 04:59:55
I don't even see where appendApp exists any more..
pedro (no code reviews)
2012/11/29 08:02:37
Correct.
| |
| 614 * |appData|. | 616 * |appData|. |
|
Evan Stade
2012/11/29 02:35:47
is this still true?
pedro (no code reviews)
2012/11/29 08:02:37
Comment has been updated.
| |
| 615 * @param {Object} appData The data that describes the app. | 617 * @param {Object} appData The data that describes the app. |
| 616 * @param {boolean} animate Whether to animate the insertion. | 618 * @param {boolean} animate Whether to animate the insertion. |
| 617 */ | 619 */ |
| 618 insertApp: function(appData, animate) { | 620 insertApp: function(appData, animate) { |
| 619 var index = this.tiles_.length; | 621 this.appendTile(new App(appData)); |
| 620 for (var i = 0; i < this.tiles_.length; i++) { | |
| 621 if (appData.app_launch_ordinal < | |
| 622 this.tiles_[i].appData.app_launch_ordinal) { | |
| 623 index = i; | |
| 624 break; | |
| 625 } | |
| 626 } | |
| 627 | |
| 628 this.addTileAt(new App(appData), index); | |
| 629 this.renderGrid_(); | 622 this.renderGrid_(); |
| 630 }, | 623 }, |
| 631 | 624 |
| 632 /** | 625 /** |
| 633 * Handler for 'cardselected' event, fired when |this| is selected. The | 626 * Handler for 'cardselected' event, fired when |this| is selected. The |
| 634 * first time this is called, we load all the app icons. | 627 * first time this is called, we load all the app icons. |
| 635 * @private | 628 * @private |
| 636 */ | 629 */ |
| 637 onCardSelected_: function(e) { | 630 onCardSelected_: function(e) { |
| 638 var apps = this.querySelectorAll('.app.icon-loading'); | 631 var apps = this.querySelectorAll('.app.icon-loading'); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 }, | 678 }, |
| 686 | 679 |
| 687 /** | 680 /** |
| 688 * A handler for when the apps page is scrolled (then we need to reposition | 681 * A handler for when the apps page is scrolled (then we need to reposition |
| 689 * the bubbles. | 682 * the bubbles. |
| 690 * @private | 683 * @private |
| 691 */ | 684 */ |
| 692 onScroll_: function(e) { | 685 onScroll_: function(e) { |
| 693 if (!this.selected) | 686 if (!this.selected) |
| 694 return; | 687 return; |
| 688 | |
| 689 TilePage.prototype.onScroll_.apply(this, arguments); | |
|
Dan Beam
2012/11/29 04:59:55
nit: I'd put super calls before if () returns; if
pedro (no code reviews)
2012/11/29 08:02:37
Done. I've also removed the selection check once t
| |
| 695 for (var i = 0; i < this.tiles_.length; i++) { | 690 for (var i = 0; i < this.tiles_.length; i++) { |
| 696 var app = this.tiles_[i]; | 691 var app = this.tiles_[i]; |
| 697 assert(app instanceof App); | 692 assert(app instanceof App); |
| 698 if (app.currentBubbleShowing_) | 693 if (app.currentBubbleShowing_) |
| 699 app.currentBubbleShowing_.resizeAndReposition(); | 694 app.currentBubbleShowing_.resizeAndReposition(); |
| 700 } | 695 } |
| 701 }, | 696 }, |
| 702 | 697 |
| 703 /** @override */ | 698 /** @override */ |
| 704 doDragOver: function(e) { | 699 doDragOver: function(e) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 if (app && !app.appData.notifications_disabled) | 835 if (app && !app.appData.notifications_disabled) |
| 841 app.setupNotification_(notification); | 836 app.setupNotification_(notification); |
| 842 } | 837 } |
| 843 | 838 |
| 844 return { | 839 return { |
| 845 appNotificationChanged: appNotificationChanged, | 840 appNotificationChanged: appNotificationChanged, |
| 846 AppsPage: AppsPage, | 841 AppsPage: AppsPage, |
| 847 launchAppAfterEnable: launchAppAfterEnable, | 842 launchAppAfterEnable: launchAppAfterEnable, |
| 848 }; | 843 }; |
| 849 }); | 844 }); |
| OLD | NEW |