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

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: Omit the custom lead item height Created 9 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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 columns_: 0, 62 columns_: 0,
63 63
64 /** 64 /**
65 * Function used to create grid items. 65 * Function used to create grid items.
66 * @type {function(): !GridItem} 66 * @type {function(): !GridItem}
67 * @override 67 * @override
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 * Whether or not the rows on list have various heights.
73 * as a regular item. 73 * Shows a warning at the setter because cr.ui.Grid does not support this.
74 * @type {number} 74 * @type {boolean}
75 * @override
76 */ 75 */
77 get leadItemHeight() { 76 get fixedHeight() {
78 return this.getItemHeight_(); 77 return true;
79 }, 78 },
80 set leadItemHeight(height) { 79 set fixedHeight(fixedHeight) {
81 // Lead item height cannot be set. 80 if (!fixedHeight)
81 console.warn('cr.ui.Grid does not support fixedHeight = false');
82 }, 82 },
83 83
84 /** 84 /**
85 * @return {number} The number of columns determined by width of the grid 85 * @return {number} The number of columns determined by width of the grid
86 * and width of the items. 86 * and width of the items.
87 * @private 87 * @private
88 */ 88 */
89 getColumnCount_: function() { 89 getColumnCount_: function() {
90 var size = this.getItemSize_(); 90 var size = this.getDefaultItemSize_();
91 var width = size.width + size.marginHorizontal; // Uncollapse margin. 91 var width = size.width + size.marginHorizontal; // Uncollapse margin.
92 return width ? Math.floor(this.clientWidth / width) : 0; 92 return width ? Math.floor(this.clientWidth / width) : 0;
93 }, 93 },
94 94
95 /** 95 /**
96 * The number of columns in the grid. If not set, determined automatically 96 * The number of columns in the grid. If not set, determined automatically
97 * as the maximum number of items fitting in the grid width. 97 * as the maximum number of items fitting in the grid width.
98 * @type {number} 98 * @type {number}
99 */ 99 */
100 get columns() { 100 get columns() {
101 if (!this.columns_) { 101 if (!this.columns_) {
102 this.columns_ = this.getColumnCount_(); 102 this.columns_ = this.getColumnCount_();
103 } 103 }
104 return this.columns_ || 1; 104 return this.columns_ || 1;
105 }, 105 },
106 set columns(value) { 106 set columns(value) {
107 if (value >= 0 && value != this.columns_) { 107 if (value >= 0 && value != this.columns_) {
108 this.columns_ = value; 108 this.columns_ = value;
109 this.redraw(); 109 this.redraw();
110 } 110 }
111 }, 111 },
112 112
113 /** 113 /**
114 * @param {number} index The index of the item. 114 * @param {number} index The index of the item.
115 * @return {number} The top position of the item inside the list, not taking 115 * @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. 116 * into account lead item. May vary in the case of multiple columns.
117 * @override 117 * @override
118 */ 118 */
119 getItemTop: function(index) { 119 getItemTop: function(index) {
120 return Math.floor(index / this.columns) * this.getItemHeight_(); 120 return Math.floor(index / this.columns) * this.getDefaultItemHeight_();
121 }, 121 },
122 122
123 /** 123 /**
124 * @param {number} index The index of the item. 124 * @param {number} index The index of the item.
125 * @return {number} The row of the item. May vary in the case 125 * @return {number} The row of the item. May vary in the case
126 * of multiple columns. 126 * of multiple columns.
127 * @override 127 * @override
128 */ 128 */
129 getItemRow: function(index) { 129 getItemRow: function(index) {
130 return Math.floor(index / this.columns); 130 return Math.floor(index / this.columns);
(...skipping 13 matching lines...) Expand all
144 * @param {cr.ui.ListSelectionModel} sm The underlying selection model. 144 * @param {cr.ui.ListSelectionModel} sm The underlying selection model.
145 * @return {!cr.ui.ListSelectionController} The newly created selection 145 * @return {!cr.ui.ListSelectionController} The newly created selection
146 * controller. 146 * controller.
147 * @override 147 * @override
148 */ 148 */
149 createSelectionController: function(sm) { 149 createSelectionController: function(sm) {
150 return new GridSelectionController(sm, this); 150 return new GridSelectionController(sm, this);
151 }, 151 },
152 152
153 /** 153 /**
154 * Calculates the number of items fitting in viewport given the index of 154 * 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. 155 * @param {number} scrollTop The scroll top position.
159 * @return {number} The number of items in view port. 156 * @param {number} clientHeight The height of viewport.
157 * @return {{first: number, length: number, last: number}} The index of
158 * first item in view port, The number of items, The item past the last.
160 * @override 159 * @override
161 */ 160 */
162 getItemsInViewPort: function(itemHeight, firstIndex, scrollTop) { 161 getItemsInViewPort: function(scrollTop, clientHeight) {
162 var itemHeight = this.getDefaultItemHeight_();
163 var firstIndex =
164 this.autoExpands ? 0 : this.getIndexForListOffset_(scrollTop);
163 var columns = this.columns; 165 var columns = this.columns;
164 var clientHeight = this.clientHeight;
165 var count = this.autoExpands_ ? this.dataModel.length : Math.max( 166 var count = this.autoExpands_ ? this.dataModel.length : Math.max(
166 columns * (Math.ceil(clientHeight / itemHeight) + 1), 167 columns * (Math.ceil(clientHeight / itemHeight) + 1),
167 this.countItemsInRange_(firstIndex, scrollTop + clientHeight)); 168 this.countItemsInRange_(firstIndex, scrollTop + clientHeight));
168 count = columns * Math.ceil(count / columns); 169 count = columns * Math.ceil(count / columns);
169 count = Math.min(count, this.dataModel.length - firstIndex); 170 count = Math.min(count, this.dataModel.length - firstIndex);
170 return count; 171 return count;
171 }, 172 },
172 173
173 /** 174 /**
174 * Adds items to the list and {@code newCachedItems}. 175 * Adds items to the list and {@code newCachedItems}.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 return index + 1; 292 return index + 1;
292 } 293 }
293 }; 294 };
294 295
295 return { 296 return {
296 Grid: Grid, 297 Grid: Grid,
297 GridItem: GridItem, 298 GridItem: GridItem,
298 GridSelectionController: GridSelectionController 299 GridSelectionController: GridSelectionController
299 } 300 }
300 }); 301 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/intents_list.js ('k') | chrome/browser/resources/shared/js/cr/ui/list.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698