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

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/table.js

Issue 11280253: Fixing column widths in tables. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 /** 5 /**
6 * @fileoverview This implements a table control. 6 * @fileoverview This implements a table control.
7 */ 7 */
8 8
9 cr.define('cr.ui', function() { 9 cr.define('cr.ui', function() {
10 /** @const */ var ListSelectionModel = cr.ui.ListSelectionModel; 10 /** @const */ var ListSelectionModel = cr.ui.ListSelectionModel;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 decorate: function() { 159 decorate: function() {
160 this.header_ = this.ownerDocument.createElement('div'); 160 this.header_ = this.ownerDocument.createElement('div');
161 this.list_ = this.ownerDocument.createElement('list'); 161 this.list_ = this.ownerDocument.createElement('list');
162 162
163 this.appendChild(this.header_); 163 this.appendChild(this.header_);
164 this.appendChild(this.list_); 164 this.appendChild(this.list_);
165 165
166 TableList.decorate(this.list_); 166 TableList.decorate(this.list_);
167 this.list_.selectionModel = new ListSelectionModel(this); 167 this.list_.selectionModel = new ListSelectionModel(this);
168 this.list_.table = this; 168 this.list_.table = this;
169 this.list_.addEventListener('scroll', this.handleScroll_.bind(this));
169 170
170 TableHeader.decorate(this.header_); 171 TableHeader.decorate(this.header_);
171 this.header_.table = this; 172 this.header_.table = this;
172 173
173 this.classList.add('table'); 174 this.classList.add('table');
174 this.ownerDocument.defaultView.addEventListener(
arv (Not doing code reviews) 2012/11/30 19:05:52 Why is this removed? If the table is using a size
SeRya 2012/12/01 20:14:37 A moved it to Task Manager. File manager has alrea
175 'resize', this.header_.updateWidth.bind(this.header_));
176 175
177 this.boundResize_ = this.resize.bind(this); 176 this.boundResize_ = this.resize.bind(this);
178 this.boundHandleSorted_ = this.handleSorted_.bind(this); 177 this.boundHandleSorted_ = this.handleSorted_.bind(this);
179 this.boundHandleChangeList_ = this.handleChangeList_.bind(this); 178 this.boundHandleChangeList_ = this.handleChangeList_.bind(this);
180 179
181 // The contained list should be focusable, not the table itself. 180 // The contained list should be focusable, not the table itself.
182 if (this.hasAttribute('tabindex')) { 181 if (this.hasAttribute('tabindex')) {
183 this.list_.setAttribute('tabindex', this.getAttribute('tabindex')); 182 this.list_.setAttribute('tabindex', this.getAttribute('tabindex'));
184 this.removeAttribute('tabindex'); 183 this.removeAttribute('tabindex');
185 } 184 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 * This handles data model 'change' and 'splice' events. 245 * This handles data model 'change' and 'splice' events.
247 * Since they may change the visibility of scrollbar, table may need to 246 * Since they may change the visibility of scrollbar, table may need to
248 * re-calculation the width of column headers. 247 * re-calculation the width of column headers.
249 * @param {Event} e The 'change' or 'splice' event. 248 * @param {Event} e The 'change' or 'splice' event.
250 */ 249 */
251 handleChangeList_: function(e) { 250 handleChangeList_: function(e) {
252 webkitRequestAnimationFrame(this.header_.updateWidth.bind(this.header_)); 251 webkitRequestAnimationFrame(this.header_.updateWidth.bind(this.header_));
253 }, 252 },
254 253
255 /** 254 /**
255 * This handles list 'scroll' events. Scrolls the header accordingly.
256 * @param {Event} e Scroll event.
257 */
258 handleScroll_: function(e) {
259 this.header_.style.marginLeft = (-this.list_.scrollLeft) + 'px';
260 },
261
262 /**
256 * Sort data by the given column. 263 * Sort data by the given column.
257 * @param {number} index The index of the column to sort by. 264 * @param {number} index The index of the column to sort by.
258 */ 265 */
259 sort: function(i) { 266 sort: function(i) {
260 var cm = this.columnModel_; 267 var cm = this.columnModel_;
261 var sortStatus = this.list_.dataModel.sortStatus; 268 var sortStatus = this.list_.dataModel.sortStatus;
262 if (sortStatus.field == cm.getId(i)) { 269 if (sortStatus.field == cm.getId(i)) {
263 var sortDirection = sortStatus.direction == 'desc' ? 'asc' : 'desc'; 270 var sortDirection = sortStatus.direction == 'desc' ? 'asc' : 'desc';
264 this.list_.dataModel.sort(sortStatus.field, sortDirection); 271 this.list_.dataModel.sort(sortStatus.field, sortDirection);
265 } else { 272 } else {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 313 }
307 }); 314 });
308 }, 315 },
309 316
310 /** 317 /**
311 * Adjust column width to fit its content. 318 * Adjust column width to fit its content.
312 * @param {number} index Index of the column to adjust width. 319 * @param {number} index Index of the column to adjust width.
313 */ 320 */
314 fitColumn: function(index) { 321 fitColumn: function(index) {
315 var list = this.list_; 322 var list = this.list_;
316 var listWidth = list.clientWidth;
317 var listHeight = list.clientHeight; 323 var listHeight = list.clientHeight;
318 if (listWidth == 0)
319 return; // Ensure won't be division by 0.
320 324
321 var cm = this.columnModel_; 325 var cm = this.columnModel_;
322 var dm = this.dataModel; 326 var dm = this.dataModel;
323 var columnId = cm.getId(index); 327 var columnId = cm.getId(index);
324 var doc = this.ownerDocument; 328 var doc = this.ownerDocument;
325 var render = cm.getRenderFunction(index); 329 var render = cm.getRenderFunction(index);
326 var table = this; 330 var table = this;
327 var MAXIMUM_ROWS_TO_MEASURE = 1000; 331 var MAXIMUM_ROWS_TO_MEASURE = 1000;
328 332
329 // Create a temporaty list item, put all cells into it and measure its 333 // Create a temporaty list item, put all cells into it and measure its
(...skipping 15 matching lines...) Expand all
345 for (var i = firstIndex; i < lastIndex; i++) { 349 for (var i = firstIndex; i < lastIndex; i++) {
346 var item = dm.item(i); 350 var item = dm.item(i);
347 var div = doc.createElement('div'); 351 var div = doc.createElement('div');
348 div.className = 'table-row-cell'; 352 div.className = 'table-row-cell';
349 div.appendChild(render(item, columnId, table)); 353 div.appendChild(render(item, columnId, table));
350 container.appendChild(div); 354 container.appendChild(div);
351 } 355 }
352 list.appendChild(container); 356 list.appendChild(container);
353 var width = parseFloat(getComputedStyle(container).width); 357 var width = parseFloat(getComputedStyle(container).width);
354 list.removeChild(container); 358 list.removeChild(container);
355 cm.setWidth(index, width * 100 / listWidth); 359 cm.setWidth(index, width);
356 }); 360 });
361 },
362
363 normalizeColumns: function() {
364 this.columnModel.normalizeWidths(this.clientWidth);
357 } 365 }
358 }; 366 };
359 367
360 /** 368 /**
361 * Whether the table or one of its descendents has focus. This is necessary 369 * Whether the table or one of its descendents has focus. This is necessary
362 * because table contents can contain controls that can be focused, and for 370 * because table contents can contain controls that can be focused, and for
363 * some purposes (e.g., styling), the table can still be conceptually focused 371 * some purposes (e.g., styling), the table can still be conceptually focused
364 * at that point even though it doesn't actually have the page focus. 372 * at that point even though it doesn't actually have the page focus.
365 */ 373 */
366 cr.defineProperty(Table, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); 374 cr.defineProperty(Table, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR);
367 375
368 return { 376 return {
369 Table: Table 377 Table: Table
370 }; 378 };
371 }); 379 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698