Bug 1332040 - Dispatch resize after fullscreen transistion for headless. r=jrmuizel
authorBrendan Dahl <bdahl@mozilla.com>
Sun, 20 May 2018 17:00:57 -0700
changeset 419902 ae756063903dda9401fac5bf0b8fb3a5e81ef9f0
parent 419901 2de498d1e77e272766410f176a3dc9fbf2200b07
child 419903 d3d46b1e864f0472db0d360a5084715230e01c5f
push id34053
push userdluca@mozilla.com
push dateSat, 26 May 2018 04:07:01 +0000
treeherdermozilla-central@e0beb6560ec9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1332040
milestone62.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 1332040 - Dispatch resize after fullscreen transistion for headless. r=jrmuizel MozReview-Commit-ID: Lo17bhJsnww
widget/headless/HeadlessWidget.cpp
--- a/widget/headless/HeadlessWidget.cpp
+++ b/widget/headless/HeadlessWidget.cpp
@@ -412,23 +412,36 @@ HeadlessWidget::MakeFullScreen(bool aFul
     if (mSizeMode != nsSizeMode_Fullscreen) {
       mLastSizeMode = mSizeMode;
     }
     mSizeMode = nsSizeMode_Fullscreen;
   } else {
     mSizeMode = mLastSizeMode;
   }
 
-  nsBaseWidget::InfallibleMakeFullScreen(aFullScreen, aTargetScreen);
-
+  // Notify the listener first so size mode change events are triggered before
+  // resize events.
   if (mWidgetListener) {
     mWidgetListener->SizeModeChanged(mSizeMode);
     mWidgetListener->FullscreenChanged(aFullScreen);
   }
 
+  // Real widget backends don't seem to follow a common approach for
+  // when and how many resize events are triggered during fullscreen
+  // transitions. InfallibleMakeFullScreen will trigger a resize, but it
+  // will be ignored if still transitioning to fullscreen, so it must be
+  // triggered on the next tick.
+  RefPtr<HeadlessWidget> self(this);
+  nsCOMPtr<nsIScreen> targetScreen(aTargetScreen);
+  NS_DispatchToCurrentThread(NS_NewRunnableFunction(
+    "HeadlessWidget::MakeFullScreen",
+    [self, targetScreen, aFullScreen]() -> void {
+      self->InfallibleMakeFullScreen(aFullScreen, targetScreen);
+    }));
+
   return NS_OK;
 }
 
 nsresult
 HeadlessWidget::AttachNativeKeyEvent(WidgetKeyboardEvent& aEvent)
 {
   HeadlessKeyBindings& bindings = HeadlessKeyBindings::GetInstance();
   return bindings.AttachNativeKeyEvent(aEvent);