Web Inspector: Canvas recording sidebar scroll position lost after switching tabs
https://bugs.webkit.org/show_bug.cgi?id=190482

Reviewed by Joseph Pecoraro.

* UserInterface/Views/Sidebar.js:
(WI.Sidebar.prototype.removeSidebarPanel):
(WI.Sidebar.prototype.set selectedSidebarPanel):
Call `hidden` before setting `selected` to `false`, as that sets `display: none;` on the
element, which sets the `scrollTop` to `0`.

* UserInterface/Views/SidebarPanel.js:
(WI.SidebarPanel.prototype.shown):
(WI.SidebarPanel.prototype.hidden):
(WI.SidebarPanel.prototype.get scrollElement): Added.
Allow subclasses to specify the scrolling element for saving/restoring the scroll position.

* UserInterface/Views/CanvasSidebarPanel.js:
(WI.CanvasSidebarPanel.prototype.get scrollElement): Added.
* UserInterface/Views/RecordingStateDetailsSidebarPanel.js:
(WI.RecordingStateDetailsSidebarPanel.prototype.get scrollElement): Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@237196 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebInspectorUI/ChangeLog b/Source/WebInspectorUI/ChangeLog
index a620064..56f6564 100644
--- a/Source/WebInspectorUI/ChangeLog
+++ b/Source/WebInspectorUI/ChangeLog
@@ -1,5 +1,29 @@
 2018-10-16  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Canvas recording sidebar scroll position lost after switching tabs
+        https://bugs.webkit.org/show_bug.cgi?id=190482
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Views/Sidebar.js:
+        (WI.Sidebar.prototype.removeSidebarPanel):
+        (WI.Sidebar.prototype.set selectedSidebarPanel):
+        Call `hidden` before setting `selected` to `false`, as that sets `display: none;` on the
+        element, which sets the `scrollTop` to `0`.
+
+        * UserInterface/Views/SidebarPanel.js:
+        (WI.SidebarPanel.prototype.shown):
+        (WI.SidebarPanel.prototype.hidden):
+        (WI.SidebarPanel.prototype.get scrollElement): Added.
+        Allow subclasses to specify the scrolling element for saving/restoring the scroll position.
+
+        * UserInterface/Views/CanvasSidebarPanel.js:
+        (WI.CanvasSidebarPanel.prototype.get scrollElement): Added.
+        * UserInterface/Views/RecordingStateDetailsSidebarPanel.js:
+        (WI.RecordingStateDetailsSidebarPanel.prototype.get scrollElement): Added.
+
+2018-10-16  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Should be a way to go directly from an event in the overview view to the specialized timeline for that event
         https://bugs.webkit.org/show_bug.cgi?id=135307
         <rdar://problem/17273966>
diff --git a/Source/WebInspectorUI/UserInterface/Views/CanvasSidebarPanel.js b/Source/WebInspectorUI/UserInterface/Views/CanvasSidebarPanel.js
index cd7ca93..b3929a7 100644
--- a/Source/WebInspectorUI/UserInterface/Views/CanvasSidebarPanel.js
+++ b/Source/WebInspectorUI/UserInterface/Views/CanvasSidebarPanel.js
@@ -222,6 +222,11 @@
 
     // Protected
 
+    get scrollElement()
+    {
+        return this._recordingContentContainer;
+    }
+
     hasCustomFilters()
     {
         return true;
diff --git a/Source/WebInspectorUI/UserInterface/Views/RecordingStateDetailsSidebarPanel.js b/Source/WebInspectorUI/UserInterface/Views/RecordingStateDetailsSidebarPanel.js
index 37bcbca..fb72219 100644
--- a/Source/WebInspectorUI/UserInterface/Views/RecordingStateDetailsSidebarPanel.js
+++ b/Source/WebInspectorUI/UserInterface/Views/RecordingStateDetailsSidebarPanel.js
@@ -74,6 +74,13 @@
         this.updateLayoutIfNeeded();
     }
 
+    // Protected
+
+    get scrollElement()
+    {
+        return this._dataGrid.scrollContainer;
+    }
+
     // Private
 
     _generateDetailsCanvas2D(action)
diff --git a/Source/WebInspectorUI/UserInterface/Views/Sidebar.js b/Source/WebInspectorUI/UserInterface/Views/Sidebar.js
index 98da99f..856aa1e 100644
--- a/Source/WebInspectorUI/UserInterface/Views/Sidebar.js
+++ b/Source/WebInspectorUI/UserInterface/Views/Sidebar.js
@@ -93,13 +93,13 @@
         if (!sidebarPanel)
             return;
 
-        sidebarPanel.selected = false;
-
         if (sidebarPanel.visible) {
             sidebarPanel.hidden();
             sidebarPanel.visibilityDidChange();
         }
 
+        sidebarPanel.selected = false;
+
         if (this._selectedSidebarPanel === sidebarPanel) {
             var index = this._sidebarPanels.indexOf(sidebarPanel);
             this.selectedSidebarPanel = this._sidebarPanels[index - 1] || this._sidebarPanels[index + 1] || null;
@@ -126,14 +126,12 @@
             return;
 
         if (this._selectedSidebarPanel) {
-            var wasVisible = this._selectedSidebarPanel.visible;
-
-            this._selectedSidebarPanel.selected = false;
-
-            if (wasVisible) {
+            if (this._selectedSidebarPanel.visible) {
                 this._selectedSidebarPanel.hidden();
                 this._selectedSidebarPanel.visibilityDidChange();
             }
+
+            this._selectedSidebarPanel.selected = false;
         }
 
         this._selectedSidebarPanel = sidebarPanel || null;
diff --git a/Source/WebInspectorUI/UserInterface/Views/SidebarPanel.js b/Source/WebInspectorUI/UserInterface/Views/SidebarPanel.js
index 8608c1c..1975510 100644
--- a/Source/WebInspectorUI/UserInterface/Views/SidebarPanel.js
+++ b/Source/WebInspectorUI/UserInterface/Views/SidebarPanel.js
@@ -94,7 +94,7 @@
 
     shown()
     {
-        this._contentView.element.scrollTop = this._savedScrollPosition;
+        this.scrollElement.scrollTop = this._savedScrollPosition;
 
         // FIXME: remove once <https://webkit.org/b/150741> is fixed.
         this.updateLayoutIfNeeded();
@@ -104,7 +104,7 @@
 
     hidden()
     {
-        this._savedScrollPosition = this._contentView.element.scrollTop;
+        this._savedScrollPosition = this.scrollElement.scrollTop;
 
         // Implemented by subclasses.
     }
@@ -113,4 +113,12 @@
     {
         // Implemented by subclasses.
     }
+
+    // Protected
+
+    get scrollElement()
+    {
+        // Overridden by sub-classes if needed.
+        return this.contentView.element;
+    }
 };