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

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

Issue 10907065: NTP5: Fix page blacklisting and remove recently closed tabs when they're clicked. Fix the styling … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bugs. Created 8 years, 3 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) 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 var Tile = ntp.Tile2; 8 var Tile = ntp.Tile2;
9 var TilePage = ntp.TilePage2; 9 var TilePage = ntp.TilePage2;
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 var favicon = thumbnailImage.querySelector('.thumbnail-favicon'); 103 var favicon = thumbnailImage.querySelector('.thumbnail-favicon');
104 if (favicon) 104 if (favicon)
105 thumbnailImage.removeChild(favicon); 105 thumbnailImage.removeChild(favicon);
106 106
107 var self = this; 107 var self = this;
108 var image = new Image(); 108 var image = new Image();
109 109
110 // If the thumbnail image fails to load, show the favicon and URL instead. 110 // If the thumbnail image fails to load, show the favicon and URL instead.
111 // TODO(jeremycho): Move to a separate function? 111 // TODO(jeremycho): Move to a separate function?
112 image.onerror = function() { 112 image.onerror = function() {
113 banner = self.ownerDocument.createElement('div'); 113 banner = thumbnailImage.querySelector('.thumbnail-banner') ||
114 self.ownerDocument.createElement('div');
114 banner.className = 'thumbnail-banner'; 115 banner.className = 'thumbnail-banner';
115 116
116 // For now, just strip leading http://www and trailing backslash. 117 // For now, just strip leading http://www and trailing backslash.
117 // TODO(jeremycho): Consult with UX on URL truncation. 118 // TODO(jeremycho): Consult with UX on URL truncation.
118 banner.textContent = dataUrl.replace(/^(http:\/\/)?(www\.)?|\/$/gi, ''); 119 banner.textContent = dataUrl.replace(/^(http:\/\/)?(www\.)?|\/$/gi, '');
119 thumbnailImage.appendChild(banner); 120 thumbnailImage.appendChild(banner);
120 121
121 favicon = self.ownerDocument.createElement('div'); 122 favicon = thumbnailImage.querySelector('.thumbnail-favicon') ||
123 self.ownerDocument.createElement('div');
122 favicon.className = 'thumbnail-favicon'; 124 favicon.className = 'thumbnail-favicon';
123 favicon.style.backgroundImage = 125 favicon.style.backgroundImage =
124 url('chrome://favicon/size/16/' + dataUrl); 126 url('chrome://favicon/size/16/' + dataUrl);
125 thumbnailImage.appendChild(favicon); 127 thumbnailImage.appendChild(favicon);
126 } 128 }
127 129
128 var thumbnailUrl = ntp.getThumbnailUrl(dataUrl); 130 var thumbnailUrl = ntp.getThumbnailUrl(dataUrl);
129 thumbnailImage.style.backgroundImage = url(thumbnailUrl); 131 thumbnailImage.style.backgroundImage = url(thumbnailUrl);
130 image.src = thumbnailUrl; 132 image.src = thumbnailUrl;
131 }, 133 },
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 }, 187 },
186 188
187 /** 189 /**
188 * Update the tiles after a change to |data_|. 190 * Update the tiles after a change to |data_|.
189 */ 191 */
190 updateTiles_: function() { 192 updateTiles_: function() {
191 if (!this.hasBeenRendered()) 193 if (!this.hasBeenRendered())
192 this.layout_(); 194 this.layout_();
193 195
194 var maxTileCount = this.config_.maxTileCount; 196 var maxTileCount = this.config_.maxTileCount;
195 var data = this.data_; 197 var data = this.getValidData_();
196 var tiles = this.tiles; 198 var tiles = this.tiles;
197 for (var i = 0; i < maxTileCount; i++) { 199 for (var i = 0; i < maxTileCount; i++) {
198 var page = data[i]; 200 var page = data[i];
199 var tile = tiles[i]; 201 var tile = tiles[i];
200 202
201 // TODO(pedrosimonetti): What do we do when there's no tile here? 203 // TODO(pedrosimonetti): What do we do when there's no tile here?
202 if (!tile) 204 if (!tile)
203 return; 205 return;
204 206
205 if (i >= data.length) 207 if (i >= data.length)
206 tile.reset(); 208 tile.reset();
207 else 209 else
208 tile.updateForData(page); 210 tile.updateForData(page);
209 } 211 }
210 }, 212 },
211 213
212 /** 214 /**
213 * Array of thumbnail data objects. 215 * Returns all non-null data entries. Null is used by Most Visited Page as
214 * @type {Array} 216 * placeholders for blacklisted entries.
217 * @private
218 * @return {Array} Non-null data entries.
215 */ 219 */
216 get data() { 220 getValidData_: function() {
pedro (no code reviews) 2012/09/05 18:57:00 I'd move this below refreshData, since getData, se
jeremycho 2012/09/05 22:42:11 Done.
221 var validData = [];
222 var data = this.data_;
223 for (var i = 0, length = data.length; i < length; i++) {
224 if (data[i])
225 validData.push(data[i]);
226 }
227 return validData;
228 },
229
230 /**
231 * Returns an array of thumbnail data objects.
232 * @return {Array} An array of thumbnail data objects.
233 */
234 getData: function() {
217 return this.data_; 235 return this.data_;
218 }, 236 },
219 set data(data) { 237
220 console.error('ThumbnailPage: data_ setter is not implemented.'); 238 /**
239 * Sets the data that will be used to create Thumbnails.
240 * @param {Array} data The array of data.
241 */
242 setData: function(data) {
243 var maxTileCount = this.config_.maxTileCount;
244
245 if (!this.data_)
246 this.data_ = data.slice(0, maxTileCount);
247 else
248 this.data_ = this.refreshData_(this.data_, data, maxTileCount);
249
250 var dataLength = this.getValidData_().length;
pedro (no code reviews) 2012/09/05 18:57:00 nit: dataLength --> validDataLength
jeremycho 2012/09/05 22:42:11 Done.
251 var tileCount = this.tileCount;
252 // Create or remove tiles if necessary.
253 if (tileCount < dataLength)
254 this.createTiles_(dataLength - tileCount);
255 else if (tileCount > dataLength) {
256 for (var i = 0; i < tileCount - dataLength; i++)
257 this.tiles_.pop();
pedro (no code reviews) 2012/09/05 18:57:00 Even though calling pop() will work, it feels wron
jeremycho 2012/09/05 22:42:11 removeTile only seems necessary if we wanted to an
258 }
259
260 if (dataLength != tileCount && tileCount > 0)
pedro (no code reviews) 2012/09/05 18:57:00 Include a TODO here. I'll fix the problem in anoth
jeremycho 2012/09/05 22:42:11 Done.
261 this.renderGrid_();
262 this.updateTiles_();
263 },
264
265 /**
266 * Given an array of new data, returns the data that should replace the
267 * current array of data. Here we simply return the new data.
268 * @param {Array} oldData The current page list.
269 * @param {Array} newData The new page list.
270 * @param {number} maxTileCount The maximum number of tiles to render.
271 * @return {Array} The merged page list that should replace the current page
272 * list.
273 * @private
274 */
275 refreshData_: function(oldData, newData, maxTileCount) {
276 return newData.slice(0, maxTileCount);
221 }, 277 },
222 278
223 /** @inheritDoc */ 279 /** @inheritDoc */
224 shouldAcceptDrag: function(e) { 280 shouldAcceptDrag: function(e) {
225 return false; 281 return false;
226 }, 282 },
227 }; 283 };
228 284
229 return { 285 return {
230 Thumbnail: Thumbnail, 286 Thumbnail: Thumbnail,
231 ThumbnailPage: ThumbnailPage 287 ThumbnailPage: ThumbnailPage
232 }; 288 };
233 }); 289 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698