Web Inspector: Canvas tab: hide navigation sidebar when viewing the overview
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Feb 2018 02:04:30 +0000 (02:04 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Feb 2018 02:04:30 +0000 (02:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182597
<rdar://problem/37341564>

Reviewed by Devin Rousso.

Support showing/hiding the navigation sidebar panel based on the current
represented object. Individual TabContentViews can opt-in to this behavior,
by overriding TabContentView.prototype.managesNavigationSidebarPanel.

* UserInterface/Views/CanvasSidebarPanel.js:
(WI.CanvasSidebarPanel.prototype.canShowRepresentedObject):
* UserInterface/Views/CanvasTabContentView.js:
(WI.CanvasTabContentView.prototype.get managesNavigationSidebarPanel):
Hide the Canvas navigation sidebar when viewing the overview.

* UserInterface/Views/ContentBrowserTabContentView.js:
(WI.ContentBrowserTabContentView):
(WI.ContentBrowserTabContentView.prototype.showNavigationSidebarPanel):
(WI.ContentBrowserTabContentView.prototype._navigationSidebarCollapsedStateDidChange):
(WI.ContentBrowserTabContentView.prototype._contentBrowserCurrentRepresentedObjectsDidChange):

* UserInterface/Views/NavigationSidebarPanel.js:
(WI.NavigationSidebarPanel.prototype.canShowRepresentedObject):
Provide default implementation that just defers to the TabContentView.
This exists so that a NavigationSidebarPanel that implements canShowRepresentedObject
will have a meaningful default to fall back on.

* UserInterface/Views/TabBrowser.js:
(WI.TabBrowser.prototype._sidebarCollapsedStateDidChange):
(WI.TabBrowser.prototype._showNavigationSidebarPanelForTabContentView):

* UserInterface/Views/TabContentView.js:
(WI.TabContentView.prototype.get managesNavigationSidebarPanel):

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/CanvasSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/CanvasTabContentView.js
Source/WebInspectorUI/UserInterface/Views/ContentBrowserTabContentView.js
Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/TabBrowser.js
Source/WebInspectorUI/UserInterface/Views/TabContentView.js

index 37d0e2b..d25a49e 100644 (file)
@@ -1,3 +1,40 @@
+2018-02-19  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: Canvas tab: hide navigation sidebar when viewing the overview
+        https://bugs.webkit.org/show_bug.cgi?id=182597
+        <rdar://problem/37341564>
+
+        Reviewed by Devin Rousso.
+
+        Support showing/hiding the navigation sidebar panel based on the current
+        represented object. Individual TabContentViews can opt-in to this behavior,
+        by overriding TabContentView.prototype.managesNavigationSidebarPanel.
+
+        * UserInterface/Views/CanvasSidebarPanel.js:
+        (WI.CanvasSidebarPanel.prototype.canShowRepresentedObject):
+        * UserInterface/Views/CanvasTabContentView.js:
+        (WI.CanvasTabContentView.prototype.get managesNavigationSidebarPanel):
+        Hide the Canvas navigation sidebar when viewing the overview.
+
+        * UserInterface/Views/ContentBrowserTabContentView.js:
+        (WI.ContentBrowserTabContentView):
+        (WI.ContentBrowserTabContentView.prototype.showNavigationSidebarPanel):
+        (WI.ContentBrowserTabContentView.prototype._navigationSidebarCollapsedStateDidChange):
+        (WI.ContentBrowserTabContentView.prototype._contentBrowserCurrentRepresentedObjectsDidChange):
+
+        * UserInterface/Views/NavigationSidebarPanel.js:
+        (WI.NavigationSidebarPanel.prototype.canShowRepresentedObject):
+        Provide default implementation that just defers to the TabContentView.
+        This exists so that a NavigationSidebarPanel that implements canShowRepresentedObject
+        will have a meaningful default to fall back on.
+
+        * UserInterface/Views/TabBrowser.js:
+        (WI.TabBrowser.prototype._sidebarCollapsedStateDidChange):
+        (WI.TabBrowser.prototype._showNavigationSidebarPanelForTabContentView):
+
+        * UserInterface/Views/TabContentView.js:
+        (WI.TabContentView.prototype.get managesNavigationSidebarPanel):
+
 2018-02-16  Matt Baker  <mattbaker@apple.com>
 
         Web Inspector: TabBar redesign: remove top-level search field and pin the Search tab
index dda2d90..fed5763 100644 (file)
@@ -151,6 +151,14 @@ WI.CanvasSidebarPanel = class CanvasSidebarPanel extends WI.NavigationSidebarPan
         super.hidden();
     }
 
+    canShowRepresentedObject(representedObject)
+    {
+        if (representedObject instanceof WI.CanvasCollection)
+            return false;
+
+        return super.canShowRepresentedObject(representedObject);
+    }
+
     // Protected
 
     hasCustomFilters()
index af99aba..aadb5ae 100644 (file)
@@ -85,6 +85,11 @@ WI.CanvasTabContentView = class CanvasTabContentView extends WI.ContentBrowserTa
         return true;
     }
 
+    get managesNavigationSidebarPanel()
+    {
+        return true;
+    }
+
     canShowRepresentedObject(representedObject)
     {
         return representedObject instanceof WI.Canvas
index 16719bc..07a0755 100644 (file)
@@ -39,9 +39,13 @@ WI.ContentBrowserTabContentView = class ContentBrowserTabContentView extends WI.
         this._contentBrowser = contentBrowser;
         this._contentBrowser.delegate = this;
 
+        this._ignoreNavigationSidebarPanelCollapsedEvent = false;
+        this._ignoreDetailsSidebarPanelCollapsedEvent = false;
+        this._ignoreDetailsSidebarPanelSelectedEvent = false;
+
         this._lastSelectedDetailsSidebarPanelSetting = new WI.Setting(identifier + "-last-selected-details-sidebar-panel", null);
 
-        this._contentBrowser.addEventListener(WI.ContentBrowser.Event.CurrentRepresentedObjectsDidChange, this.showDetailsSidebarPanels, this);
+        this._contentBrowser.addEventListener(WI.ContentBrowser.Event.CurrentRepresentedObjectsDidChange, this._contentBrowserCurrentRepresentedObjectsDidChange, this);
         this._contentBrowser.addEventListener(WI.ContentBrowser.Event.CurrentContentViewDidChange, this._contentBrowserCurrentContentViewDidChange, this);
 
         // If any content views were shown during sidebar construction, contentBrowserTreeElementForRepresentedObject() would have returned null.
@@ -134,6 +138,36 @@ WI.ContentBrowserTabContentView = class ContentBrowserTabContentView extends WI.
         return true;
     }
 
+    showNavigationSidebarPanel()
+    {
+        if (!this.visible)
+            return;
+
+        if (!this.navigationSidebarPanel)
+            return;
+
+        this._ignoreNavigationSidebarPanelCollapsedEvent = true;
+
+        let currentRepresentedObjects = this._contentBrowser.currentRepresentedObjects;
+        let shouldShowSidebar = currentRepresentedObjects.some((object) => this.navigationSidebarPanel.canShowRepresentedObject(object));
+
+        if (shouldShowSidebar) {
+            if (!this.navigationSidebarPanel.parentSidebar)
+                WI.navigationSidebar.addSidebarPanel(this.navigationSidebarPanel);
+        } else if (this.navigationSidebarPanel.parentSidebar)
+            WI.navigationSidebar.removeSidebarPanel(this.navigationSidebarPanel);
+
+        if (this.navigationSidebarPanel.parentSidebar) {
+            WI.navigationSidebar.selectedSidebarPanel = this.navigationSidebarPanel;
+            WI.navigationSidebar.collapsed = this.navigationSidebarCollapsedSetting.value;
+        } else
+            WI.navigationSidebar.collapsed = true;
+
+        this._ignoreNavigationSidebarPanelCollapsedEvent = false;
+
+        this._showNavigationSidebarItem.enabled = !!this.navigationSidebarPanel.parentSidebar;
+    }
+
     showDetailsSidebarPanels()
     {
         if (!this.visible)
@@ -220,7 +254,15 @@ WI.ContentBrowserTabContentView = class ContentBrowserTabContentView extends WI.
 
     _navigationSidebarCollapsedStateDidChange(event)
     {
+        if (!this.visible)
+            return;
+
         this._showNavigationSidebarItem.activated = !WI.navigationSidebar.collapsed;
+
+        if (this._ignoreNavigationSidebarPanelCollapsedEvent)
+            return;
+
+        this.navigationSidebarCollapsedSetting.value = WI.navigationSidebar.collapsed;
     }
 
     _detailsSidebarCollapsedStateDidChange(event)
@@ -279,4 +321,11 @@ WI.ContentBrowserTabContentView = class ContentBrowserTabContentView extends WI.
         else if (this.navigationSidebarPanel && this.navigationSidebarPanel.contentTreeOutline.selectedTreeElement)
             this.navigationSidebarPanel.contentTreeOutline.selectedTreeElement.deselect(true);
     }
+
+    _contentBrowserCurrentRepresentedObjectsDidChange()
+    {
+        if (this.managesNavigationSidebarPanel)
+            this.showNavigationSidebarPanel();
+        this.showDetailsSidebarPanels();
+    }
 };
index 06d1b5b..6628bb8 100644 (file)
@@ -201,6 +201,13 @@ WI.NavigationSidebarPanel = class NavigationSidebarPanel extends WI.SidebarPanel
         return true;
     }
 
+    canShowRepresentedObject(representedObject)
+    {
+        let selectedTabContentView = WI.tabBrowser.selectedTabContentView;
+        console.assert(selectedTabContentView instanceof WI.TabContentView, "Missing TabContentView for NavigationSidebarPanel.");
+        return selectedTabContentView && selectedTabContentView.canShowRepresentedObject(representedObject);
+    }
+
     saveStateToCookie(cookie)
     {
         console.assert(cookie);
index abd73f9..d3cb504 100644 (file)
@@ -321,7 +321,7 @@ WI.TabBrowser = class TabBrowser extends WI.View
         if (!tabContentView)
             return;
 
-        if (event.target === this._navigationSidebar)
+        if (event.target === this._navigationSidebar && !tabContentView.managesNavigationSidebarPanel)
             tabContentView.navigationSidebarCollapsedSetting.value = this._navigationSidebar.collapsed;
         else if (event.target === this._detailsSidebar && !tabContentView.managesDetailsSidebarPanels)
             tabContentView.detailsSidebarCollapsedSetting.value = this._detailsSidebar.collapsed;
@@ -373,6 +373,12 @@ WI.TabBrowser = class TabBrowser extends WI.View
             return;
         }
 
+        if (tabContentView.managesNavigationSidebarPanel) {
+            tabContentView.showNavigationSidebarPanel();
+            this._ignoreSidebarEvents = false;
+            return;
+        }
+
         this._navigationSidebar.addSidebarPanel(navigationSidebarPanel);
         this._navigationSidebar.selectedSidebarPanel = navigationSidebarPanel;
 
index 672c905..c8e193e 100644 (file)
@@ -99,6 +99,12 @@ WI.TabContentView = class TabContentView extends WI.ContentView
         return this._tabBarItem;
     }
 
+    get managesNavigationSidebarPanel()
+    {
+        // Implemented by subclasses.
+        return false;
+    }
+
     get managesDetailsSidebarPanels()
     {
         // Implemented by subclasses.