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

Side by Side Diff: ui/webui/resources/js/cr/ui/table.js

Issue 2745593003: Use actual client width of list excluding scroll bar for adjusting column widths.
Patch Set: Add comment to describe existing issue. Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 185 }
186 186
187 this.addEventListener('focus', this.handleElementFocus_, true); 187 this.addEventListener('focus', this.handleElementFocus_, true);
188 this.addEventListener('blur', this.handleElementBlur_, true); 188 this.addEventListener('blur', this.handleElementBlur_, true);
189 }, 189 },
190 190
191 /** 191 /**
192 * Redraws the table. 192 * Redraws the table.
193 */ 193 */
194 redraw: function() { 194 redraw: function() {
195 var widthBeforeUpdate = this.list_.clientWidth;
195 this.list_.redraw(); 196 this.list_.redraw();
197 // When resizing the window, vertical scrollbar might appear/disappear
198 // based on the balance between the view size and # of items. This logic
199 // is placed here instead of resize() because clientWidth is updated
200 // after drawing.
201 if (this.list_.clientWidth != widthBeforeUpdate) {
202 this.normalizeColumns();
203 this.list_.redraw();
204 }
196 this.header_.redraw(); 205 this.header_.redraw();
197 }, 206 },
198 207
199 startBatchUpdates: function() { 208 startBatchUpdates: function() {
200 this.list_.startBatchUpdates(); 209 this.list_.startBatchUpdates();
201 this.header_.startBatchUpdates(); 210 this.header_.startBatchUpdates();
202 }, 211 },
203 212
204 endBatchUpdates: function() { 213 endBatchUpdates: function() {
214 var widthBeforeUpdate = this.list_.clientWidth;
205 this.list_.endBatchUpdates(); 215 this.list_.endBatchUpdates();
216 // Update of the list content may change the client width of the list
217 // because vertical scrollbar might appear/disappear depending on the
218 // number of items.
219 if (this.list_.clientWidth != widthBeforeUpdate) {
220 this.normalizeColumns();
221 this.list_.redraw();
222 }
206 this.header_.endBatchUpdates(); 223 this.header_.endBatchUpdates();
207 }, 224 },
208 225
209 /** 226 /**
210 * Resize the table columns. 227 * Resize the table columns.
211 */ 228 */
212 resize: function() { 229 resize: function() {
213 // We resize columns only instead of full redraw. 230 // We resize columns only instead of full redraw.
214 this.list_.resize(); 231 this.list_.resize();
215 this.header_.resize(); 232 this.header_.resize();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 container.appendChild(div); 371 container.appendChild(div);
355 } 372 }
356 list.appendChild(container); 373 list.appendChild(container);
357 var width = parseFloat(window.getComputedStyle(container).width); 374 var width = parseFloat(window.getComputedStyle(container).width);
358 list.removeChild(container); 375 list.removeChild(container);
359 cm.setWidth(index, width); 376 cm.setWidth(index, width);
360 }); 377 });
361 }, 378 },
362 379
363 normalizeColumns: function() { 380 normalizeColumns: function() {
364 this.columnModel.normalizeWidths(this.clientWidth); 381 // list_.clientWidth must be used here instead of this.clientWidth,
382 // because it can be narrower by the thickness of the vertical scrollbar.
383 this.columnModel.normalizeWidths(this.list_.clientWidth);
yamaguchi 2017/03/14 09:07:30 cr.ui.table.TableColumnModel.normalizeWidths only
365 } 384 }
366 }; 385 };
367 386
368 /** 387 /**
369 * Whether the table or one of its descendents has focus. This is necessary 388 * Whether the table or one of its descendents has focus. This is necessary
370 * because table contents can contain controls that can be focused, and for 389 * because table contents can contain controls that can be focused, and for
371 * some purposes (e.g., styling), the table can still be conceptually focused 390 * some purposes (e.g., styling), the table can still be conceptually focused
372 * at that point even though it doesn't actually have the page focus. 391 * at that point even though it doesn't actually have the page focus.
373 */ 392 */
374 cr.defineProperty(Table, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); 393 cr.defineProperty(Table, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR);
375 394
376 return {Table: Table}; 395 return {Table: Table};
377 }); 396 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698