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

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

Issue 7031078: Retry r88137: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for test failures Created 9 years, 6 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 /**
11 */
12 var tileID = 0;
13
14 /**
11 * Creates a new Most Visited object for tiling. 15 * Creates a new Most Visited object for tiling.
12 * @constructor 16 * @constructor
13 * @extends {HTMLAnchorElement} 17 * @extends {HTMLAnchorElement}
14 */ 18 */
15 function MostVisited() { 19 function MostVisited() {
16 var el = cr.doc.createElement('a'); 20 var el = cr.doc.createElement('a');
17 el.__proto__ = MostVisited.prototype; 21 el.__proto__ = MostVisited.prototype;
18 el.initialize(); 22 el.initialize();
19 23
20 return el; 24 return el;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // thumbnail-shield provides a gradient fade effect. 60 // thumbnail-shield provides a gradient fade effect.
57 '<div class="thumbnail-shield fills-parent"></div>' + 61 '<div class="thumbnail-shield fills-parent"></div>' +
58 '</span>' + 62 '</span>' +
59 '<span class="color-bar"></span>' + 63 '<span class="color-bar"></span>' +
60 '</span>' + 64 '</span>' +
61 '<span class="title"></span>' + 65 '<span class="title"></span>' +
62 '</div>'; 66 '</div>';
63 67
64 this.tabIndex = -1; 68 this.tabIndex = -1;
65 this.data_ = null; 69 this.data_ = null;
70 this.removeAttribute('id');
66 }, 71 },
67 72
68 /** 73 /**
69 * Update the appearance of this tile according to |data|. 74 * Update the appearance of this tile according to |data|.
70 * @param {Object} data A dictionary of relevant data for the page. 75 * @param {Object} data A dictionary of relevant data for the page.
71 */ 76 */
72 updateForData: function(data) { 77 updateForData: function(data) {
73 if (!data || data.filler) { 78 if (!data || data.filler) {
74 if (this.data_) 79 if (this.data_)
75 this.reset(); 80 this.reset();
76 return; 81 return;
77 } 82 }
78 83
84 var id = tileID++;
85 this.setAttribute('id', 'tile' + id);
79 this.data_ = data; 86 this.data_ = data;
80 this.tabIndex = 0; 87 this.tabIndex = 0;
81 this.classList.remove('filler'); 88 this.classList.remove('filler');
82 89
83 var colorBar = this.querySelector('.color-bar'); 90 var colorBar = this.querySelector('.color-bar');
84 var faviconUrl = data.faviconUrl || 'chrome://favicon/' + data.url; 91 var faviconUrl = data.faviconUrl || 'chrome://favicon/' + data.url;
85 colorBar.style.backgroundImage = url(faviconUrl); 92 colorBar.style.backgroundImage = url(faviconUrl);
86 colorBar.dir = data.direction; 93 colorBar.dir = data.direction;
87 // TODO(estade): add a band of color based on the favicon. 94 if (data.faviconDominantColor)
95 this.setBarColor(data.faviconDominantColor);
96 else
97 chrome.send('getFaviconDominantColor', [faviconUrl, id]);
88 98
89 var title = this.querySelector('.title'); 99 var title = this.querySelector('.title');
90 title.textContent = data.title; 100 title.textContent = data.title;
91 title.dir = data.direction; 101 title.dir = data.direction;
92 102
93 var thumbnailUrl = data.thumbnailUrl || 'chrome://thumb/' + data.url; 103 var thumbnailUrl = data.thumbnailUrl || 'chrome://thumb/' + data.url;
94 this.querySelector('.thumbnail').style.backgroundImage = 104 this.querySelector('.thumbnail').style.backgroundImage =
95 url(thumbnailUrl); 105 url(thumbnailUrl);
96 106
97 this.href = data.url; 107 this.href = data.url;
98 108
99 this.updatePinnedState_(); 109 this.updatePinnedState_();
100 }, 110 },
101 111
102 /** 112 /**
113 * Sets the color of the favicon dominant color bar.
114 * @param {string} color The css-parsable value for the color.
115 */
116 setBarColor: function(color) {
117 // TODO(estade): use color.
118 },
119
120 /**
103 * Handles a click on the tile. 121 * Handles a click on the tile.
104 * @param {Event} e The click event. 122 * @param {Event} e The click event.
105 */ 123 */
106 handleClick_: function(e) { 124 handleClick_: function(e) {
107 var target = e.target; 125 var target = e.target;
108 126
109 // Don't navigate on edit bar clicks. 127 // Don't navigate on edit bar clicks.
110 if (this.querySelector('.edit-bar').contains(target)) 128 if (this.querySelector('.edit-bar').contains(target))
111 e.preventDefault(); 129 e.preventDefault();
112 130
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 401
384 // Clear 'updated' flags so this function will work next time it's called. 402 // Clear 'updated' flags so this function will work next time it's called.
385 for (var i = 0; i < THUMBNAIL_COUNT; i++) { 403 for (var i = 0; i < THUMBNAIL_COUNT; i++) {
386 if (oldData[i]) 404 if (oldData[i])
387 oldData[i].updated = false; 405 oldData[i].updated = false;
388 } 406 }
389 407
390 return oldData; 408 return oldData;
391 }; 409 };
392 410
411 function setFaviconDominantColor(id, color) {
412 var tile = $('tile' + id);
413 if (tile)
414 tile.setBarColor(color);
415 };
416
393 return { 417 return {
394 MostVisitedPage: MostVisitedPage, 418 MostVisitedPage: MostVisitedPage,
395 refreshData: refreshData, 419 refreshData: refreshData,
420 setFaviconDominantColor: setFaviconDominantColor,
396 }; 421 };
397 }); 422 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698