Bug 1364412: Convert pseudo-elements to an enum. r=hiro,xidorn

This allows us to access metadata using `match` instead of comparison with
atoms, which makes it doable to get the pseudo-element flags in the future.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>

MozReview-Commit-ID: KgGjFePmhyS
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>

--HG--
extra : rebase_source : 57614aed13d2c088fe129ecf3fabf9869d5a6d50
This commit is contained in:
Emilio Cobos Álvarez 2017-05-14 18:39:22 +02:00
Родитель 4949107f0b
Коммит 8b2a66ab16
10 изменённых файлов: 59 добавлений и 60 удалений

Просмотреть файл

@ -1016,24 +1016,20 @@ EffectCompositor::PreTraverseInSubtree(Element* aRoot)
}
bool
EffectCompositor::PreTraverse(dom::Element* aElement, nsIAtom* aPseudoTagOrNull)
EffectCompositor::PreTraverse(dom::Element* aElement,
CSSPseudoElementType aPseudoType)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mPresContext->RestyleManager()->IsServo());
bool found = false;
if (aPseudoTagOrNull &&
aPseudoTagOrNull != nsCSSPseudoElements::before &&
aPseudoTagOrNull != nsCSSPseudoElements::after) {
if (aPseudoType != CSSPseudoElementType::NotPseudo &&
aPseudoType != CSSPseudoElementType::before &&
aPseudoType != CSSPseudoElementType::after) {
return found;
}
CSSPseudoElementType pseudoType =
nsCSSPseudoElements::GetPseudoType(aPseudoTagOrNull,
CSSEnabledState::eForAllContent);
PseudoElementHashEntry::KeyType key = { aElement, pseudoType };
PseudoElementHashEntry::KeyType key = { aElement, aPseudoType };
for (size_t i = 0; i < kCascadeLevelCount; ++i) {
CascadeLevel cascadeLevel = CascadeLevel(i);
@ -1050,9 +1046,9 @@ EffectCompositor::PreTraverse(dom::Element* aElement, nsIAtom* aPseudoTagOrNull)
? eRestyle_CSSTransitions
: eRestyle_CSSAnimations);
EffectSet* effects = EffectSet::GetEffectSet(aElement, pseudoType);
EffectSet* effects = EffectSet::GetEffectSet(aElement, aPseudoType);
if (effects) {
MaybeUpdateCascadeResults(aElement, pseudoType);
MaybeUpdateCascadeResults(aElement, aPseudoType);
for (KeyframeEffectReadOnly* effect : *effects) {
effect->GetAnimation()->WillComposeStyle();

Просмотреть файл

@ -247,7 +247,7 @@ public:
bool PreTraverse();
// Similar to the above but only for the (pseudo-)element.
bool PreTraverse(dom::Element* aElement, nsIAtom* aPseudoTagOrNull);
bool PreTraverse(dom::Element* aElement, CSSPseudoElementType aPseudoType);
// Similar to the above but for all elements in the subtree rooted
// at aElement.

Просмотреть файл

@ -527,12 +527,9 @@ KeyframeEffectReadOnly::EnsureBaseStyles(
"a valid nsPresContext");
RefPtr<ServoComputedValues> baseComputedValues;
nsIAtom* pseudoAtom = mTarget->mPseudoType < CSSPseudoElementType::Count
? nsCSSPseudoElements::GetPseudoAtom(mTarget->mPseudoType)
: nullptr;
for (const AnimationProperty& property : aProperties) {
EnsureBaseStyle(property,
pseudoAtom,
mTarget->mPseudoType,
presContext,
baseComputedValues);
}
@ -541,7 +538,7 @@ KeyframeEffectReadOnly::EnsureBaseStyles(
void
KeyframeEffectReadOnly::EnsureBaseStyle(
const AnimationProperty& aProperty,
nsIAtom* aPseudoAtom,
CSSPseudoElementType aPseudoType,
nsPresContext* aPresContext,
RefPtr<ServoComputedValues>& aBaseComputedValues)
{
@ -561,7 +558,7 @@ KeyframeEffectReadOnly::EnsureBaseStyle(
if (!aBaseComputedValues) {
aBaseComputedValues =
aPresContext->StyleSet()->AsServo()->
GetBaseComputedValuesForElement(mTarget->mElement, aPseudoAtom);
GetBaseComputedValuesForElement(mTarget->mElement, aPseudoType);
}
RefPtr<RawServoAnimationValue> baseValue =
Servo_ComputedValues_ExtractAnimationValue(aBaseComputedValues,

Просмотреть файл

@ -380,7 +380,7 @@ protected:
// Stylo version of the above function that also first checks for an additive
// value in |aProperty|'s list of segments.
void EnsureBaseStyle(const AnimationProperty& aProperty,
nsIAtom* aPseudoAtom,
CSSPseudoElementType aPseudoType,
nsPresContext* aPresContext,
RefPtr<ServoComputedValues>& aBaseComputedValues);

Просмотреть файл

@ -2874,7 +2874,9 @@ GetFontStyleForServo(Element* aElement, const nsAString& aFont,
// We need to use ResolveTransientServoStyle, which involves traversal,
// instead of ResolveServoStyle() because we need up-to-date style even if
// the canvas element is display:none.
parentStyle = styleSet->ResolveTransientServoStyle(aElement, nullptr);
parentStyle =
styleSet->ResolveTransientServoStyle(aElement,
CSSPseudoElementType::NotPseudo);
} else {
RefPtr<RawServoDeclarationBlock> declarations =
CreateFontDeclarationForServo(NS_LITERAL_STRING("10px sans-serif"),

Просмотреть файл

@ -355,7 +355,7 @@ SERVO_BINDING_FUNC(Servo_CSSSupports, bool,
SERVO_BINDING_FUNC(Servo_ComputedValues_GetForAnonymousBox,
ServoComputedValuesStrong,
ServoComputedValuesBorrowedOrNull parent_style_or_null,
nsIAtom* pseudoTag, bool skip_display_fixup,
nsIAtom* pseudo_tag, bool skip_display_fixup,
RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_ComputedValues_Inherit, ServoComputedValuesStrong,
RawServoStyleSetBorrowed set,
@ -383,7 +383,8 @@ SERVO_BINDING_FUNC(Servo_ResolveStyle, ServoComputedValuesStrong,
RawServoStyleSetBorrowed set,
bool allow_stale)
SERVO_BINDING_FUNC(Servo_ResolvePseudoStyle, ServoComputedValuesStrong,
RawGeckoElementBorrowed element, nsIAtom* pseudo_tag,
RawGeckoElementBorrowed element,
mozilla::CSSPseudoElementType pseudo_type,
bool is_probe, RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_HasAuthorSpecifiedRules, bool,
RawGeckoElementBorrowed element,
@ -400,7 +401,7 @@ SERVO_BINDING_FUNC(Servo_HasAuthorSpecifiedRules, bool,
// performed, and this function maintains that invariant.
SERVO_BINDING_FUNC(Servo_ResolveStyleLazily, ServoComputedValuesStrong,
RawGeckoElementBorrowed element,
nsIAtom* pseudo_tag,
mozilla::CSSPseudoElementType pseudo_type,
const mozilla::ServoElementSnapshotTable* snapshots,
RawServoStyleSetBorrowed set)
@ -423,7 +424,7 @@ SERVO_BINDING_FUNC(Servo_StyleSet_GetBaseComputedValuesForElement,
RawServoStyleSetBorrowed set,
RawGeckoElementBorrowed element,
const mozilla::ServoElementSnapshotTable* snapshots,
nsIAtom* pseudo_tag)
mozilla::CSSPseudoElementType pseudo_type)
// Style-struct management.
#define STYLE_STRUCT(name, checkdata_cb) \

Просмотреть файл

@ -314,13 +314,10 @@ Gecko_GetStyleContext(RawGeckoElementBorrowed aElement,
return fc->GetDisplayContentsStyleFor(aElement);
}
nsIAtom*
CSSPseudoElementType
Gecko_GetImplementedPseudo(RawGeckoElementBorrowed aElement)
{
CSSPseudoElementType pseudo = aElement->GetPseudoElementType();
if (pseudo == CSSPseudoElementType::NotPseudo)
return nullptr;
return nsCSSPseudoElements::GetPseudoAtom(pseudo);
return aElement->GetPseudoElementType();
}
nsChangeHint

Просмотреть файл

@ -35,6 +35,7 @@ struct nsFont;
namespace mozilla {
class FontFamilyList;
enum FontFamilyType : uint32_t;
enum class CSSPseudoElementType : uint8_t;
struct Keyframe;
enum Side;
struct StyleTransition;
@ -329,7 +330,7 @@ void Gecko_SetOwnerDocumentNeedsStyleFlush(RawGeckoElementBorrowed element);
// Not if we do them in Gecko...
nsStyleContext* Gecko_GetStyleContext(RawGeckoElementBorrowed element,
nsIAtom* aPseudoTagOrNull);
nsIAtom* Gecko_GetImplementedPseudo(RawGeckoElementBorrowed element);
mozilla::CSSPseudoElementType Gecko_GetImplementedPseudo(RawGeckoElementBorrowed element);
nsChangeHint Gecko_CalcStyleDifference(nsStyleContext* oldstyle,
ServoComputedValuesBorrowed newstyle);
nsChangeHint Gecko_HintsHandledForDescendants(nsChangeHint aHint);

Просмотреть файл

@ -199,7 +199,8 @@ ServoStyleSet::GetContext(nsIContent* aContent,
RefPtr<ServoComputedValues> computedValues;
if (aMayCompute == LazyComputeBehavior::Allow) {
PreTraverseSync();
computedValues = ResolveStyleLazily(element, nullptr);
computedValues =
ResolveStyleLazily(element, CSSPseudoElementType::NotPseudo);
} else {
computedValues = ResolveServoStyle(element);
}
@ -442,7 +443,6 @@ ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
// should just inherit from aOriginatingElement's primary style, which Servo
// already knows.
MOZ_ASSERT(aType < CSSPseudoElementType::Count);
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
RefPtr<ServoComputedValues> computedValues;
if (aPseudoElement) {
@ -452,7 +452,7 @@ ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
} else {
computedValues =
Servo_ResolvePseudoStyle(aOriginatingElement,
pseudoTag,
aType,
/* is_probe = */ false,
mRawSet.get()).Consume();
}
@ -461,6 +461,8 @@ ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
aType == CSSPseudoElementType::after;
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
return GetContext(computedValues.forget(), aParentContext, pseudoTag, aType,
isBeforeOrAfter ? aOriginatingElement : nullptr);
}
@ -471,7 +473,7 @@ ServoStyleSet::ResolveTransientStyle(Element* aElement,
CSSPseudoElementType aPseudoType)
{
RefPtr<ServoComputedValues> computedValues =
ResolveTransientServoStyle(aElement, aPseudoTag);
ResolveTransientServoStyle(aElement, aPseudoType);
return GetContext(computedValues.forget(),
nullptr,
@ -481,10 +483,10 @@ ServoStyleSet::ResolveTransientStyle(Element* aElement,
already_AddRefed<ServoComputedValues>
ServoStyleSet::ResolveTransientServoStyle(Element* aElement,
nsIAtom* aPseudoTag)
CSSPseudoElementType aPseudoType)
{
PreTraverseSync();
return ResolveStyleLazily(aElement, aPseudoTag);
return ResolveStyleLazily(aElement, aPseudoType);
}
already_AddRefed<nsStyleContext>
@ -771,10 +773,9 @@ ServoStyleSet::ProbePseudoElementStyle(Element* aOriginatingElement,
// should just inherit from aOriginatingElement's primary style, which Servo
// already knows.
MOZ_ASSERT(aType < CSSPseudoElementType::Count);
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
RefPtr<ServoComputedValues> computedValues =
Servo_ResolvePseudoStyle(aOriginatingElement, pseudoTag,
Servo_ResolvePseudoStyle(aOriginatingElement, aType,
/* is_probe = */ true, mRawSet.get()).Consume();
if (!computedValues) {
return nullptr;
@ -783,11 +784,11 @@ ServoStyleSet::ProbePseudoElementStyle(Element* aOriginatingElement,
// 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 = pseudoTag == nsCSSPseudoElements::before ||
pseudoTag == nsCSSPseudoElements::after;
bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
aType == CSSPseudoElementType::after;
if (isBeforeOrAfter) {
const nsStyleDisplay *display = Servo_GetStyleDisplay(computedValues);
const nsStyleContent *content = Servo_GetStyleContent(computedValues);
const nsStyleDisplay* display = Servo_GetStyleDisplay(computedValues);
const nsStyleContent* content = Servo_GetStyleContent(computedValues);
// XXXldb What is contentCount for |content: ""|?
if (display->mDisplay == StyleDisplay::None ||
content->ContentCount() == 0) {
@ -795,6 +796,7 @@ ServoStyleSet::ProbePseudoElementStyle(Element* aOriginatingElement,
}
}
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
return GetContext(computedValues.forget(), aParentContext, pseudoTag, aType,
isBeforeOrAfter ? aOriginatingElement : nullptr);
}
@ -942,12 +944,12 @@ ServoStyleSet::GetComputedKeyframeValuesFor(
already_AddRefed<ServoComputedValues>
ServoStyleSet::GetBaseComputedValuesForElement(Element* aElement,
nsIAtom* aPseudoTag)
CSSPseudoElementType aPseudoType)
{
return Servo_StyleSet_GetBaseComputedValuesForElement(mRawSet.get(),
aElement,
&Snapshots(),
aPseudoTag).Consume();
aPseudoType).Consume();
}
already_AddRefed<RawServoAnimationValue>
@ -985,9 +987,10 @@ ServoStyleSet::ClearNonInheritingStyleContexts()
}
already_AddRefed<ServoComputedValues>
ServoStyleSet::ResolveStyleLazily(Element* aElement, nsIAtom* aPseudoTag)
ServoStyleSet::ResolveStyleLazily(Element* aElement,
CSSPseudoElementType aPseudoType)
{
mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoTag);
mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType);
MOZ_ASSERT(!mStylistMayNeedRebuild);
AutoSetInServoTraversal guard(this);
@ -1004,29 +1007,29 @@ ServoStyleSet::ResolveStyleLazily(Element* aElement, nsIAtom* aPseudoTag)
* style of the pseudo-element if it exists instead.
*/
Element* elementForStyleResolution = aElement;
nsIAtom* pseudoTagForStyleResolution = aPseudoTag;
if (aPseudoTag == nsCSSPseudoElements::before) {
CSSPseudoElementType pseudoTypeForStyleResolution = aPseudoType;
if (aPseudoType == CSSPseudoElementType::before) {
if (Element* pseudo = nsLayoutUtils::GetBeforePseudo(aElement)) {
elementForStyleResolution = pseudo;
pseudoTagForStyleResolution = nullptr;
pseudoTypeForStyleResolution = CSSPseudoElementType::NotPseudo;
}
} else if (aPseudoTag == nsCSSPseudoElements::after) {
} else if (aPseudoType == CSSPseudoElementType::after) {
if (Element* pseudo = nsLayoutUtils::GetAfterPseudo(aElement)) {
elementForStyleResolution = pseudo;
pseudoTagForStyleResolution = nullptr;
pseudoTypeForStyleResolution = CSSPseudoElementType::NotPseudo;
}
}
RefPtr<ServoComputedValues> computedValues =
Servo_ResolveStyleLazily(elementForStyleResolution,
pseudoTagForStyleResolution,
pseudoTypeForStyleResolution,
&Snapshots(),
mRawSet.get()).Consume();
if (mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoTag)) {
if (mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType)) {
computedValues =
Servo_ResolveStyleLazily(elementForStyleResolution,
pseudoTagForStyleResolution,
pseudoTypeForStyleResolution,
&Snapshots(),
mRawSet.get()).Consume();
}

Просмотреть файл

@ -165,7 +165,7 @@ public:
// style attributes; otherwise, it is ignored.
already_AddRefed<nsStyleContext>
ResolvePseudoElementStyle(dom::Element* aOriginatingElement,
mozilla::CSSPseudoElementType aType,
CSSPseudoElementType aType,
nsStyleContext* aParentContext,
dom::Element* aPseudoElement);
@ -181,7 +181,8 @@ public:
// Similar to ResolveTransientStyle() but returns ServoComputedValues.
// Unlike ResolveServoStyle() this function calls PreTraverseSync().
already_AddRefed<ServoComputedValues>
ResolveTransientServoStyle(dom::Element* aElement, nsIAtom* aPseudoTag);
ResolveTransientServoStyle(dom::Element* aElement,
CSSPseudoElementType aPseudoTag);
// Get a style context for an anonymous box. aPseudoTag is the pseudo-tag to
// use and must be non-null. It must be an anon box, and must be one that
@ -307,7 +308,8 @@ public:
bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
already_AddRefed<ServoComputedValues>
GetBaseComputedValuesForElement(dom::Element* aElement, nsIAtom* aPseudoTag);
GetBaseComputedValuesForElement(dom::Element* aElement,
CSSPseudoElementType aPseudoType);
/**
* Resolve style for a given declaration block with/without the parent style.
@ -431,8 +433,8 @@ private:
}
}
already_AddRefed<ServoComputedValues> ResolveStyleLazily(dom::Element* aElement,
nsIAtom* aPseudoTag);
already_AddRefed<ServoComputedValues>
ResolveStyleLazily(dom::Element* aElement, CSSPseudoElementType aPseudoType);
void RunPostTraversalTasks();