From 84de3367d5aba922c9e6729e1bb763d928c2e526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 12 Aug 2016 11:30:29 -0700 Subject: [PATCH] Bug 1292618: Specialize ServoStyleSet::ResolveStyleForText to take into account generated nodes. r=heycam MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Emilio Cobos Álvarez --- layout/style/ServoStyleSet.cpp | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 253a538d8369..cd7da5fa091a 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -96,7 +96,8 @@ ServoStyleSet::GetContext(nsIContent* aContent, nsIAtom* aPseudoTag, CSSPseudoElementType aPseudoType) { - RefPtr computedValues = Servo_GetComputedValues(aContent).Consume(); + RefPtr computedValues = + Servo_GetComputedValues(aContent).Consume(); MOZ_ASSERT(computedValues); return GetContext(computedValues.forget(), aParentContext, aPseudoTag, aPseudoType); } @@ -133,8 +134,40 @@ 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 computedValues; + if (parent->IsRootOfAnonymousSubtree() && + (parentName == nsGkAtoms::mozgeneratedcontentbefore || + parentName == nsGkAtoms::mozgeneratedcontentafter)) { + MOZ_ASSERT(aParentContext); + ServoComputedValues* parentComputedValues = + aParentContext->StyleSource().AsServoComputedValues(); + computedValues = + Servo_InheritComputedValues(parentComputedValues).Consume(); + } else { + computedValues = Servo_GetComputedValues(aTextNode).Consume(); + } + + return GetContext(computedValues.forget(), aParentContext, + nsCSSAnonBoxes::mozText, CSSPseudoElementType::AnonBox); } already_AddRefed @@ -144,7 +177,8 @@ ServoStyleSet::ResolveStyleForOtherNonElement(nsStyleContext* aParentContext) // with the root of an anonymous subtree. ServoComputedValues* parent = aParentContext ? aParentContext->StyleSource().AsServoComputedValues() : nullptr; - RefPtr computedValues = Servo_InheritComputedValues(parent).Consume(); + RefPtr computedValues = + Servo_InheritComputedValues(parent).Consume(); MOZ_ASSERT(computedValues); return GetContext(computedValues.forget(), aParentContext,