Bug 1292618: Specialize ServoStyleSet::ResolveStyleForText to take into account generated nodes. r?heycam draft
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Fri, 12 Aug 2016 11:30:29 -0700
changeset 400243 547fad136e8e2b6e96bd8ec7c6ced53e5d9f146b
parent 400242 b8e047a610a6795e5030311cdb7c038a29b5a499
child 528166 98a100ef867861abc0335e543827a2e5174ad2f1
push id26102
push userbmo:ealvarez@mozilla.com
push dateFri, 12 Aug 2016 20:17:45 +0000
reviewersheycam
bugs1292618
milestone51.0a1
Bug 1292618: Specialize ServoStyleSet::ResolveStyleForText to take into account generated nodes. r?heycam Eventually, we might want to use the same mechanism that Gecko uses directly, and stop styling text nodes from Servo. This would have the benefit of removing the "stash the change on the parent" thing. MozReview-Commit-ID: IOxNR05jkh
layout/style/ServoStyleSet.cpp
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -128,28 +128,60 @@ ServoStyleSet::ResolveStyleFor(Element* 
   return ResolveStyleFor(aElement, aParentContext);
 }
 
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ResolveStyleForText(nsIContent* aTextNode,
                                    nsStyleContext* aParentContext)
 {
   MOZ_ASSERT(aTextNode && aTextNode->IsNodeOfType(nsINode::eTEXT));
-  return GetContext(aTextNode, aParentContext, nsCSSAnonBoxes::mozText,
-                    CSSPseudoElementType::AnonBox);
+  MOZ_ASSERT(aTextNode->GetParent());
+
+  nsIContent* parent = aTextNode->GetParent();
+  nsIAtom* parentName = parent->NodeInfo()->NameAtom();
+
+  // If this text node is a child of a generated content node, it'll never have
+  // been traversed by Servo, and thus isn't styled.
+  //
+  // We inherit the style from the parent here, but also taking into account
+  // that only the frame of the parent has the correct style, given we take it
+  // from the map, and the content hasn't also being traversed from Servo.
+  //
+  // Otherwise, we rely on the fact that this text node should have been
+  // traversed by servo to just grab the computed values as appropriate.
+  //
+  // TODO: We might want to just do this and skip styling nodes entirely from
+  // Servo. This would accidentally fix the issue of having to stash
+  // change-hints from children in the parent element just because of inherited
+  // style struct changes.
+  RefPtr<ServoComputedValues> computedValues;
+  if (parentName == nsGkAtoms::mozgeneratedcontentbefore ||
+      parentName == nsGkAtoms::mozgeneratedcontentafter) {
+    MOZ_ASSERT(aParentContext);
+    ServoComputedValues* parentComputedValues =
+      aParentContext->StyleSource().AsServoComputedValues();
+    computedValues =
+      dont_AddRef(Servo_InheritComputedValues(parentComputedValues));
+  } else {
+    computedValues = dont_AddRef(Servo_GetComputedValues(aTextNode));
+  }
+
+  return GetContext(computedValues.forget(), aParentContext,
+                    nsCSSAnonBoxes::mozText, CSSPseudoElementType::AnonBox);
 }
 
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ResolveStyleForOtherNonElement(nsStyleContext* aParentContext)
 {
   // The parent context can be null if the non-element share a style context
   // with the root of an anonymous subtree.
   ServoComputedValues* parent =
     aParentContext ? aParentContext->StyleSource().AsServoComputedValues() : nullptr;
-  RefPtr<ServoComputedValues> computedValues = dont_AddRef(Servo_InheritComputedValues(parent));
+  RefPtr<ServoComputedValues> computedValues =
+    dont_AddRef(Servo_InheritComputedValues(parent));
   MOZ_ASSERT(computedValues);
 
   return GetContext(computedValues.forget(), aParentContext,
                     nsCSSAnonBoxes::mozOtherNonElement,
                     CSSPseudoElementType::AnonBox);
 }
 
 already_AddRefed<nsStyleContext>