Web Inspector: sidebar panels shouldn't be added as subviews unless visible
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / Sidebar.js
index 62431d8..3768485 100644 (file)
@@ -42,7 +42,7 @@ WI.Sidebar = class Sidebar extends WI.View
         if (hasNavigationBar) {
             this.element.classList.add("has-navigation-bar");
 
-            this._navigationBar = new WI.NavigationBar(null, null, "tablist");
+            this._navigationBar = new WI.SidebarNavigationBar(null, null, "tablist");
             this._navigationBar.addEventListener(WI.NavigationBar.Event.NavigationItemSelected, this._navigationItemSelected, this);
             this.addSubview(this._navigationBar);
         }
@@ -78,15 +78,10 @@ WI.Sidebar = class Sidebar extends WI.View
         console.assert(index >= 0 && index <= this._sidebarPanels.length);
         this._sidebarPanels.splice(index, 0, sidebarPanel);
 
-        let referenceView = this._sidebarPanels[index + 1] || null;
-        this.insertSubviewBefore(sidebarPanel, referenceView);
-
         if (this._navigationBar) {
             console.assert(sidebarPanel.navigationItem);
             this._navigationBar.insertNavigationItem(sidebarPanel.navigationItem, index);
         }
-
-        sidebarPanel.added();
     }
 
     removeSidebarPanel(sidebarPanelOrIdentifierOrIndex)
@@ -95,27 +90,24 @@ WI.Sidebar = class Sidebar extends WI.View
         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;
         }
 
         this._sidebarPanels.remove(sidebarPanel);
-        this.removeSubview(sidebarPanel);
 
         if (this._navigationBar) {
             console.assert(sidebarPanel.navigationItem);
             this._navigationBar.removeNavigationItem(sidebarPanel.navigationItem);
         }
-
-        sidebarPanel.removed();
     }
 
     get selectedSidebarPanel()
@@ -130,14 +122,10 @@ WI.Sidebar = class Sidebar extends WI.View
             return;
 
         if (this._selectedSidebarPanel) {
-            var wasVisible = this._selectedSidebarPanel.visible;
-
+            this._selectedSidebarPanel.hidden();
+            this._selectedSidebarPanel.visibilityDidChange();
             this._selectedSidebarPanel.selected = false;
-
-            if (wasVisible) {
-                this._selectedSidebarPanel.hidden();
-                this._selectedSidebarPanel.visibilityDidChange();
-            }
+            this.removeSubview(this._selectedSidebarPanel);
         }
 
         this._selectedSidebarPanel = sidebarPanel || null;
@@ -146,12 +134,10 @@ WI.Sidebar = class Sidebar extends WI.View
             this._navigationBar.selectedNavigationItem = sidebarPanel ? sidebarPanel.navigationItem : null;
 
         if (this._selectedSidebarPanel) {
+            this.addSubview(this._selectedSidebarPanel);
             this._selectedSidebarPanel.selected = true;
-
-            if (this._selectedSidebarPanel.visible) {
-                this._selectedSidebarPanel.shown();
-                this._selectedSidebarPanel.visibilityDidChange();
-            }
+            this._selectedSidebarPanel.shown();
+            this._selectedSidebarPanel.visibilityDidChange();
         }
 
         this.dispatchEventToListeners(WI.Sidebar.Event.SidebarPanelSelected);
@@ -261,7 +247,7 @@ WI.Sidebar = class Sidebar extends WI.View
 
         var newWidth = positionDelta + this._widthBeforeResize;
         this.width = newWidth;
-        this.collapsed = (newWidth < (this.minimumWidth / 2));
+        this.collapsed = newWidth < (this.minimumWidth / 2);
     }
 
     resizerDragEnded(resizer)