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

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

Issue 7342017: ntp4: Most Visited appearance refresh (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cursor 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
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 var TilePage = ntp4.TilePage; 8 var TilePage = ntp4.TilePage;
9 9
10 /** 10 /**
(...skipping 27 matching lines...) Expand all
38 assert(this.tile); 38 assert(this.tile);
39 return this.tile.index; 39 return this.tile.index;
40 }, 40 },
41 41
42 /** 42 /**
43 * Clears the DOM hierarchy for this node, setting it back to the default 43 * Clears the DOM hierarchy for this node, setting it back to the default
44 * for a blank thumbnail. 44 * for a blank thumbnail.
45 */ 45 */
46 reset: function() { 46 reset: function() {
47 this.className = 'most-visited filler real'; 47 this.className = 'most-visited filler real';
48 // TODO(estade): why do we need edit-mode-border?
49 this.innerHTML = 48 this.innerHTML =
50 '<div class="edit-mode-border fills-parent">' + 49 '<span class="thumbnail-wrapper fills-parent">' +
51 '<div class="edit-bar-wrapper">' + 50 '<div class="close-button"></div>' +
52 '<div class="edit-bar">' + 51 '<span class="thumbnail fills-parent">' +
53 '<div class="pin"></div>' + 52 // thumbnail-shield provides a gradient fade effect.
54 '<div class="spacer"></div>' + 53 '<div class="thumbnail-shield fills-parent"></div>' +
55 '<div class="remove"></div>' +
56 '</div>' +
57 '</div>' +
58 '<span class="thumbnail-wrapper fills-parent">' +
59 '<span class="thumbnail fills-parent">' +
60 // thumbnail-shield provides a gradient fade effect.
61 '<div class="thumbnail-shield fills-parent"></div>' +
62 '</span>' +
63 '<span class="favicon"></span>' +
64 '</span>' + 54 '</span>' +
65 '<div class="color-stripe"></div>' + 55 '<span class="favicon"></span>' +
66 '<span class="title"></span>' + 56 '</span>' +
67 '</div>'; 57 '<div class="color-stripe"></div>' +
58 '<span class="title"></span>';
68 59
69 this.tabIndex = -1; 60 this.tabIndex = -1;
70 this.data_ = null; 61 this.data_ = null;
71 this.removeAttribute('id'); 62 this.removeAttribute('id');
72 }, 63 },
73 64
74 /** 65 /**
75 * Update the appearance of this tile according to |data|. 66 * Update the appearance of this tile according to |data|.
76 * @param {Object} data A dictionary of relevant data for the page. 67 * @param {Object} data A dictionary of relevant data for the page.
77 */ 68 */
(...skipping 22 matching lines...) Expand all
100 91
101 var title = this.querySelector('.title'); 92 var title = this.querySelector('.title');
102 title.textContent = data.title; 93 title.textContent = data.title;
103 title.dir = data.direction; 94 title.dir = data.direction;
104 95
105 var thumbnailUrl = data.thumbnailUrl || 'chrome://thumb/' + data.url; 96 var thumbnailUrl = data.thumbnailUrl || 'chrome://thumb/' + data.url;
106 this.querySelector('.thumbnail').style.backgroundImage = 97 this.querySelector('.thumbnail').style.backgroundImage =
107 url(thumbnailUrl); 98 url(thumbnailUrl);
108 99
109 this.href = data.url; 100 this.href = data.url;
110
111 this.updatePinnedState_();
112 }, 101 },
113 102
114 /** 103 /**
115 * Sets the color of the favicon dominant color bar. 104 * Sets the color of the favicon dominant color bar.
116 * @param {string} color The css-parsable value for the color. 105 * @param {string} color The css-parsable value for the color.
117 */ 106 */
118 setStripeColor: function(color) { 107 setStripeColor: function(color) {
119 this.querySelector('.color-stripe').style.backgroundColor = color; 108 this.querySelector('.color-stripe').style.backgroundColor = color;
120 }, 109 },
121 110
122 /** 111 /**
123 * Handles a click on the tile. 112 * Handles a click on the tile.
124 * @param {Event} e The click event. 113 * @param {Event} e The click event.
125 */ 114 */
126 handleClick_: function(e) { 115 handleClick_: function(e) {
127 var target = e.target; 116 if (e.target.classList.contains('close-button')) {
128 117 this.blacklist_();
129 // Don't navigate on edit bar clicks.
130 if (this.querySelector('.edit-bar').contains(target))
131 e.preventDefault(); 118 e.preventDefault();
132
133 if (target.classList.contains('pin')) {
134 this.setPinned_(!this.data_.pinned);
135 } else if (target.classList.contains('remove')) {
136 this.blacklist_();
137 } else { 119 } else {
138 chrome.send('recordInHistogram', ['NTP_MostVisited', this.index, 8]); 120 chrome.send('recordInHistogram', ['NTP_MostVisited', this.index, 8]);
139 } 121 }
140 }, 122 },
141 123
142 /** 124 /**
143 * Allow blacklisting most visited site using the keyboard. 125 * Allow blacklisting most visited site using the keyboard.
144 */ 126 */
145 handleKeyDown_: function(e) { 127 handleKeyDown_: function(e) {
146 if (!IS_MAC && e.keyCode == 46 || // Del 128 if (!IS_MAC && e.keyCode == 46 || // Del
147 IS_MAC && e.metaKey && e.keyCode == 8) { // Cmd + Backspace 129 IS_MAC && e.metaKey && e.keyCode == 8) { // Cmd + Backspace
148 this.blacklist_(); 130 this.blacklist_();
149 } 131 }
150 }, 132 },
151 133
152 /** 134 /**
153 * Changes the visual state of the page and updates the model.
154 */
155 setPinned_: function(pinned) {
156 var data = this.data_;
157 data.pinned = pinned;
158 if (data.pinned) {
159 chrome.send('addPinnedURL', [
160 data.url,
161 data.title,
162 data.faviconUrl || '',
163 data.thumbnailUrl || '',
164 // TODO(estade): should not need to convert index to string.
165 String(this.index)
166 ]);
167 } else {
168 chrome.send('removePinnedURL', [data.url]);
169 }
170
171 this.updatePinnedState_();
172 },
173
174 /**
175 * Updates the DOM for the current pinned state.
176 */
177 updatePinnedState_: function() {
178 if (this.data_.pinned) {
179 this.classList.add('pinned');
180 this.querySelector('.pin').title = templateData.unpinthumbnailtooltip;
181 } else {
182 this.classList.remove('pinned');
183 this.querySelector('.pin').title = templateData.pinthumbnailtooltip;
184 }
185 },
186
187 /**
188 * Permanently removes a page from Most Visited. 135 * Permanently removes a page from Most Visited.
189 */ 136 */
190 blacklist_: function() { 137 blacklist_: function() {
191 this.showUndoNotification_(); 138 this.showUndoNotification_();
192 chrome.send('blacklistURLFromMostVisited', [this.data_.url]); 139 chrome.send('blacklistURLFromMostVisited', [this.data_.url]);
193 this.reset(); 140 this.reset();
194 chrome.send('getMostVisited'); 141 chrome.send('getMostVisited');
195 }, 142 },
196 143
197 showUndoNotification_: function() { 144 showUndoNotification_: function() {
198 var data = this.data_; 145 var data = this.data_;
199 var pinned = data.pinned;
200 var self = this; 146 var self = this;
201 var doUndo = function () { 147 var doUndo = function () {
202 chrome.send('removeURLsFromMostVisitedBlacklist', [data.url]); 148 chrome.send('removeURLsFromMostVisitedBlacklist', [data.url]);
203 self.updateForData(data); 149 self.updateForData(data);
204 self.setPinned_(data.pinned);
205 // chrome.send('getMostVisited');
206 } 150 }
207 151
208 var undo = { 152 var undo = {
209 action: doUndo, 153 action: doUndo,
210 text: templateData.undothumbnailremove, 154 text: templateData.undothumbnailremove,
211 } 155 }
212 156
213 var undoAll = { 157 var undoAll = {
214 action: function() { 158 action: function() {
215 chrome.send('clearMostVisitedURLsBlacklist', []); 159 chrome.send('clearMostVisitedURLsBlacklist', []);
(...skipping 29 matching lines...) Expand all
245 // TODO(estade): Change these to real values. 189 // TODO(estade): Change these to real values.
246 // The smallest a tile can be. 190 // The smallest a tile can be.
247 minTileWidth: 200, 191 minTileWidth: 200,
248 // The biggest a tile can be. 192 // The biggest a tile can be.
249 maxTileWidth: 240, 193 maxTileWidth: 240,
250 }; 194 };
251 TilePage.initGridValues(mostVisitedPageGridValues); 195 TilePage.initGridValues(mostVisitedPageGridValues);
252 196
253 /** 197 /**
254 * Calculates the height for a Most Visited tile for a given width. The size 198 * Calculates the height for a Most Visited tile for a given width. The size
255 * is based on the thumbnail, which should have a 212:132 ratio (the rest of 199 * is based on the thumbnail, which should have a 212:132 ratio.
256 * the arithmetic accounts for padding).
257 * @return {number} The height. 200 * @return {number} The height.
258 */ 201 */
259 function heightForWidth(width) { 202 function heightForWidth(width) {
260 return (width - 2) * 132 / 212 + 48; 203 // The 2s are for borders, the 23 is for the title.
204 return (width - 2) * 132 / 212 + 2 + 23;
261 } 205 }
262 206
263 var THUMBNAIL_COUNT = 8; 207 var THUMBNAIL_COUNT = 8;
264 208
265 /** 209 /**
266 * Creates a new MostVisitedPage object. 210 * Creates a new MostVisitedPage object.
267 * @constructor 211 * @constructor
268 * @extends {TilePage} 212 * @extends {TilePage}
269 */ 213 */
270 function MostVisitedPage() { 214 function MostVisitedPage() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 this.data_ = data.slice(0, THUMBNAIL_COUNT); 268 this.data_ = data.slice(0, THUMBNAIL_COUNT);
325 } else { 269 } else {
326 this.data_ = refreshData(this.data_, data); 270 this.data_ = refreshData(this.data_, data);
327 } 271 }
328 272
329 this.updateTiles_(); 273 this.updateTiles_();
330 }, 274 },
331 275
332 /** @inheritDoc */ 276 /** @inheritDoc */
333 shouldAcceptDrag: function(dataTransfer) { 277 shouldAcceptDrag: function(dataTransfer) {
334 return this.contains(ntp4.getCurrentlyDraggingTile()); 278 return false;
335 }, 279 },
336 280
337 /** @inheritDoc */ 281 /** @inheritDoc */
338 heightForWidth: heightForWidth, 282 heightForWidth: heightForWidth,
339 }; 283 };
340 284
341 /** 285 /**
342 * We've gotten additional Most Visited data. Update our old data with the 286 * We've gotten additional Most Visited data. Update our old data with the
343 * new data. The ordering of the new data is not important, except when a 287 * new data. The ordering of the new data is not important, except when a
344 * page is pinned. Thus we try to minimize re-ordering. 288 * page is pinned. Thus we try to minimize re-ordering.
csilv 2011/07/12 21:31:09 nit: remove reference to a pinned item in the comm
345 * @param {Object} oldData The current Most Visited page list. 289 * @param {Object} oldData The current Most Visited page list.
346 * @param {Object} newData The new Most Visited page list. 290 * @param {Object} newData The new Most Visited page list.
347 * @return The merged page list that should replace the current page list. 291 * @return The merged page list that should replace the current page list.
348 */ 292 */
349 function refreshData(oldData, newData) { 293 function refreshData(oldData, newData) {
350 oldData = oldData.slice(0, THUMBNAIL_COUNT); 294 oldData = oldData.slice(0, THUMBNAIL_COUNT);
351 newData = newData.slice(0, THUMBNAIL_COUNT); 295 newData = newData.slice(0, THUMBNAIL_COUNT);
352 296
353 // Copy over pinned sites directly. 297 // Copy over pinned sites directly.
csilv 2011/07/12 21:31:09 This block is obsolete.
Evan Stade 2011/07/12 21:47:29 it doesn't do any harm so I left it there for now.
354 for (var j = 0; j < newData.length; j++) { 298 for (var j = 0; j < newData.length; j++) {
355 if (newData[j].pinned) { 299 if (newData[j].pinned) {
356 oldData[j] = newData[j]; 300 oldData[j] = newData[j];
357 // Mark the entry as 'updated' so we don't try to update again. 301 // Mark the entry as 'updated' so we don't try to update again.
358 oldData[j].updated = true; 302 oldData[j].updated = true;
359 // Mark the newData page as 'used' so we don't try to re-use it. 303 // Mark the newData page as 'used' so we don't try to re-use it.
360 newData[j].used = true; 304 newData[j].used = true;
361 } 305 }
362 } 306 }
363 307
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (tile) 358 if (tile)
415 tile.setStripeColor(color); 359 tile.setStripeColor(color);
416 }; 360 };
417 361
418 return { 362 return {
419 MostVisitedPage: MostVisitedPage, 363 MostVisitedPage: MostVisitedPage,
420 refreshData: refreshData, 364 refreshData: refreshData,
421 setFaviconDominantColor: setFaviconDominantColor, 365 setFaviconDominantColor: setFaviconDominantColor,
422 }; 366 };
423 }); 367 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/most_visited_page.css ('k') | chrome/browser/resources/ntp4/new_tab.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698