Bug 1366157 - stylo: Implement getDefaultComputedStyle. r=emilio

MozReview-Commit-ID: GKr06ylK4tA

--HG--
extra : rebase_source : 04907d98d62a0b06f7d3753aaedf999b63483a77
This commit is contained in:
Cameron McCormack 2017-05-24 14:37:47 +08:00
Родитель 40bf61aba0
Коммит e958203c53
6 изменённых файлов: 38 добавлений и 14 удалений

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

@ -453,6 +453,7 @@ SERVO_BINDING_FUNC(Servo_HasAuthorSpecifiedRules, bool,
SERVO_BINDING_FUNC(Servo_ResolveStyleLazily, ServoComputedValuesStrong, SERVO_BINDING_FUNC(Servo_ResolveStyleLazily, ServoComputedValuesStrong,
RawGeckoElementBorrowed element, RawGeckoElementBorrowed element,
mozilla::CSSPseudoElementType pseudo_type, mozilla::CSSPseudoElementType pseudo_type,
mozilla::StyleRuleInclusion rule_inclusion,
const mozilla::ServoElementSnapshotTable* snapshots, const mozilla::ServoElementSnapshotTable* snapshots,
RawServoStyleSetBorrowed set) RawServoStyleSetBorrowed set)

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

@ -250,6 +250,7 @@ whitelist-types = [
"mozilla::binding_danger::AssertAndSuppressCleanupPolicy", "mozilla::binding_danger::AssertAndSuppressCleanupPolicy",
"mozilla::ParsingMode", "mozilla::ParsingMode",
"mozilla::InheritTarget", "mozilla::InheritTarget",
"mozilla::StyleRuleInclusion",
] ]
opaque-types = [ opaque-types = [
"std::pair__PCCP", "std::pair__PCCP",
@ -426,6 +427,7 @@ structs-types = [
"ParsingMode", "ParsingMode",
"InheritTarget", "InheritTarget",
"URLMatchingFunction", "URLMatchingFunction",
"StyleRuleInclusion",
] ]
array-types = [ array-types = [
{ cpp-type = "uintptr_t", rust-type = "usize" }, { cpp-type = "uintptr_t", rust-type = "usize" },

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

@ -476,10 +476,11 @@ ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
already_AddRefed<nsStyleContext> already_AddRefed<nsStyleContext>
ServoStyleSet::ResolveTransientStyle(Element* aElement, ServoStyleSet::ResolveTransientStyle(Element* aElement,
nsIAtom* aPseudoTag, nsIAtom* aPseudoTag,
CSSPseudoElementType aPseudoType) CSSPseudoElementType aPseudoType,
StyleRuleInclusion aRuleInclusion)
{ {
RefPtr<ServoComputedValues> computedValues = RefPtr<ServoComputedValues> computedValues =
ResolveTransientServoStyle(aElement, aPseudoType); ResolveTransientServoStyle(aElement, aPseudoType, aRuleInclusion);
return GetContext(computedValues.forget(), return GetContext(computedValues.forget(),
nullptr, nullptr,
@ -488,11 +489,13 @@ ServoStyleSet::ResolveTransientStyle(Element* aElement,
} }
already_AddRefed<ServoComputedValues> already_AddRefed<ServoComputedValues>
ServoStyleSet::ResolveTransientServoStyle(Element* aElement, ServoStyleSet::ResolveTransientServoStyle(
CSSPseudoElementType aPseudoType) Element* aElement,
CSSPseudoElementType aPseudoType,
StyleRuleInclusion aRuleInclusion)
{ {
PreTraverseSync(); PreTraverseSync();
return ResolveStyleLazily(aElement, aPseudoType); return ResolveStyleLazily(aElement, aPseudoType, aRuleInclusion);
} }
already_AddRefed<nsStyleContext> already_AddRefed<nsStyleContext>
@ -1049,7 +1052,8 @@ ServoStyleSet::ClearNonInheritingStyleContexts()
already_AddRefed<ServoComputedValues> already_AddRefed<ServoComputedValues>
ServoStyleSet::ResolveStyleLazily(Element* aElement, ServoStyleSet::ResolveStyleLazily(Element* aElement,
CSSPseudoElementType aPseudoType) CSSPseudoElementType aPseudoType,
StyleRuleInclusion aRuleInclusion)
{ {
mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType); mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType);
MOZ_ASSERT(!StylistNeedsUpdate()); MOZ_ASSERT(!StylistNeedsUpdate());
@ -1084,6 +1088,7 @@ ServoStyleSet::ResolveStyleLazily(Element* aElement,
RefPtr<ServoComputedValues> computedValues = RefPtr<ServoComputedValues> computedValues =
Servo_ResolveStyleLazily(elementForStyleResolution, Servo_ResolveStyleLazily(elementForStyleResolution,
pseudoTypeForStyleResolution, pseudoTypeForStyleResolution,
aRuleInclusion,
&Snapshots(), &Snapshots(),
mRawSet.get()).Consume(); mRawSet.get()).Consume();
@ -1091,6 +1096,7 @@ ServoStyleSet::ResolveStyleLazily(Element* aElement,
computedValues = computedValues =
Servo_ResolveStyleLazily(elementForStyleResolution, Servo_ResolveStyleLazily(elementForStyleResolution,
pseudoTypeForStyleResolution, pseudoTypeForStyleResolution,
aRuleInclusion,
&Snapshots(), &Snapshots(),
mRawSet.get()).Consume(); mRawSet.get()).Consume();
} }

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

@ -172,13 +172,17 @@ public:
already_AddRefed<nsStyleContext> already_AddRefed<nsStyleContext>
ResolveTransientStyle(dom::Element* aElement, ResolveTransientStyle(dom::Element* aElement,
nsIAtom* aPseudoTag, nsIAtom* aPseudoTag,
CSSPseudoElementType aPseudoType); CSSPseudoElementType aPseudoType,
StyleRuleInclusion aRules =
StyleRuleInclusion::All);
// Similar to ResolveTransientStyle() but returns ServoComputedValues. // Similar to ResolveTransientStyle() but returns ServoComputedValues.
// Unlike ResolveServoStyle() this function calls PreTraverseSync(). // Unlike ResolveServoStyle() this function calls PreTraverseSync().
already_AddRefed<ServoComputedValues> already_AddRefed<ServoComputedValues>
ResolveTransientServoStyle(dom::Element* aElement, ResolveTransientServoStyle(dom::Element* aElement,
CSSPseudoElementType aPseudoTag); CSSPseudoElementType aPseudoTag,
StyleRuleInclusion aRules =
StyleRuleInclusion::All);
// Get a style context for an anonymous box. aPseudoTag is the pseudo-tag to // 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 // use and must be non-null. It must be an anon box, and must be one that
@ -491,7 +495,10 @@ private:
void UpdateStylist(); void UpdateStylist();
already_AddRefed<ServoComputedValues> already_AddRefed<ServoComputedValues>
ResolveStyleLazily(dom::Element* aElement, CSSPseudoElementType aPseudoType); ResolveStyleLazily(dom::Element* aElement,
CSSPseudoElementType aPseudoType,
StyleRuleInclusion aRules =
StyleRuleInclusion::All);
void RunPostTraversalTasks(); void RunPostTraversalTasks();

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

@ -73,6 +73,15 @@ enum class TraversalRestyleBehavior {
ForCSSRuleChanges, ForCSSRuleChanges,
}; };
// Indicates which rules should be included when performing selecting matching
// on an element. DefaultOnly is used to exclude all rules except for those
// that come from UA style sheets, and is used to implemented
// getDefaultComputedStyle.
enum class StyleRuleInclusion {
All,
DefaultOnly,
};
// Represents which tasks are performed in a SequentialTask of UpdateAnimations. // Represents which tasks are performed in a SequentialTask of UpdateAnimations.
enum class UpdateAnimationsTasks : uint8_t { enum class UpdateAnimationsTasks : uint8_t {
CSSAnimations = 1 << 0, CSSAnimations = 1 << 0,

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

@ -662,11 +662,10 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
// For Servo, compute the result directly without recursively building up // For Servo, compute the result directly without recursively building up
// a throwaway style context chain. // a throwaway style context chain.
if (ServoStyleSet* servoSet = styleSet->GetAsServo()) { if (ServoStyleSet* servoSet = styleSet->GetAsServo()) {
if (aStyleType == eDefaultOnly) { StyleRuleInclusion rules = aStyleType == eDefaultOnly
NS_WARNING("stylo: ServoStyleSets cannot supply UA-only styles yet"); ? StyleRuleInclusion::DefaultOnly
return nullptr; : StyleRuleInclusion::All;
} return servoSet->ResolveTransientStyle(aElement, aPseudo, type, rules);
return servoSet->ResolveTransientStyle(aElement, aPseudo, type);
} }
RefPtr<nsStyleContext> parentContext; RefPtr<nsStyleContext> parentContext;