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
--- 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"/>