Bug 605365 - Properly update visibility of the previously visible popup (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Mon, 19 Sep 2011 09:45:44 -0700
changeset 77137 4e1b3e291b1bc0ee611abb67d1e027345602662e
parent 77136 aada4d669948e1ed4f59d3d99ca11354f9cbfd17
child 77138 a9adf1767b4668df8ad0fa036db2bf19a07616d0
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmfinkle
bugs605365
milestone9.0a1
Bug 605365 - Properly update visibility of the previously visible popup (r=mfinkle) ContentPopupHelper is meant to only handle one popup at a time. This means that if you update the popup (via the popup setter), the previously visible popup should be properly hidden and released before showing the new popup.
mobile/chrome/content/ContentPopupHelper.js
--- a/mobile/chrome/content/ContentPopupHelper.js
+++ b/mobile/chrome/content/ContentPopupHelper.js
@@ -40,17 +40,37 @@ var ContentPopupHelper = {
     return this._popup;
   },
 
   set popup(aPopup) {
     // If there is nothing to do then bail out
     if (!this._popup && !aPopup)
       return;
 
-    if (aPopup) {
+    if (this._popup) {
+      this._popup.hidden = true;
+      this._anchorRect = null;
+
+      window.removeEventListener("TabSelect", this, false);
+      window.removeEventListener("TabClose", this, false);
+      window.removeEventListener("AnimatedZoomBegin", this, false);
+      window.removeEventListener("AnimatedZoomEnd", this, false);
+      window.removeEventListener("MozBeforeResize", this, true);
+      window.removeEventListener("resize", this, false);
+      Elements.browsers.removeEventListener("PanBegin", this, false);
+      Elements.browsers.removeEventListener("PanFinished", this, false);
+
+      let event = document.createEvent("Events");
+      event.initEvent("contentpopuphidden", true, false);
+      this._popup.dispatchEvent(event);
+    }
+
+    this._popup = aPopup;
+
+    if (this._popup) {
       // Keeps the new popup element hidden until it is positioned, but using
       // visibility: 'hidden' instead of display: 'none' will allow to
       // workaround some bugs with arrowscrollbox's arrows that does not
       // update their hidden state correctly when used as a child (because of
       // missed underflow events)
       //
       // Also the popup is moved to the left border of the window otherwise the
       // sidebars position are messed up when the content of the popup's child
@@ -66,35 +86,17 @@ var ContentPopupHelper = {
       window.addEventListener("TabSelect", this, false);
       window.addEventListener("TabClose", this, false);
       window.addEventListener("AnimatedZoomBegin", this, false);
       window.addEventListener("AnimatedZoomEnd", this, false);
       window.addEventListener("MozBeforeResize", this, true);
       window.addEventListener("resize", this, false);
       Elements.browsers.addEventListener("PanBegin", this, false);
       Elements.browsers.addEventListener("PanFinished", this, false);
-    } else {
-      this._popup.hidden = true;
-      this._anchorRect = null;
-
-      window.removeEventListener("TabSelect", this, false);
-      window.removeEventListener("TabClose", this, false);
-      window.removeEventListener("AnimatedZoomBegin", this, false);
-      window.removeEventListener("AnimatedZoomEnd", this, false);
-      window.removeEventListener("MozBeforeResize", this, true);
-      window.removeEventListener("resize", this, false);
-      Elements.browsers.removeEventListener("PanBegin", this, false);
-      Elements.browsers.removeEventListener("PanFinished", this, false);
-
-      let event = document.createEvent("Events");
-      event.initEvent("contentpopuphidden", true, false);
-      this._popup.dispatchEvent(event);
     }
-
-    this._popup = aPopup;
   },
 
   /**
    * This method positions an arrowbox on the screen using a 'virtual'
    * element as referrer that match the real content element
    * This method calls element.getBoundingClientRect() many times and can be
    * expensive, do not call it too many times.
    */