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

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

Issue 1006003004: Adding a visibility property to cr.ui.table.TableColumn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 is a table column model 6 * @fileoverview This is a table column model
7 */ 7 */
8 cr.define('cr.ui.table', function() { 8 cr.define('cr.ui.table', function() {
9 /** @const */ var EventTarget = cr.EventTarget; 9 /** @const */ var EventTarget = cr.EventTarget;
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 /** 91 /**
92 * Sets width of column at the given index. 92 * Sets width of column at the given index.
93 * @param {number} index The index of the column. 93 * @param {number} index The index of the column.
94 * @param {number} width Column width. 94 * @param {number} width Column width.
95 */ 95 */
96 setWidth: function(index, width) { 96 setWidth: function(index, width) {
97 if (index < 0 || index >= this.columns_.size - 1) 97 if (index < 0 || index >= this.columns_.size - 1)
98 return; 98 return;
99 99
100 var column = this.columns_[index];
101 var widthProperty = column.visible ? 'width' : 'hiddenWidth';
102
100 width = Math.max(width, MIMIMAL_WIDTH); 103 width = Math.max(width, MIMIMAL_WIDTH);
101 if (width == this.columns_[index].width) 104 if (width == column[widthProperty])
102 return; 105 return;
103 106
104 this.columns_[index].width = width; 107 column[widthProperty] = width;
105 cr.dispatchSimpleEvent(this, 'resize'); 108
109 // Dispatch an event if a visible column was resized.
110 if (column.visible)
111 cr.dispatchSimpleEvent(this, 'resize');
Dan Beam 2015/03/17 23:04:13 wouldn't we dispatch this even if a column is hidd
Ben Kwa 2015/03/18 02:48:11 If the column is hidden, resizing it does nothing
106 }, 112 },
107 113
108 /** 114 /**
109 * Returns render function for the column at the given index. 115 * Returns render function for the column at the given index.
110 * @param {number} index The index of the column. 116 * @param {number} index The index of the column.
111 * @return {function(*, string, cr.ui.Table): HTMLElement} Render function. 117 * @return {function(*, string, cr.ui.Table): HTMLElement} Render function.
112 */ 118 */
113 getRenderFunction: function(index) { 119 getRenderFunction: function(index) {
114 return this.columns_[index].renderFunction; 120 return this.columns_[index].renderFunction;
115 }, 121 },
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 * @param {string} id The id to find. 182 * @param {string} id The id to find.
177 * @return {number} The index of column with given id or -1 if not found. 183 * @return {number} The index of column with given id or -1 if not found.
178 */ 184 */
179 indexOf: function(id) { 185 indexOf: function(id) {
180 for (var i = 0; i < this.size; i++) { 186 for (var i = 0; i < this.size; i++) {
181 if (this.getId(i) == id) 187 if (this.getId(i) == id)
182 return i; 188 return i;
183 } 189 }
184 return -1; 190 return -1;
185 }, 191 },
192
193 /**
194 * Show/hide a column.
195 * @param {number} index The column index.
196 * @param {boolean} visible The column visibility.
197 */
198 setVisible: function(index, visible) {
199 if (index < 0 || index > this.columns_.size - 1)
Dan Beam 2015/03/17 23:04:13 should this be an assert?
Ben Kwa 2015/03/18 02:48:11 It could be. I was following the pattern in the r
200 return;
201
202 var column = this.columns_[index];
203 if (column.visible === visible) {
Dan Beam 2015/03/17 23:04:13 prefer ==
Dan Beam 2015/03/17 23:04:13 no curlies
Ben Kwa 2015/03/18 16:13:50 Done.
Ben Kwa 2015/03/18 16:13:50 Done.
204 return;
205 }
206
207 // Changing column visibility alters the width. Save the total width out
208 // first, then change the column visibility, then relayout the table.
209 var contentWidth = this.totalWidth;
210 column.visible = visible;
211 this.normalizeWidths(contentWidth);
212 },
213
214 /**
215 * Returns a column's visibility.
216 * @param {number} index The column index.
217 * @return {boolean} Whether the column is visible.
218 */
219 isVisible: function(index) {
Dan Beam 2015/03/17 23:04:13 assert(this.columns_[index]);
Ben Kwa 2015/03/18 02:48:11 This was me going with convention again - the othe
220 return this.columns_[index].visible;
221 }
186 }; 222 };
187 223
188 return { 224 return {
189 TableColumnModel: TableColumnModel 225 TableColumnModel: TableColumnModel
190 }; 226 };
191 }); 227 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698