Bug 1385194 - Make PopupNotifications handle windows without a location bar or a tab bar. r=Paolo
This also fixes a bug where notifications would not be displayed
correctly when PopupNotifications.jsm was initialized while the
window is in DOM fullscreen.
MozReview-Commit-ID: D5SCqd9efGk
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -254,25 +254,31 @@ this.PopupNotifications = function Popup
focusedElement == this.tabbrowser.selectedBrowser ||
// Ignore focused elements inside the notification.
getNotificationFromElement(focusedElement) == notification ||
notification.contains(focusedElement)) {
this._onButtonEvent(aEvent, "secondarybuttoncommand", notification);
}
};
+ let documentElement = this.window.document.documentElement;
+ let locationBarHidden = documentElement.getAttribute("chromehidden").includes("location");
+ let isFullscreen = !!this.window.document.fullscreenElement;
+
+ this.panel.setAttribute("followanchor", !locationBarHidden && !isFullscreen);
+
// There are no anchor icons in DOM fullscreen mode, but we would
// still like to show the popup notification. To avoid an infinite
// loop of showing and hiding, we have to disable followanchor
// (which hides the element without an anchor) in fullscreen.
this.window.addEventListener("MozDOMFullscreen:Entered", () => {
this.panel.setAttribute("followanchor", "false");
}, true);
this.window.addEventListener("MozDOMFullscreen:Exited", () => {
- this.panel.setAttribute("followanchor", "true");
+ this.panel.setAttribute("followanchor", !locationBarHidden);
}, true);
this.window.addEventListener("activate", this, true);
if (this.tabbrowser.tabContainer)
this.tabbrowser.tabContainer.addEventListener("TabSelect", this, true);
}
PopupNotifications.prototype = {
@@ -935,16 +941,23 @@ PopupNotifications.prototype = {
// If the identity icon is not available in this window, or maybe the
// entire location bar is hidden for any reason, use the tab as the
// anchor. We only ever show notifications for the current browser, so we
// can just use the current tab.
if (!anchorElement || (anchorElement.boxObject.height == 0 &&
anchorElement.boxObject.width == 0)) {
anchorElement = this.tabbrowser.selectedTab;
+
+ // If we're in an entirely chromeless environment, set the anchorElement
+ // to null and let openPopup show the notification at (0,0) later.
+ if (!anchorElement || (anchorElement.boxObject.height == 0 &&
+ anchorElement.boxObject.width == 0)) {
+ anchorElement = null;
+ }
}
}
if (this.isPanelOpen && this._currentAnchorElement == anchorElement) {
notificationsToShow.forEach(function(n) {
this._fireCallback(n, NOTIFICATION_EVENT_SHOWN);
}, this);
@@ -1018,17 +1031,17 @@ PopupNotifications.prototype = {
this.panel.dispatchEvent(new this.window.CustomEvent("Shown"));
let event = new this.window.CustomEvent("PanelUpdated",
{"detail": notificationIds});
this.panel.dispatchEvent(event);
};
this._popupshownListener = this._popupshownListener.bind(this);
target.addEventListener("popupshown", this._popupshownListener, true);
- this.panel.openPopup(anchorElement, "bottomcenter topleft");
+ this.panel.openPopup(anchorElement, "bottomcenter topleft", 0, 0);
});
},
/**
* Updates the notification state in response to window activation or tab
* selection changes.
*
* @param notifications an array of Notification instances. if null,