Bug 1367227 - Part 1 - Match headless fullscreen behavior to other widget backends. r=jrmuizel
authorBrendan Dahl <bdahl@mozilla.com>
Fri, 26 May 2017 14:11:38 -0700
changeset 409849 8a78af3f02805279a1ac130a9daa336af3a1d65a
parent 409848 9a7debda755d22df58bffe5132d7ec47ad5447b1
child 409850 812a3f2737d4a2674da91a9d60cbfb7268d46f63
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1367227
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1367227 - Part 1 - Match headless fullscreen behavior to other widget backends. r=jrmuizel Restore size mode after leaving fullscreen. Also, trigger fullscreen and size mode changed events during MakeFullScreen.
widget/headless/HeadlessWidget.cpp
widget/headless/HeadlessWidget.h
--- a/widget/headless/HeadlessWidget.cpp
+++ b/widget/headless/HeadlessWidget.cpp
@@ -145,16 +145,19 @@ HeadlessWidget::Resize(double aX,
     NotifyWindowMoved(aX, aY);
   }
   return Resize(aWidth, aHeight, aRepaint);
 }
 
 void
 HeadlessWidget::SetSizeMode(nsSizeMode aMode)
 {
+  if (aMode == mSizeMode) {
+    return;
+  }
   if (mSizeMode == nsSizeMode_Normal) {
     // Store the last normal size bounds so it can be restored when entering
     // normal mode again.
     mRestoreBounds = mBounds;
   }
 
   nsBaseWidget::SetSizeMode(aMode);
 
@@ -163,33 +166,60 @@ HeadlessWidget::SetSizeMode(nsSizeMode a
   // the window must manually be resized.
   switch(aMode) {
   case nsSizeMode_Normal: {
     Resize(mRestoreBounds.x, mRestoreBounds.y, mRestoreBounds.width, mRestoreBounds.height, false);
     break;
   }
   case nsSizeMode_Minimized:
     break;
-  case nsSizeMode_Maximized:
-  case nsSizeMode_Fullscreen: {
+  case nsSizeMode_Maximized: {
     nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
     if (screen) {
       int32_t left, top, width, height;
       if (NS_SUCCEEDED(screen->GetRectDisplayPix(&left, &top, &width, &height))) {
         Resize(0, 0, width, height, true);
       }
     }
     break;
   }
+  case nsSizeMode_Fullscreen:
+    // This will take care of resizing the window.
+    nsBaseWidget::InfallibleMakeFullScreen(true);
+    break;
   default:
     break;
   }
 }
 
 nsresult
+HeadlessWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aTargetScreen)
+{
+  // Directly update the size mode here so a later call SetSizeMode does
+  // nothing.
+  if (aFullScreen) {
+    if (mSizeMode != nsSizeMode_Fullscreen) {
+      mLastSizeMode = mSizeMode;
+    }
+    mSizeMode = nsSizeMode_Fullscreen;
+  } else {
+    mSizeMode = mLastSizeMode;
+  }
+
+  nsBaseWidget::InfallibleMakeFullScreen(aFullScreen, aTargetScreen);
+
+  if (mWidgetListener) {
+    mWidgetListener->SizeModeChanged(mSizeMode);
+    mWidgetListener->FullscreenChanged(aFullScreen);
+  }
+
+  return NS_OK;
+}
+
+nsresult
 HeadlessWidget::DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus)
 {
 #ifdef DEBUG
   debug_DumpEvent(stdout, aEvent->mWidget, aEvent, "HeadlessWidget", 0);
 #endif
 
   aStatus = nsEventStatus_eIgnore;
 
--- a/widget/headless/HeadlessWidget.h
+++ b/widget/headless/HeadlessWidget.h
@@ -42,16 +42,18 @@ public:
                       double aHeight,
                       bool   aRepaint) override;
   virtual void Resize(double aX,
                       double aY,
                       double aWidth,
                       double aHeight,
                       bool   aRepaint) override;
   virtual void SetSizeMode(nsSizeMode aMode) override;
+  virtual nsresult MakeFullScreen(bool aFullScreen,
+                                  nsIScreen* aTargetScreen = nullptr) override;
   virtual void Enable(bool aState) override;
   virtual bool IsEnabled() const override;
   virtual nsresult SetFocus(bool aRaise) override { return NS_OK; }
   virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) override
   {
     MOZ_ASSERT_UNREACHABLE("Headless widgets do not support configuring children.");
     return NS_ERROR_FAILURE;
   }
@@ -81,16 +83,18 @@ public:
 
   virtual nsresult DispatchEvent(WidgetGUIEvent* aEvent,
                                  nsEventStatus& aStatus) override;
 
 private:
   ~HeadlessWidget() {}
   bool mEnabled;
   bool mVisible;
+  // The size mode before entering fullscreen mode.
+  nsSizeMode mLastSizeMode;
   InputContext mInputContext;
   // In headless there is no window manager to track window bounds
   // across size mode changes, so we must track it to emulate.
   LayoutDeviceIntRect mRestoreBounds;
 };
 
 } // namespace widget
 } // namespace mozilla