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

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

Issue 8608007: cr/ui/list.js: Support rows with variable heights. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // require: list_selection_model.js 5 // require: list_selection_model.js
6 // require: list_selection_controller.js 6 // require: list_selection_controller.js
7 // require: list.js 7 // require: list.js
8 8
9 /** 9 /**
10 * @fileoverview This implements a grid control. Grid contains a bunch of 10 * @fileoverview This implements a grid control. Grid contains a bunch of
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 */ 68 */
69 itemConstructor_: GridItem, 69 itemConstructor_: GridItem,
70 70
71 /** 71 /**
72 * In the case of multiple columns lead item must have the same height 72 * In the case of multiple columns lead item must have the same height
73 * as a regular item. 73 * as a regular item.
74 * @type {number} 74 * @type {number}
75 * @override 75 * @override
76 */ 76 */
77 get leadItemHeight() { 77 get leadItemHeight() {
78 return this.getItemHeight_(); 78 return this.getDefaultItemHeight_();
79 }, 79 },
80 set leadItemHeight(height) { 80 set leadItemHeight(height) {
81 // Lead item height cannot be set. 81 // Lead item height cannot be set.
82 }, 82 },
83 83
84 /** 84 /**
85 * Whether or not the rows on list have various heights.
86 * Shows a warning at the setter because cr.ui.Grid does not support this.
87 * @type {boolean}
88 */
89 set fixedHeight(fixedHeight) {
arv (Not doing code reviews) 2011/11/21 20:38:01 missing getter
yoshiki 2011/11/28 11:03:31 Done.
90 if (!fixedHeight)
91 console.warn("cr.ui.Grid does not support fixedHeight = false");
arv (Not doing code reviews) 2011/11/21 20:38:01 Use single quotes
yoshiki 2011/11/28 11:03:31 Done.
92 },
93
94 /**
85 * @return {number} The number of columns determined by width of the grid 95 * @return {number} The number of columns determined by width of the grid
86 * and width of the items. 96 * and width of the items.
87 * @private 97 * @private
88 */ 98 */
89 getColumnCount_: function() { 99 getColumnCount_: function() {
90 var size = this.getItemSize_(); 100 var size = this.getDefaultItemSize_();
91 var width = size.width + size.marginHorizontal; // Uncollapse margin. 101 var width = size.width + size.marginHorizontal; // Uncollapse margin.
92 return width ? Math.floor(this.clientWidth / width) : 0; 102 return width ? Math.floor(this.clientWidth / width) : 0;
93 }, 103 },
94 104
95 /** 105 /**
96 * The number of columns in the grid. If not set, determined automatically 106 * The number of columns in the grid. If not set, determined automatically
97 * as the maximum number of items fitting in the grid width. 107 * as the maximum number of items fitting in the grid width.
98 * @type {number} 108 * @type {number}
99 */ 109 */
100 get columns() { 110 get columns() {
101 if (!this.columns_) { 111 if (!this.columns_) {
102 this.columns_ = this.getColumnCount_(); 112 this.columns_ = this.getColumnCount_();
103 } 113 }
104 return this.columns_ || 1; 114 return this.columns_ || 1;
105 }, 115 },
106 set columns(value) { 116 set columns(value) {
107 if (value >= 0 && value != this.columns_) { 117 if (value >= 0 && value != this.columns_) {
108 this.columns_ = value; 118 this.columns_ = value;
109 this.redraw(); 119 this.redraw();
110 } 120 }
111 }, 121 },
112 122
113 /** 123 /**
114 * @param {number} index The index of the item. 124 * @param {number} index The index of the item.
115 * @return {number} The top position of the item inside the list, not taking 125 * @return {number} The top position of the item inside the list, not taking
116 * into account lead item. May vary in the case of multiple columns. 126 * into account lead item. May vary in the case of multiple columns.
117 * @override 127 * @override
118 */ 128 */
119 getItemTop: function(index) { 129 getItemTop: function(index) {
120 return Math.floor(index / this.columns) * this.getItemHeight_(); 130 return Math.floor(index / this.columns) * this.getDefaultItemHeight_();
121 }, 131 },
122 132
123 /** 133 /**
124 * @param {number} index The index of the item. 134 * @param {number} index The index of the item.
125 * @return {number} The row of the item. May vary in the case 135 * @return {number} The row of the item. May vary in the case
126 * of multiple columns. 136 * of multiple columns.
127 * @override 137 * @override
128 */ 138 */
129 getItemRow: function(index) { 139 getItemRow: function(index) {
130 return Math.floor(index / this.columns); 140 return Math.floor(index / this.columns);
(...skipping 13 matching lines...) Expand all
144 * @param {cr.ui.ListSelectionModel} sm The underlying selection model. 154 * @param {cr.ui.ListSelectionModel} sm The underlying selection model.
145 * @return {!cr.ui.ListSelectionController} The newly created selection 155 * @return {!cr.ui.ListSelectionController} The newly created selection
146 * controller. 156 * controller.
147 * @override 157 * @override
148 */ 158 */
149 createSelectionController: function(sm) { 159 createSelectionController: function(sm) {
150 return new GridSelectionController(sm, this); 160 return new GridSelectionController(sm, this);
151 }, 161 },
152 162
153 /** 163 /**
154 * Calculates the number of items fitting in viewport given the index of 164 * Calculates the number of items fitting in the given viewport.
155 * first item and heights.
156 * @param {number} itemHeight The height of the item.
157 * @param {number} firstIndex Index of the first item in viewport.
158 * @param {number} scrollTop The scroll top position. 165 * @param {number} scrollTop The scroll top position.
159 * @return {number} The number of items in view port. 166 * @param {number} clientHeight The height of viewport.
167 * @return {{first: number, length: number, last: number}} The index of
168 * first item in view port, The number of items, The item past the last.
160 * @override 169 * @override
161 */ 170 */
162 getItemsInViewPort: function(itemHeight, firstIndex, scrollTop) { 171 getItemsInViewPort: function(scrollTop, clientHeight) {
172 var itemHeight = this.getDefaultItemHeight_();
173 var firstIndex =
174 this.autoExpands ? 0 : this.getIndexForListOffset_(scrollTop);
163 var columns = this.columns; 175 var columns = this.columns;
164 var clientHeight = this.clientHeight;
165 var count = this.autoExpands_ ? this.dataModel.length : Math.max( 176 var count = this.autoExpands_ ? this.dataModel.length : Math.max(
166 columns * (Math.ceil(clientHeight / itemHeight) + 1), 177 columns * (Math.ceil(clientHeight / itemHeight) + 1),
167 this.countItemsInRange_(firstIndex, scrollTop + clientHeight)); 178 this.countItemsInRange_(firstIndex, scrollTop + clientHeight));
168 count = columns * Math.ceil(count / columns); 179 count = columns * Math.ceil(count / columns);
169 count = Math.min(count, this.dataModel.length - firstIndex); 180 count = Math.min(count, this.dataModel.length - firstIndex);
170 return count; 181 return count;
171 }, 182 },
172 183
173 /** 184 /**
174 * Adds items to the list and {@code newCachedItems}. 185 * Adds items to the list and {@code newCachedItems}.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 return index + 1; 302 return index + 1;
292 } 303 }
293 }; 304 };
294 305
295 return { 306 return {
296 Grid: Grid, 307 Grid: Grid,
297 GridItem: GridItem, 308 GridItem: GridItem,
298 GridSelectionController: GridSelectionController 309 GridSelectionController: GridSelectionController
299 } 310 }
300 }); 311 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/shared/js/cr/ui/list.js » ('j') | chrome/browser/resources/shared/js/cr/ui/list.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698