Bug 1452080: Remove ComputedStyle::PresContext usage in animation code. r=hiro

MozReview-Commit-ID: HwooTF9PGnq
This commit is contained in:
Emilio Cobos Álvarez 2018-04-06 14:49:45 +02:00
parent 7c9fb52220
commit cfbc602521
2 changed files with 24 additions and 42 deletions

View File

@ -191,30 +191,15 @@ KeyframeEffectReadOnly::SetKeyframes(JSContext* aContext,
} }
RefPtr<ComputedStyle> style = GetTargetComputedStyle(); RefPtr<ComputedStyle> style = GetTargetComputedStyle();
if (style) { SetKeyframes(Move(keyframes), style);
SetKeyframes(Move(keyframes), style);
} else {
// SetKeyframes has the same behavior for null StyleType* for
// both backends, just pick one and use it.
SetKeyframes(Move(keyframes), (ComputedStyle*) nullptr);
}
} }
void void
KeyframeEffectReadOnly::SetKeyframes( KeyframeEffectReadOnly::SetKeyframes(
nsTArray<Keyframe>&& aKeyframes, nsTArray<Keyframe>&& aKeyframes,
const ComputedStyle* aComputedValues) const ComputedStyle* aStyle)
{ {
DoSetKeyframes(Move(aKeyframes), aComputedValues);
}
template<typename StyleType>
void
KeyframeEffectReadOnly::DoSetKeyframes(nsTArray<Keyframe>&& aKeyframes,
StyleType* aStyle)
{
if (KeyframesEqualIgnoringComputedOffsets(aKeyframes, mKeyframes)) { if (KeyframesEqualIgnoringComputedOffsets(aKeyframes, mKeyframes)) {
return; return;
} }
@ -293,14 +278,7 @@ SpecifiedKeyframeArraysAreEqual(const nsTArray<Keyframe>& aA,
#endif #endif
void void
KeyframeEffectReadOnly::UpdateProperties(const ComputedStyle* aComputedStyle) KeyframeEffectReadOnly::UpdateProperties(const ComputedStyle* aStyle)
{
DoUpdateProperties(aComputedStyle);
}
template<typename StyleType>
void
KeyframeEffectReadOnly::DoUpdateProperties(StyleType* aStyle)
{ {
MOZ_ASSERT(aStyle); MOZ_ASSERT(aStyle);
@ -1478,13 +1456,14 @@ already_AddRefed<ComputedStyle>
KeyframeEffectReadOnly::CreateComputedStyleForAnimationValue( KeyframeEffectReadOnly::CreateComputedStyleForAnimationValue(
nsCSSPropertyID aProperty, nsCSSPropertyID aProperty,
const AnimationValue& aValue, const AnimationValue& aValue,
nsPresContext* aPresContext,
const ComputedStyle* aBaseComputedStyle) const ComputedStyle* aBaseComputedStyle)
{ {
MOZ_ASSERT(aBaseComputedStyle, MOZ_ASSERT(aBaseComputedStyle,
"CreateComputedStyleForAnimationValue needs to be called " "CreateComputedStyleForAnimationValue needs to be called "
"with a valid ComputedStyle"); "with a valid ComputedStyle");
ServoStyleSet* styleSet = aBaseComputedStyle->PresContext()->StyleSet(); ServoStyleSet* styleSet = aPresContext->StyleSet();
Element* elementForResolve = Element* elementForResolve =
EffectCompositor::GetElementToRestyle(mTarget->mElement, EffectCompositor::GetElementToRestyle(mTarget->mElement,
mTarget->mPseudoType); mTarget->mPseudoType);
@ -1494,12 +1473,20 @@ KeyframeEffectReadOnly::CreateComputedStyleForAnimationValue(
aValue.mServo); aValue.mServo);
} }
template<typename StyleType>
void void
KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aComputedStyle) KeyframeEffectReadOnly::CalculateCumulativeChangeHint(const ComputedStyle* aComputedStyle)
{ {
mCumulativeChangeHint = nsChangeHint(0); mCumulativeChangeHint = nsChangeHint(0);
nsPresContext* presContext =
nsContentUtils::GetContextForContent(mTarget->mElement);
if (!presContext) {
// Change hints make no sense if we're not rendered.
//
// Actually, we cannot even post them anywhere.
return;
}
for (const AnimationProperty& property : mProperties) { for (const AnimationProperty& property : mProperties) {
// For opacity property we don't produce any change hints that are not // For opacity property we don't produce any change hints that are not
// included in nsChangeHint_Hints_CanIgnoreIfNotVisible so we can throttle // included in nsChangeHint_Hints_CanIgnoreIfNotVisible so we can throttle
@ -1521,8 +1508,9 @@ KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aComputedStyle)
} }
RefPtr<ComputedStyle> fromContext = RefPtr<ComputedStyle> fromContext =
CreateComputedStyleForAnimationValue(property.mProperty, CreateComputedStyleForAnimationValue(property.mProperty,
segment.mFromValue, segment.mFromValue,
aComputedStyle); presContext,
aComputedStyle);
if (!fromContext) { if (!fromContext) {
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible; mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
return; return;
@ -1530,8 +1518,9 @@ KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aComputedStyle)
RefPtr<ComputedStyle> toContext = RefPtr<ComputedStyle> toContext =
CreateComputedStyleForAnimationValue(property.mProperty, CreateComputedStyleForAnimationValue(property.mProperty,
segment.mToValue, segment.mToValue,
aComputedStyle); presContext,
aComputedStyle);
if (!toContext) { if (!toContext) {
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible; mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
return; return;

View File

@ -166,7 +166,7 @@ public:
void SetKeyframes(JSContext* aContext, JS::Handle<JSObject*> aKeyframes, void SetKeyframes(JSContext* aContext, JS::Handle<JSObject*> aKeyframes,
ErrorResult& aRv); ErrorResult& aRv);
void SetKeyframes(nsTArray<Keyframe>&& aKeyframes, void SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
const ComputedStyle* aComputedValues); const ComputedStyle* aStyle);
// Returns true if the effect includes |aProperty| regardless of whether the // Returns true if the effect includes |aProperty| regardless of whether the
// property is overridden by !important rule. // property is overridden by !important rule.
@ -244,8 +244,7 @@ public:
// Cumulative change hint on each segment for each property. // Cumulative change hint on each segment for each property.
// This is used for deciding the animation is paint-only. // This is used for deciding the animation is paint-only.
template<typename StyleType> void CalculateCumulativeChangeHint(const ComputedStyle* aStyle);
void CalculateCumulativeChangeHint(StyleType* aComputedStyle);
// Returns true if all of animation properties' change hints // Returns true if all of animation properties' change hints
// can ignore painting if the animation is not visible. // can ignore painting if the animation is not visible.
@ -379,13 +378,6 @@ protected:
private: private:
nsChangeHint mCumulativeChangeHint; nsChangeHint mCumulativeChangeHint;
template<typename StyleType>
void DoSetKeyframes(nsTArray<Keyframe>&& aKeyframes, StyleType* aStyle);
template<typename StyleType>
void DoUpdateProperties(StyleType* aStyle);
void ComposeStyleRule(RawServoAnimationValueMap& aAnimationValues, void ComposeStyleRule(RawServoAnimationValueMap& aAnimationValues,
const AnimationProperty& aProperty, const AnimationProperty& aProperty,
const AnimationPropertySegment& aSegment, const AnimationPropertySegment& aSegment,
@ -395,6 +387,7 @@ private:
already_AddRefed<ComputedStyle> CreateComputedStyleForAnimationValue( already_AddRefed<ComputedStyle> CreateComputedStyleForAnimationValue(
nsCSSPropertyID aProperty, nsCSSPropertyID aProperty,
const AnimationValue& aValue, const AnimationValue& aValue,
nsPresContext* aPresContext,
const ComputedStyle* aBaseComputedStyle); const ComputedStyle* aBaseComputedStyle);
nsIFrame* GetAnimationFrame() const; nsIFrame* GetAnimationFrame() const;