Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js b/third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js |
| index fb920efd36231c0f209a8d3e89b031b26ea8aba1..e65a43f4b97b5d12115421d892123c3832ec40fa 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js |
| @@ -61,6 +61,7 @@ WebInspector.ViewportControl = function(provider) |
| this._headSelection = null; |
| this._stickToBottom = false; |
| this._scrolledToBottom = true; |
| + this._itemCount = 0; |
| } |
| /** |
| @@ -195,6 +196,7 @@ WebInspector.ViewportControl.prototype = { |
| { |
| delete this._cumulativeHeights; |
| delete this._cachedProviderElements; |
| + this._itemCount = this._provider.itemCount(); |
| this.refresh(); |
| }, |
| @@ -205,7 +207,7 @@ WebInspector.ViewportControl.prototype = { |
| _providerElement: function(index) |
| { |
| if (!this._cachedProviderElements) |
| - this._cachedProviderElements = new Array(this._provider.itemCount()); |
| + this._cachedProviderElements = new Array(this._itemCount); |
| var element = this._cachedProviderElements[index]; |
| if (!element) { |
| element = this._provider.itemElement(index); |
| @@ -218,14 +220,13 @@ WebInspector.ViewportControl.prototype = { |
| { |
| if (this._cumulativeHeights) |
| return; |
| - var itemCount = this._provider.itemCount(); |
| - if (!itemCount) |
| + if (!this._itemCount) |
| return; |
| var firstVisibleIndex = this._firstVisibleIndex; |
| var lastVisibleIndex = this._lastVisibleIndex; |
| var height = 0; |
| - this._cumulativeHeights = new Int32Array(itemCount); |
| - for (var i = 0; i < itemCount; ++i) { |
| + this._cumulativeHeights = new Int32Array(this._itemCount); |
| + for (var i = 0; i < this._itemCount; ++i) { |
| if (firstVisibleIndex <= i && i <= lastVisibleIndex) |
| height += this._renderedItems[i - firstVisibleIndex].element().offsetHeight; |
| else |
| @@ -310,7 +311,7 @@ WebInspector.ViewportControl.prototype = { |
| if (!this._anchorSelection || !this._headSelection) { |
| this._anchorSelection = this._createSelectionModel(0, this.element, 0); |
| - this._headSelection = this._createSelectionModel(this._provider.itemCount() - 1, this.element, this.element.children.length); |
| + this._headSelection = this._createSelectionModel(this._itemCount - 1, this.element, this.element.children.length); |
| this._selectionIsBackward = false; |
| } |
| @@ -378,7 +379,7 @@ WebInspector.ViewportControl.prototype = { |
| if (!this._visibleHeight()) |
| return; // Do nothing for invisible controls. |
| - if (!this._provider.itemCount()) { |
| + if (!this._itemCount) { |
| for (var i = 0; i < this._renderedItems.length; ++i) |
| this._renderedItems[i].willHide(); |
| this._renderedItems = []; |
| @@ -404,20 +405,19 @@ WebInspector.ViewportControl.prototype = { |
| delete this._cumulativeHeights; |
| } |
| this._rebuildCumulativeHeightsIfNeeded(); |
| - var itemCount = this._cumulativeHeights.length; |
| var oldFirstVisibleIndex = this._firstVisibleIndex; |
| var oldLastVisibleIndex = this._lastVisibleIndex; |
| var shouldStickToBottom = isInvalidating && this._stickToBottom && this._scrolledToBottom; |
| if (shouldStickToBottom) { |
| - this._lastVisibleIndex = itemCount - 1; |
| - this._firstVisibleIndex = Math.max(itemCount - Math.ceil(visibleHeight / this._provider.minimumRowHeight()), 0); |
| + this._lastVisibleIndex = this._itemCount - 1; |
| + this._firstVisibleIndex = Math.max(this._itemCount - Math.ceil(visibleHeight / this._provider.minimumRowHeight()), 0); |
| } else { |
| this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(this._cumulativeHeights, visibleFrom + 1), 0); |
| // Proactively render more rows in case some of them will be collapsed without triggering refresh. @see crbug.com/390169 |
| this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visibleHeight / this._provider.minimumRowHeight()) - 1; |
| - this._lastVisibleIndex = Math.min(this._lastVisibleIndex, itemCount - 1); |
| + this._lastVisibleIndex = Math.min(this._lastVisibleIndex, this._itemCount - 1); |
| } |
| var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1] || 0; |
| var bottomGapHeight = this._cumulativeHeights[this._cumulativeHeights.length - 1] - this._cumulativeHeights[this._lastVisibleIndex]; |
| @@ -442,7 +442,7 @@ WebInspector.ViewportControl.prototype = { |
| // Should be the last call in the method as it might force layout. |
| if (shouldRestoreSelection) |
| this._restoreSelection(selection); |
| - if (shouldStickToBottom) |
| + if (this._lastVisibleIndex === this._itemCount - 1 && this._scrolledToBottom && this._stickToBottom) |
| this.element.scrollTop = this.element.scrollHeight; |
|
dgozman
2016/04/07 00:40:12
Let's replace scrollHeight with 10000000000.
lushnikov
2016/04/07 00:54:25
Done.
|
| }, |