Bug 1369899 - Listen to MozDOMFullscreen events r=Gijs

While we are now correctly evaluating the fullscreen situation
in OSX so that our update doorhangers behave as if we're in
windowed mode, we aren't correctly listening for state changes.
This addresses that, and tries to limit the chattiness by only
listening to the fullscreen events that we care about.

MozReview-Commit-ID: 9J009l4w21E

--HG--
extra : rebase_source : 4bcb607ec066b5cac390aac2dd649563d3b15beb
This commit is contained in:
Doug Thayer 2017-06-02 15:13:23 -07:00
Родитель e6640b566c
Коммит 0813b229d6
3 изменённых файлов: 85 добавлений и 4 удалений

Просмотреть файл

@ -60,7 +60,33 @@ const PanelUI = {
Services.obs.addObserver(this, "fullscreen-nav-toolbox");
Services.obs.addObserver(this, "appMenu-notifications");
window.addEventListener("fullscreen", this);
XPCOMUtils.defineLazyPreferenceGetter(this, "autoHideToolbarInFullScreen",
"browser.fullscreen.autohide", false, (pref, previousValue, newValue) => {
// On OSX, or with autohide preffed off, MozDOMFullscreen is the only
// event we care about, since fullscreen should behave just like non
// fullscreen. Otherwise, we don't want to listen to these because
// we'd just be spamming ourselves with both of them whenever a user
// opened a video.
if (newValue) {
window.removeEventListener("MozDOMFullscreen:Entered", this);
window.removeEventListener("MozDOMFullscreen:Exited", this);
window.addEventListener("fullscreen", this);
} else {
window.addEventListener("MozDOMFullscreen:Entered", this);
window.addEventListener("MozDOMFullscreen:Exited", this);
window.removeEventListener("fullscreen", this);
}
this._updateNotifications(false);
}, autoHidePref => autoHidePref && Services.appinfo.OS !== "Darwin");
if (this.autoHideToolbarInFullScreen) {
window.addEventListener("fullscreen", this);
} else {
window.addEventListener("MozDOMFullscreen:Entered", this);
window.addEventListener("MozDOMFullscreen:Exited", this);
}
window.addEventListener("activate", this);
window.matchMedia("(-moz-overlay-scrollbars)").addListener(this._overlayScrollListenerBoundFn);
CustomizableUI.addListener(this);
@ -175,6 +201,8 @@ const PanelUI = {
Services.obs.removeObserver(this, "fullscreen-nav-toolbox");
Services.obs.removeObserver(this, "appMenu-notifications");
window.removeEventListener("MozDOMFullscreen:Entered", this);
window.removeEventListener("MozDOMFullscreen:Exited", this);
window.removeEventListener("fullscreen", this);
window.removeEventListener("activate", this);
this.menuButton.removeEventListener("mousedown", this);
@ -326,6 +354,8 @@ const PanelUI = {
case "keypress":
this.toggle(aEvent);
break;
case "MozDOMFullscreen:Entered":
case "MozDOMFullscreen:Exited":
case "fullscreen":
case "activate":
this._updateNotifications();
@ -744,10 +774,8 @@ const PanelUI = {
this._showBannerItem(notifications[0]);
}
} else if (doorhangers.length > 0) {
let autoHideFullScreen = Services.prefs.getBoolPref("browser.fullscreen.autohide", false) &&
Services.appinfo.OS !== "Darwin";
// Only show the doorhanger if the window is focused and not fullscreen
if ((window.fullScreen && autoHideFullScreen) || Services.focus.activeWindow !== window) {
if ((window.fullScreen && this.autoHideToolbarInFullScreen) || Services.focus.activeWindow !== window) {
this._hidePopup();
this._showBadge(doorhangers[0]);
this._showBannerItem(doorhangers[0]);

Просмотреть файл

@ -156,6 +156,8 @@ skip-if = os == "mac"
[browser_panelUINotifications_fullscreen.js]
tags = fullscreen
skip-if = os == "mac"
[browser_panelUINotifications_fullscreen_noAutoHideToolbar.js]
tags = fullscreen
[browser_panelUINotifications_multiWindow.js]
[browser_switch_to_customize_mode.js]
[browser_synced_tabs_menu.js]

Просмотреть файл

@ -0,0 +1,51 @@
"use strict";
Cu.import("resource://gre/modules/AppMenuNotifications.jsm");
add_task(async function testFullscreen() {
if (Services.appinfo.OS !== "Darwin") {
await SpecialPowers.pushPrefEnv({
set: [
["browser.fullscreen.autohide", false],
]});
}
is(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is closed.");
let mainActionCalled = false;
let mainAction = {
callback: () => { mainActionCalled = true; }
};
AppMenuNotifications.showNotification("update-manual", mainAction);
isnot(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is showing.");
let notifications = [...PanelUI.notificationPanel.children].filter(n => !n.hidden);
is(notifications.length, 1, "PanelUI doorhanger is only displaying one notification.");
let doorhanger = notifications[0];
is(doorhanger.id, "appMenu-update-manual-notification", "PanelUI is displaying the update-manual notification.");
EventUtils.synthesizeKey("VK_F11", {});
isnot(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is still showing after entering fullscreen.");
let popuphiddenPromise = BrowserTestUtils.waitForEvent(PanelUI.notificationPanel, "popuphidden");
await ContentTask.spawn(gBrowser.selectedBrowser, {}, async () => {
content.document.documentElement.requestFullscreen();
});
await popuphiddenPromise;
await new Promise(executeSoon);
is(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is hidden after entering DOM fullscreen.");
let popupshownPromise = BrowserTestUtils.waitForEvent(PanelUI.notificationPanel, "popupshown");
await ContentTask.spawn(gBrowser.selectedBrowser, {}, async () => {
content.document.exitFullscreen();
});
await popupshownPromise;
await new Promise(executeSoon);
isnot(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is shown after exiting DOM fullscreen.");
isnot(PanelUI.menuButton.getAttribute("badge-status"), "update-manual", "Badge is not displaying on PanelUI button.");
let mainActionButton = document.getAnonymousElementByAttribute(doorhanger, "anonid", "button");
mainActionButton.click();
ok(mainActionCalled, "Main action callback was called");
is(PanelUI.notificationPanel.state, "closed", "update-manual doorhanger is closed.");
is(PanelUI.menuButton.hasAttribute("badge-status"), false, "Should not have a badge status");
});