Chromium Code Reviews| 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 /** | 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 Loading... | |
| 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 Loading... | |
| 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 }); |
| OLD | NEW |