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,
RawGeckoElementBorrowed element,
mozilla::CSSPseudoElementType pseudo_type,
mozilla::StyleRuleInclusion rule_inclusion,
const mozilla::ServoElementSnapshotTable* snapshots,
RawServoStyleSetBorrowed set)

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

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

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

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

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

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

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

@ -73,6 +73,15 @@ enum class TraversalRestyleBehavior {
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.
enum class UpdateAnimationsTasks : uint8_t {
CSSAnimations = 1 << 0,

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

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