Bug 1351535 - Part 9: Call StyleSubtreeForReconstruct when doing frame reconstruction. r=bholley draft
authorCameron McCormack <cam@mcc.id.au>
Tue, 04 Apr 2017 19:36:09 +0800
changeset 558869 e7582f89ad1ea49ab36327a45bc97f7ff140ae75
parent 558868 06d9b89d08c2e88a4eaf75372ed0e68cfcde1448
child 623288 84eec93ab8959b564ef1c2d0199b105ff637bc6c
push id52975
push userbmo:cam@mcc.id.au
push dateSat, 08 Apr 2017 09:24:07 +0000
reviewersbholley
bugs1351535
milestone55.0a1
Bug 1351535 - Part 9: Call StyleSubtreeForReconstruct when doing frame reconstruction. r=bholley MozReview-Commit-ID: HxoGLPKJpnt
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSFrameConstructor.h
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -7439,16 +7439,32 @@ nsCSSFrameConstructor::StyleNewChildRang
       if (parent->HasServoData()) {
         styleSet->StyleNewChildren(parent);
       }
     }
   }
 }
 
 void
+nsCSSFrameConstructor::StyleChildRangeForReconstruct(nsIContent* aStartChild,
+                                                     nsIContent* aEndChild)
+{
+  ServoStyleSet* styleSet = mPresShell->StyleSet()->AsServo();
+
+  // We take a parallelism hit here, since we don't have a great API to pass
+  // a range of elements to style to Servo.
+  for (nsIContent* child = aStartChild; child != aEndChild;
+       child = child->GetNextSibling()) {
+    if (child->IsElement()) {
+      styleSet->StyleSubtreeForReconstruct(child->AsElement());
+    }
+  }
+}
+
+void
 nsCSSFrameConstructor::ContentAppended(nsIContent* aContainer,
                                        nsIContent* aFirstNewContent,
                                        bool aAllowLazyConstruction,
                                        bool aForReconstruction,
                                        TreeMatchContext* aProvidedTreeMatchContext)
 {
   MOZ_ASSERT_IF(aProvidedTreeMatchContext, !aAllowLazyConstruction);
   MOZ_ASSERT_IF(aAllowLazyConstruction, !RestyleManager()->IsInStyleRefresh());
@@ -7526,18 +7542,22 @@ nsCSSFrameConstructor::ContentAppended(n
       if (isNewlyAddedContentForServo) {
         LazilyStyleNewChildRange(aFirstNewContent, nullptr);
       }
       return;
     }
   }
 
   // We couldn't construct lazily. Make Servo eagerly traverse the new content.
-  if (isNewlyAddedContentForServo) {
-    StyleNewChildRange(aFirstNewContent, nullptr);
+  if (aContainer->IsStyledByServo()) {
+    if (aForReconstruction) {
+      StyleChildRangeForReconstruct(aFirstNewContent, nullptr);
+    } else {
+      StyleNewChildRange(aFirstNewContent, nullptr);
+    }
   }
 
   if (isNewShadowTreeContent) {
     // Recreate frames if content is appended into a ShadowRoot
     // because children of ShadowRoot are rendered in place of children
     // of the host.
     //XXXsmaug This is super unefficient!
     nsIContent* bindingParent = aContainer->GetBindingParent();
@@ -8007,18 +8027,22 @@ nsCSSFrameConstructor::ContentRangeInser
       if (isNewlyAddedContentForServo) {
         LazilyStyleNewChildRange(aStartChild, aEndChild);
       }
       return;
     }
   }
 
   // We couldn't construct lazily. Make Servo eagerly traverse the new content.
-  if (isNewlyAddedContentForServo) {
-    StyleNewChildRange(aStartChild, aEndChild);
+  if (aContainer->IsStyledByServo()) {
+    if (aForReconstruction) {
+      StyleChildRangeForReconstruct(aStartChild, aEndChild);
+    } else {
+      StyleNewChildRange(aStartChild, aEndChild);
+    }
   }
 
   if (isNewShadowTreeContent) {
     // Recreate frames if content is inserted into a ShadowRoot
     // because children of ShadowRoot are rendered in place of
     // the children of the host.
     //XXXsmaug This is super unefficient!
     nsIContent* bindingParent = aContainer->GetBindingParent();
--- a/layout/base/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -173,16 +173,23 @@ private:
    * on their flattened tree parents.  This is used when content is inserted
    * into the document and we decide that we cannot do lazy frame construction.
    * It handles children being rebound to different insertion points by calling
    * StyleNewChildren on each child's flattened tree parent.  Only used when we
    * are styled by Servo.
    */
   void StyleNewChildRange(nsIContent* aStartChild, nsIContent* aEndChild);
 
+  /**
+   * Calls StyleSubtreeForReconstruct on each child in the aStartChild/aEndChild
+   * range. Only used when we are styled by Servo.
+   */
+  void StyleChildRangeForReconstruct(nsIContent* aStartChild,
+                                     nsIContent* aEndChild);
+
 public:
   /**
    * Lazy frame construction is controlled by the aAllowLazyConstruction bool
    * parameter of nsCSSFrameConstructor::ContentAppended/Inserted. It is true
    * for all inserts/appends as passed from the presshell, except for the
    * insert of the root element, which is always non-lazy. Even if the
    * aAllowLazyConstruction passed to ContentAppended/Inserted is true we still
    * may not be able to construct lazily, so we call MaybeConstructLazily.