mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
Bug 1343753 - Part 3: Use AnimationValue in ElementPropertyTransition and CSSTransition. r=birtles
We also need to update the interpolation code based on ServoAnimationValue in ElementPropertyTransition::UpdateStartValueFromReplacedTransition(). Therefore, ElementPropertyTransition can be used by both Gecko and Servo. MozReview-Commit-ID: BrIpvRR3te8 --HG-- extra : rebase_source : df49fdf39811dcd1661cc815dbf0b1bc192f9d81
This commit is contained in:
parent
6b6ab8a902
commit
f4f6aed21d
@ -5209,6 +5209,12 @@ AnimationValue::operator==(const AnimationValue& aOther) const
|
||||
mGecko == aOther.mGecko;
|
||||
}
|
||||
|
||||
bool
|
||||
AnimationValue::operator!=(const AnimationValue& aOther) const
|
||||
{
|
||||
return !operator==(aOther);
|
||||
}
|
||||
|
||||
float
|
||||
AnimationValue::GetOpacity() const
|
||||
{
|
||||
|
@ -579,6 +579,7 @@ struct AnimationValue
|
||||
RefPtr<RawServoAnimationValue> mServo;
|
||||
|
||||
bool operator==(const AnimationValue& aOther) const;
|
||||
bool operator!=(const AnimationValue& aOther) const;
|
||||
|
||||
bool IsNull() const { return mGecko.IsNull() && !mServo; }
|
||||
|
||||
|
@ -108,27 +108,43 @@ ElementPropertyTransition::UpdateStartValueFromReplacedTransition()
|
||||
ComputedTimingFunction::GetPortion(mReplacedTransition->mTimingFunction,
|
||||
computedTiming.mProgress.Value(),
|
||||
computedTiming.mBeforeFlag);
|
||||
StyleAnimationValue startValue;
|
||||
if (StyleAnimationValue::Interpolate(mProperties[0].mProperty,
|
||||
mReplacedTransition->mFromValue,
|
||||
mReplacedTransition->mToValue,
|
||||
valuePosition, startValue)) {
|
||||
MOZ_ASSERT(mProperties.Length() == 1 &&
|
||||
mProperties[0].mSegments.Length() == 1,
|
||||
"The transition should have one property and one segment");
|
||||
|
||||
MOZ_ASSERT(mProperties.Length() == 1 &&
|
||||
mProperties[0].mSegments.Length() == 1,
|
||||
"The transition should have one property and one segment");
|
||||
MOZ_ASSERT(mKeyframes.Length() == 2,
|
||||
"Transitions should have exactly two animation keyframes");
|
||||
MOZ_ASSERT(mKeyframes[0].mPropertyValues.Length() == 1,
|
||||
"Transitions should have exactly one property in their first "
|
||||
"frame");
|
||||
|
||||
const AnimationValue& replacedFrom = mReplacedTransition->mFromValue;
|
||||
const AnimationValue& replacedTo = mReplacedTransition->mToValue;
|
||||
AnimationValue startValue;
|
||||
if (mDocument->IsStyledByServo()) {
|
||||
startValue.mServo =
|
||||
Servo_AnimationValues_Interpolate(replacedFrom.mServo,
|
||||
replacedTo.mServo,
|
||||
valuePosition).Consume();
|
||||
if (startValue.mServo) {
|
||||
mKeyframes[0].mPropertyValues[0].mServoDeclarationBlock =
|
||||
Servo_AnimationValue_Uncompute(startValue.mServo).Consume();
|
||||
mProperties[0].mSegments[0].mFromValue = Move(startValue);
|
||||
}
|
||||
} else if (StyleAnimationValue::Interpolate(mProperties[0].mProperty,
|
||||
replacedFrom.mGecko,
|
||||
replacedTo.mGecko,
|
||||
valuePosition,
|
||||
startValue.mGecko)) {
|
||||
nsCSSValue cssValue;
|
||||
DebugOnly<bool> uncomputeResult =
|
||||
StyleAnimationValue::UncomputeValue(mProperties[0].mProperty,
|
||||
startValue,
|
||||
startValue.mGecko,
|
||||
cssValue);
|
||||
mProperties[0].mSegments[0].mFromValue.mGecko = Move(startValue);
|
||||
MOZ_ASSERT(uncomputeResult, "UncomputeValue should not fail");
|
||||
MOZ_ASSERT(mKeyframes.Length() == 2,
|
||||
"Transitions should have exactly two animation keyframes");
|
||||
MOZ_ASSERT(mKeyframes[0].mPropertyValues.Length() == 1,
|
||||
"Transitions should have exactly one property in their first "
|
||||
"frame");
|
||||
mKeyframes[0].mPropertyValues[0].mValue = cssValue;
|
||||
|
||||
mProperties[0].mSegments[0].mFromValue = Move(startValue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +359,7 @@ CSSTransition::TransitionProperty() const
|
||||
return mTransitionProperty;
|
||||
}
|
||||
|
||||
StyleAnimationValue
|
||||
AnimationValue
|
||||
CSSTransition::ToValue() const
|
||||
{
|
||||
MOZ_ASSERT(!mTransitionToValue.IsNull(),
|
||||
@ -698,7 +714,7 @@ nsTransitionManager::UpdateTransitions(
|
||||
// matching currentValue
|
||||
!ExtractNonDiscreteComputedValue(anim->TransitionProperty(),
|
||||
aNewStyleContext, currentValue) ||
|
||||
currentValue != anim->ToValue()) {
|
||||
currentValue != anim->ToValue().mGecko) {
|
||||
// stop the transition
|
||||
if (anim->HasCurrentEffect()) {
|
||||
EffectSet* effectSet =
|
||||
@ -811,7 +827,7 @@ nsTransitionManager::ConsiderInitiatingTransition(
|
||||
ExtractNonDiscreteComputedValue(aProperty, aNewStyleContext,
|
||||
endValue.mGecko);
|
||||
|
||||
bool haveChange = startValue.mGecko != endValue.mGecko;
|
||||
bool haveChange = startValue != endValue;
|
||||
|
||||
bool shouldAnimate =
|
||||
haveValues &&
|
||||
@ -857,8 +873,7 @@ nsTransitionManager::ConsiderInitiatingTransition(
|
||||
// a new transition for the reasons described in
|
||||
// https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html .
|
||||
if (haveCurrentTransition && haveValues &&
|
||||
aElementTransitions->mAnimations[currentIndex]->ToValue() ==
|
||||
endValue.mGecko) {
|
||||
aElementTransitions->mAnimations[currentIndex]->ToValue() == endValue) {
|
||||
// GetAnimationRule already called RestyleForAnimation.
|
||||
return;
|
||||
}
|
||||
@ -911,7 +926,7 @@ nsTransitionManager::ConsiderInitiatingTransition(
|
||||
if (haveCurrentTransition &&
|
||||
aElementTransitions->mAnimations[currentIndex]->HasCurrentEffect() &&
|
||||
oldPT &&
|
||||
oldPT->mStartForReversingTest == endValue.mGecko) {
|
||||
oldPT->mStartForReversingTest == endValue) {
|
||||
// Compute the appropriate negative transition-delay such that right
|
||||
// now we'd end up at the current position.
|
||||
double valuePortion =
|
||||
@ -942,7 +957,7 @@ nsTransitionManager::ConsiderInitiatingTransition(
|
||||
|
||||
duration *= valuePortion;
|
||||
|
||||
startForReversingTest.mGecko = oldPT->ToValue();
|
||||
startForReversingTest = oldPT->ToValue();
|
||||
reversePortion = valuePortion;
|
||||
}
|
||||
|
||||
@ -958,7 +973,7 @@ nsTransitionManager::ConsiderInitiatingTransition(
|
||||
KeyframeEffectParams effectOptions;
|
||||
RefPtr<ElementPropertyTransition> pt =
|
||||
new ElementPropertyTransition(aElement->OwnerDoc(), target, timing,
|
||||
startForReversingTest.mGecko, reversePortion,
|
||||
startForReversingTest, reversePortion,
|
||||
effectOptions);
|
||||
|
||||
pt->SetKeyframes(GetTransitionKeyframes(aProperty,
|
||||
@ -1023,8 +1038,8 @@ nsTransitionManager::ConsiderInitiatingTransition(
|
||||
oldPT->GetAnimation()->PlaybackRate(),
|
||||
oldPT->SpecifiedTiming(),
|
||||
segment.mTimingFunction,
|
||||
segment.mFromValue.mGecko,
|
||||
segment.mToValue.mGecko
|
||||
segment.mFromValue,
|
||||
segment.mToValue
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -1078,9 +1093,10 @@ nsTransitionManager::PruneCompletedTransitions(mozilla::dom::Element* aElement,
|
||||
|
||||
// Since effect is a finished transition, we know it didn't
|
||||
// influence style.
|
||||
StyleAnimationValue currentValue;
|
||||
AnimationValue currentValue;
|
||||
if (!ExtractNonDiscreteComputedValue(anim->TransitionProperty(),
|
||||
aNewStyleContext, currentValue) ||
|
||||
aNewStyleContext,
|
||||
currentValue.mGecko) ||
|
||||
currentValue != anim->ToValue()) {
|
||||
anim->CancelFromStyle();
|
||||
animations.RemoveElementAt(i);
|
||||
|
@ -39,7 +39,7 @@ struct ElementPropertyTransition : public dom::KeyframeEffectReadOnly
|
||||
ElementPropertyTransition(nsIDocument* aDocument,
|
||||
Maybe<OwningAnimationTarget>& aTarget,
|
||||
const TimingParams &aTiming,
|
||||
StyleAnimationValue aStartForReversingTest,
|
||||
AnimationValue aStartForReversingTest,
|
||||
double aReversePortion,
|
||||
const KeyframeEffectParams& aEffectOptions)
|
||||
: dom::KeyframeEffectReadOnly(aDocument, aTarget, aTiming, aEffectOptions)
|
||||
@ -63,7 +63,7 @@ struct ElementPropertyTransition : public dom::KeyframeEffectReadOnly
|
||||
return mKeyframes[0].mPropertyValues[0].mProperty;
|
||||
}
|
||||
|
||||
StyleAnimationValue ToValue() const {
|
||||
AnimationValue ToValue() const {
|
||||
// If we failed to generate properties from the transition frames,
|
||||
// return a null value but also show a warning since we should be
|
||||
// detecting that kind of situation in advance and not generating a
|
||||
@ -71,9 +71,9 @@ struct ElementPropertyTransition : public dom::KeyframeEffectReadOnly
|
||||
if (mProperties.Length() < 1 ||
|
||||
mProperties[0].mSegments.Length() < 1) {
|
||||
NS_WARNING("Failed to generate transition property values");
|
||||
return StyleAnimationValue();
|
||||
return AnimationValue();
|
||||
}
|
||||
return mProperties[0].mSegments[0].mToValue.mGecko;
|
||||
return mProperties[0].mSegments[0].mToValue;
|
||||
}
|
||||
|
||||
// This is the start value to be used for a check for whether a
|
||||
@ -81,7 +81,7 @@ struct ElementPropertyTransition : public dom::KeyframeEffectReadOnly
|
||||
// mProperties[0].mSegments[0].mFromValue, except when this transition
|
||||
// started as the reversal of another in-progress transition.
|
||||
// Needed so we can handle two reverses in a row.
|
||||
StyleAnimationValue mStartForReversingTest;
|
||||
AnimationValue mStartForReversingTest;
|
||||
// Likewise, the portion (in value space) of the "full" reversed
|
||||
// transition that we're actually covering. For example, if a :hover
|
||||
// effect has a transition that moves the element 10px to the right
|
||||
@ -108,7 +108,7 @@ struct ElementPropertyTransition : public dom::KeyframeEffectReadOnly
|
||||
double mPlaybackRate;
|
||||
TimingParams mTiming;
|
||||
Maybe<ComputedTimingFunction> mTimingFunction;
|
||||
StyleAnimationValue mFromValue, mToValue;
|
||||
AnimationValue mFromValue, mToValue;
|
||||
};
|
||||
Maybe<ReplacedTransitionProperties> mReplacedTransition;
|
||||
};
|
||||
@ -175,7 +175,7 @@ public:
|
||||
void Tick() override;
|
||||
|
||||
nsCSSPropertyID TransitionProperty() const;
|
||||
StyleAnimationValue ToValue() const;
|
||||
AnimationValue ToValue() const;
|
||||
|
||||
bool HasLowerCompositeOrderThan(const CSSTransition& aOther) const;
|
||||
EffectCompositor::CascadeLevel CascadeLevel() const override
|
||||
@ -275,7 +275,7 @@ protected:
|
||||
// ElementPropertyTransition (effect) however since it can be replaced
|
||||
// using the Web Animations API.
|
||||
nsCSSPropertyID mTransitionProperty;
|
||||
StyleAnimationValue mTransitionToValue;
|
||||
AnimationValue mTransitionToValue;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user