Bug 1441284 - Part 6 - Do not move out subviews when the window is closing. r=Gijs
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 26 Feb 2018 19:47:29 +0000
changeset 761254 3e819acb990a3ec8c9c8448eae9278266118642f
parent 761253 c4b46b5edc28678ca60daaeccedd3e566e811b70
child 761255 cd1250f642803879894ad3e39362a9548b248096
push id100926
push userrwood@mozilla.com
push dateWed, 28 Feb 2018 21:51:29 +0000
reviewersGijs
bugs1441284
milestone60.0a1
Bug 1441284 - Part 6 - Do not move out subviews when the window is closing. r=Gijs Since we control the code path that invokes the PanelMultiView destructor, it is now possible to call the _moveOutKids function only as needed, avoiding some unnecessary DOM modifications when the browser window is closing. MozReview-Commit-ID: JTJQmhZKFOh
browser/components/customizableui/PanelMultiView.jsm
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -88,20 +88,16 @@
  *     └───┴───┴───┴───┘            └───┘
  *       │ ┌───┬───┬───┬───┐        ┌───┐
  *       │ │{A}│(C)│ D │ B │        │ E │              Go back
  *       │ └───┴───┴───┴───┘        └───┘
  *       │   │   │
  *       │   │   └── Currently visible view
  *       │   │   │
  *       └───┴───┴── Open views
- *
- * If the <panelmultiview> element is "ephemeral", imported subviews will be
- * moved out again to the element specified by the viewCacheId attribute, so
- * that the panel element can be removed safely.
  */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = [
   "PanelMultiView",
   "PanelView",
 ];
@@ -302,24 +298,30 @@ var PanelMultiView = class extends this.
       panelNode.hidePopup();
     }
   }
 
   /**
    * Removes the specified <panel> from the document, ensuring that any
    * <panelmultiview> node it contains is destroyed properly.
    *
+   * If the viewCacheId attribute is present on the <panelmultiview> element,
+   * imported subviews will be moved out again to the element it specifies, so
+   * that the panel element can be removed safely.
+   *
    * If the panel does not contain a <panelmultiview>, it is removed directly.
    * This allows consumers like page actions to accept different panel types.
    */
   static removePopup(panelNode) {
     try {
       let panelMultiViewNode = panelNode.querySelector("panelmultiview");
       if (panelMultiViewNode) {
-        this.forNode(panelMultiViewNode).disconnect();
+        let panelMultiView = this.forNode(panelMultiViewNode);
+        panelMultiView._moveOutKids();
+        panelMultiView.disconnect();
       }
     } finally {
       // Make sure to remove the panel element even if disconnecting fails.
       panelNode.remove();
     }
   }
 
   /**
@@ -434,17 +436,16 @@ var PanelMultiView = class extends this.
 
   disconnect() {
     // Guard against re-entrancy.
     if (!this.node || !this.connected)
       return;
 
     this._cleanupTransitionPhase();
 
-    this._moveOutKids();
     this._panel.removeEventListener("mousemove", this);
     this._panel.removeEventListener("popupshowing", this);
     this._panel.removeEventListener("popuppositioned", this);
     this._panel.removeEventListener("popupshown", this);
     this._panel.removeEventListener("popuphidden", this);
     this.window.removeEventListener("keydown", this);
     this.node = this._openPopupPromise = this._openPopupCancelCallback =
       this._viewContainer = this._viewStack = this.__dwu =