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

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

Issue 9116037: [NTP4] Make TilePage and CardSlider evented to simplify code and fix page switcher bug (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: found one more bug when you leave a tab while mousing over page switcher Created 8 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/resources/ntp4/nav_dot.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 * @param {string} color The css-parsable value for the color. 270 * @param {string} color The css-parsable value for the color.
271 */ 271 */
272 set stripeColor(color) { 272 set stripeColor(color) {
273 this.querySelector('.color-stripe').style.backgroundColor = color; 273 this.querySelector('.color-stripe').style.backgroundColor = color;
274 }, 274 },
275 275
276 /** 276 /**
277 * Removes the app tile from the page. Should be called after the app has 277 * Removes the app tile from the page. Should be called after the app has
278 * been uninstalled. 278 * been uninstalled.
279 */ 279 */
280 remove: function() { 280 remove: function(opt_animate) {
281 // Unset the ID immediately, because the app is already gone. But leave 281 // Unset the ID immediately, because the app is already gone. But leave
282 // the tile on the page as it animates out. 282 // the tile on the page as it animates out.
283 this.id = ''; 283 this.id = '';
284 this.tile.doRemove(); 284 this.tile.doRemove(opt_animate);
285 }, 285 },
286 286
287 /** 287 /**
288 * Set the URL of the icon from |appData_|. This won't actually show the 288 * Set the URL of the icon from |appData_|. This won't actually show the
289 * icon until loadIcon() is called (for performance reasons; we don't want 289 * icon until loadIcon() is called (for performance reasons; we don't want
290 * to load icons until we have to). 290 * to load icons until we have to).
291 */ 291 */
292 setIcon: function() { 292 setIcon: function() {
293 var src = this.useSmallIcon_ ? this.appData_.icon_small : 293 var src = this.useSmallIcon_ ? this.appData_.icon_small :
294 this.appData_.icon_big; 294 this.appData_.icon_big;
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 __proto__: TilePage.prototype, 643 __proto__: TilePage.prototype,
644 644
645 initialize: function() { 645 initialize: function() {
646 this.classList.add('apps-page'); 646 this.classList.add('apps-page');
647 647
648 this.addEventListener('cardselected', this.onCardSelected_); 648 this.addEventListener('cardselected', this.onCardSelected_);
649 // Add event listeners for two events, so we can temporarily suppress 649 // Add event listeners for two events, so we can temporarily suppress
650 // the app notification bubbles when the app card slides in and out of 650 // the app notification bubbles when the app card slides in and out of
651 // view. 651 // view.
652 this.addEventListener('carddeselected', this.onCardDeselected_); 652 this.addEventListener('carddeselected', this.onCardDeselected_);
653 this.addEventListener('cardSelectionCompleted', 653 this.addEventListener('cardSlider:card_change_ended',
654 this.onCardSelectionCompleted_); 654 this.onCardChangeEnded_);
655
656 this.addEventListener('tilePage:tile_added', this.onTileAdded_);
655 657
656 this.content_.addEventListener('scroll', this.onScroll_.bind(this)); 658 this.content_.addEventListener('scroll', this.onScroll_.bind(this));
657 }, 659 },
658 660
659 /** 661 /**
660 * Creates an app DOM element and places it at the last position on the 662 * Creates an app DOM element and places it at the last position on the
661 * page. 663 * page.
662 * @param {Object} appData The data object that describes the app. 664 * @param {Object} appData The data object that describes the app.
663 * @param {boolean=} animate If true, the app tile plays an animation. 665 * @param {boolean=} animate If true, the app tile plays an animation.
664 */ 666 */
665 appendApp: function(appData, animate) { 667 appendApp: function(appData, animate) {
666 if (animate) { 668 if (animate) {
667 // Select the page and scroll all the way down so the animation is 669 // Select the page and scroll all the way down so the animation is
668 // visible. 670 // visible.
669 ntp4.getCardSlider().selectCardByValue(this); 671 ntp4.getCardSlider().selectCardByValue(this);
670 this.content_.scrollTop = this.content_.scrollHeight; 672 this.content_.scrollTop = this.content_.scrollHeight;
671 } 673 }
672 var app = new App(appData); 674 this.appendTile(new App(appData), animate);
673 if (this.classList.contains('selected-card'))
674 app.loadIcon();
675 this.appendTile(app, animate);
676 }, 675 },
677 676
678 /** 677 /**
679 * Handler for 'cardselected' event, fired when |this| is selected. The 678 * Handler for 'cardselected' event, fired when |this| is selected. The
680 * first time this is called, we load all the app icons. 679 * first time this is called, we load all the app icons.
681 * @private 680 * @private
682 */ 681 */
683 onCardSelected_: function(e) { 682 onCardSelected_: function(e) {
684 var apps = this.querySelectorAll('.app.icon-loading'); 683 var apps = this.querySelectorAll('.app.icon-loading');
685 for (var i = 0; i < apps.length; i++) { 684 for (var i = 0; i < apps.length; i++) {
686 apps[i].loadIcon(); 685 apps[i].loadIcon();
687 if (apps[i].currentBubbleShowing_) 686 if (apps[i].currentBubbleShowing_)
688 apps[i].currentBubbleShowing_.suppressed = false; 687 apps[i].currentBubbleShowing_.suppressed = false;
689 } 688 }
690 }, 689 },
691 690
692 /** 691 /**
693 * Handler for the 'cardSelectionCompleted' event, fired when the app card 692 * Handler for tile additions to this page.
694 * is done transitioning into view (and all the apps have repositioned). 693 * @param {Event} e The tilePage:tile_added event.
694 */
695 onTileAdded_: function(e) {
696 assert(e.currentTarget == this);
697 assert(e.addedTile.firstChild instanceof App);
698 if (this.classList.contains('selected-card'))
699 e.addedTile.firstChild.loadIcon();
700 },
701
702 /**
703 * Handler for the when this.cardSlider ends change its card. If animated,
704 * this happens when the -webkit-transition is done, otherwise happens
705 * immediately (but after cardSlider:card_changed).
695 * @private 706 * @private
696 */ 707 */
697 onCardSelectionCompleted_: function(e) { 708 onCardChangeEnded_: function(e) {
698 for (var i = 0; i < this.tileElements_.length; i++) { 709 for (var i = 0; i < this.tileElements_.length; i++) {
699 var app = this.tileElements_[i].firstChild; 710 var app = this.tileElements_[i].firstChild;
700 assert(app instanceof App); 711 assert(app instanceof App);
701 if (app.currentBubbleShowing_) 712 if (app.currentBubbleShowing_)
702 app.currentBubbleShowing_.suppressed = false; 713 app.currentBubbleShowing_.suppressed = false;
703 } 714 }
704 }, 715 },
705 716
706 /** 717 /**
707 * Handler for the 'carddeselected' event, fired when the user switches 718 * Handler for the 'carddeselected' event, fired when the user switches
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); 762 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1);
752 }, 763 },
753 764
754 /** @inheritDoc */ 765 /** @inheritDoc */
755 addDragData: function(dataTransfer, index) { 766 addDragData: function(dataTransfer, index) {
756 var sourceId = -1; 767 var sourceId = -1;
757 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile(); 768 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile();
758 if (currentlyDraggingTile) { 769 if (currentlyDraggingTile) {
759 var tileContents = currentlyDraggingTile.firstChild; 770 var tileContents = currentlyDraggingTile.firstChild;
760 if (tileContents.classList.contains('app')) { 771 if (tileContents.classList.contains('app')) {
761 sourceId = currentlyDraggingTile.tilePage == this ? 772 var originalPage = currentlyDraggingTile.tilePage;
762 DRAG_SOURCE.SAME_APPS_PANE : DRAG_SOURCE.OTHER_APPS_PANE; 773 var samePageDrag = originalPage == this;
763 this.tileGrid_.insertBefore( 774 sourceId = samePageDrag ? DRAG_SOURCE.SAME_APPS_PANE :
764 currentlyDraggingTile, 775 DRAG_SOURCE.OTHER_APPS_PANE;
765 this.tileElements_[index]); 776 this.tileGrid_.insertBefore(currentlyDraggingTile,
777 this.tileElements_[index]);
766 this.tileMoved(currentlyDraggingTile); 778 this.tileMoved(currentlyDraggingTile);
779 if (!samePageDrag) {
780 originalPage.fireRemovedEvent(currentlyDraggingTile, index, true);
781 this.fireAddedEvent(currentlyDraggingTile, index, true);
782 }
767 } else if (currentlyDraggingTile.querySelector('.most-visited')) { 783 } else if (currentlyDraggingTile.querySelector('.most-visited')) {
768 this.generateAppForLink(tileContents.data); 784 this.generateAppForLink(tileContents.data);
769 sourceId = DRAG_SOURCE.MOST_VISITED_PANE; 785 sourceId = DRAG_SOURCE.MOST_VISITED_PANE;
770 } 786 }
771 } else { 787 } else {
772 this.addOutsideData_(dataTransfer); 788 this.addOutsideData_(dataTransfer);
773 sourceId = DRAG_SOURCE.OUTSIDE_NTP; 789 sourceId = DRAG_SOURCE.OUTSIDE_NTP;
774 } 790 }
775 791
776 assert(sourceId != -1); 792 assert(sourceId != -1);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 appNotificationChanged: appNotificationChanged, 894 appNotificationChanged: appNotificationChanged,
879 AppsPage: AppsPage, 895 AppsPage: AppsPage,
880 launchAppAfterEnable: launchAppAfterEnable, 896 launchAppAfterEnable: launchAppAfterEnable,
881 }; 897 };
882 }); 898 });
883 899
884 // TODO(estade): update the content handlers to use ntp namespace instead of 900 // TODO(estade): update the content handlers to use ntp namespace instead of
885 // making these global. 901 // making these global.
886 var appNotificationChanged = ntp4.appNotificationChanged; 902 var appNotificationChanged = ntp4.appNotificationChanged;
887 var launchAppAfterEnable = ntp4.launchAppAfterEnable; 903 var launchAppAfterEnable = ntp4.launchAppAfterEnable;
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/ntp4/nav_dot.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698