Bug 1440613: Flush pending media feature values changes before initializing the shell. r=dbaron
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 21 Feb 2018 12:56:49 +0100
changeset 759115 bd876f6cfc077e29607949c1d06bfceca0fcee03
parent 759114 ce6adae0faa1a40db9e0015d880c3d086f755d23
child 759116 7d73206bcde2886a5be0f99e994ba54d331f32ea
push id100272
push userrwood@mozilla.com
push dateFri, 23 Feb 2018 18:27:33 +0000
reviewersdbaron
bugs1440613
milestone60.0a1
Bug 1440613: Flush pending media feature values changes before initializing the shell. r=dbaron This is guaranteed not to run script because of: https://searchfox.org/mozilla-central/rev/47cb352984bac15c476dcd75f8360f902673cb98/layout/base/nsPresContext.cpp#2152 This doesn't have any effect on the top-level chrome window, but avoids a full document restyle on XUL popups on startup. With this patch, there are no more full document restyles due to media feature changes on my machine on startup. MozReview-Commit-ID: HLkhIsIIa2W
layout/base/PresShell.cpp
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -1747,16 +1747,24 @@ PresShell::Initialize()
 
   NS_ASSERTION(!mDidInitialize, "Why are we being called?");
 
   nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
 
   RecomputeFontSizeInflationEnabled();
   MOZ_DIAGNOSTIC_ASSERT(!mIsDestroying);
 
+  // Ensure the pres context doesn't think it has changed, since we haven't even
+  // started layout. This avoids spurious restyles / reflows afterwards.
+  //
+  // Note that this is very intentionally before setting mDidInitialize so it
+  // doesn't notify the document, or run media query change events.
+  mPresContext->FlushPendingMediaFeatureValuesChanged();
+  MOZ_DIAGNOSTIC_ASSERT(!mIsDestroying);
+
   mDidInitialize = true;
 
 #ifdef DEBUG
   if (VERIFY_REFLOW_NOISY_RC & gVerifyReflowFlags) {
     if (mDocument) {
       nsIURI *uri = mDocument->GetDocumentURI();
       if (uri) {
         printf("*** PresShell::Initialize (this=%p, url='%s')\n",