Bug 1183786 - Part 2: Delay updating after prefs changed if detached. r=tn r=dholbert
authorEric Rahm <erahm@mozilla.com>
Thu, 30 Jul 2015 20:47:26 -0700
changeset 287676 3ee7019afe884b9b486559abb6c43561ea266851
parent 287675 d4d1a87bd2c0935a59c15c6679bf39d21c3cad54
child 287677 db090fd8b881f2ecc5a194e3a42d6c2f7880f03c
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn, dholbert
bugs1183786
milestone42.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 1183786 - Part 2: Delay updating after prefs changed if detached. r=tn r=dholbert
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -943,16 +943,22 @@ nsPresContext::PreferenceChanged(const c
   }
 }
 
 void
 nsPresContext::UpdateAfterPreferencesChanged()
 {
   mPrefChangedTimer = nullptr;
 
+  if (!mContainer) {
+    // Delay updating until there is a container
+    mNeedsPrefUpdate = true;
+    return;
+  }
+
   nsCOMPtr<nsIDocShellTreeItem> docShell(mContainer);
   if (docShell && nsIDocShellTreeItem::typeChrome == docShell->ItemType()) {
     return;
   }
 
   // Initialize our state from the user preferences
   GetUserPreferences();
 
@@ -1564,17 +1570,25 @@ nsPresContext::ScreenSizeInchesForFontIn
 
   return deviceSizeInches;
 }
 
 void
 nsPresContext::SetContainer(nsIDocShell* aDocShell)
 {
   if (aDocShell) {
+    NS_ASSERTION(!(!!mContainer && mNeedsPrefUpdate),
+                 "Should only need pref update if mContainer is null.");
     mContainer = static_cast<nsDocShell*>(aDocShell);
+    if (mNeedsPrefUpdate) {
+      if (!mPrefChangedTimer) {
+        InitTimer(mPrefChangedTimer, nsPresContext::PrefChangedUpdateTimerCallback, 0);
+      }
+      mNeedsPrefUpdate = false;
+    }
   } else {
     mContainer = WeakPtr<nsDocShell>();
   }
   UpdateIsChrome();
   if (mContainer) {
     GetDocumentColorPreferences();
   }
 }
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -1372,16 +1372,19 @@ protected:
   mutable unsigned mPaintFlashing : 1;
   mutable unsigned mPaintFlashingInitialized : 1;
 
   unsigned mHasWarnedAboutPositionedTableParts : 1;
 
   // Have we added quirk.css to the style set?
   unsigned              mQuirkSheetAdded : 1;
 
+  // Is there a pref update to process once we have a container?
+  unsigned              mNeedsPrefUpdate : 1;
+
 #ifdef RESTYLE_LOGGING
   // Should we output debug information about restyling for this document?
   bool                  mRestyleLoggingEnabled;
 #endif
 
 #ifdef DEBUG
   bool                  mInitialized;
 #endif