--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -170,43 +170,24 @@ ServoStyleSet::EndUpdate()
return NS_OK;
}
already_AddRefed<ServoStyleContext>
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);
}
const ServoElementSnapshotTable&
ServoStyleSet::Snapshots()
{
return mPresContext->RestyleManager()->AsServo()->Snapshots();
}
@@ -379,32 +360,29 @@ ServoStyleSet::ResolveStyleForText(nsICo
// rules: inherit the inherit structs, reset the reset structs. This is cheap
// enough to do on the main thread, which means that the parallel style system
// can avoid worrying about text nodes.
RefPtr<ServoStyleContext> computedValues =
Servo_ComputedValues_Inherit(mRawSet.get(),
nsCSSAnonBoxes::mozText,
aParentContext,
InheritTarget::Text).Consume();
- computedValues->UpdateWithElementState(nullptr);
return computedValues.forget();
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::ResolveStyleForFirstLetterContinuation(ServoStyleContext* aParentContext)
{
RefPtr<ServoStyleContext> computedValues =
Servo_ComputedValues_Inherit(mRawSet.get(),
nsCSSAnonBoxes::firstLetterContinuation,
aParentContext,
InheritTarget::FirstLetterContinuation)
.Consume();
MOZ_ASSERT(computedValues);
-
- computedValues->UpdateWithElementState(nullptr);
return computedValues.forget();
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::ResolveStyleForPlaceholder()
{
RefPtr<ServoStyleContext>& cache =
mNonInheritingStyleContexts[nsCSSAnonBoxes::NonInheriting::oofPlaceholder];
@@ -416,17 +394,16 @@ ServoStyleSet::ResolveStyleForPlaceholde
RefPtr<ServoStyleContext> computedValues =
Servo_ComputedValues_Inherit(mRawSet.get(),
nsCSSAnonBoxes::oofPlaceholder,
nullptr,
InheritTarget::PlaceholderFrame)
.Consume();
MOZ_ASSERT(computedValues);
- computedValues->UpdateWithElementState(nullptr);
cache = computedValues;
return computedValues.forget();
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
CSSPseudoElementType aType,
ServoStyleContext* aParentContext,
@@ -449,32 +426,27 @@ ServoStyleSet::ResolvePseudoElementStyle
Servo_ResolvePseudoStyle(aOriginatingElement,
aType,
/* is_probe = */ false,
aParentContext,
mRawSet.get()).Consume();
}
MOZ_ASSERT(computedValues);
-
- bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
- aType == CSSPseudoElementType::after;
- computedValues->UpdateWithElementState(isBeforeOrAfter ? aOriginatingElement : nullptr);
return computedValues.forget();
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::ResolveTransientStyle(Element* aElement,
CSSPseudoElementType aPseudoType,
nsIAtom* aPseudoTag,
StyleRuleInclusion aRuleInclusion)
{
RefPtr<ServoStyleContext> result =
ResolveTransientServoStyle(aElement, aPseudoType, aPseudoTag, aRuleInclusion);
- result->UpdateWithElementState(nullptr);
return result.forget();
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::ResolveTransientServoStyle(
Element* aElement,
CSSPseudoElementType aPseudoType,
nsIAtom* aPseudoTag,
@@ -502,17 +474,16 @@ ServoStyleSet::ResolveInheritingAnonymou
nsString pseudo;
aPseudoTag->ToString(pseudo);
NS_ERROR(nsPrintfCString("stylo: could not get anon-box: %s",
NS_ConvertUTF16toUTF8(pseudo).get()).get());
MOZ_CRASH();
}
#endif
- computedValues->UpdateWithElementState(nullptr);
return computedValues.forget();
}
already_AddRefed<ServoStyleContext>
ServoStyleSet::ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag)
{
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
@@ -547,17 +518,16 @@ ServoStyleSet::ResolveNonInheritingAnony
nsString pseudo;
aPseudoTag->ToString(pseudo);
NS_ERROR(nsPrintfCString("stylo: could not get anon-box: %s",
NS_ConvertUTF16toUTF8(pseudo).get()).get());
MOZ_CRASH();
}
#endif
- computedValues->UpdateWithElementState(nullptr);
cache = computedValues;
return computedValues.forget();
}
// manage the set of style sheets in the style set
nsresult
ServoStyleSet::AppendStyleSheet(SheetType aType,
ServoStyleSheet* aSheet)
@@ -779,40 +749,38 @@ ServoStyleSet::ProbePseudoElementStyle(E
// For :before and :after pseudo-elements, having display: none or no
// 'content' property is equivalent to not having the pseudo-element
// at all.
bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
aType == CSSPseudoElementType::after;
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();
}
nsRestyleHint
ServoStyleSet::HasStateDependentStyle(dom::Element* aElement,
EventStates aStateMask)
{
NS_WARNING("stylo: HasStateDependentStyle always returns zero!");
return nsRestyleHint(0);
}
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);
}
bool
ServoStyleSet::StyleDocument(TraversalRestyleBehavior aRestyleBehavior)
{
@@ -1083,24 +1051,55 @@ ServoStyleSet::ClearDataAndMarkDeviceDir
}
void
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
ServoStyleSet::ClearNonInheritingStyleContexts()
{
for (RefPtr<ServoStyleContext>& ptr : mNonInheritingStyleContexts) {
ptr = nullptr;
}
@@ -1154,16 +1153,20 @@ ServoStyleSet::ResolveStyleLazily(Elemen
computedValues =
Servo_ResolveStyleLazily(elementForStyleResolution,
pseudoTypeForStyleResolution,
aRuleInclusion,
&Snapshots(),
mRawSet.get()).Consume();
}
+ if (aPseudoType == CSSPseudoElementType::NotPseudo) {
+ UpdateBodyTextColorIfNeeded(*aElement, *computedValues, *mPresContext);
+ }
+
return computedValues.forget();
}
bool
ServoStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
{
UpdateStylistIfNeeded();
Servo_StyleSet_GetFontFaceRules(mRawSet.get(), &aArray);