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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_table.js

Issue 14096016: Restyled Files.app's file list, including scrollbars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 8 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) 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 * Namespace for utility functions. 8 * Namespace for utility functions.
9 */ 9 */
10 var filelist = {}; 10 var filelist = {};
11 11
12 /** 12 /**
13 * Custom column model for advanced auto-resizing.
14 *
15 * @param {Array.<cr.ui.table.TableColumn>} tableColumns Table columns.
16 * @extends {cr.ui.table.TableColumnModel}
17 * @constructor
18 */
19 function FileTableColumnModel(tableColumns) {
20 cr.ui.table.TableColumnModel.call(this, tableColumns);
21 }
22
23 /**
24 * Inherits from cr.ui.Table.
25 */
26 FileTableColumnModel.prototype.__proto__ =
27 cr.ui.table.TableColumnModel.prototype;
28
29 /**
30 * Normalizes widths to make their sum 100%. Uses the proportional approach
31 * with some additional constraints.
32 *
33 * @param {number} contentWidth Target width.
34 * @override
35 */
36 FileTableColumnModel.prototype.normalizeWidths = function(contentWidth) {
37 var fixedWidth = 0;
38 var flexibleWidth = 0;
39
40 // Some columns have fixed width.
41 for (var index = 0; index < this.size; index++) {
42 var column = this.columns_[index];
43 if (column.id == 'selection')
44 fixedWidth += column.width;
45 else
46 flexibleWidth += column.width;
47 }
48
49 var factor = (contentWidth - fixedWidth) / flexibleWidth;
50 for (var index = 0; index < this.size; index++) {
51 var column = this.columns_[index];
52 if (column.id == 'selection')
53 continue;
54 column.width = column.width * factor;
55 }
56 };
57
58 /**
13 * File list Table View. 59 * File list Table View.
14 * @constructor 60 * @constructor
15 */ 61 */
16 function FileTable() { 62 function FileTable() {
17 throw new Error('Designed to decorate elements'); 63 throw new Error('Designed to decorate elements');
18 } 64 }
19 65
20 /** 66 /**
21 * Inherits from cr.ui.Table. 67 * Inherits from cr.ui.Table.
22 */ 68 */
23 FileTable.prototype.__proto__ = cr.ui.Table.prototype; 69 FileTable.prototype.__proto__ = cr.ui.Table.prototype;
24 70
25 /** 71 /**
26 * Decorates the element. 72 * Decorates the element.
27 * @param {HTMLElement} self Table to decorate. 73 * @param {HTMLElement} self Table to decorate.
28 * @param {MetadataCache} metadataCache To retrieve metadata. 74 * @param {MetadataCache} metadataCache To retrieve metadata.
29 * @param {boolean} fullPage True if it's full page File Manager, 75 * @param {boolean} fullPage True if it's full page File Manager,
30 * False if a file open/save dialog. 76 * False if a file open/save dialog.
31 */ 77 */
32 FileTable.decorate = function(self, metadataCache, fullPage) { 78 FileTable.decorate = function(self, metadataCache, fullPage) {
33 cr.ui.Table.decorate(self); 79 cr.ui.Table.decorate(self);
34 self.__proto__ = FileTable.prototype; 80 self.__proto__ = FileTable.prototype;
35 self.metadataCache_ = metadataCache; 81 self.metadataCache_ = metadataCache;
36 self.collator_ = v8Intl.Collator([], {numeric: true, sensitivity: 'base'}); 82 self.collator_ = v8Intl.Collator([], {numeric: true, sensitivity: 'base'});
37 83
38 var columns = [ 84 var columns = [
39 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), 85 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'),
40 fullPage ? 386 : 324), 86 fullPage ? 386 : 324),
41 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), 87 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'),
42 fullPage ? 100 : 92, true), 88 fullPage ? 100 : 92, true),
43 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'), 89 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'),
44 fullPage ? 160 : 160), 90 fullPage ? 160 : 160),
45 new cr.ui.table.TableColumn('modificationTime', 91 new cr.ui.table.TableColumn('modificationTime',
46 str('DATE_COLUMN_LABEL'), 92 str('DATE_COLUMN_LABEL'),
47 fullPage ? 150 : 210), 93 fullPage ? 150 : 210)
48 new cr.ui.table.TableColumn('offline', 94 ];
49 str('OFFLINE_COLUMN_LABEL'),
50 130)
51 ];
52 95
53 columns[0].renderFunction = self.renderName_.bind(self); 96 columns[0].renderFunction = self.renderName_.bind(self);
54 columns[1].renderFunction = self.renderSize_.bind(self); 97 columns[1].renderFunction = self.renderSize_.bind(self);
55 columns[1].defaultOrder = 'desc'; 98 columns[1].defaultOrder = 'desc';
56 columns[2].renderFunction = self.renderType_.bind(self); 99 columns[2].renderFunction = self.renderType_.bind(self);
57 columns[3].renderFunction = self.renderDate_.bind(self); 100 columns[3].renderFunction = self.renderDate_.bind(self);
58 columns[3].defaultOrder = 'desc'; 101 columns[3].defaultOrder = 'desc';
59 columns[4].renderFunction = self.renderOffline_.bind(self);
60 102
61 columns[0].headerRenderFunction = 103 var tableColumnModelClass;
62 self.renderNameColumnHeader_.bind(self, columns[0].name); 104 if (util.platform.newUI()) {
105 tableColumnModelClass = FileTableColumnModel;
106 columns.push(new cr.ui.table.TableColumn('selection',
107 '',
108 50, true));
109 columns[4].renderFunction = self.renderSelection_.bind(self);
110 columns[4].headerRenderFunction =
111 self.renderSelectionColumnHeader_.bind(self);
112 } else {
113 tableColumnModelClass = cr.ui.table.TableColumnModel;
114 columns.push(new cr.ui.table.TableColumn('offline',
115 str('OFFLINE_COLUMN_LABEL'),
116 130));
117 columns[4].renderFunction = self.renderOffline_.bind(self);
118 columns[0].headerRenderFunction =
119 self.renderNameColumnHeader_.bind(self, columns[0].name);
120 }
63 121
64 var columnModel = Object.create(cr.ui.table.TableColumnModel.prototype, { 122 var columnModel = Object.create(tableColumnModelClass.prototype, {
65 size: { 123 size: {
66 get: function() { 124 get: function() {
125 if (util.platform.newUI())
126 return this.totalSize;
67 return this.showOfflineColumn ? this.totalSize : this.totalSize - 1; 127 return this.showOfflineColumn ? this.totalSize : this.totalSize - 1;
68 } 128 }
69 }, 129 },
70 130
71 totalSize: { 131 totalSize: {
72 get: function() { 132 get: function() {
73 return columns.length; 133 return columns.length;
74 } 134 }
75 }, 135 },
76 136
77 showOfflineColumn: { 137 showOfflineColumn: {
78 writable: true, 138 writable: true,
79 value: false 139 value: false
80 } 140 }
81 }); 141 });
82 cr.ui.table.TableColumnModel.call(columnModel, columns); 142
143 tableColumnModelClass.call(columnModel, columns);
83 self.columnModel = columnModel; 144 self.columnModel = columnModel;
84 self.setDateTimeFormat(true); 145 self.setDateTimeFormat(true);
85 self.setRenderFunction(self.renderTableRow_.bind(self, 146 self.setRenderFunction(self.renderTableRow_.bind(self,
86 self.getRenderFunction())); 147 self.getRenderFunction()));
87 148
149 if (util.platform.newUI())
150 ScrollBar.createVertical(self, self.list);
151
88 var handleSelectionChange = function() { 152 var handleSelectionChange = function() {
89 var selectAll = self.querySelector('#select-all-checkbox'); 153 var selectAll = self.querySelector('#select-all-checkbox');
90 if (selectAll) 154 if (selectAll)
91 self.updateSelectAllCheckboxState_(selectAll); 155 self.updateSelectAllCheckboxState_(selectAll);
92 }; 156 };
93 157
94 Object.defineProperty(self.list_, 'selectionModel', { 158 Object.defineProperty(self.list_, 'selectionModel', {
95 get: function() { 159 get: function() {
96 return this.selectionModel_; 160 return this.selectionModel_;
97 }, 161 },
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 * Invoked by cr.ui.Table when a file needs to be rendered. 235 * Invoked by cr.ui.Table when a file needs to be rendered.
172 * 236 *
173 * @param {Entry} entry The Entry object to render. 237 * @param {Entry} entry The Entry object to render.
174 * @param {string} columnId The id of the column to be rendered. 238 * @param {string} columnId The id of the column to be rendered.
175 * @param {cr.ui.Table} table The table doing the rendering. 239 * @param {cr.ui.Table} table The table doing the rendering.
176 * @return {HTMLDivElement} Created element. 240 * @return {HTMLDivElement} Created element.
177 * @private 241 * @private
178 */ 242 */
179 FileTable.prototype.renderName_ = function(entry, columnId, table) { 243 FileTable.prototype.renderName_ = function(entry, columnId, table) {
180 var label = this.ownerDocument.createElement('div'); 244 var label = this.ownerDocument.createElement('div');
181 if (this.selectionModel.multiple) { 245 if (!util.platform.newUI()) {
182 var checkBox = this.ownerDocument.createElement('INPUT'); 246 if (this.selectionModel.multiple) {
183 filelist.decorateSelectionCheckbox(checkBox, entry, this.list); 247 var checkBox = this.ownerDocument.createElement('input');
184 label.appendChild(checkBox); 248 filelist.decorateSelectionCheckbox(checkBox, entry, this.list);
249 label.appendChild(checkBox);
250 }
185 } 251 }
186 label.appendChild(this.renderIconType_(entry, columnId, table)); 252 label.appendChild(this.renderIconType_(entry, columnId, table));
187 label.entry = entry; 253 label.entry = entry;
188 label.className = 'detail-name'; 254 label.className = 'detail-name';
189 label.appendChild(filelist.renderFileNameLabel(this.ownerDocument, entry)); 255 label.appendChild(filelist.renderFileNameLabel(this.ownerDocument, entry));
190 return label; 256 return label;
191 }; 257 };
192 258
193 /** 259 /**
260 * Render the Selection column of the detail table.
261 *
262 * Invoked by cr.ui.Table when a file needs to be rendered.
263 *
264 * @param {Entry} entry The Entry object to render.
265 * @param {string} columnId The id of the column to be rendered.
266 * @param {cr.ui.Table} table The table doing the rendering.
267 * @return {HTMLDivElement} Created element.
268 * @private
269 */
270 FileTable.prototype.renderSelection_ = function(entry, columnId, table) {
271 var label = this.ownerDocument.createElement('div');
272 label.className = 'selection-label';
273 if (this.selectionModel.multiple) {
274 var checkBox = this.ownerDocument.createElement('input');
275 filelist.decorateSelectionCheckbox(checkBox, entry, this.list);
276 label.appendChild(checkBox);
277 }
278 return label;
279 };
280
281 /**
194 * Render the Size column of the detail table. 282 * Render the Size column of the detail table.
195 * 283 *
196 * @param {Entry} entry The Entry object to render. 284 * @param {Entry} entry The Entry object to render.
197 * @param {string} columnId The id of the column to be rendered. 285 * @param {string} columnId The id of the column to be rendered.
198 * @param {cr.ui.Table} table The table doing the rendering. 286 * @param {cr.ui.Table} table The table doing the rendering.
199 * @return {HTMLDivElement} Created element. 287 * @return {HTMLDivElement} Created element.
200 * @private 288 * @private
201 */ 289 */
202 FileTable.prototype.renderSize_ = function(entry, columnId, table) { 290 FileTable.prototype.renderSize_ = function(entry, columnId, table) {
203 var div = this.ownerDocument.createElement('div'); 291 var div = this.ownerDocument.createElement('div');
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 * @return {HTMLDivElement} Created element. 409 * @return {HTMLDivElement} Created element.
322 * @private 410 * @private
323 */ 411 */
324 FileTable.prototype.renderOffline_ = function(entry, columnId, table) { 412 FileTable.prototype.renderOffline_ = function(entry, columnId, table) {
325 var div = this.ownerDocument.createElement('div'); 413 var div = this.ownerDocument.createElement('div');
326 div.className = 'offline'; 414 div.className = 'offline';
327 415
328 if (entry.isDirectory) 416 if (entry.isDirectory)
329 return div; 417 return div;
330 418
331 var checkbox = this.ownerDocument.createElement('INPUT'); 419 var checkbox = this.ownerDocument.createElement('input');
332 filelist.decorateCheckbox(checkbox); 420 filelist.decorateCheckbox(checkbox);
333 checkbox.classList.add('pin'); 421 checkbox.classList.add('pin');
334 422
335 var command = this.ownerDocument.querySelector('command#toggle-pinned'); 423 var command = this.ownerDocument.querySelector('command#toggle-pinned');
336 var onPinClick = function(event) { 424 var onPinClick = function(event) {
337 command.canExecuteChange(checkbox); 425 command.canExecuteChange(checkbox);
338 command.execute(checkbox); 426 command.execute(checkbox);
339 event.preventDefault(); 427 event.preventDefault();
340 }; 428 };
341 429
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 return item; 576 return item;
489 }; 577 };
490 578
491 /** 579 /**
492 * Renders the name column header. 580 * Renders the name column header.
493 * @param {string} name Localized column name. 581 * @param {string} name Localized column name.
494 * @return {HTMLLiElement} Created element. 582 * @return {HTMLLiElement} Created element.
495 * @private 583 * @private
496 */ 584 */
497 FileTable.prototype.renderNameColumnHeader_ = function(name) { 585 FileTable.prototype.renderNameColumnHeader_ = function(name) {
498 if (!this.selectionModel.multiple) { 586 if (!this.selectionModel.multiple)
499 return this.ownerDocument.createTextNode(name); 587 return this.ownerDocument.createTextNode(name);
500 } 588
501 var input = this.ownerDocument.createElement('input'); 589 var input = this.ownerDocument.createElement('input');
502 input.setAttribute('type', 'checkbox'); 590 input.setAttribute('type', 'checkbox');
503 input.setAttribute('tabindex', -1); 591 input.setAttribute('tabindex', -1);
504 input.id = 'select-all-checkbox'; 592 input.id = 'select-all-checkbox';
505 input.className = 'common'; 593 input.className = 'common';
506 594
507 this.updateSelectAllCheckboxState_(input); 595 this.updateSelectAllCheckboxState_(input);
508 596
509 input.addEventListener('click', function(event) { 597 input.addEventListener('click', function(event) {
510 if (input.checked) 598 if (input.checked)
511 this.selectionModel.selectAll(); 599 this.selectionModel.selectAll();
512 else 600 else
513 this.selectionModel.unselectAll(); 601 this.selectionModel.unselectAll();
514 event.stopPropagation(); 602 event.stopPropagation();
515 }.bind(this)); 603 }.bind(this));
516 604
517 var fragment = this.ownerDocument.createDocumentFragment(); 605 var fragment = this.ownerDocument.createDocumentFragment();
518 fragment.appendChild(input); 606 fragment.appendChild(input);
519 fragment.appendChild(this.ownerDocument.createTextNode(name)); 607 fragment.appendChild(this.ownerDocument.createTextNode(name));
520 return fragment; 608 return fragment;
521 }; 609 };
522 610
523 /** 611 /**
612 * Renders the selection column header.
613 * @param {string} name Localized column name.
614 * @return {HTMLLiElement} Created element.
615 * @private
616 */
617 FileTable.prototype.renderSelectionColumnHeader_ = function(name) {
618 if (!this.selectionModel.multiple)
619 return this.ownerDocument.createTextNode('');
620
621 var input = this.ownerDocument.createElement('input');
622 input.setAttribute('type', 'checkbox');
623 input.setAttribute('tabindex', -1);
624 input.id = 'select-all-checkbox';
625 input.className = 'common';
626
627 this.updateSelectAllCheckboxState_(input);
628
629 input.addEventListener('click', function(event) {
630 if (input.checked)
631 this.selectionModel.selectAll();
632 else
633 this.selectionModel.unselectAll();
634 event.stopPropagation();
635 }.bind(this));
636
637 var fragment = this.ownerDocument.createDocumentFragment();
638 fragment.appendChild(input);
639 return fragment;
640 };
641
642 /**
524 * Render the type column of the detail table. 643 * Render the type column of the detail table.
525 * 644 *
526 * Invoked by cr.ui.Table when a file needs to be rendered. 645 * Invoked by cr.ui.Table when a file needs to be rendered.
527 * 646 *
528 * @param {Entry} entry The Entry object to render. 647 * @param {Entry} entry The Entry object to render.
529 * @param {string} columnId The id of the column to be rendered. 648 * @param {string} columnId The id of the column to be rendered.
530 * @param {cr.ui.Table} table The table doing the rendering. 649 * @param {cr.ui.Table} table The table doing the rendering.
531 * @return {HTMLDivElement} Created element. 650 * @return {HTMLDivElement} Created element.
532 * @private 651 * @private
533 */ 652 */
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 break; 806 break;
688 } 807 }
689 } 808 }
690 if (url) { 809 if (url) {
691 iconDiv.style.backgroundImage = 'url(' + url + ')'; 810 iconDiv.style.backgroundImage = 'url(' + url + ')';
692 } else { 811 } else {
693 iconDiv.style.backgroundImage = null; 812 iconDiv.style.backgroundImage = null;
694 } 813 }
695 } 814 }
696 }; 815 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | chrome/browser/resources/file_manager/js/main_scripts.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698