Bug 1292930: stylo: Reuse RestyleManager::PostRestyleEventInternal. r=heycam
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Wed, 03 Aug 2016 18:58:06 -0700
changeset 309171 2d5a7f342256264b31c8378795c03b5844bfc53b
parent 309170 32e07e32891d070cdba97e2872cd30265278c0bf
child 309172 294df63717f1e5b7665164bda1e080fd95914a38
push id31321
push userkwierso@gmail.com
push dateFri, 12 Aug 2016 23:30:18 +0000
treeherderautoland@c385cb6a0838 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1292930
milestone51.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 1292930: stylo: Reuse RestyleManager::PostRestyleEventInternal. r=heycam MozReview-Commit-ID: J6rw1feAYWh
layout/base/RestyleManager.cpp
layout/base/RestyleManager.h
layout/base/RestyleManagerBase.cpp
layout/base/RestyleManagerBase.h
layout/base/ServoRestyleManager.cpp
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -81,17 +81,16 @@ ElementTagToString(dom::Element* aElemen
   return result;
 }
 #endif
 
 RestyleManager::RestyleManager(nsPresContext* aPresContext)
   : RestyleManagerBase(aPresContext)
   , mDoRebuildAllStyleData(false)
   , mInRebuildAllStyleData(false)
-  , mInStyleRefresh(false)
   , mSkipAnimationRules(false)
   , mHavePendingNonAnimationRestyles(false)
   , mRebuildAllExtraHint(nsChangeHint(0))
   , mRebuildAllRestyleHint(nsRestyleHint(0))
   , mAnimationGeneration(0)
   , mReframingStyleContexts(nullptr)
   , mAnimationsWithDestroyedFrame(nullptr)
   , mPendingRestyles(ELEMENT_HAS_PENDING_RESTYLE |
@@ -946,35 +945,16 @@ RestyleManager::PostRestyleEvent(Element
   if (aRestyleHint & ~eRestyle_AllHintsWithAnimations) {
     mHavePendingNonAnimationRestyles = true;
   }
 
   PostRestyleEventInternal(false);
 }
 
 void
-RestyleManager::PostRestyleEventInternal(bool aForLazyConstruction)
-{
-  // Make sure we're not in a style refresh; if we are, we still have
-  // a call to ProcessPendingRestyles coming and there's no need to
-  // add ourselves as a refresh observer until then.
-  bool inRefresh = !aForLazyConstruction && mInStyleRefresh;
-  nsIPresShell* presShell = PresContext()->PresShell();
-  if (!ObservingRefreshDriver() && !inRefresh) {
-    SetObservingRefreshDriver(PresContext()->RefreshDriver()->
-        AddStyleFlushObserver(presShell));
-  }
-
-  // Unconditionally flag our document as needing a flush.  The other
-  // option here would be a dedicated boolean to track whether we need
-  // to do so (set here and unset in ProcessPendingRestyles).
-  presShell->GetDocument()->SetNeedStyleFlush();
-}
-
-void
 RestyleManager::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
                                              nsRestyleHint aRestyleHint)
 {
   NS_ASSERTION(!(aExtraHint & nsChangeHint_ReconstructFrame),
                "Should not reconstruct the root of the frame tree.  "
                "Use ReconstructDocElementHierarchy instead.");
   MOZ_ASSERT(!(aRestyleHint & eRestyle_SomeDescendants),
              "PostRebuildAllStyleDataEvent does not handle "
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -379,19 +379,16 @@ public:
   {
     PostRestyleEventInternal(true);
   }
 
 #ifdef DEBUG
   static nsCString ChangeHintToString(nsChangeHint aHint);
 #endif
 
-private:
-  void PostRestyleEventInternal(bool aForLazyConstruction);
-
 public:
   /**
    * Asynchronously clear style data from the root frame downwards and ensure
    * it will all be rebuilt. This is safe to call anytime; it will schedule
    * a restyle and take effect next time style changes are flushed.
    * This method is used to recompute the style data when some change happens
    * outside of any style rules, like a color preference change or a change
    * in a system font size, or to fix things up when an optimization in the
@@ -485,18 +482,16 @@ private:
   }
 
 private:
   // True if we need to reconstruct the rule tree the next time we
   // process restyles.
   bool mDoRebuildAllStyleData : 1;
   // True if we're currently in the process of reconstructing the rule tree.
   bool mInRebuildAllStyleData : 1;
-  // True if we're in the middle of a nsRefreshDriver refresh
-  bool mInStyleRefresh : 1;
   // Whether rule matching should skip styles associated with animation
   bool mSkipAnimationRules : 1;
   bool mHavePendingNonAnimationRestyles : 1;
 
   nsChangeHint mRebuildAllExtraHint;
   nsRestyleHint mRebuildAllRestyleHint;
 
   // The total number of animation flushes by this frame constructor.
--- a/layout/base/RestyleManagerBase.cpp
+++ b/layout/base/RestyleManagerBase.cpp
@@ -10,16 +10,17 @@
 
 namespace mozilla {
 
 RestyleManagerBase::RestyleManagerBase(nsPresContext* aPresContext)
   : mPresContext(aPresContext)
   , mRestyleGeneration(1)
   , mHoverGeneration(0)
   , mObservingRefreshDriver(false)
+  , mInStyleRefresh(false)
 {
   MOZ_ASSERT(mPresContext);
 }
 
 /**
  * Calculates the change hint and the restyle hint for a given content state
  * change.
  *
@@ -130,16 +131,35 @@ RestyleManagerBase::RestyleHintToString(
   } else {
     if (!any) {
       result.AppendLiteral("0");
     }
   }
   return result;
 }
 
+void
+RestyleManagerBase::PostRestyleEventInternal(bool aForLazyConstruction)
+{
+  // Make sure we're not in a style refresh; if we are, we still have
+  // a call to ProcessPendingRestyles coming and there's no need to
+  // add ourselves as a refresh observer until then.
+  bool inRefresh = !aForLazyConstruction && mInStyleRefresh;
+  nsIPresShell* presShell = PresContext()->PresShell();
+  if (!ObservingRefreshDriver() && !inRefresh) {
+    SetObservingRefreshDriver(PresContext()->RefreshDriver()->
+        AddStyleFlushObserver(presShell));
+  }
+
+  // Unconditionally flag our document as needing a flush.  The other
+  // option here would be a dedicated boolean to track whether we need
+  // to do so (set here and unset in ProcessPendingRestyles).
+  presShell->GetDocument()->SetNeedStyleFlush();
+}
+
 /**
  * Frame construction helpers follow.
  */
 #ifdef DEBUG
 static bool gInApplyRenderingChangeToTree = false;
 #endif
 
 #ifdef DEBUG
--- a/layout/base/RestyleManagerBase.h
+++ b/layout/base/RestyleManagerBase.h
@@ -116,18 +116,23 @@ protected:
 private:
   nsPresContext* mPresContext; // weak, can be null after Disconnect().
   uint32_t mRestyleGeneration;
   uint32_t mHoverGeneration;
   // True if we're already waiting for a refresh notification.
   bool mObservingRefreshDriver;
 
 protected:
+  // True if we're in the middle of a nsRefreshDriver refresh
+  bool mInStyleRefresh;
+
   OverflowChangedTracker mOverflowChangedTracker;
 
+  void PostRestyleEventInternal(bool aForLazyConstruction);
+
   /**
    * These are protected static methods that help with the change hint
    * processing bits of the restyle managers.
    */
   static nsIFrame*
   GetNearestAncestorFrame(nsIContent* aContent);
 
   static nsIFrame*
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -33,29 +33,23 @@ ServoRestyleManager::PostRestyleEvent(El
   // Note that unlike in Servo, we don't mark elements as dirty until we process
   // the restyle hints in ProcessPendingRestyles.
   if (aRestyleHint || aMinChangeHint) {
     ServoElementSnapshot* snapshot = SnapshotForElement(aElement);
     snapshot->AddExplicitRestyleHint(aRestyleHint);
     snapshot->AddExplicitChangeHint(aMinChangeHint);
   }
 
-  nsIPresShell* presShell = PresContext()->PresShell();
-  if (!ObservingRefreshDriver()) {
-    SetObservingRefreshDriver(
-      PresContext()->RefreshDriver()->AddStyleFlushObserver(presShell));
-  }
-
-  presShell->GetDocument()->SetNeedStyleFlush();
+  PostRestyleEventInternal(false);
 }
 
 void
 ServoRestyleManager::PostRestyleEventForLazyConstruction()
 {
-  NS_WARNING("stylo: ServoRestyleManager::PostRestyleEventForLazyConstruction not implemented");
+  PostRestyleEventInternal(true);
 }
 
 void
 ServoRestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
                                          nsRestyleHint aRestyleHint)
 {
   NS_WARNING("stylo: ServoRestyleManager::RebuildAllStyleData not implemented");
 }
@@ -238,32 +232,34 @@ ServoRestyleManager::ProcessPendingResty
       hint |= snapshot->ExplicitRestyleHint();
 
       if (hint) {
         NoteRestyleHint(element, hint);
       }
     }
 
     if (root->IsDirtyForServo() || root->HasDirtyDescendantsForServo()) {
+      mInStyleRefresh = true;
       styleSet->RestyleSubtree(root);
 
       // First do any queued-up frame creation. (see bugs 827239 and 997506).
       //
       // XXXEmilio I'm calling this to avoid random behavior changes, since we
       // delay frame construction after styling we should re-check once our
       // model is more stable whether we can skip this call.
       //
       // Note this has to be *after* restyling, because otherwise frame
       // construction will find unstyled nodes, and that's not funny.
       PresContext()->FrameConstructor()->CreateNeededFrames();
 
       nsStyleChangeList changeList;
-
       RecreateStyleContexts(root, nullptr, styleSet, changeList);
       ProcessRestyledFrames(changeList);
+
+      mInStyleRefresh = false;
     }
   }
 
   mModifiedElements.Clear();
 
   // NB: we restyle from the root element, but the document also gets the
   // HAS_DIRTY_DESCENDANTS flag as part of the loop on PostRestyleEvent, and we
   // use that to check we have pending restyles.