Chromium Code Reviews| Index: chrome/browser/resources/shared/js/cr/ui/list.js |
| diff --git a/chrome/browser/resources/shared/js/cr/ui/list.js b/chrome/browser/resources/shared/js/cr/ui/list.js |
| index 8766f1183276401242f3410e14cf5b98dd68654a..b8d67d85c5658b6b02a38b6451f322f9789dcf18 100644 |
| --- a/chrome/browser/resources/shared/js/cr/ui/list.js |
| +++ b/chrome/browser/resources/shared/js/cr/ui/list.js |
| @@ -192,7 +192,7 @@ cr.define('cr.ui', function() { |
| this.dataModel_ = dataModel; |
| this.cachedItems_ = {}; |
| - this.cachedItemSizes_ = {}; |
| + this.cachedItemHeights_ = {}; |
| this.selectionModel.clear(); |
| if (dataModel) |
| this.selectionModel.adjustLength(dataModel.length); |
| @@ -383,6 +383,22 @@ cr.define('cr.ui', function() { |
| }, |
| /** |
| + * @param {ListItem=} item The list item to use to do the measuring. |
|
James Hawkins
2012/01/26 01:34:05
"The list item to measure."
yoshiki
2012/01/26 10:10:45
Done.
|
| + * @return {number} The height of the given item. If the fixed height on CSS |
| + * is set, uses that value. Otherwise, measures the size. |
|
mazda
2012/01/26 09:37:16
Please note that the fixed height is used only if
yoshiki
2012/01/26 10:10:45
Done.
|
| + * @private |
| + */ |
| + measureItemHeight_: function(item) { |
| + var height = item.style.height; |
| + // Uses the fixed height if set it on CSS, to save a time of rayout |
|
James Hawkins
2012/01/26 01:34:05
s/rayout/layout/
yoshiki
2012/01/26 10:10:45
Done.
|
| + // calculation. |
| + if (height && height.substr(-2) == 'px') |
| + return parseInt(height.substr(0, height.length - 2)); |
| + |
| + return measureItem(this, item).height; |
| + }, |
| + |
| + /** |
| * @return {number} The height of default item, measuring it if necessary. |
| * @private |
| */ |
| @@ -392,32 +408,24 @@ cr.define('cr.ui', function() { |
| /** |
| * @param {number} index The index of the item. |
| - * @return {number} The height of the item. |
| + * @return {number} The height of the item, measuring it if necessary. |
| */ |
| getItemHeightByIndex_: function(index) { |
| // If |this.fixedHeight_| is true, all the rows have same default height. |
| if (this.fixedHeight_) |
| return this.getDefaultItemHeight_(); |
| - if (this.cachedItemSizes_[index]) |
| - return this.cachedItemSizes_[index].height; |
| + if (this.cachedItemHeights_[index]) |
| + return this.cachedItemHeights_[index]; |
| var item = this.getListItemByIndex(index); |
| if (item) |
| - return this.getItemSize_(item).height; |
| + return this.measureItemHeight_(item); |
| return this.getDefaultItemHeight_(); |
| }, |
| /** |
| - * @return {number} The width of default item, measuring it if necessary. |
| - * @private |
| - */ |
| - getDefaultItemWidth_: function() { |
| - return this.getDefaultItemSize_().width; |
| - }, |
| - |
| - /** |
| * @return {{height: number, width: number}} The height and width |
| * of default item, measuring it if necessary. |
| * @private |
| @@ -430,22 +438,6 @@ cr.define('cr.ui', function() { |
| }, |
| /** |
| - * @return {{height: number, width: number}} The height and width |
| - * of an item, measuring it if necessary. |
| - * @private |
| - */ |
| - getItemSize_: function(item) { |
| - if (this.cachedItemSizes_[item.listIndex]) |
| - return this.cachedItemSizes_[item.listIndex]; |
| - |
| - var size = measureItem(this, item); |
| - if (!isNaN(size.height) && !isNaN(size.weight)) |
| - this.cachedItemSizes_[item.listIndex] = size; |
| - |
| - return size; |
| - }, |
| - |
| - /** |
| * Callback for the double click event. |
| * @param {Event} e The mouse event object. |
| * @private |
| @@ -980,7 +972,7 @@ cr.define('cr.ui', function() { |
| ensureAllItemSizesInCache: function() { |
| var measuringIndexes = []; |
| for (var y = 0; y < this.dataModel.length; y++) { |
| - if (!this.cachedItemSizes_[y]) |
| + if (!this.cachedItemHeights_[y]) |
| measuringIndexes.push(y); |
| } |
| @@ -1000,7 +992,8 @@ cr.define('cr.ui', function() { |
| // performance reducing. |
| for (var y = 0; y < measuringIndexes.length; y++) { |
| var index = measuringIndexes[y]; |
| - this.cachedItemSizes_[index] = measureItem(this, measuringItems[y]); |
| + var height = this.measureItemHeight_(measuringItems[y]); |
|
James Hawkins
2012/01/26 01:34:05
No need to temp variable, just assign directly.
yoshiki
2012/01/26 10:10:45
Done.
|
| + this.cachedItemHeights_[index] = height; |
| } |
| // Removes all the temprary elements. |
| @@ -1058,9 +1051,6 @@ cr.define('cr.ui', function() { |
| var scrollTop = this.scrollTop; |
| var clientHeight = this.clientHeight; |
| - var lastItemHeights = this.getHeightsForIndex_(dataModel.length - 1); |
| - var desiredScrollHeight = lastItemHeights.top + lastItemHeights.height; |
| - |
| var itemsInViewPort = this.getItemsInViewPort(scrollTop, clientHeight); |
| // Draws the hidden rows just above/below the viewport to prevent |
| // flashing in scroll. |
| @@ -1113,7 +1103,8 @@ cr.define('cr.ui', function() { |
| // performance reducing. |
| if (!this.fixedHeight_) { |
| for (var y = firstIndex; y < lastIndex; y++) |
| - this.cachedItemSizes_[y] = measureItem(this, newCachedItems[y]); |
| + var height = this.measureItemHeight_(newCachedItems[y]); |
| + this.cachedItemHeights_[y] = height; |
| } |
| // Measure again in case the item height has changed due to a page zoom. |