Bug 1296556: Recreate style contexts inside generated content. r=heycam
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Sat, 20 Aug 2016 00:17:04 -0700
changeset 312451 774608c1757086d7abebea577ac6e561a22b65c7
parent 312450 1bb4fec092645bd00840ec15605444921ffa3749
child 312452 54394c32a1068afdbdbd78faa4c41d2591d467bc
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1296556
milestone51.0a1
Bug 1296556: Recreate style contexts inside generated content. r=heycam MozReview-Commit-ID: JvVyml8yCrO
layout/base/ServoRestyleManager.cpp
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -143,44 +143,58 @@ ServoRestyleManager::RecreateStyleContex
          f = GetNextContinuationWithSameStyle(f, oldStyleContext)) {
       f->SetStyleContext(newContext);
     }
 
     // Update pseudo-elements state if appropriate.
     if (aContent->IsElement()) {
       Element* aElement = aContent->AsElement();
       const static CSSPseudoElementType pseudosToRestyle[] = {
-        CSSPseudoElementType::before, CSSPseudoElementType::after,
+        CSSPseudoElementType::before,
+        CSSPseudoElementType::after,
       };
 
       for (CSSPseudoElementType pseudoType : pseudosToRestyle) {
-        nsIAtom* pseudoTag =
-          nsCSSPseudoElements::GetPseudoAtom(pseudoType);
+        nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(pseudoType);
+
         if (nsIFrame* pseudoFrame =
               FrameForPseudoElement(aElement, pseudoTag)) {
           // TODO: we could maybe make this more performant via calling into
           // Servo just once to know which pseudo-elements we've got to restyle?
           RefPtr<nsStyleContext> pseudoContext =
             aStyleSet->ProbePseudoElementStyle(aElement, pseudoType,
                                                newContext);
 
           // If pseudoContext is null here, it means the frame is going away, so
           // our change hint computation should have already indicated we need
           // to reframe.
           MOZ_ASSERT_IF(!pseudoContext,
                         changeHint & nsChangeHint_ReconstructFrame);
           if (pseudoContext) {
             pseudoFrame->SetStyleContext(pseudoContext);
+
+            // We only care restyling text nodes, since other type of nodes
+            // (images), are still not supported. If that eventually changes, we
+            // may have to write more code here... Or not, I don't think too
+            // many inherited properties can affect those other frames.
+            StyleChildrenIterator it(pseudoFrame->GetContent());
+            for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
+              if (n->IsNodeOfType(nsINode::eTEXT)) {
+                RefPtr<nsStyleContext> childContext =
+                  aStyleSet->ResolveStyleForText(n, pseudoContext);
+                MOZ_ASSERT(n->GetPrimaryFrame(),
+                           "How? This node is created at FC time!");
+                n->GetPrimaryFrame()->SetStyleContext(childContext);
+              }
+            }
           }
         }
       }
     }
 
-    // TODO: There are other continuations we still haven't restyled, mostly
-    // pseudo-elements. We have to deal with those, and with anonymous boxes.
     aContent->UnsetIsDirtyForServo();
   }
 
   if (aContent->HasDirtyDescendantsForServo()) {
     MOZ_ASSERT(primaryFrame,
                "Frame construction should be scheduled, and it takes the "
                "correct style for the children, so no need to be here.");
     StyleChildrenIterator it(aContent);