Web Inspector: Table should recalculate scrollable height when resized
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Nov 2018 22:54:18 +0000 (22:54 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Nov 2018 22:54:18 +0000 (22:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191328
<rdar://problem/45854412>

Reviewed by Devin Rousso.

* UserInterface/Views/NetworkTableContentView.js:
(WI.NetworkTableContentView.prototype._hideDetailView):
Force table columns to layout after hiding the detail view.

* UserInterface/Views/Table.js:
(WI.Table):
(WI.Table.prototype.showColumn):
Call `_resizeColumnsAndFiller` instead of `resize`. The latter also cleared
`_cachedWidth`, which isn't unnecessary since the width hasn't changed.

(WI.Table.prototype.layout):
previously `_resizeColumnsAndFiller` always occurred after `_updateVisibleRows`,
it was just a matter of whether the cached width and height were cleared first.
That now happens in `sizeDidChange`.

(WI.Table.prototype.sizeDidChange):
(WI.Table.prototype._updateVisibleRows):
(WI.Table.prototype.resize): Deleted.
Internally this cleared the cached width and height, which moved to `sizeDidChange`.
Externally this was used by NetworkTableContentView to force columns to
layout after hiding the details view. Calling `updateLayout` on the table
accomplishes the same thing using the standard View API.

(WI.Table.prototype._resizeColumnsAndFiller):
Only update the cached width, since the height will already have been
updated. The number of rows doesn't change during this method, so that
check was removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238203 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js
Source/WebInspectorUI/UserInterface/Views/Table.js

index 4bc5834..f8428bf 100644 (file)
@@ -1,3 +1,39 @@
+2018-11-14  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: Table should recalculate scrollable height when resized
+        https://bugs.webkit.org/show_bug.cgi?id=191328
+        <rdar://problem/45854412>
+
+        Reviewed by Devin Rousso.
+
+        * UserInterface/Views/NetworkTableContentView.js:
+        (WI.NetworkTableContentView.prototype._hideDetailView):
+        Force table columns to layout after hiding the detail view.
+
+        * UserInterface/Views/Table.js:
+        (WI.Table):
+        (WI.Table.prototype.showColumn):
+        Call `_resizeColumnsAndFiller` instead of `resize`. The latter also cleared
+        `_cachedWidth`, which isn't unnecessary since the width hasn't changed.
+
+        (WI.Table.prototype.layout):
+        previously `_resizeColumnsAndFiller` always occurred after `_updateVisibleRows`,
+        it was just a matter of whether the cached width and height were cleared first.
+        That now happens in `sizeDidChange`.
+
+        (WI.Table.prototype.sizeDidChange):
+        (WI.Table.prototype._updateVisibleRows):
+        (WI.Table.prototype.resize): Deleted.
+        Internally this cleared the cached width and height, which moved to `sizeDidChange`.
+        Externally this was used by NetworkTableContentView to force columns to
+        layout after hiding the details view. Calling `updateLayout` on the table
+        accomplishes the same thing using the standard View API.
+
+        (WI.Table.prototype._resizeColumnsAndFiller):
+        Only update the cached width, since the height will already have been
+        updated. The number of rows doesn't change during this method, so that
+        check was removed.
+
 2018-11-14  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: REGRESSION(r236540): Debugger: breakpoints are sorted alphabetically instead of numerically
index 90bcd56..1cd3646 100644 (file)
@@ -1297,7 +1297,7 @@ WI.NetworkTableContentView = class NetworkTableContentView extends WI.ContentVie
         this._detailView.hidden();
         this._detailView = null;
 
-        this._table.resize();
+        this._table.updateLayout(WI.View.LayoutReason.Resize);
         this._table.reloadVisibleColumnCells(this._waterfallColumn);
     }
 
index 2769fed..ec4f883 100644 (file)
@@ -109,7 +109,7 @@ WI.Table = class Table extends WI.View
         this._cachedWidth = NaN;
         this._cachedHeight = NaN;
         this._cachedScrollTop = NaN;
-        this._cachedScrollableHeight = NaN;
+        this._previousCachedWidth = NaN;
         this._previousRevealedRowCount = NaN;
         this._topSpacerHeight = NaN;
         this._bottomSpacerHeight = NaN;
@@ -244,14 +244,6 @@ WI.Table = class Table extends WI.View
         return this._selectedRows.has(rowIndex);
     }
 
-    resize()
-    {
-        this._cachedWidth = NaN;
-        this._cachedHeight = NaN;
-
-        this._resizeColumnsAndFiller();
-    }
-
     reloadData()
     {
         this._cachedRows.clear();
@@ -582,7 +574,7 @@ WI.Table = class Table extends WI.View
 
         // Re-layout all columns to make space.
         this._columnWidths = null;
-        this.resize();
+        this._resizeColumnsAndFiller();
 
         // Now populate only the new cells for this column.
         for (let cell of cellsToPopulate)
@@ -663,11 +655,16 @@ WI.Table = class Table extends WI.View
     layout()
     {
         this._updateVisibleRows();
+        this._resizeColumnsAndFiller();
+    }
 
-        if (this.layoutReason === WI.View.LayoutReason.Resize)
-            this.resize();
-        else
-            this._resizeColumnsAndFiller();
+    sizeDidChange()
+    {
+        super.sizeDidChange();
+
+        this._previousCachedWidth = this._cachedWidth;
+        this._cachedWidth = NaN;
+        this._cachedHeight = NaN;
     }
 
     // Resizer delegate
@@ -873,15 +870,8 @@ WI.Table = class Table extends WI.View
 
     _resizeColumnsAndFiller()
     {
-        let oldWidth = this._cachedWidth;
-        let oldHeight = this._cachedHeight;
-        let oldNumberOfRows = this._cachedNumberOfRows;
-
-        if (isNaN(this._cachedWidth)) {
-            let boundingClientRect = this._scrollContainerElement.getBoundingClientRect();
-            this._cachedWidth = Math.floor(boundingClientRect.width);
-            this._cachedHeight = Math.floor(boundingClientRect.height);
-        }
+        if (isNaN(this._cachedWidth) || !this._cachedWidth)
+            this._cachedWidth = Math.floor(this._scrollContainerElement.getBoundingClientRect().width);
 
         // Not visible yet.
         if (!this._cachedWidth)
@@ -890,19 +880,18 @@ WI.Table = class Table extends WI.View
         let availableWidth = this._cachedWidth;
         let availableHeight = this._cachedHeight;
 
-        let numberOfRows = this.numberOfRows;
-        this._cachedNumberOfRows = numberOfRows;
-
-        let contentHeight = numberOfRows * this._rowHeight;
+        let contentHeight = this.numberOfRows * this._rowHeight;
         this._fillerHeight = Math.max(availableHeight - contentHeight, 0);
 
         // No change to layout metrics so no resizing is needed.
-        if (this._columnWidths && availableWidth === oldWidth && availableWidth === oldHeight && numberOfRows === oldNumberOfRows) {
+        if (this._columnWidths && this._cachedWidth === this._previousCachedWidth) {
             this._updateFillerRowWithNewHeight();
             this._applyColumnWidthsToColumnsIfNeeded();
             return;
         }
 
+        this._previousCachedWidth = this._cachedWidth;
+
         let lockedWidth = 0;
         let lockedColumnCount = 0;
         let totalMinimumWidth = 0;
@@ -1094,11 +1083,11 @@ WI.Table = class Table extends WI.View
         if (isNaN(this._cachedScrollTop))
             this._cachedScrollTop = this._scrollContainerElement.scrollTop;
 
-        if (isNaN(this._cachedScrollableHeight) || !this._cachedScrollableHeight)
-            this._cachedScrollableHeight = this._scrollContainerElement.getBoundingClientRect().height;
+        if (isNaN(this._cachedHeight) || !this._cachedHeight)
+            this._cachedHeight = Math.floor(this._scrollContainerElement.getBoundingClientRect().height);
 
         let scrollTop = this._cachedScrollTop;
-        let scrollableOffsetHeight = this._cachedScrollableHeight;
+        let scrollableOffsetHeight = this._cachedHeight;
 
         let visibleRowCount = Math.ceil((scrollableOffsetHeight + (overflowPadding * 2)) / rowHeight);
         let currentTopMargin = this._topSpacerHeight;