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();
if (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);
}
SetKeyframes(Move(keyframes), style);
}
void
KeyframeEffectReadOnly::SetKeyframes(
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)) {
return;
}
@ -293,14 +278,7 @@ SpecifiedKeyframeArraysAreEqual(const nsTArray<Keyframe>& aA,
#endif
void
KeyframeEffectReadOnly::UpdateProperties(const ComputedStyle* aComputedStyle)
{
DoUpdateProperties(aComputedStyle);
}
template<typename StyleType>
void
KeyframeEffectReadOnly::DoUpdateProperties(StyleType* aStyle)
KeyframeEffectReadOnly::UpdateProperties(const ComputedStyle* aStyle)
{
MOZ_ASSERT(aStyle);
@ -1478,13 +1456,14 @@ already_AddRefed<ComputedStyle>
KeyframeEffectReadOnly::CreateComputedStyleForAnimationValue(
nsCSSPropertyID aProperty,
const AnimationValue& aValue,
nsPresContext* aPresContext,
const ComputedStyle* aBaseComputedStyle)
{
MOZ_ASSERT(aBaseComputedStyle,
"CreateComputedStyleForAnimationValue needs to be called "
"with a valid ComputedStyle");
ServoStyleSet* styleSet = aBaseComputedStyle->PresContext()->StyleSet();
ServoStyleSet* styleSet = aPresContext->StyleSet();
Element* elementForResolve =
EffectCompositor::GetElementToRestyle(mTarget->mElement,
mTarget->mPseudoType);
@ -1494,12 +1473,20 @@ KeyframeEffectReadOnly::CreateComputedStyleForAnimationValue(
aValue.mServo);
}
template<typename StyleType>
void
KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aComputedStyle)
KeyframeEffectReadOnly::CalculateCumulativeChangeHint(const ComputedStyle* aComputedStyle)
{
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 opacity property we don't produce any change hints that are not
// included in nsChangeHint_Hints_CanIgnoreIfNotVisible so we can throttle
@ -1521,8 +1508,9 @@ KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aComputedStyle)
}
RefPtr<ComputedStyle> fromContext =
CreateComputedStyleForAnimationValue(property.mProperty,
segment.mFromValue,
aComputedStyle);
segment.mFromValue,
presContext,
aComputedStyle);
if (!fromContext) {
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
return;
@ -1530,8 +1518,9 @@ KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aComputedStyle)
RefPtr<ComputedStyle> toContext =
CreateComputedStyleForAnimationValue(property.mProperty,
segment.mToValue,
aComputedStyle);
segment.mToValue,
presContext,
aComputedStyle);
if (!toContext) {
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
return;

View File

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