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

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

Issue 7312016: ntp4: small followup to r91606 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 5 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 | no next file » | 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) 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 }, 250 },
251 251
252 /** 252 /**
253 * Callback for the webkitAnimationEnd event on the tile's contents. 253 * Callback for the webkitAnimationEnd event on the tile's contents.
254 * @param {Event} e The event object. 254 * @param {Event} e The event object.
255 */ 255 */
256 onContentsAnimationEnd_: function(e) { 256 onContentsAnimationEnd_: function(e) {
257 if (this.firstChild.classList.contains('new-tile-contents')) 257 if (this.firstChild.classList.contains('new-tile-contents'))
258 this.firstChild.classList.remove('new-tile-contents'); 258 this.firstChild.classList.remove('new-tile-contents');
259 else if (this.firstChild.classList.contains('removing-tile-contents')) 259 else if (this.firstChild.classList.contains('removing-tile-contents'))
260 this.parentNode.removeChild(this); 260 this.tilePage.removeTile(this);
261 }, 261 },
262 }; 262 };
263 263
264 /** 264 /**
265 * Gives the proportion of the row width that is devoted to a single icon. 265 * Gives the proportion of the row width that is devoted to a single icon.
266 * @param {number} rowTileCount The number of tiles in a row. 266 * @param {number} rowTileCount The number of tiles in a row.
267 * @return {number} The ratio between icon width and row width. 267 * @return {number} The ratio between icon width and row width.
268 */ 268 */
269 function tileWidthFraction(rowTileCount) { 269 function tileWidthFraction(rowTileCount) {
270 return rowTileCount + 270 return rowTileCount +
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 * @protected 444 * @protected
445 */ 445 */
446 appendTile: function(tileElement, animate) { 446 appendTile: function(tileElement, animate) {
447 this.addTileAt(tileElement, this.tileElements_.length, animate); 447 this.addTileAt(tileElement, this.tileElements_.length, animate);
448 }, 448 },
449 449
450 /** 450 /**
451 * Adds the given element to the tile grid. 451 * Adds the given element to the tile grid.
452 * @param {Node} tileElement The tile object/node to insert. 452 * @param {Node} tileElement The tile object/node to insert.
453 * @param {number} index The location in the tile grid to insert it at. 453 * @param {number} index The location in the tile grid to insert it at.
454 * @param {?boolean} animate If true, the add will be animated. 454 * @param {?boolean} animate If true, the tile in question will be animated
455 * (other tiles, if they must reposition, do not animate).
455 * @protected 456 * @protected
456 */ 457 */
457 addTileAt: function(tileElement, index, animate) { 458 addTileAt: function(tileElement, index, animate) {
458 this.classList.remove('animating-tile-page'); 459 this.classList.remove('animating-tile-page');
459 if (animate) 460 if (animate)
460 tileElement.classList.add('new-tile-contents'); 461 tileElement.classList.add('new-tile-contents');
461 var wrapperDiv = new Tile(tileElement); 462 var wrapperDiv = new Tile(tileElement);
462 if (index == this.tileElements_.length) { 463 if (index == this.tileElements_.length) {
463 this.tileGrid_.appendChild(wrapperDiv); 464 this.tileGrid_.appendChild(wrapperDiv);
464 } else { 465 } else {
465 this.tileGrid_.insertBefore(wrapperDiv, 466 this.tileGrid_.insertBefore(wrapperDiv,
466 this.tileElements_[index]); 467 this.tileElements_[index]);
467 } 468 }
468 this.calculateLayoutValues_(); 469 this.calculateLayoutValues_();
469 470
470 this.positionTile_(index); 471 this.positionTile_(index);
471 }, 472 },
472 473
473 /** 474 /**
475 * Removes the given tile and animates the respositioning of the other
476 * tiles.
477 * @param {HTMLElement} tile The tile to remove from |tileGrid_|.
478 */
479 removeTile: function(tile) {
480 this.classList.add('animating-tile-page');
481 var index = Array.prototype.indexOf.call(this.tileElements_, tile);
482 tile.parentNode.removeChild(tile);
483 this.calculateLayoutValues_();
484 for (var i = index; i < this.tileElements_.length; i++) {
485 this.positionTile_(i);
486 }
487 },
488
489 /**
474 * Makes some calculations for tile layout. These change depending on 490 * Makes some calculations for tile layout. These change depending on
475 * height, width, and the number of tiles. 491 * height, width, and the number of tiles.
476 * @private 492 * @private
477 */ 493 */
478 calculateLayoutValues_: function() { 494 calculateLayoutValues_: function() {
479 var grid = this.gridValues_; 495 var grid = this.gridValues_;
480 var availableSpace = this.tileGrid_.clientWidth - 2 * MIN_WIDE_MARGIN; 496 var availableSpace = this.tileGrid_.clientWidth - 2 * MIN_WIDE_MARGIN;
481 var wide = availableSpace >= grid.minWideWidth; 497 var wide = availableSpace >= grid.minWideWidth;
482 var numRowTiles = wide ? grid.maxColCount : grid.minColCount; 498 var numRowTiles = wide ? grid.maxColCount : grid.minColCount;
483 499
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 */ 1018 */
1003 tileMoved: function(draggedTile) { 1019 tileMoved: function(draggedTile) {
1004 }, 1020 },
1005 }; 1021 };
1006 1022
1007 return { 1023 return {
1008 getCurrentlyDraggingTile: getCurrentlyDraggingTile, 1024 getCurrentlyDraggingTile: getCurrentlyDraggingTile,
1009 TilePage: TilePage, 1025 TilePage: TilePage,
1010 }; 1026 };
1011 }); 1027 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698