Bug 1357917 - (pt. 2) Listen to MozDOMFullscreen events r?Gijs draft
authorDoug Thayer <dothayer@mozilla.com>
Fri, 02 Jun 2017 15:13:23 -0700
changeset 588499 f4099aaf816b913d95f329a6707ed147d847609a
parent 588345 87c745019518b1d6cd782534f2553721e5735657
child 631594 8eb30273f2dbb96d69bd013b512d2c5d93f859c5
push id62061
push userbmo:dothayer@mozilla.com
push dateFri, 02 Jun 2017 22:15:04 +0000
reviewersGijs
bugs1357917
milestone55.0a1
Bug 1357917 - (pt. 2) 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: DbfNa3dFFlh
browser/components/customizableui/content/panelUI.js
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -55,17 +55,29 @@ const PanelUI = {
 
     this.menuButton.addEventListener("mousedown", this);
     this.menuButton.addEventListener("keypress", this);
     this._overlayScrollListenerBoundFn = this._overlayScrollListener.bind(this);
 
     Services.obs.addObserver(this, "fullscreen-nav-toolbox");
     Services.obs.addObserver(this, "appMenu-notifications");
 
-    window.addEventListener("fullscreen", this);
+    Services.prefs.addObserver("browser.fullscreen.autohide", this);
+
+    // 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 (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);
 
     for (let event of this.kEvents) {
       this.notificationPanel.addEventListener(event, this);
     }
 
@@ -170,16 +182,20 @@ const PanelUI = {
     this._removeEventListeners();
     for (let event of this.kEvents) {
       this.notificationPanel.removeEventListener(event, this);
     }
 
     Services.obs.removeObserver(this, "fullscreen-nav-toolbox");
     Services.obs.removeObserver(this, "appMenu-notifications");
 
+    Services.prefs.removeObserver("browser.fullscreen.autohide", this);
+
+    window.removeEventListener("MozDOMFullscreen:Entered", this);
+    window.removeEventListener("MozDOMFullscreen:Exited", this);
     window.removeEventListener("fullscreen", this);
     window.removeEventListener("activate", this);
     this.menuButton.removeEventListener("mousedown", this);
     this.menuButton.removeEventListener("keypress", this);
     window.matchMedia("(-moz-overlay-scrollbars)").removeListener(this._overlayScrollListenerBoundFn);
     CustomizableUI.removeListener(this);
     this._overlayScrollListenerBoundFn = null;
   },
@@ -283,16 +299,31 @@ const PanelUI = {
       case "appMenu-notifications":
         // Don't initialize twice.
         if (status == "init" && this._notifications) {
           break;
         }
         this._notifications = AppMenuNotifications.notifications;
         this._updateNotifications(true);
         break;
+      case "nsPref:changed":
+        if (status == "browser.fullscreen.autohide") {
+          if (this.autoHideToolbarInFullScreen) {
+            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);
+        }
+        break;
     }
   },
 
   handleEvent(aEvent) {
     // Ignore context menus and menu button menus showing and hiding:
     if (aEvent.type.startsWith("popup") &&
         aEvent.target != this.panel) {
       return;
@@ -321,16 +352,18 @@ const PanelUI = {
         break;
       case "mousedown":
         if (aEvent.button == 0)
           this.toggle(aEvent);
         break;
       case "keypress":
         this.toggle(aEvent);
         break;
+      case "MozDOMFullscreen:Entered":
+      case "MozDOMFullscreen:Exited":
       case "fullscreen":
       case "activate":
         this._updateNotifications();
         break;
     }
   },
 
   get isReady() {
@@ -338,16 +371,21 @@ const PanelUI = {
   },
 
   get isNotificationPanelOpen() {
     let panelState = this.notificationPanel.state;
 
     return panelState == "showing" || panelState == "open";
   },
 
+  get autoHideToolbarInFullScreen() {
+    return Services.prefs.getBoolPref("browser.fullscreen.autohide", false) &&
+           Services.appinfo.OS !== "Darwin";
+  },
+
   /**
    * Registering the menu panel is done lazily for performance reasons. This
    * method is exposed so that CustomizationMode can force panel-readyness in the
    * event that customization mode is started before the panel has been opened
    * by the user.
    *
    * @param aCustomizing (optional) set to true if this was called while entering
    *        customization mode. If that's the case, we trust that customization
@@ -739,20 +777,18 @@ const PanelUI = {
       // since we don't want their doorhangers competing for attention
       doorhangers.forEach(n => { n.dismissed = true; })
       this._hidePopup();
       this._clearBadge();
       if (!notifications[0].options.badgeOnly) {
         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]);
       } else {
         this._clearBadge();
         this._showNotificationPanel(doorhangers[0]);
       }
     } else {