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

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

Issue 7592001: ntp4: most visited dragging onto apps page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: most visited polish Created 9 years, 4 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 21 matching lines...) Expand all
32 32
33 this.addEventListener('click', this.handleClick_.bind(this)); 33 this.addEventListener('click', this.handleClick_.bind(this));
34 this.addEventListener('keydown', this.handleKeyDown_.bind(this)); 34 this.addEventListener('keydown', this.handleKeyDown_.bind(this));
35 }, 35 },
36 36
37 get index() { 37 get index() {
38 assert(this.tile); 38 assert(this.tile);
39 return this.tile.index; 39 return this.tile.index;
40 }, 40 },
41 41
42 get data() {
43 return this.data_;
44 },
45
42 /** 46 /**
43 * Clears the DOM hierarchy for this node, setting it back to the default 47 * Clears the DOM hierarchy for this node, setting it back to the default
44 * for a blank thumbnail. 48 * for a blank thumbnail.
45 */ 49 */
46 reset: function() { 50 reset: function() {
47 this.className = 'most-visited filler real'; 51 this.className = 'most-visited filler real';
48 this.innerHTML = 52 this.innerHTML =
49 '<span class="thumbnail-wrapper fills-parent">' + 53 '<span class="thumbnail-wrapper fills-parent">' +
50 '<div class="close-button"></div>' + 54 '<div class="close-button"></div>' +
51 '<span class="thumbnail fills-parent">' + 55 '<span class="thumbnail fills-parent">' +
52 // thumbnail-shield provides a gradient fade effect. 56 // thumbnail-shield provides a gradient fade effect.
53 '<div class="thumbnail-shield fills-parent"></div>' + 57 '<div class="thumbnail-shield fills-parent"></div>' +
54 '</span>' + 58 '</span>' +
55 '<span class="favicon"></span>' + 59 '<span class="favicon"></span>' +
56 '</span>' + 60 '</span>' +
57 '<div class="color-stripe"></div>' + 61 '<div class="color-stripe"></div>' +
58 '<span class="title"></span>'; 62 '<span class="title"></span>';
59 63
60 this.removeAttribute('tabIndex'); 64 this.removeAttribute('tabIndex');
61 this.data_ = null; 65 this.data_ = null;
62 this.removeAttribute('id'); 66 this.removeAttribute('id');
63 }, 67 },
64 68
65 /** 69 /**
66 * Update the appearance of this tile according to |data|. 70 * Update the appearance of this tile according to |data|.
67 * @param {Object} data A dictionary of relevant data for the page. 71 * @param {Object} data A dictionary of relevant data for the page.
68 */ 72 */
69 updateForData: function(data) { 73 updateForData: function(data) {
74 if (this.classList.contains('blacklisted') && data) {
75 // Animate appearance of new tile.
76 this.classList.add('new-tile-contents');
77 }
78 this.classList.remove('blacklisted');
79
70 if (!data || data.filler) { 80 if (!data || data.filler) {
71 if (this.data_) 81 if (this.data_)
72 this.reset(); 82 this.reset();
73 return; 83 return;
74 } 84 }
75 85
76 var id = tileID++; 86 var id = tileID++;
77 this.setAttribute('id', 'tile' + id); 87 this.setAttribute('id', 'tile' + id);
78 this.data_ = data; 88 this.data_ = data;
79 // TODO(estade): this shouldn't be focusable if the page isn't showing. 89 // TODO(estade): this shouldn't be focusable if the page isn't showing.
80 this.tabIndex = 0; 90 this.tabIndex = 0;
81 this.classList.remove('filler');
82 91
83 var faviconDiv = this.querySelector('.favicon'); 92 var faviconDiv = this.querySelector('.favicon');
84 var faviconUrl = data.faviconUrl || 93 var faviconUrl = data.faviconUrl ||
85 'chrome://favicon/size/32/' + data.url; 94 'chrome://favicon/size/32/' + data.url;
86 faviconDiv.style.backgroundImage = url(faviconUrl); 95 faviconDiv.style.backgroundImage = url(faviconUrl);
87 faviconDiv.dir = data.direction; 96 faviconDiv.dir = data.direction;
88 if (data.faviconDominantColor) 97 if (data.faviconDominantColor)
89 this.setStripeColor(data.faviconDominantColor); 98 this.setStripeColor(data.faviconDominantColor);
90 else 99 else
91 chrome.send('getFaviconDominantColor', [faviconUrl, id]); 100 chrome.send('getFaviconDominantColor', [faviconUrl, id]);
92 101
93 var title = this.querySelector('.title'); 102 var title = this.querySelector('.title');
94 title.textContent = data.title; 103 title.textContent = data.title;
95 title.dir = data.direction; 104 title.dir = data.direction;
96 105
97 var thumbnailUrl = data.thumbnailUrl || 'chrome://thumb/' + data.url; 106 var thumbnailUrl = data.thumbnailUrl || 'chrome://thumb/' + data.url;
98 this.querySelector('.thumbnail').style.backgroundImage = 107 this.querySelector('.thumbnail').style.backgroundImage =
99 url(thumbnailUrl); 108 url(thumbnailUrl);
100 109
101 this.href = data.url; 110 this.href = data.url;
111
112 this.classList.remove('filler');
102 }, 113 },
103 114
104 /** 115 /**
105 * Sets the color of the favicon dominant color bar. 116 * Sets the color of the favicon dominant color bar.
106 * @param {string} color The css-parsable value for the color. 117 * @param {string} color The css-parsable value for the color.
107 */ 118 */
108 setStripeColor: function(color) { 119 setStripeColor: function(color) {
109 this.querySelector('.color-stripe').style.backgroundColor = color; 120 this.querySelector('.color-stripe').style.backgroundColor = color;
110 }, 121 },
111 122
(...skipping 29 matching lines...) Expand all
141 }, 152 },
142 153
143 /** 154 /**
144 * Permanently removes a page from Most Visited. 155 * Permanently removes a page from Most Visited.
145 */ 156 */
146 blacklist_: function() { 157 blacklist_: function() {
147 this.showUndoNotification_(); 158 this.showUndoNotification_();
148 chrome.send('blacklistURLFromMostVisited', [this.data_.url]); 159 chrome.send('blacklistURLFromMostVisited', [this.data_.url]);
149 this.reset(); 160 this.reset();
150 chrome.send('getMostVisited'); 161 chrome.send('getMostVisited');
162 this.classList.add('blacklisted');
151 }, 163 },
152 164
153 showUndoNotification_: function() { 165 showUndoNotification_: function() {
154 var data = this.data_; 166 var data = this.data_;
155 var self = this; 167 var self = this;
156 var doUndo = function () { 168 var doUndo = function () {
157 chrome.send('removeURLsFromMostVisitedBlacklist', [data.url]); 169 chrome.send('removeURLsFromMostVisitedBlacklist', [data.url]);
158 self.updateForData(data); 170 self.updateForData(data);
159 } 171 }
160 172
(...skipping 21 matching lines...) Expand all
182 * animate. 194 * animate.
183 */ 195 */
184 setBounds: function(size, x, y) { 196 setBounds: function(size, x, y) {
185 this.style.width = size + 'px'; 197 this.style.width = size + 'px';
186 this.style.height = heightForWidth(size) + 'px'; 198 this.style.height = heightForWidth(size) + 'px';
187 199
188 this.style.left = x + 'px'; 200 this.style.left = x + 'px';
189 this.style.right = x + 'px'; 201 this.style.right = x + 'px';
190 this.style.top = y + 'px'; 202 this.style.top = y + 'px';
191 }, 203 },
204
205 /**
206 * Returns whether this element can be 'removed' from chrome (i.e. whether
207 * the user can drag it onto the trash and expect something to happen).
208 * @return {boolean} True, since most visited pages can always be
209 * blacklisted.
210 */
211 canBeRemoved: function() {
212 return true;
213 },
214
215 /**
216 * Removes this element from chrome, i.e. blacklists it.
217 */
218 removeFromChrome: function() {
219 this.blacklist_();
220 this.parentNode.classList.add('restoring');
Rick Byers 2011/08/08 15:24:15 I'm confused by the name 'restoring' in this situa
Evan Stade 2011/08/08 18:26:58 you're right, finishing-drag might make more sense
221 },
222
223 /**
224 * Called when a drag of this tile has ended (after all animations have
225 * finished).
226 */
227 finalizeDrag: function() {
228 this.parentNode.classList.remove('restoring');
229 },
192 }; 230 };
193 231
194 var mostVisitedPageGridValues = { 232 var mostVisitedPageGridValues = {
195 // The fewest tiles we will show in a row. 233 // The fewest tiles we will show in a row.
196 minColCount: 2, 234 minColCount: 2,
197 // The most tiles we will show in a row. 235 // The most tiles we will show in a row.
198 maxColCount: 4, 236 maxColCount: 4,
199 237
200 // TODO(estade): Change these to real values. 238 // TODO(estade): Change these to real values.
201 // The smallest a tile can be. 239 // The smallest a tile can be.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (tile) 409 if (tile)
372 tile.setStripeColor(color); 410 tile.setStripeColor(color);
373 }; 411 };
374 412
375 return { 413 return {
376 MostVisitedPage: MostVisitedPage, 414 MostVisitedPage: MostVisitedPage,
377 refreshData: refreshData, 415 refreshData: refreshData,
378 setFaviconDominantColor: setFaviconDominantColor, 416 setFaviconDominantColor: setFaviconDominantColor,
379 }; 417 };
380 }); 418 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698