OLD | NEW |
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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * FileGrid constructor. | 8 * FileGrid constructor. |
9 * | 9 * |
10 * Represents grid for the Grid Vew in the File Manager. | 10 * Represents grid for the Grid Vew in the File Manager. |
(...skipping 22 matching lines...) Expand all Loading... |
33 self.metadataCache_ = metadataCache; | 33 self.metadataCache_ = metadataCache; |
34 | 34 |
35 if (util.platform.newUI()) | 35 if (util.platform.newUI()) |
36 ScrollBar.createVertical(self.parentNode, self); | 36 ScrollBar.createVertical(self.parentNode, self); |
37 | 37 |
38 self.itemConstructor = function(entry) { | 38 self.itemConstructor = function(entry) { |
39 var item = self.ownerDocument.createElement('LI'); | 39 var item = self.ownerDocument.createElement('LI'); |
40 FileGrid.Item.decorate(item, entry, self); | 40 FileGrid.Item.decorate(item, entry, self); |
41 return item; | 41 return item; |
42 }; | 42 }; |
| 43 |
| 44 self.relayoutAggregation_ = |
| 45 new AsyncUtil.Aggregation(self.relayoutImmediately_.bind(self)); |
43 }; | 46 }; |
44 | 47 |
45 /** | 48 /** |
46 * Updates items to reflect metadata changes. | 49 * Updates items to reflect metadata changes. |
47 * @param {string} type Type of metadata changed. | 50 * @param {string} type Type of metadata changed. |
48 * @param {Object<string, Object>} props Map from entry URLs to metadata props. | 51 * @param {Object<string, Object>} props Map from entry URLs to metadata props. |
49 */ | 52 */ |
50 FileGrid.prototype.updateListItemsMetadata = function(type, props) { | 53 FileGrid.prototype.updateListItemsMetadata = function(type, props) { |
51 var boxes = this.querySelectorAll('.img-container'); | 54 var boxes = this.querySelectorAll('.img-container'); |
52 for (var i = 0; i < boxes.length; i++) { | 55 for (var i = 0; i < boxes.length; i++) { |
53 var box = boxes[i]; | 56 var box = boxes[i]; |
54 var entry = this.dataModel.item(this.getListItemAncestor(box)); | 57 var entry = this.dataModel.item(this.getListItemAncestor(box)); |
55 if (!entry || !(entry.toURL() in props)) | 58 if (!entry || !(entry.toURL() in props)) |
56 continue; | 59 continue; |
57 | 60 |
58 FileGrid.decorateThumbnailBox(box, entry, this.metadataCache_, | 61 FileGrid.decorateThumbnailBox(box, entry, this.metadataCache_, |
59 ThumbnailLoader.FillMode.FIT); | 62 ThumbnailLoader.FillMode.FIT); |
60 } | 63 } |
61 }; | 64 }; |
62 | 65 |
63 /** | 66 /** |
64 * Redraws the UI. Skips multiple consecutive calls. | 67 * Redraws the UI. Skips multiple consecutive calls. |
65 */ | 68 */ |
66 FileGrid.prototype.relayout = function() { | 69 FileGrid.prototype.relayout = function() { |
67 if (this.resizeGridTimer_) { | 70 this.relayoutAggregation_.run(); |
68 clearTimeout(this.resizeGridTimer_); | |
69 this.resizeGridTimer_ = null; | |
70 } | |
71 this.resizeGridTimer_ = setTimeout(function() { | |
72 this.startBatchUpdates(); | |
73 this.columns = 0; | |
74 this.redraw(); | |
75 cr.dispatchSimpleEvent(this, 'relayout'); | |
76 this.endBatchUpdates(); | |
77 this.resizeGridTimer_ = null; | |
78 }.bind(this), 100); | |
79 }; | 71 }; |
80 | 72 |
81 /** | 73 /** |
| 74 * Redraws the UI immediately. |
| 75 * @private |
| 76 */ |
| 77 FileGrid.prototype.relayoutImmediately_ = function() { |
| 78 this.startBatchUpdates(); |
| 79 this.columns = 0; |
| 80 this.redraw(); |
| 81 this.endBatchUpdates(); |
| 82 cr.dispatchSimpleEvent(this, 'relayout'); |
| 83 }; |
| 84 |
| 85 /** |
82 * Decorates thumbnail. | 86 * Decorates thumbnail. |
83 * @param {HTMLElement} li List item. | 87 * @param {HTMLElement} li List item. |
84 * @param {Entry} entry Entry to render a thumbnail for. | 88 * @param {Entry} entry Entry to render a thumbnail for. |
85 * @param {MetadataCache} metadataCache To retrieve metadata. | 89 * @param {MetadataCache} metadataCache To retrieve metadata. |
86 */ | 90 */ |
87 FileGrid.decorateThumbnail = function(li, entry, metadataCache) { | 91 FileGrid.decorateThumbnail = function(li, entry, metadataCache) { |
88 li.className = 'thumbnail-item'; | 92 li.className = 'thumbnail-item'; |
89 filelist.decorateListItem(li, entry, metadataCache); | 93 filelist.decorateListItem(li, entry, metadataCache); |
90 | 94 |
91 var frame = li.ownerDocument.createElement('div'); | 95 var frame = li.ownerDocument.createElement('div'); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 checkBox.classList.add('white'); | 201 checkBox.classList.add('white'); |
198 var bottom = li.querySelector('.thumbnail-bottom'); | 202 var bottom = li.querySelector('.thumbnail-bottom'); |
199 bottom.appendChild(checkBox); | 203 bottom.appendChild(checkBox); |
200 bottom.classList.add('show-checkbox'); | 204 bottom.classList.add('show-checkbox'); |
201 } | 205 } |
202 | 206 |
203 // Override the default role 'listitem' to 'option' to match the parent's | 207 // Override the default role 'listitem' to 'option' to match the parent's |
204 // role (listbox). | 208 // role (listbox). |
205 li.setAttribute('role', 'option'); | 209 li.setAttribute('role', 'option'); |
206 }; | 210 }; |
OLD | NEW |