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

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

Issue 11445009: NTP5: Reuse insertion/removal animations for Apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Dan's comment Created 8 years 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) 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 8
9 /** 9 /**
10 * The maximum gap from the edge of the scrolling area which will display 10 * The maximum gap from the edge of the scrolling area which will display
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 tile.data = data; 473 tile.data = data;
474 } 474 }
475 }, 475 },
476 476
477 /** 477 /**
478 * Sets the dataList that will be used to create Tiles. This method will 478 * Sets the dataList that will be used to create Tiles. This method will
479 * create/remove necessary/unnecessary tiles, render the grid when the 479 * create/remove necessary/unnecessary tiles, render the grid when the
480 * number of tiles has changed, and finally will call |updateTiles_| which 480 * number of tiles has changed, and finally will call |updateTiles_| which
481 * will in turn render the individual tiles. 481 * will in turn render the individual tiles.
482 * @param {Array} dataList The array of data. 482 * @param {Array} dataList The array of data.
483 * @param {boolean=} opt_create Whether to create tiles.
483 */ 484 */
484 setDataList: function(dataList) { 485 setDataList: function(dataList, opt_create) {
485 this.dataList_ = dataList.slice(0, this.config.maxTileCount); 486 this.dataList_ = dataList.slice(0, this.config.maxTileCount);
486 487
488 opt_create = typeof opt_create == 'undefined' ? true : opt_create;
489 if (!opt_create)
Dan Beam 2012/12/05 18:40:44 why isn't this simply 2 methods? `set dataList` an
pedro (no code reviews) 2012/12/05 20:03:55 For simplicity reasons, I'm trying to share as muc
Dan Beam 2012/12/05 20:05:54 If only I had a $1 for every time I heard that ;)
490 return;
491
487 var dataListLength = this.dataList_.length; 492 var dataListLength = this.dataList_.length;
488 var tileCount = this.tileCount; 493 var tileCount = this.tileCount;
489 // Create or remove tiles if necessary. 494 // Create or remove tiles if necessary.
490 if (tileCount < dataListLength) { 495 if (tileCount < dataListLength) {
491 this.createTiles_(dataListLength - tileCount); 496 this.createTiles_(dataListLength - tileCount);
492 } else if (tileCount > dataListLength) { 497 } else if (tileCount > dataListLength) {
493 var tiles = this.tiles_; 498 var tiles = this.tiles_;
494 while (tiles.length > dataListLength) { 499 while (tiles.length > dataListLength) {
495 var previousLength = tiles.length; 500 var previousLength = tiles.length;
496 // It doesn't matter which tiles are being removed here because 501 // It doesn't matter which tiles are being removed here because
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 844
840 var repositioningStartIndex = index; 845 var repositioningStartIndex = index;
841 var repositioningEndIndex = tileCount - (extraTileData ? 1 : 0); 846 var repositioningEndIndex = tileCount - (extraTileData ? 1 : 0);
842 847
843 this.initializeRepositioningAnimation_(index, repositioningEndIndex); 848 this.initializeRepositioningAnimation_(index, repositioningEndIndex);
844 849
845 var restoredData = newDataList[index]; 850 var restoredData = newDataList[index];
846 var tileBeingRestored = createTile(this, restoredData); 851 var tileBeingRestored = createTile(this, restoredData);
847 tileCells[index].appendChild(tileBeingRestored); 852 tileCells[index].appendChild(tileBeingRestored);
848 853
849 var extraTile = extraCell.firstChild; 854 if (this.config.scrollable)
855 this.content_.scrollTop = tileCells[index].offsetTop;
856
857 var extraTile = extraCell && extraCell.firstChild;
Dan Beam 2012/12/05 18:40:44 IMO, these are slightly easier to understand for C
pedro (no code reviews) 2012/12/05 20:03:55 Done.
850 858
851 this.executeRepositioningAnimation_(tileBeingRestored, extraTile, 859 this.executeRepositioningAnimation_(tileBeingRestored, extraTile,
852 repositioningStartIndex, repositioningEndIndex, false); 860 repositioningStartIndex, repositioningEndIndex, false);
853 861
854 // Cleans up the animation. 862 // Cleans up the animation.
855 var onPositioningTransitionEnd = function(e) { 863 var onPositioningTransitionEnd = function(e) {
856 var propertyName = e.propertyName; 864 var propertyName = e.propertyName;
857 if (!(propertyName == '-webkit-transform' || 865 if (!(propertyName == '-webkit-transform' ||
858 propertyName == 'opacity')) { 866 propertyName == 'opacity')) {
859 return; 867 return;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 * @param {number} endIndex Index of the last tile to be repositioned. 948 * @param {number} endIndex Index of the last tile to be repositioned.
941 * @param {boolean} isRemoving Whether the tile is being removed. 949 * @param {boolean} isRemoving Whether the tile is being removed.
942 * @private 950 * @private
943 */ 951 */
944 executeRepositioningAnimation_: function(targetTile, extraTile, startIndex, 952 executeRepositioningAnimation_: function(targetTile, extraTile, startIndex,
945 endIndex, isRemoving) { 953 endIndex, isRemoving) {
946 targetTile.classList.add('target-tile'); 954 targetTile.classList.add('target-tile');
947 955
948 // Alternate the visualization of the target and extra tiles. 956 // Alternate the visualization of the target and extra tiles.
949 fadeTile(targetTile, !isRemoving); 957 fadeTile(targetTile, !isRemoving);
950 fadeTile(extraTile, isRemoving); 958 if (extraTile)
959 fadeTile(extraTile, isRemoving);
951 960
952 // Move tiles to the new position. 961 // Move tiles to the new position.
953 var tiles = this.tiles_; 962 var tiles = this.tiles_;
954 var positionDiff = isRemoving ? -1 : 1; 963 var positionDiff = isRemoving ? -1 : 1;
955 for (var i = startIndex; i < endIndex; i++) { 964 for (var i = startIndex; i < endIndex; i++) {
956 var position = this.getTilePosition_(i + positionDiff); 965 var position = this.getTilePosition_(i + positionDiff);
957 this.moveTileTo_(tiles[i], position.left, position.top); 966 this.moveTileTo_(tiles[i], position.left, position.top);
958 } 967 }
959 }, 968 },
960 969
(...skipping 14 matching lines...) Expand all
975 targetTile.classList.remove('target-tile'); 984 targetTile.classList.remove('target-tile');
976 985
977 // Move tiles back to relative position. 986 // Move tiles back to relative position.
978 var tiles = this.tiles_; 987 var tiles = this.tiles_;
979 var tileCells = this.querySelectorAll('.tile-cell'); 988 var tileCells = this.querySelectorAll('.tile-cell');
980 var positionDiff = isRemoving ? -1 : 1; 989 var positionDiff = isRemoving ? -1 : 1;
981 for (var i = startIndex; i < endIndex; i++) { 990 for (var i = startIndex; i < endIndex; i++) {
982 var tile = tiles[i]; 991 var tile = tiles[i];
983 this.resetTilePosition_(tile); 992 this.resetTilePosition_(tile);
984 tile.style.zIndex = ''; 993 tile.style.zIndex = '';
985 tileCells[i + positionDiff].assign(tile); 994 var tileCell = tileCells[i + positionDiff];
995 if (tileCell)
996 tileCell.assign(tile);
986 } 997 }
987 }, 998 },
988 999
989 /** 1000 /**
990 * Animates the display of columns. 1001 * Animates the display of columns.
991 * @param {number} col The column number. 1002 * @param {number} col The column number.
992 * @param {boolean} show Whether or not to show the row. 1003 * @param {boolean} show Whether or not to show the row.
993 */ 1004 */
994 showTileCols_: function(col, show) { 1005 showTileCols_: function(col, show) {
995 var prop = show ? 'remove' : 'add'; 1006 var prop = show ? 'remove' : 'add';
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 tile.scrollTop; 1098 tile.scrollTop;
1088 tile.classList.remove(className); 1099 tile.classList.remove(className);
1089 } 1100 }
1090 } 1101 }
1091 1102
1092 return { 1103 return {
1093 Tile: Tile, 1104 Tile: Tile,
1094 TilePage: TilePage, 1105 TilePage: TilePage,
1095 }; 1106 };
1096 }); 1107 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698