From b3ceb979cec1a5b8bc10ab70f3034ea72eac2a6c Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Wed, 26 Apr 2017 20:05:04 +0800 Subject: [PATCH] Bug 1346052 - Part 2: Implement AnimationValue::ComputeDistance. r=birtles We will use this API to compute the distance between two AnimationValues in the patch series. MozReview-Commit-ID: 2Tw9xumuz45 --HG-- extra : rebase_source : 298baaf597a81e03191a0468f9d7509e092a5e78 --- layout/style/StyleAnimationValue.cpp | 28 ++++++++++++++++++++++++++++ layout/style/StyleAnimationValue.h | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/layout/style/StyleAnimationValue.cpp b/layout/style/StyleAnimationValue.cpp index 7984b5d7b0b2..5ce8d95bdb3f 100644 --- a/layout/style/StyleAnimationValue.cpp +++ b/layout/style/StyleAnimationValue.cpp @@ -5295,3 +5295,31 @@ AnimationValue::IsInterpolableWith(nsCSSPropertyID aProperty, return StyleAnimationValue::Interpolate( aProperty, mGecko, aToValue.mGecko, 0.5, dummy); } + +double +AnimationValue::ComputeDistance(nsCSSPropertyID aProperty, + const AnimationValue& aOther, + nsStyleContext* aStyleContext) const +{ + if (IsNull() || aOther.IsNull()) { + return 0.0; + } + + MOZ_ASSERT(!mServo != mGecko.IsNull()); + MOZ_ASSERT(mGecko.IsNull() == aOther.mGecko.IsNull() && + !mServo == !aOther.mServo, + "Animation values should have the same style engine"); + + if (mServo) { + return Servo_AnimationValues_ComputeDistance(mServo, aOther.mServo); + } + + double distance = 0.0; + return StyleAnimationValue::ComputeDistance(aProperty, + mGecko, + aOther.mGecko, + aStyleContext, + distance) + ? distance + : 0.0; +} diff --git a/layout/style/StyleAnimationValue.h b/layout/style/StyleAnimationValue.h index 6be78462cc25..9729b26257c9 100644 --- a/layout/style/StyleAnimationValue.h +++ b/layout/style/StyleAnimationValue.h @@ -602,6 +602,13 @@ struct AnimationValue // Check if |*this| and |aToValue| can be interpolated. bool IsInterpolableWith(nsCSSPropertyID aProperty, const AnimationValue& aToValue) const; + + // Compute the distance between *this and aOther. + // If |aStyleContext| is nullptr, we will return 0.0 if we have mismatched + // transform lists. + double ComputeDistance(nsCSSPropertyID aProperty, + const AnimationValue& aOther, + nsStyleContext* aStyleContext) const; }; struct PropertyStyleAnimationValuePair