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('ntp4', function() { | 5 cr.define('ntp4', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var localStrings = new LocalStrings; | 8 var localStrings = new LocalStrings; |
9 | 9 |
10 var APP_LAUNCH = { | 10 var APP_LAUNCH = { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 268 |
269 /** | 269 /** |
270 * Sets the color of the favicon dominant color bar. | 270 * Sets the color of the favicon dominant color bar. |
271 * @param {string} color The css-parsable value for the color. | 271 * @param {string} color The css-parsable value for the color. |
272 */ | 272 */ |
273 set stripeColor(color) { | 273 set stripeColor(color) { |
274 this.querySelector('.color-stripe').style.backgroundColor = color; | 274 this.querySelector('.color-stripe').style.backgroundColor = color; |
275 }, | 275 }, |
276 | 276 |
277 /** | 277 /** |
278 * Removes the app tile from the page. Should be called after the app has | |
279 * been uninstalled. | |
280 */ | |
281 remove: function() { | |
282 // Unset the ID immediately, because the app is already gone. But leave | |
283 // the tile on the page as it animates out. | |
284 this.id = ''; | |
285 this.tile.doRemove(); | |
286 }, | |
287 | |
288 /** | |
289 * Set the URL of the icon from |appData_|. This won't actually show the | 278 * Set the URL of the icon from |appData_|. This won't actually show the |
290 * icon until loadIcon() is called (for performance reasons; we don't want | 279 * icon until loadIcon() is called (for performance reasons; we don't want |
291 * to load icons until we have to). | 280 * to load icons until we have to). |
292 */ | 281 */ |
293 setIcon: function() { | 282 setIcon: function() { |
294 var src = this.useSmallIcon_ ? this.appData_.icon_small : | 283 var src = this.useSmallIcon_ ? this.appData_.icon_small : |
295 this.appData_.icon_big; | 284 this.appData_.icon_big; |
296 if (!this.appData_.enabled || | 285 if (!this.appData_.enabled || |
297 (!this.appData_.offline_enabled && !navigator.onLine)) { | 286 (!this.appData_.offline_enabled && !navigator.onLine)) { |
298 src += '?grayscale=true'; | 287 src += '?grayscale=true'; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 // The padding between tiles, as a fraction of the tile width. | 616 // The padding between tiles, as a fraction of the tile width. |
628 tileSpacingFraction: 1 / 8, | 617 tileSpacingFraction: 1 / 8, |
629 }; | 618 }; |
630 TilePage.initGridValues(appsPageGridValues); | 619 TilePage.initGridValues(appsPageGridValues); |
631 | 620 |
632 /** | 621 /** |
633 * Creates a new AppsPage object. | 622 * Creates a new AppsPage object. |
634 * @constructor | 623 * @constructor |
635 * @extends {TilePage} | 624 * @extends {TilePage} |
636 */ | 625 */ |
637 function AppsPage() { | 626 function AppsPage(ordinal) { |
638 var el = new TilePage(appsPageGridValues); | 627 var el = new TilePage(appsPageGridValues); |
639 el.__proto__ = AppsPage.prototype; | 628 el.__proto__ = AppsPage.prototype; |
640 el.initialize(); | 629 el.initialize(ordinal); |
641 | 630 |
642 return el; | 631 return el; |
643 } | 632 } |
644 | 633 |
645 AppsPage.prototype = { | 634 AppsPage.prototype = { |
646 __proto__: TilePage.prototype, | 635 __proto__: TilePage.prototype, |
647 | 636 |
648 initialize: function() { | 637 initialize: function(ordinal) { |
| 638 this.ordinal_ = ordinal; |
649 this.classList.add('apps-page'); | 639 this.classList.add('apps-page'); |
650 | 640 |
651 this.addEventListener('cardselected', this.onCardSelected_); | 641 this.addEventListener('cardselected', this.onCardSelected_); |
652 // Add event listeners for two events, so we can temporarily suppress | 642 // Add event listeners for two events, so we can temporarily suppress |
653 // the app notification bubbles when the app card slides in and out of | 643 // the app notification bubbles when the app card slides in and out of |
654 // view. | 644 // view. |
655 this.addEventListener('carddeselected', this.onCardDeselected_); | 645 this.addEventListener('carddeselected', this.onCardDeselected_); |
656 this.addEventListener('cardSelectionCompleted', | 646 this.addEventListener(cr.ui.CardSlider.EventType.CARD_CHANGE_ENDED, |
657 this.onCardSelectionCompleted_); | 647 this.onCardChangeEnded_); |
| 648 |
| 649 this.addEventListener(TilePage.EventType.TILE_ADDED, this.onTileAdded_); |
658 | 650 |
659 this.content_.addEventListener('scroll', this.onScroll_.bind(this)); | 651 this.content_.addEventListener('scroll', this.onScroll_.bind(this)); |
660 }, | 652 }, |
661 | 653 |
| 654 get ordinal() { |
| 655 assert(typeof this.ordinal_ == 'string' && this.ordinal_); |
| 656 return this.ordinal_; |
| 657 }, |
| 658 |
| 659 set ordinal(ordinal) { |
| 660 assert(typeof ordinal == 'string' && ordinal); |
| 661 this.ordinal_ = ordinal; |
| 662 }, |
| 663 |
662 /** | 664 /** |
663 * Creates an app DOM element and places it at the last position on the | 665 * Creates an app DOM element and places it at the last position on the |
664 * page. | 666 * page. |
665 * @param {Object} appData The data object that describes the app. | 667 * @param {Object} appData The data object that describes the app. |
666 * @param {?boolean} animate If true, the app tile plays an animation. | 668 * @param {?boolean} animate If true, the app tile plays an animation. |
667 */ | 669 */ |
668 appendApp: function(appData, animate) { | 670 appendApp: function(appData, animate) { |
669 if (animate) { | 671 if (animate) { |
670 // Select the page and scroll all the way down so the animation is | 672 // Select the page and scroll all the way down so the animation is |
671 // visible. | 673 // visible. |
672 ntp4.getCardSlider().selectCardByValue(this); | 674 ntp4.getCardSlider().selectCardByValue(this); |
673 this.content_.scrollTop = this.content_.scrollHeight; | 675 this.content_.scrollTop = this.content_.scrollHeight; |
674 } | 676 } |
675 var app = new App(appData); | 677 this.appendTile(new App(appData), animate); |
676 if (this.classList.contains('selected-card')) | |
677 app.loadIcon(); | |
678 this.appendTile(app, animate); | |
679 }, | 678 }, |
680 | 679 |
681 /** | 680 /** |
682 * Handler for 'cardselected' event, fired when |this| is selected. The | 681 * Handler for 'cardselected' event, fired when |this| is selected. The |
683 * first time this is called, we load all the app icons. | 682 * first time this is called, we load all the app icons. |
684 * @private | 683 * @private |
685 */ | 684 */ |
686 onCardSelected_: function(e) { | 685 onCardSelected_: function(e) { |
687 var apps = this.querySelectorAll('.app.icon-loading'); | 686 var apps = this.querySelectorAll('.app.icon-loading'); |
688 for (var i = 0; i < apps.length; i++) { | 687 for (var i = 0; i < apps.length; i++) { |
689 apps[i].loadIcon(); | 688 apps[i].loadIcon(); |
690 if (apps[i].currentBubbleShowing_) | 689 if (apps[i].currentBubbleShowing_) |
691 apps[i].currentBubbleShowing_.suppressed = false; | 690 apps[i].currentBubbleShowing_.suppressed = false; |
692 } | 691 } |
693 }, | 692 }, |
694 | 693 |
695 /** | 694 /** |
696 * Handler for the 'cardSelectionCompleted' event, fired when the app card | 695 * Handler for tile additions to this page. |
697 * is done transitioning into view (and all the apps have repositioned). | 696 * @param {Event} e The TILE_MOVED event. |
| 697 */ |
| 698 onTileAdded_: function(e) { |
| 699 assert(e.tilePage == this); |
| 700 var tileContents = e.tilePage.tiles[e.tileIndex].firstChild; |
| 701 assert(tileContents instanceof App); |
| 702 if (e.tilePage.classList.contains('selected-card')) |
| 703 tileContents.loadIcon(); |
| 704 }, |
| 705 |
| 706 /** |
| 707 * Handler for the when this.cardSlider ends change its card. If animated, |
| 708 * this happens when the -webkit-transition is done, otherwise happens |
| 709 * immediately (but after CardSlider.EventType.CARD_CHANGED). |
698 * @private | 710 * @private |
699 */ | 711 */ |
700 onCardSelectionCompleted_: function(e) { | 712 onCardChangeEnded: function(e) { |
701 for (var i = 0; i < this.tileElements_.length; i++) { | 713 for (var i = 0; i < this.tileElements_.length; i++) { |
702 var app = this.tileElements_[i].firstChild; | 714 var app = this.tileElements_[i].firstChild; |
703 assert(app instanceof App); | 715 assert(app instanceof App); |
704 if (app.currentBubbleShowing_) | 716 if (app.currentBubbleShowing_) |
705 app.currentBubbleShowing_.suppressed = false; | 717 app.currentBubbleShowing_.suppressed = false; |
706 } | 718 } |
707 }, | 719 }, |
708 | 720 |
709 /** | 721 /** |
710 * Handler for the 'carddeselected' event, fired when the user switches | 722 * Handler for the 'carddeselected' event, fired when the user switches |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); | 766 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); |
755 }, | 767 }, |
756 | 768 |
757 /** @inheritDoc */ | 769 /** @inheritDoc */ |
758 addDragData: function(dataTransfer, index) { | 770 addDragData: function(dataTransfer, index) { |
759 var sourceId = -1; | 771 var sourceId = -1; |
760 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile(); | 772 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile(); |
761 if (currentlyDraggingTile) { | 773 if (currentlyDraggingTile) { |
762 var tileContents = currentlyDraggingTile.firstChild; | 774 var tileContents = currentlyDraggingTile.firstChild; |
763 if (tileContents.classList.contains('app')) { | 775 if (tileContents.classList.contains('app')) { |
764 sourceId = currentlyDraggingTile.tilePage == this ? | 776 var originalPage = currentlyDraggingTile.tilePage; |
765 DRAG_SOURCE.SAME_APPS_PANE : DRAG_SOURCE.OTHER_APPS_PANE; | 777 var samePageDrag = originalPage == this; |
766 this.tileGrid_.insertBefore( | 778 sourceId = samePageDrag ? DRAG_SOURCE.SAME_APPS_PANE : |
767 currentlyDraggingTile, | 779 DRAG_SOURCE.OTHER_APPS_PANE; |
768 this.tileElements_[index]); | 780 this.tileGrid_.insertBefore(currentlyDraggingTile, |
| 781 this.tileElements_[index]); |
769 this.tileMoved(currentlyDraggingTile); | 782 this.tileMoved(currentlyDraggingTile); |
| 783 if (!samePageDrag) |
| 784 originalPage.fireRemovedEvent(true); |
| 785 if (originalPage) |
| 786 originalPage.cleanupDrag(); |
770 } else if (currentlyDraggingTile.querySelector('.most-visited')) { | 787 } else if (currentlyDraggingTile.querySelector('.most-visited')) { |
771 this.generateAppForLink(tileContents.data); | 788 this.generateAppForLink(tileContents.data); |
772 sourceId = DRAG_SOURCE.MOST_VISITED_PANE; | 789 sourceId = DRAG_SOURCE.MOST_VISITED_PANE; |
773 } | 790 } |
774 } else { | 791 } else { |
775 this.addOutsideData_(dataTransfer, index); | 792 this.addOutsideData_(dataTransfer); |
776 sourceId = DRAG_SOURCE.OUTSIDE_NTP; | 793 sourceId = DRAG_SOURCE.OUTSIDE_NTP; |
777 } | 794 } |
778 | 795 |
779 assert(sourceId != -1); | 796 assert(sourceId != -1); |
780 chrome.send('metricsHandler:recordInHistogram', | 797 chrome.send('metricsHandler:recordInHistogram', |
781 ['NewTabPage.AppsPageDragSource', sourceId, DRAG_SOURCE_LIMIT]); | 798 ['NewTabPage.AppsPageDragSource', sourceId, DRAG_SOURCE_LIMIT]); |
782 }, | 799 }, |
783 | 800 |
784 /** | 801 /** |
785 * Adds drag data that has been dropped from a source that is not a tile. | 802 * Adds drag data that has been dropped from a source that is not a tile. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 appNotificationChanged: appNotificationChanged, | 900 appNotificationChanged: appNotificationChanged, |
884 AppsPage: AppsPage, | 901 AppsPage: AppsPage, |
885 launchAppAfterEnable: launchAppAfterEnable, | 902 launchAppAfterEnable: launchAppAfterEnable, |
886 }; | 903 }; |
887 }); | 904 }); |
888 | 905 |
889 // TODO(estade): update the content handlers to use ntp namespace instead of | 906 // TODO(estade): update the content handlers to use ntp namespace instead of |
890 // making these global. | 907 // making these global. |
891 var appNotificationChanged = ntp4.appNotificationChanged; | 908 var appNotificationChanged = ntp4.appNotificationChanged; |
892 var launchAppAfterEnable = ntp4.launchAppAfterEnable; | 909 var launchAppAfterEnable = ntp4.launchAppAfterEnable; |
OLD | NEW |