Bug 1251569 - It's not possible to hide the Blocked Popup menu by clicking its anchor button in urlbar. r=dolske draft
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 28 Sep 2016 13:52:44 +0200
changeset 418332 427b264cc3cee738a6d67d5a3a8795d0f463ccf0
parent 417914 66a77b9bfe5dcacd50eccf85de7c0e7e15ce0ffd
child 532337 452fff79af8f6a66b24fa6b47c6b80ef300cbd56
push id30673
push usermak77@bonardo.net
push dateWed, 28 Sep 2016 12:06:33 +0000
reviewersdolske
bugs1251569
milestone52.0a1
Bug 1251569 - It's not possible to hide the Blocked Popup menu by clicking its anchor button in urlbar. r=dolske MozReview-Commit-ID: 7L6JwLNJt5x
browser/base/content/browser.js
browser/base/content/browser.xul
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -386,19 +386,21 @@ function findChildShell(aDocument, aDocS
       return docShell;
   }
   return null;
 }
 
 var gPopupBlockerObserver = {
   _reportButton: null,
 
-  onReportButtonClick: function (aEvent)
+  onReportButtonMousedown: function (aEvent)
   {
-    if (aEvent.button != 0 || aEvent.target != this._reportButton)
+    // If this method is called on the same event tick as the popup gets
+    // hidden, do nothing to avoid re-opening the popup.
+    if (aEvent.button != 0 || aEvent.target != this._reportButton || this.isPopupHidingTick)
       return;
 
     document.getElementById("blockedPopupOptions")
             .openPopup(this._reportButton, "after_end", 0, 2, false, false, aEvent);
   },
 
   handleEvent: function (aEvent)
   {
@@ -586,16 +588,19 @@ var gPopupBlockerObserver = {
         blockedPopupsSeparator.removeAttribute("hidden");
     }, null);
   },
 
   onPopupHiding: function (aEvent) {
     if (aEvent.target.anchorNode.id == "page-report-button")
       aEvent.target.anchorNode.removeAttribute("open");
 
+    this.isPopupHidingTick = true;
+    setTimeout(() => this.isPopupHidingTick = false, 0);
+
     let item = aEvent.target.lastChild;
     while (item && item.getAttribute("observes") != "blockedPopupsSeparator") {
       let next = item.previousSibling;
       item.parentNode.removeChild(item);
       item = next;
     }
   },
 
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -749,17 +749,17 @@
               <box id="urlbar-display-box" align="center">
                 <label class="urlbar-display urlbar-display-switchtab" value="&urlbar.switchToTab.label;"/>
               </box>
               <hbox id="urlbar-icons">
                 <image id="page-report-button"
                        class="urlbar-icon"
                        hidden="true"
                        tooltiptext="&pageReportIcon.tooltip;"
-                       onclick="gPopupBlockerObserver.onReportButtonClick(event);"/>
+                       onmousedown="gPopupBlockerObserver.onReportButtonMousedown(event);"/>
                 <image id="reader-mode-button"
                        class="urlbar-icon"
                        hidden="true"
                        onclick="ReaderParent.buttonClick(event);"/>
                 <toolbarbutton id="urlbar-zoom-button"
                        onclick="FullZoom.reset();"
                        tooltiptext="&urlbar.zoomReset.tooltip;"
                        hidden="true"/>