OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
6 * Scrollable thumbnail ribbon at the bottom of the Gallery in the Slide mode. | 6 * Scrollable thumbnail ribbon at the bottom of the Gallery in the Slide mode. |
7 * | 7 * |
8 * @param {Document} document Document. | 8 * @param {!Document} document Document. |
9 * @param {cr.ui.ArrayDataModel} dataModel Data model. | 9 * @param {!cr.ui.ArrayDataModel} dataModel Data model. |
10 * @param {cr.ui.ListSelectionModel} selectionModel Selection model. | 10 * @param {!cr.ui.ListSelectionModel} selectionModel Selection model. |
11 * @return {Element} Ribbon element. | 11 * @return {!HTMLElement} Ribbon element. |
12 * @extends {HTMLElement} | |
12 * @constructor | 13 * @constructor |
14 * @suppress {checkStructDictInheritance} | |
15 * @struct | |
13 */ | 16 */ |
14 function Ribbon(document, dataModel, selectionModel) { | 17 function Ribbon(document, dataModel, selectionModel) { |
15 var self = document.createElement('div'); | 18 var self = assertInstanceof(document.createElement('div'), HTMLElement); |
16 Ribbon.decorate(self, dataModel, selectionModel); | 19 Ribbon.decorate(self, dataModel, selectionModel); |
17 return self; | 20 return self; |
18 } | 21 } |
19 | 22 |
20 /** | 23 /** |
21 * Inherit from HTMLDivElement. | 24 * Inherit from HTMLDivElement. |
22 */ | 25 */ |
23 Ribbon.prototype.__proto__ = HTMLDivElement.prototype; | 26 Ribbon.prototype.__proto__ = HTMLDivElement.prototype; |
24 | 27 |
25 /** | 28 /** |
26 * Decorate a Ribbon instance. | 29 * Decorate a Ribbon instance. |
27 * | 30 * |
28 * @param {Ribbon} self Self pointer. | 31 * @param {!HTMLElement} self Self pointer. |
29 * @param {cr.ui.ArrayDataModel} dataModel Data model. | 32 * @param {!cr.ui.ArrayDataModel} dataModel Data model. |
30 * @param {cr.ui.ListSelectionModel} selectionModel Selection model. | 33 * @param {!cr.ui.ListSelectionModel} selectionModel Selection model. |
31 */ | 34 */ |
32 Ribbon.decorate = function(self, dataModel, selectionModel) { | 35 Ribbon.decorate = function(self, dataModel, selectionModel) { |
33 self.__proto__ = Ribbon.prototype; | 36 self.__proto__ = Ribbon.prototype; |
37 self = /** @type{!Ribbon} */ (self); | |
34 self.dataModel_ = dataModel; | 38 self.dataModel_ = dataModel; |
35 self.selectionModel_ = selectionModel; | 39 self.selectionModel_ = selectionModel; |
36 | 40 |
41 /** @type {!Object} */ self.renderCache_ = {}; | |
fukino
2014/11/13 07:14:26
I like the following style to be consistent with o
yawano
2014/11/13 08:18:52
Done.
| |
42 /** @type {number} */ self.firstVisibleIndex_ = 0; | |
43 /** @type {number} */ self.lastVisibleIndex_ = -1; | |
44 /** @type {?function(!Event)} */ self.onContentBound_ = null; | |
45 /** @type {?function(!Event)} */ self.onSpliceBound_ = null; | |
46 /** @type {?function(!Event)} */ self.onSelectionBound_ = null; | |
47 /** @type {?number}*/ self.removeTimeout_ = null; | |
48 | |
37 self.className = 'ribbon'; | 49 self.className = 'ribbon'; |
38 }; | 50 }; |
39 | 51 |
40 /** | 52 /** |
41 * Max number of thumbnails in the ribbon. | 53 * Max number of thumbnails in the ribbon. |
42 * @type {number} | 54 * @type {!number} |
fukino
2014/11/13 07:14:26
number (and string, function) are non-nullable by
yawano
2014/11/13 08:18:52
Done.
| |
55 * @const | |
43 */ | 56 */ |
44 Ribbon.ITEMS_COUNT = 5; | 57 Ribbon.ITEMS_COUNT = 5; |
45 | 58 |
46 /** | 59 /** |
47 * Force redraw the ribbon. | 60 * Force redraw the ribbon. |
48 */ | 61 */ |
49 Ribbon.prototype.redraw = function() { | 62 Ribbon.prototype.redraw = function() { |
50 this.onSelection_(); | 63 this.onSelection_(); |
51 }; | 64 }; |
52 | 65 |
(...skipping 30 matching lines...) Expand all Loading... | |
83 this.dataModel_.removeEventListener('content', this.onContentBound_); | 96 this.dataModel_.removeEventListener('content', this.onContentBound_); |
84 this.dataModel_.removeEventListener('splice', this.onSpliceBound_); | 97 this.dataModel_.removeEventListener('splice', this.onSpliceBound_); |
85 this.selectionModel_.removeEventListener('change', this.onSelectionBound_); | 98 this.selectionModel_.removeEventListener('change', this.onSelectionBound_); |
86 | 99 |
87 this.removeVanishing_(); | 100 this.removeVanishing_(); |
88 this.textContent = ''; | 101 this.textContent = ''; |
89 }; | 102 }; |
90 | 103 |
91 /** | 104 /** |
92 * Data model splice handler. | 105 * Data model splice handler. |
93 * @param {Event} event Event. | 106 * @param {!Event} event Event. |
94 * @private | 107 * @private |
95 */ | 108 */ |
96 Ribbon.prototype.onSplice_ = function(event) { | 109 Ribbon.prototype.onSplice_ = function(event) { |
97 if (event.removed.length > 1) { | 110 if (event.removed.length > 1) { |
98 console.error('Cannot remove multiple items.'); | 111 console.error('Cannot remove multiple items.'); |
99 return; | 112 return; |
100 } | 113 } |
101 | 114 |
102 if (event.removed.length > 0 && event.added.length > 0) { | 115 if (event.removed.length > 0 && event.added.length > 0) { |
103 console.error('Replacing is not implemented.'); | 116 console.error('Replacing is not implemented.'); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 var vanishingNodes = this.querySelectorAll('[vanishing]'); | 303 var vanishingNodes = this.querySelectorAll('[vanishing]'); |
291 for (var i = 0; i != vanishingNodes.length; i++) { | 304 for (var i = 0; i != vanishingNodes.length; i++) { |
292 vanishingNodes[i].removeAttribute('vanishing'); | 305 vanishingNodes[i].removeAttribute('vanishing'); |
293 this.removeChild(vanishingNodes[i]); | 306 this.removeChild(vanishingNodes[i]); |
294 } | 307 } |
295 }; | 308 }; |
296 | 309 |
297 /** | 310 /** |
298 * Create a DOM element for a thumbnail. | 311 * Create a DOM element for a thumbnail. |
299 * | 312 * |
300 * @param {number} index Item index. | 313 * @param {!number} index Item index. |
fukino
2014/11/13 07:14:26
ditto
yawano
2014/11/13 08:18:52
Done.
| |
301 * @return {Element} Newly created element. | 314 * @return {!Element} Newly created element. |
302 * @private | 315 * @private |
303 */ | 316 */ |
304 Ribbon.prototype.renderThumbnail_ = function(index) { | 317 Ribbon.prototype.renderThumbnail_ = function(index) { |
305 var item = this.dataModel_.item(index); | 318 var item = this.dataModel_.item(index); |
306 var url = item.getEntry().toURL(); | 319 var url = item.getEntry().toURL(); |
307 | 320 |
308 var cached = this.renderCache_[url]; | 321 var cached = this.renderCache_[url]; |
309 if (cached) { | 322 if (cached) { |
310 var img = cached.querySelector('img'); | 323 var img = cached.querySelector('img'); |
311 if (img) | 324 if (img) |
(...skipping 16 matching lines...) Expand all Loading... | |
328 // TODO: Implement LRU eviction. | 341 // TODO: Implement LRU eviction. |
329 // Never evict the thumbnails that are currently in the DOM because we rely | 342 // Never evict the thumbnails that are currently in the DOM because we rely |
330 // on this cache to find them by URL. | 343 // on this cache to find them by URL. |
331 this.renderCache_[url] = thumbnail; | 344 this.renderCache_[url] = thumbnail; |
332 return thumbnail; | 345 return thumbnail; |
333 }; | 346 }; |
334 | 347 |
335 /** | 348 /** |
336 * Set the thumbnail image. | 349 * Set the thumbnail image. |
337 * | 350 * |
338 * @param {Element} thumbnail Thumbnail element. | 351 * @param {!Element} thumbnail Thumbnail element. |
339 * @param {Gallery.Item} item Gallery item. | 352 * @param {!Gallery.Item} item Gallery item. |
340 * @private | 353 * @private |
341 */ | 354 */ |
342 Ribbon.prototype.setThumbnailImage_ = function(thumbnail, item) { | 355 Ribbon.prototype.setThumbnailImage_ = function(thumbnail, item) { |
343 var loader = new ThumbnailLoader( | 356 var loader = new ThumbnailLoader( |
344 item.getEntry(), | 357 item.getEntry(), |
345 ThumbnailLoader.LoaderType.IMAGE, | 358 ThumbnailLoader.LoaderType.IMAGE, |
346 item.getMetadata()); | 359 item.getMetadata()); |
347 loader.load( | 360 loader.load( |
348 thumbnail.querySelector('.image-wrapper'), | 361 thumbnail.querySelector('.image-wrapper'), |
349 ThumbnailLoader.FillMode.FILL /* fill */, | 362 ThumbnailLoader.FillMode.FILL /* fill */, |
350 ThumbnailLoader.OptimizationMode.NEVER_DISCARD); | 363 ThumbnailLoader.OptimizationMode.NEVER_DISCARD); |
351 }; | 364 }; |
352 | 365 |
353 /** | 366 /** |
354 * Content change handler. | 367 * Content change handler. |
355 * | 368 * |
356 * @param {Event} event Event. | 369 * @param {!Event} event Event. |
357 * @private | 370 * @private |
358 */ | 371 */ |
359 Ribbon.prototype.onContentChange_ = function(event) { | 372 Ribbon.prototype.onContentChange_ = function(event) { |
360 var url = event.item.getEntry().toURL(); | 373 var url = event.item.getEntry().toURL(); |
361 if (event.oldEntry.toURL() !== url) | 374 if (event.oldEntry.toURL() !== url) |
362 this.remapCache_(event.oldEntry.toURL(), url); | 375 this.remapCache_(event.oldEntry.toURL(), url); |
363 | 376 |
364 var thumbnail = this.renderCache_[url]; | 377 var thumbnail = this.renderCache_[url]; |
365 if (thumbnail && event.item) | 378 if (thumbnail && event.item) |
366 this.setThumbnailImage_(thumbnail, event.item); | 379 this.setThumbnailImage_(thumbnail, event.item); |
367 }; | 380 }; |
368 | 381 |
369 /** | 382 /** |
370 * Update the thumbnail element cache. | 383 * Update the thumbnail element cache. |
371 * | 384 * |
372 * @param {string} oldUrl Old url. | 385 * @param {!string} oldUrl Old url. |
fukino
2014/11/13 07:14:26
ditto
yawano
2014/11/13 08:18:52
Done.
| |
373 * @param {string} newUrl New url. | 386 * @param {!string} newUrl New url. |
fukino
2014/11/13 07:14:26
ditto
yawano
2014/11/13 08:18:52
Done.
| |
374 * @private | 387 * @private |
375 */ | 388 */ |
376 Ribbon.prototype.remapCache_ = function(oldUrl, newUrl) { | 389 Ribbon.prototype.remapCache_ = function(oldUrl, newUrl) { |
377 if (oldUrl != newUrl && (oldUrl in this.renderCache_)) { | 390 if (oldUrl != newUrl && (oldUrl in this.renderCache_)) { |
378 this.renderCache_[newUrl] = this.renderCache_[oldUrl]; | 391 this.renderCache_[newUrl] = this.renderCache_[oldUrl]; |
379 delete this.renderCache_[oldUrl]; | 392 delete this.renderCache_[oldUrl]; |
380 } | 393 } |
381 }; | 394 }; |
OLD | NEW |