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

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

Issue 8637001: [NTP4] Auto-deletion of empty apps panes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removing bits for refactor 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // We can't pass the currently dragging tile via dataTransfer because of 8 // We can't pass the currently dragging tile via dataTransfer because of
9 // http://crbug.com/31037 9 // http://crbug.com/31037
10 var currentlyDraggingTile = null; 10 var currentlyDraggingTile = null;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 this.finalizeDrag_(); 193 this.finalizeDrag_();
194 } else { 194 } else {
195 // The CSS3 transitions spec intentionally leaves it up to individual 195 // The CSS3 transitions spec intentionally leaves it up to individual
196 // user agents to determine when styles should be applied. On some 196 // user agents to determine when styles should be applied. On some
197 // platforms (at the moment, Windows), when you apply both classes 197 // platforms (at the moment, Windows), when you apply both classes
198 // immediately a transition may not occur correctly. That's why we're 198 // immediately a transition may not occur correctly. That's why we're
199 // using a setTimeout here to queue adding the class until the 199 // using a setTimeout here to queue adding the class until the
200 // previous class (currently: .placing) sets up a transition. 200 // previous class (currently: .placing) sets up a transition.
201 // http://dev.w3.org/csswg/css3-transitions/#starting 201 // http://dev.w3.org/csswg/css3-transitions/#starting
202 window.setTimeout(function() { 202 window.setTimeout(function() {
203 this.dragClone.classList.add('dropped-on-other-page'); 203 if (this.dragClone)
204 this.dragClone.classList.add('dropped-on-other-page');
204 }.bind(this), 0); 205 }.bind(this), 0);
205 } 206 }
206 } 207 }
207 208
208 delete this.lastDropEffect; 209 delete this.lastDropEffect;
209 this.landedOnTrash = false; 210 this.landedOnTrash = false;
210 }, 211 },
211 212
212 /** 213 /**
213 * Creates a clone of this node offset by the coordinates. Used for the 214 * Creates a clone of this node offset by the coordinates. Used for the
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 */ 284 */
284 onDragCloneTransitionEnd_: function(e) { 285 onDragCloneTransitionEnd_: function(e) {
285 if (this.classList.contains('dragging') && 286 if (this.classList.contains('dragging') &&
286 (e.propertyName == 'left' || e.propertyName == 'top' || 287 (e.propertyName == 'left' || e.propertyName == 'top' ||
287 e.propertyName == '-webkit-transform')) { 288 e.propertyName == '-webkit-transform')) {
288 this.finalizeDrag_(); 289 this.finalizeDrag_();
289 } 290 }
290 }, 291 },
291 292
292 /** 293 /**
293 * Called when an app is removed from Chrome. Animates its disappearance.
294 */
295 doRemove: function() {
296 this.firstChild.classList.add('removing-tile-contents');
297 },
298
299 /**
300 * Callback for the webkitAnimationEnd event on the tile's contents. 294 * Callback for the webkitAnimationEnd event on the tile's contents.
301 * @param {Event} e The event object. 295 * @param {Event} e The event object.
302 */ 296 */
303 onContentsAnimationEnd_: function(e) { 297 onContentsAnimationEnd_: function(e) {
304 if (this.firstChild.classList.contains('new-tile-contents')) 298 if (this.firstChild.classList.contains('new-tile-contents'))
305 this.firstChild.classList.remove('new-tile-contents'); 299 this.firstChild.classList.remove('new-tile-contents');
306 if (this.firstChild.classList.contains('removing-tile-contents')) 300 if (this.firstChild.classList.contains('removing-tile-contents'))
307 this.tilePage.removeTile(this, true); 301 this.tilePage.removeTile(this, true);
308 }, 302 },
309 }; 303 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 function TilePage(gridValues) { 350 function TilePage(gridValues) {
357 var el = cr.doc.createElement('div'); 351 var el = cr.doc.createElement('div');
358 el.gridValues_ = gridValues; 352 el.gridValues_ = gridValues;
359 el.__proto__ = TilePage.prototype; 353 el.__proto__ = TilePage.prototype;
360 el.initialize(); 354 el.initialize();
361 355
362 return el; 356 return el;
363 } 357 }
364 358
365 /** 359 /**
360 * The type of events TilePage dispatches.
361 * @public
362 * @static
363 * @memberOf TilePage
364 */
365 TilePage.EventType = {
366 TILE_ADDED: 'tilePage:tile_added',
367 TILE_REMOVED: 'tilePage:tile_removed',
368 };
369
370 /**
366 * Takes a collection of grid layout pixel values and updates them with 371 * Takes a collection of grid layout pixel values and updates them with
367 * additional tiling values that are calculated from TilePage constants. 372 * additional tiling values that are calculated from TilePage constants.
368 * @param {Object} grid The grid layout pixel values to update. 373 * @param {Object} grid The grid layout pixel values to update.
369 */ 374 */
370 TilePage.initGridValues = function(grid) { 375 TilePage.initGridValues = function(grid) {
371 // The amount of space we need to display a narrow grid (all narrow grids 376 // The amount of space we need to display a narrow grid (all narrow grids
372 // are this size). 377 // are this size).
373 grid.narrowWidth = 378 grid.narrowWidth =
374 grid.minTileWidth * tileWidthFraction(grid.minColCount, 379 grid.minTileWidth * tileWidthFraction(grid.minColCount,
375 grid.tileSpacingFraction); 380 grid.tileSpacingFraction);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 /** 496 /**
492 * Returns any extra padding to insert to the bottom of a tile page. By 497 * Returns any extra padding to insert to the bottom of a tile page. By
493 * default there is none, but subclasses can override. 498 * default there is none, but subclasses can override.
494 * @type {number} 499 * @type {number}
495 */ 500 */
496 get extraBottomPadding() { 501 get extraBottomPadding() {
497 return 0; 502 return 0;
498 }, 503 },
499 504
500 /** 505 /**
506 * Removes the tilePage from the DOM and cleans up event handlers.
507 */
508 remove: function() {
509 // This checks arguments.length as most remove functions have a boolean
510 // |opt_animate| argument, but that's not necesarilly applicable to
511 // removing a tilePage. Selecting a different card in an animated way and
512 // deleting the card afterward is probably a better choice.
513 assert(typeof arguments[0] != 'boolean',
514 'This function takes no |opt_animate| argument.');
515 assert(this.tileCount == 0, 'Only removal of an empty page is allowed.');
516 this.tearDown_();
517 this.parentNode.removeChild(this);
518 },
519
520 /**
501 * Cleans up resources that are no longer needed after this TilePage 521 * Cleans up resources that are no longer needed after this TilePage
502 * instance is removed from the DOM. 522 * instance is removed from the DOM.
523 * @private
503 */ 524 */
504 tearDown: function() { 525 tearDown_: function() {
505 this.eventTracker.removeAll(); 526 this.eventTracker.removeAll();
506 }, 527 },
507 528
508 /** 529 /**
509 * Appends a tile to the end of the tile grid. 530 * Appends a tile to the end of the tile grid.
510 * @param {HTMLElement} tileElement The contents of the tile. 531 * @param {HTMLElement} tileElement The contents of the tile.
511 * @param {?boolean} animate If true, the append will be animated. 532 * @param {?boolean} animate If true, the append will be animated.
512 * @protected 533 * @protected
513 */ 534 */
514 appendTile: function(tileElement, animate) { 535 appendTile: function(tileElement, animate) {
515 this.addTileAt(tileElement, this.tileElements_.length, animate); 536 this.addTileAt(tileElement, this.tileElements_.length, animate);
516 }, 537 },
517 538
518 /** 539 /**
519 * Adds the given element to the tile grid. 540 * Adds the given element to the tile grid.
520 * @param {Node} tileElement The tile object/node to insert. 541 * @param {Node} tileElement The tile object/node to insert.
521 * @param {number} index The location in the tile grid to insert it at. 542 * @param {number} index The location in the tile grid to insert it at.
522 * @param {?boolean} animate If true, the tile in question will be animated 543 * @param {boolean=} opt_animate If true, the tile in question will be
523 * (other tiles, if they must reposition, do not animate). 544 * animated (other tiles, if they must reposition, do not animate).
524 * @protected 545 * @protected
525 */ 546 */
526 addTileAt: function(tileElement, index, animate) { 547 addTileAt: function(tileElement, index, opt_animate) {
527 this.classList.remove('animating-tile-page'); 548 this.classList.remove('animating-tile-page');
528 if (animate) 549 if (opt_animate)
529 tileElement.classList.add('new-tile-contents'); 550 tileElement.classList.add('new-tile-contents');
551
552 // Make sure the index is positive and either in the the bounds of
553 // this.tileElements_ or at the end (meaning append).
554 assert(index >= 0 && index <= this.tileElements_.length);
555
530 var wrapperDiv = new Tile(tileElement); 556 var wrapperDiv = new Tile(tileElement);
531 if (index == this.tileElements_.length) { 557 // If is out of the bounds of the tile element list, .insertBefore() will
532 this.tileGrid_.appendChild(wrapperDiv); 558 // act just like appendChild().
533 } else { 559 this.tileGrid_.insertBefore(wrapperDiv, this.tileElements_[index]);
534 this.tileGrid_.insertBefore(wrapperDiv,
535 this.tileElements_[index]);
536 }
537 this.calculateLayoutValues_(); 560 this.calculateLayoutValues_();
538 this.heightChanged_(); 561 this.heightChanged_();
539 562
540 this.positionTile_(index); 563 this.positionTile_(index);
564 this.fireAddedEvent(index, !!opt_animate);
541 }, 565 },
542 566
543 /** 567 /**
544 * Removes the given tile and animates the respositioning of the other 568 * Notify interested subscribers that a tile has been removed from this
545 * tiles. 569 * page.
546 * @param {HTMLElement} tile The tile to remove from |tileGrid_|. 570 * @param {number} index The index of the tile that was added.
547 * @param {?boolean} animate If true, remaining tiles will animate. 571 * @param {boolean} wasAnimated Whether the removal was animated.
548 */ 572 */
549 removeTile: function(tile, animate) { 573 fireAddedEvent: function(index, wasAnimated) {
550 if (animate) 574 var e = document.createEvent('Event');
575 e.initEvent(TilePage.EventType.TILE_ADDED, true, true);
576 e.tileIndex = index;
577 e.tilePage = this;
578 e.wasAnimated = wasAnimated;
579 this.dispatchEvent(e);
580 },
581
582 /**
583 * Removes the given tile and animates the repositioning of the other tiles.
584 * @param {boolean=} opt_animate Whether the removal should be animated.
585 * @param {boolean=} opt_dontNotify Whether a page should be removed if the
586 * last tile is removed from it.
587 */
588 removeTile: function(tile, opt_animate, opt_dontNotify) {
589 if (opt_animate)
551 this.classList.add('animating-tile-page'); 590 this.classList.add('animating-tile-page');
552 var index = tile.index;
553 tile.parentNode.removeChild(tile); 591 tile.parentNode.removeChild(tile);
554 this.calculateLayoutValues_(); 592 this.calculateLayoutValues_();
555 this.cleanupDrag(); 593 this.cleanupDrag();
594
595 if (!opt_dontNotify)
596 this.fireRemovedEvent(!!opt_animate);
556 }, 597 },
557 598
558 /** 599 /**
600 * Notify interested subscribers that a tile has been removed from this
601 * page.
602 * @param {boolean} wasAnimated Whether the removal was animated.
603 */
604 fireRemovedEvent: function(wasAnimated) {
605 var e = document.createEvent('Event');
606 e.initEvent(TilePage.EventType.TILE_REMOVED, true, true);
607 e.tilePage = this;
608 e.wasAnimated = wasAnimated;
609 this.dispatchEvent(e);
610 },
611
612 /**
559 * Removes all tiles from the page. 613 * Removes all tiles from the page.
560 */ 614 */
561 removeAllTiles: function() { 615 removeAllTiles: function() {
562 this.tileGrid_.innerHTML = ''; 616 this.tileGrid_.innerHTML = '';
563 }, 617 },
564 618
565 /** 619 /**
566 * Called when the page is selected (in the card selector). 620 * Called when the page is selected (in the card selector).
567 * @param {Event} e A custom cardselected event. 621 * @param {Event} e A custom cardselected event.
568 * @private 622 * @private
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 /** 1189 /**
1136 * Appends the currently dragged tile to the end of the page. Called 1190 * Appends the currently dragged tile to the end of the page. Called
1137 * from outside the page, e.g. when dropping on a nav dot. 1191 * from outside the page, e.g. when dropping on a nav dot.
1138 */ 1192 */
1139 appendDraggingTile: function() { 1193 appendDraggingTile: function() {
1140 var originalPage = currentlyDraggingTile.tilePage; 1194 var originalPage = currentlyDraggingTile.tilePage;
1141 if (originalPage == this) 1195 if (originalPage == this)
1142 return; 1196 return;
1143 1197
1144 this.addDragData(null, this.tileElements_.length); 1198 this.addDragData(null, this.tileElements_.length);
1145 originalPage.cleanupDrag(); 1199 if (originalPage)
1200 originalPage.cleanupDrag();
1146 }, 1201 },
1147 1202
1148 /** 1203 /**
1149 * Makes sure all the tiles are in the right place after a drag is over. 1204 * Makes sure all the tiles are in the right place after a drag is over.
1150 */ 1205 */
1151 cleanupDrag: function() { 1206 cleanupDrag: function() {
1152 this.repositionTiles_(currentlyDraggingTile); 1207 this.repositionTiles_(currentlyDraggingTile);
1153 // Remove the drag mask. 1208 // Remove the drag mask.
1154 this.updateMask_(); 1209 this.updateMask_();
1155 }, 1210 },
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 assert(false); 1285 assert(false);
1231 }, 1286 },
1232 }; 1287 };
1233 1288
1234 return { 1289 return {
1235 getCurrentlyDraggingTile: getCurrentlyDraggingTile, 1290 getCurrentlyDraggingTile: getCurrentlyDraggingTile,
1236 setCurrentDropEffect: setCurrentDropEffect, 1291 setCurrentDropEffect: setCurrentDropEffect,
1237 TilePage: TilePage, 1292 TilePage: TilePage,
1238 }; 1293 };
1239 }); 1294 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/page_list_view.js ('k') | chrome/browser/resources/shared/js/cr/ui/card_slider.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698