From 0813b229d6c603efd947c1a982fca823a87a6652 Mon Sep 17 00:00:00 2001 From: Doug Thayer Date: Fri, 2 Jun 2017 15:13:23 -0700 Subject: [PATCH] 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 --- .../customizableui/content/panelUI.js | 36 +++++++++++-- .../customizableui/test/browser.ini | 2 + ...ifications_fullscreen_noAutoHideToolbar.js | 51 +++++++++++++++++++ 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 browser/components/customizableui/test/browser_panelUINotifications_fullscreen_noAutoHideToolbar.js diff --git a/browser/components/customizableui/content/panelUI.js b/browser/components/customizableui/content/panelUI.js index 187fff24a911..44e86e6854f0 100644 --- a/browser/components/customizableui/content/panelUI.js +++ b/browser/components/customizableui/content/panelUI.js @@ -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]); diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index 9b5e9237f544..b2bbb49008ba 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -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] diff --git a/browser/components/customizableui/test/browser_panelUINotifications_fullscreen_noAutoHideToolbar.js b/browser/components/customizableui/test/browser_panelUINotifications_fullscreen_noAutoHideToolbar.js new file mode 100644 index 000000000000..cd0a4a89a0a6 --- /dev/null +++ b/browser/components/customizableui/test/browser_panelUINotifications_fullscreen_noAutoHideToolbar.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"); +});