Bug 1383307: Remove ServoStyleContext::UpdateWithElementState. r=manishearth

And kill one GetParentAllowServo call while at it, and some other dumbness...

MozReview-Commit-ID: GmvzXwGorlX
This commit is contained in:
Emilio Cobos Álvarez 2017-07-23 05:06:07 +02:00
parent ecbfd2ef14
commit 2477a4b823
5 changed files with 45 additions and 93 deletions

View File

@ -603,12 +603,9 @@ ServoRestyleManager::ProcessPostTraversal(
RefPtr<ServoStyleContext> newContext = nullptr;
if (wasRestyled && oldStyleContext) {
MOZ_ASSERT(styleFrame || displayContentsNode);
RefPtr<ServoStyleContext> currentContext =
newContext =
aRestyleState.StyleSet().ResolveServoStyle(aElement, aRestyleBehavior);
MOZ_ASSERT(oldStyleContext->ComputedData() != currentContext->ComputedData());
newContext = currentContext;
newContext->UpdateWithElementState(aElement);
MOZ_ASSERT(oldStyleContext->ComputedData() != newContext->ComputedData());
newContext->ResolveSameStructsAs(oldStyleContext);

View File

@ -32,42 +32,4 @@ ServoStyleContext::ServoStyleContext(
// producing the ServoComputedData.
}
void
ServoStyleContext::UpdateWithElementState(Element* aElementForAnimation)
{
bool isLink = false;
bool isVisitedLink = false;
// If we need visited styles for callers where `aElementForAnimation` is null,
// we can precompute these and pass them as flags, similar to nsStyleSet.cpp.
if (aElementForAnimation) {
isLink = nsCSSRuleProcessor::IsLink(aElementForAnimation);
isVisitedLink = nsCSSRuleProcessor::GetContentState(aElementForAnimation)
.HasState(NS_EVENT_STATE_VISITED);
}
auto parent = GetParentAllowServo();
// The true visited state of the relevant link is used to decided whether
// visited styles should be consulted for all visited dependent properties.
bool relevantLinkVisited = isLink ? isVisitedLink :
(parent && parent->RelevantLinkVisited());
if (relevantLinkVisited && GetStyleIfVisited()) {
AddStyleBit(NS_STYLE_RELEVANT_LINK_VISITED);
}
// Set the body color on the pres context. See nsStyleSet::GetContext
if (aElementForAnimation &&
aElementForAnimation->IsHTMLElement(nsGkAtoms::body) &&
GetPseudoType() == CSSPseudoElementType::NotPseudo &&
mPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
nsIDocument* doc = aElementForAnimation->GetUncomposedDoc();
if (doc && doc->GetBodyElement() == aElementForAnimation) {
// Update the prescontext's body color
mPresContext->SetBodyTextColor(StyleColor()->mColor);
}
}
}
} // namespace mozilla

View File

@ -35,10 +35,6 @@ public:
return ComputedData()->visited_style.mPtr;
}
// Update visited state for a given element, and set the prescontext's
// body text color if applicable.
void UpdateWithElementState(dom::Element* aElement);
/**
* Makes this context match |aOther| in terms of which style structs have
* been resolved.

View File

@ -175,33 +175,14 @@ ServoStyleSet::ResolveStyleFor(Element* aElement,
ServoStyleContext* aParentContext,
LazyComputeBehavior aMayCompute)
{
return GetContext(aElement, aParentContext, nullptr,
CSSPseudoElementType::NotPseudo, aMayCompute);
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::GetContext(nsIContent* aContent,
ServoStyleContext* aParentContext,
nsIAtom* aPseudoTag,
CSSPseudoElementType aPseudoType,
LazyComputeBehavior aMayCompute)
{
MOZ_ASSERT(aContent->IsElement());
Element* element = aContent->AsElement();
RefPtr<ServoStyleContext> computedValues;
if (aMayCompute == LazyComputeBehavior::Allow) {
PreTraverseSync();
computedValues =
ResolveStyleLazily(element, CSSPseudoElementType::NotPseudo, aPseudoTag, aParentContext);
computedValues->UpdateWithElementState(element);
} else {
computedValues = ResolveServoStyle(element,
TraversalRestyleBehavior::Normal);
return ResolveStyleLazily(
aElement, CSSPseudoElementType::NotPseudo, nullptr, aParentContext);
}
MOZ_ASSERT(computedValues);
return computedValues.forget();
return ResolveServoStyle(aElement, TraversalRestyleBehavior::Normal);
}
@ -384,7 +365,6 @@ ServoStyleSet::ResolveStyleForText(nsIContent* aTextNode,
nsCSSAnonBoxes::mozText,
aParentContext,
InheritTarget::Text).Consume();
computedValues->UpdateWithElementState(nullptr);
return computedValues.forget();
}
@ -398,8 +378,6 @@ ServoStyleSet::ResolveStyleForFirstLetterContinuation(ServoStyleContext* aParent
InheritTarget::FirstLetterContinuation)
.Consume();
MOZ_ASSERT(computedValues);
computedValues->UpdateWithElementState(nullptr);
return computedValues.forget();
}
@ -421,7 +399,6 @@ ServoStyleSet::ResolveStyleForPlaceholder()
.Consume();
MOZ_ASSERT(computedValues);
computedValues->UpdateWithElementState(nullptr);
cache = computedValues;
return computedValues.forget();
}
@ -454,10 +431,6 @@ ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
}
MOZ_ASSERT(computedValues);
bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
aType == CSSPseudoElementType::after;
computedValues->UpdateWithElementState(isBeforeOrAfter ? aOriginatingElement : nullptr);
return computedValues.forget();
}
@ -469,7 +442,6 @@ ServoStyleSet::ResolveTransientStyle(Element* aElement,
{
RefPtr<ServoStyleContext> result =
ResolveTransientServoStyle(aElement, aPseudoType, aPseudoTag, aRuleInclusion);
result->UpdateWithElementState(nullptr);
return result.forget();
}
@ -507,7 +479,6 @@ ServoStyleSet::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
}
#endif
computedValues->UpdateWithElementState(nullptr);
return computedValues.forget();
}
@ -552,7 +523,6 @@ ServoStyleSet::ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag)
}
#endif
computedValues->UpdateWithElementState(nullptr);
cache = computedValues;
return computedValues.forget();
}
@ -784,14 +754,12 @@ ServoStyleSet::ProbePseudoElementStyle(Element* aOriginatingElement,
if (isBeforeOrAfter) {
const nsStyleDisplay* display = computedValues->ComputedData()->GetStyleDisplay();
const nsStyleContent* content = computedValues->ComputedData()->GetStyleContent();
// XXXldb What is contentCount for |content: ""|?
if (display->mDisplay == StyleDisplay::None ||
content->ContentCount() == 0) {
return nullptr;
}
}
computedValues->UpdateWithElementState(isBeforeOrAfter ? aOriginatingElement : nullptr);
return computedValues.forget();
}
@ -806,8 +774,8 @@ ServoStyleSet::HasStateDependentStyle(dom::Element* aElement,
nsRestyleHint
ServoStyleSet::HasStateDependentStyle(dom::Element* aElement,
CSSPseudoElementType aPseudoType,
dom::Element* aPseudoElement,
EventStates aStateMask)
dom::Element* aPseudoElement,
EventStates aStateMask)
{
NS_WARNING("stylo: HasStateDependentStyle always returns zero!");
return nsRestyleHint(0);
@ -1088,14 +1056,45 @@ ServoStyleSet::CompatibilityModeChanged()
Servo_StyleSet_CompatModeChanged(mRawSet.get());
}
inline static void
UpdateBodyTextColorIfNeeded(
const Element& aElement,
ServoStyleContext& aStyleContext,
nsPresContext& aPresContext)
{
if (aPresContext.CompatibilityMode() != eCompatibility_NavQuirks) {
return;
}
if (!aElement.IsHTMLElement(nsGkAtoms::body)) {
return;
}
nsIDocument* doc = aElement.GetUncomposedDoc();
if (!doc || doc->GetBodyElement() != &aElement) {
return;
}
MOZ_ASSERT(!aStyleContext.GetPseudo());
// NOTE(emilio): We do the ComputedData() dance to avoid triggering the
// IsInServoTraversal() assertion in StyleColor(), which seems useful enough
// in the general case, I guess...
aPresContext.SetBodyTextColor(
aStyleContext.ComputedData()->GetStyleColor()->mColor);
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::ResolveServoStyle(Element* aElement,
TraversalRestyleBehavior aRestyleBehavior)
{
UpdateStylistIfNeeded();
return Servo_ResolveStyle(aElement,
mRawSet.get(),
aRestyleBehavior).Consume();
RefPtr<ServoStyleContext> result =
Servo_ResolveStyle(aElement,
mRawSet.get(),
aRestyleBehavior).Consume();
UpdateBodyTextColorIfNeeded(*aElement, *result, *mPresContext);
return result.forget();
}
void
@ -1159,6 +1158,10 @@ ServoStyleSet::ResolveStyleLazily(Element* aElement,
mRawSet.get()).Consume();
}
if (aPseudoType == CSSPseudoElementType::NotPseudo) {
UpdateBodyTextColorIfNeeded(*aElement, *computedValues, *mPresContext);
}
return computedValues.forget();
}

View File

@ -481,12 +481,6 @@ private:
ServoStyleSet* mSet;
};
already_AddRefed<ServoStyleContext> GetContext(nsIContent* aContent,
ServoStyleContext* aParentContext,
nsIAtom* aPseudoTag,
CSSPseudoElementType aPseudoType,
LazyComputeBehavior aMayCompute);
/**
* Rebuild the style data. This will force a stylesheet flush, and also
* recompute the default computed styles.