Bug 1351791: Move PostRestyleEventForLazyConstruction and PostRestyleEventInternal to GeckoRestyleManager. r?bholley draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 30 Mar 2017 10:24:44 +0200
changeset 554372 893f2c476fe50615aa2e24d4cd6dfea22637b96b
parent 554371 bca6e683b5a50b420011f869948310ec1d1cfd6d
child 554373 d302423da8a4407f93b2d21d0552c7b7787670c4
push id51896
push userbmo:emilio+bugs@crisal.io
push dateFri, 31 Mar 2017 09:59:00 +0000
reviewersbholley
bugs1351791
milestone55.0a1
Bug 1351791: Move PostRestyleEventForLazyConstruction and PostRestyleEventInternal to GeckoRestyleManager. r?bholley MozReview-Commit-ID: 5lrNlkbrnZb
layout/base/GeckoRestyleManager.cpp
layout/base/GeckoRestyleManager.h
layout/base/RestyleManager.cpp
layout/base/RestyleManager.h
layout/base/ServoRestyleManager.cpp
layout/base/nsCSSFrameConstructor.cpp
--- a/layout/base/GeckoRestyleManager.cpp
+++ b/layout/base/GeckoRestyleManager.cpp
@@ -600,16 +600,35 @@ GeckoRestyleManager::UpdateOnlyAnimation
   }
 
   ProcessRestyles(tracker);
 
   transitionManager->SetInAnimationOnlyStyleUpdate(false);
 }
 
 void
+GeckoRestyleManager::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 (!inRefresh) {
+    presShell->ObserveStyleFlushes();
+  }
+
+  // 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->SetNeedStyleFlush();
+}
+
+
+void
 GeckoRestyleManager::PostRestyleEvent(Element* aElement,
                                       nsRestyleHint aRestyleHint,
                                       nsChangeHint aMinChangeHint,
                                       const RestyleHintData* aRestyleHintData)
 {
   if (MOZ_UNLIKELY(IsDisconnected()) ||
       MOZ_UNLIKELY(PresContext()->PresShell()->IsDestroying())) {
     return;
--- a/layout/base/GeckoRestyleManager.h
+++ b/layout/base/GeckoRestyleManager.h
@@ -52,16 +52,18 @@ protected:
   }
 
 public:
   // Forwarded nsIDocumentObserver method, to handle restyling (and
   // passing the notification to the frame).
   void ContentStateChanged(nsIContent* aContent,
                            EventStates aStateMask);
 
+  void PostRestyleEventForLazyConstruction() { PostRestyleEventInternal(true); }
+
   // Forwarded nsIMutationObserver method, to handle restyling.
   void AttributeWillChange(Element* aElement,
                            int32_t  aNameSpaceID,
                            nsIAtom* aAttribute,
                            int32_t  aModType,
                            const nsAttrValue* aNewValue);
   // Forwarded nsIMutationObserver method, to handle restyling (and
   // passing the notification to the frame).
@@ -109,16 +111,18 @@ public:
    */
   nsresult ReparentStyleContext(nsIFrame* aFrame);
 
   void ClearSelectors() {
     mPendingRestyles.ClearSelectors();
   }
 
 private:
+  void PostRestyleEventInternal(bool aForLazyConstruction);
+
   // Used when restyling an element with a frame.
   void ComputeAndProcessStyleChange(nsIFrame*              aFrame,
                                     nsChangeHint           aMinChange,
                                     RestyleTracker&        aRestyleTracker,
                                     nsRestyleHint          aRestyleHint,
                                     const RestyleHintData& aRestyleHintData);
 
   // Used when restyling a display:contents element.
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -489,34 +489,16 @@ RestyleManager::ChangeHintToString(nsCha
     if (!any) {
       result.AppendLiteral("nsChangeHint(0)");
     }
   }
   return result;
 }
 #endif
 
-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 (!inRefresh) {
-    presShell->ObserveStyleFlushes();
-  }
-
-  // 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->SetNeedStyleFlush();
-}
-
 /**
  * Frame construction helpers follow.
  */
 #ifdef DEBUG
 static bool gInApplyRenderingChangeToTree = false;
 #endif
 
 #ifdef DEBUG
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -129,18 +129,16 @@ public:
   /**
    * Return the current AnimationsWithDestroyedFrame struct, or null if we're
    * not currently in a restyling operation.
    */
   AnimationsWithDestroyedFrame* GetAnimationsWithDestroyedFrame() {
     return mAnimationsWithDestroyedFrame;
   }
 
-  void PostRestyleEventForLazyConstruction() { PostRestyleEventInternal(true); }
-
   void ContentInserted(nsINode* aContainer, nsIContent* aChild);
   void ContentAppended(nsIContent* aContainer, nsIContent* aFirstNewContent);
 
   // This would be have the same logic as RestyleForInsertOrChange if we got the
   // notification before the removal.  However, we get it after, so we need the
   // following sibling in addition to the old child.  |aContainer| must be
   // non-null; when the container is null, no work is needed.  aFollowingSibling
   // is the sibling that used to come after aOldChild before the removal.
@@ -230,18 +228,16 @@ private:
   const StyleBackendType mType;
 
 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
@@ -50,21 +50,17 @@ ServoRestyleManager::PostRestyleEvent(El
   // Processing change hints sometimes causes new change hints to be generated,
   // and very occasionally, additional restyle hints. We collect the change
   // hints manually to avoid re-traversing the DOM to find them.
   if (mReentrantChanges && !aRestyleHint) {
     mReentrantChanges->AppendElement(ReentrantChange { aElement, aMinChangeHint });
     return;
   }
 
-  if (aRestyleHint || aMinChangeHint) {
-    Servo_NoteExplicitHints(aElement, aRestyleHint, aMinChangeHint);
-  }
-
-  PostRestyleEventInternal(false);
+  Servo_NoteExplicitHints(aElement, aRestyleHint, aMinChangeHint);
 }
 
 /* static */ void
 ServoRestyleManager::PostRestyleEventForAnimations(Element* aElement,
                                                    nsRestyleHint aRestyleHint)
 {
   Servo_NoteExplicitHints(aElement, aRestyleHint, nsChangeHint(0));
 }
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -7165,17 +7165,20 @@ nsCSSFrameConstructor::MaybeConstructLaz
                    //XXX the child->GetPrimaryFrame()->GetContent() != child
                    // check is needed due to bug 135040. Remove it once that's
                    // fixed.
                    "setting NEEDS_FRAME on a node that already has a frame?");
       child->SetFlags(NODE_NEEDS_FRAME);
     }
   }
 
-  RestyleManager()->PostRestyleEventForLazyConstruction();
+  if (mozilla::GeckoRestyleManager* geckoRM = RestyleManager()->GetAsGecko()) {
+    geckoRM->PostRestyleEventForLazyConstruction();
+  }
+
   return true;
 }
 
 void
 nsCSSFrameConstructor::CreateNeededFrames(
     nsIContent* aContent,
     TreeMatchContext& aTreeMatchContext)
 {
@@ -7478,16 +7481,21 @@ nsCSSFrameConstructor::ContentAppended(n
       }
       return;
     }
 
     if (aAllowLazyConstruction &&
         MaybeConstructLazily(CONTENTAPPEND, aContainer, aFirstNewContent)) {
       if (isNewlyAddedContentForServo) {
         aContainer->AsElement()->NoteDirtyDescendantsForServo();
+      } else {
+        // Lazy frame construction is done by the restyle flushes, so we need to
+        // ensure a refresh happens.
+        mPresShell->SetNeedStyleFlush();
+        mPresShell->ObserveStyleFlushes();
       }
       return;
     }
   }
 
   // We couldn't construct lazily. Make Servo eagerly traverse the new content.
   if (isNewlyAddedContentForServo) {
     StyleNewChildRange(aFirstNewContent, nullptr);
@@ -7955,16 +7963,21 @@ nsCSSFrameConstructor::ContentRangeInser
     // Otherwise, we've got parent content. Find its frame.
     NS_ASSERTION(!parentFrame || parentFrame->GetContent() == aContainer ||
                  GetDisplayContentsStyleFor(aContainer), "New XBL code is possibly wrong!");
 
     if (aAllowLazyConstruction &&
         MaybeConstructLazily(CONTENTINSERT, aContainer, aStartChild)) {
       if (isNewlyAddedContentForServo) {
         aContainer->AsElement()->NoteDirtyDescendantsForServo();
+      } else {
+        // Lazy frame construction is done by the restyle flushes, so we need to
+        // ensure a refresh happens.
+        mPresShell->SetNeedStyleFlush();
+        mPresShell->ObserveStyleFlushes();
       }
       return;
     }
   }
 
   // We couldn't construct lazily. Make Servo eagerly traverse the new content.
   if (isNewlyAddedContentForServo) {
     StyleNewChildRange(aStartChild, aEndChild);