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

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

Issue 11438009: NTP5: Refactoring appData to use Tile's data implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 this.reset(); 71 this.reset();
72 }, 72 },
73 73
74 /** 74 /**
75 * Resets the tile DOM. 75 * Resets the tile DOM.
76 */ 76 */
77 reset: function() { 77 reset: function() {
78 }, 78 },
79 79
80 /** 80 /**
81 * Update the appearance of this tile according to |data|. 81 * The data for this Tile.
82 * @param {Object} data A dictionary of relevant data for the page. 82 * @param {Object} data A dictionary of relevant data for the page.
83 */ 83 */
84 setData: function(data) { 84 set data(data) {
85 // TODO(pedrosimonetti): Remove data.filler usage everywhere. 85 // TODO(pedrosimonetti): Remove data.filler usage everywhere.
86 if (!data || data.filler) { 86 if (!data || data.filler) {
87 if (this.data_) 87 if (this.data_)
88 this.reset(); 88 this.reset();
89 return; 89 return;
90 } 90 }
91 91
92 this.data_ = data; 92 this.data_ = data;
93 } 93 },
94 }; 94 };
95 95
96 var TileGetters = { 96 var TileGetters = {
97 /** 97 /**
98 * The TileCell associated to this Tile. 98 * The TileCell associated to this Tile.
99 * @type {TileCell} 99 * @type {TileCell}
100 */ 100 */
101 'tileCell': function() { 101 'tileCell': function() {
102 return findAncestorByClass(this, 'tile-cell'); 102 return findAncestorByClass(this, 'tile-cell');
103 }, 103 },
104 104
105 /** 105 /**
106 * The index of the Tile. 106 * The index of the Tile.
107 * @type {number} 107 * @type {number}
108 */ 108 */
109 'index': function() { 109 'index': function() {
110 assert(this.tileCell); 110 assert(this.tileCell);
111 return this.tileCell.index; 111 return this.tileCell.index;
112 }, 112 },
113
114 /**
115 * Tile data object.
116 * @type {Object}
117 */
118 'data': function() {
119 return this.data_;
120 }
121 }; 113 };
122 114
123 //---------------------------------------------------------------------------- 115 //----------------------------------------------------------------------------
124 // TileCell 116 // TileCell
125 //---------------------------------------------------------------------------- 117 //----------------------------------------------------------------------------
126 118
127 /** 119 /**
128 * Creates a new TileCell object. A TileCell represents a cell in the 120 * Creates a new TileCell object. A TileCell represents a cell in the
129 * TilePage's grid. A TilePage uses TileCells to position Tiles in the proper 121 * TilePage's grid. A TilePage uses TileCells to position Tiles in the proper
130 * place and to animate them individually. Each TileCell is associated to 122 * place and to animate them individually. Each TileCell is associated to
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 this.replaceChild(tile, this.firstChild); 178 this.replaceChild(tile, this.firstChild);
187 else 179 else
188 this.appendChild(tile); 180 this.appendChild(tile);
189 }, 181 },
190 182
191 /** 183 /**
192 * Called when an app is removed from Chrome. Animates its disappearance. 184 * Called when an app is removed from Chrome. Animates its disappearance.
193 * @param {boolean=} opt_animate Whether the animation should be animated. 185 * @param {boolean=} opt_animate Whether the animation should be animated.
194 */ 186 */
195 doRemove: function(opt_animate) { 187 doRemove: function(opt_animate) {
196 if (opt_animate) 188 this.tilePage.removeTile(this.firstChild, false);
Dan Beam 2012/12/05 18:34:05 nit: you may want firstElementChild (which ignores
pedro (no code reviews) 2012/12/05 19:41:34 The tile cell and the tile (its child) are being c
197 this.firstChild.classList.add('removing-tile-contents');
198 else
199 this.tilePage.removeTile(this, false);
200 }, 189 },
201 }; 190 };
202 191
203 //---------------------------------------------------------------------------- 192 //----------------------------------------------------------------------------
204 // TilePage 193 // TilePage
205 //---------------------------------------------------------------------------- 194 //----------------------------------------------------------------------------
206 195
207 /** 196 /**
208 * Creates a new TilePage object. This object contains tiles and controls 197 * Creates a new TilePage object. This object contains tiles and controls
209 * their layout. 198 * their layout.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 var data = dataList[i]; 463 var data = dataList[i];
475 var tile = tiles[i]; 464 var tile = tiles[i];
476 465
477 // TODO(pedrosimonetti): What do we do when there's no tile here? 466 // TODO(pedrosimonetti): What do we do when there's no tile here?
478 if (!tile) 467 if (!tile)
479 return; 468 return;
480 469
481 if (i >= dataList.length) 470 if (i >= dataList.length)
482 tile.reset(); 471 tile.reset();
483 else 472 else
484 tile.setData(data); 473 tile.data = data;
485 } 474 }
486 }, 475 },
487 476
488 /** 477 /**
489 * 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
490 * create/remove necessary/unnecessary tiles, render the grid when the 479 * create/remove necessary/unnecessary tiles, render the grid when the
491 * number of tiles has changed, and finally will call |updateTiles_| which 480 * number of tiles has changed, and finally will call |updateTiles_| which
492 * will in turn render the individual tiles. 481 * will in turn render the individual tiles.
493 * @param {Array} dataList The array of data. 482 * @param {Array} dataList The array of data.
494 */ 483 */
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 * a tile filler will be created. 1057 * a tile filler will be created.
1069 * @param {TilePage} tilePage A TilePage. 1058 * @param {TilePage} tilePage A TilePage.
1070 * @param {Object=} opt_data The data that will be used to create the tile. 1059 * @param {Object=} opt_data The data that will be used to create the tile.
1071 * @return {Tile} The new tile. 1060 * @return {Tile} The new tile.
1072 */ 1061 */
1073 function createTile(tilePage, opt_data) { 1062 function createTile(tilePage, opt_data) {
1074 var tile; 1063 var tile;
1075 if (opt_data) { 1064 if (opt_data) {
1076 // If there's data, the new tile will be a real one (not a filler). 1065 // If there's data, the new tile will be a real one (not a filler).
1077 tile = new tilePage.TileClass(tilePage.config); 1066 tile = new tilePage.TileClass(tilePage.config);
1078 tile.setData(opt_data); 1067 tile.data = opt_data;
1079 } else { 1068 } else {
1080 // Otherwise, it will be a fake filler tile. 1069 // Otherwise, it will be a fake filler tile.
1081 tile = cr.doc.createElement('span'); 1070 tile = cr.doc.createElement('span');
1082 tile.className = 'tile'; 1071 tile.className = 'tile';
1083 } 1072 }
1084 return tile; 1073 return tile;
1085 } 1074 }
1086 1075
1087 /** 1076 /**
1088 * Fades a tile. 1077 * Fades a tile.
1089 * @param {Tile} tile A Tile. 1078 * @param {Tile} tile A Tile.
1090 * @param {boolean} isFadeIn Whether to fade-in the tile. If |isFadeIn| is 1079 * @param {boolean} isFadeIn Whether to fade-in the tile. If |isFadeIn| is
1091 * false, then the tile is going to fade-out. 1080 * false, then the tile is going to fade-out.
1092 */ 1081 */
1093 function fadeTile(tile, isFadeIn) { 1082 function fadeTile(tile, isFadeIn) {
1094 var className = 'animate-hide-tile'; 1083 var className = 'animate-hide-tile';
1095 tile.classList.add(className); 1084 tile.classList.add(className);
1096 if (isFadeIn) { 1085 if (isFadeIn) {
1097 // Forces a reflow to ensure that the fade-out animation will work. 1086 // Forces a reflow to ensure that the fade-out animation will work.
1098 tile.scrollTop; 1087 tile.scrollTop;
1099 tile.classList.remove(className); 1088 tile.classList.remove(className);
1100 } 1089 }
1101 } 1090 }
1102 1091
1103 return { 1092 return {
1104 Tile: Tile, 1093 Tile: Tile,
1105 TilePage: TilePage, 1094 TilePage: TilePage,
1106 }; 1095 };
1107 }); 1096 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698