Bug 1392081 - Reset the Places toolbar view when the toolbar is collapsed. r=gijs draft
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 29 Aug 2017 23:26:24 +0200
changeset 660630 490b5bf65edffa7bfb4a714c3e8035c843d46aa2
parent 660629 683f2a78f3759e154ded86dab28a2dffadc75490
child 730315 d434331157e4fc4f164289ea847b12638375039c
push id78485
push usermak77@bonardo.net
push dateThu, 07 Sep 2017 09:11:04 +0000
reviewersgijs
bugs1392081
milestone57.0a1
Bug 1392081 - Reset the Places toolbar view when the toolbar is collapsed. r=gijs MozReview-Commit-ID: IFOxCnslZRX
browser/base/content/browser-places.js
browser/base/content/browser.js
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1197,34 +1197,53 @@ var PlacesToolbarHelper = {
     let viewElt = this._viewElt;
     if (!viewElt || viewElt._placesView)
       return;
 
     // CustomizableUI.addListener is idempotent, so we can safely
     // call this multiple times.
     CustomizableUI.addListener(this);
 
+    if (!this._isObservingToolbars) {
+      this._isObservingToolbars = true;
+      window.addEventListener("toolbarvisibilitychange", this);
+    }
+
     // If the bookmarks toolbar item is:
     // - not in a toolbar, or;
     // - the toolbar is collapsed, or;
     // - the toolbar is hidden some other way:
     // don't initialize.  Also, there is no need to initialize the toolbar if
     // customizing, because that will happen when the customization is done.
     let toolbar = this._getParentToolbar(viewElt);
     if (!toolbar || toolbar.collapsed || this._isCustomizing ||
-        getComputedStyle(toolbar, "").display == "none")
+        getComputedStyle(toolbar, "").display == "none") {
       return;
+    }
 
     new PlacesToolbar(this._place);
     if (forceToolbarOverflowCheck) {
       viewElt._placesView.updateOverflowStatus();
     }
   },
 
+  handleEvent(event) {
+    switch (event.type) {
+      case "toolbarvisibilitychange":
+        if (event.target == this._viewElt.parentNode.parentNode)
+          this._resetView();
+        break;
+    }
+  },
+
   uninit: function PTH_uninit() {
+    if (this._isObservingToolbars) {
+      delete this._isObservingToolbars;
+      window.removeEventListener("toolbarvisibilitychange", this);
+    }
     CustomizableUI.removeListener(this);
   },
 
   customizeStart: function PTH_customizeStart() {
     try {
       let viewElt = this._viewElt;
       if (viewElt && viewElt._placesView)
         viewElt._placesView.uninit();
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5512,17 +5512,16 @@ function setToolbarVisibility(toolbar, i
     detail: {
       visible: isVisible
     },
     bubbles: true
   };
   let event = new CustomEvent("toolbarvisibilitychange", eventParams);
   toolbar.dispatchEvent(event);
 
-  PlacesToolbarHelper.init();
   BookmarkingUI.onToolbarVisibilityChange();
 }
 
 function updateToggleControlLabel(control) {
   if (!control.hasAttribute("label-checked")) {
     return;
   }