Bug 1296556: Recreate style contexts inside generated content. r?heycam draft
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Sat, 20 Aug 2016 00:17:04 -0700
changeset 408962 9cbddf9d357a2234ebca67b9f21f62c698c146aa
parent 408961 dad30a79c352fe374a076be29eed0f7a19f18648
child 408963 2010051c631710db08241d69c27605e6a917d833
push id28335
push userbmo:ecoal95@gmail.com
push dateThu, 01 Sep 2016 22:18:00 +0000
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);