Pass property to nsStyleAnimation interpolation functions. (Bug 528234) r=dholbert

This commit is contained in:
L. David Baron 2009-11-14 19:16:58 -08:00
parent a34c72abd2
commit eea2f3996a
4 changed files with 39 additions and 26 deletions

View File

@ -212,7 +212,7 @@ nsSMILCSSValueType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
if (destWrapper->mPropID == eCSSProperty_font_size_adjust) {
return NS_ERROR_FAILURE;
}
return nsStyleAnimation::Add(destWrapper->mCSSValue,
return nsStyleAnimation::Add(destWrapper->mPropID, destWrapper->mCSSValue,
*realValueToAdd, aCount) ?
NS_OK : NS_ERROR_FAILURE;
}
@ -248,7 +248,8 @@ nsSMILCSSValueType::ComputeDistance(const nsSMILValue& aFrom,
!toWrapper->mCSSValue.IsNull() && toWrapper->mPresContext,
"ComputeDistance endpoint should be a parsed value");
return nsStyleAnimation::ComputeDistance(*fromCSSValue, toWrapper->mCSSValue,
return nsStyleAnimation::ComputeDistance(toWrapper->mPropID,
*fromCSSValue, toWrapper->mCSSValue,
aDistance) ?
NS_OK : NS_ERROR_FAILURE;
}
@ -291,7 +292,8 @@ nsSMILCSSValueType::Interpolate(const nsSMILValue& aStartVal,
!endWrapper->mCSSValue.IsNull() && endWrapper->mPresContext,
"Interpolate endpoint should be a parsed value");
if (nsStyleAnimation::Interpolate(*startCSSValue,
if (nsStyleAnimation::Interpolate(endWrapper->mPropID,
*startCSSValue,
endWrapper->mCSSValue,
aUnitDistance,
resultWrapper->mCSSValue)) {

View File

@ -117,7 +117,8 @@ lcm(PRUint32 a, PRUint32 b)
// -------------
PRBool
nsStyleAnimation::ComputeDistance(const Value& aStartValue,
nsStyleAnimation::ComputeDistance(nsCSSProperty aProperty,
const Value& aStartValue,
const Value& aEndValue,
double& aDistance)
{
@ -237,8 +238,10 @@ nsStyleAnimation::ComputeDistance(const Value& aStartValue,
// Call AddWeighted to make us lists of the same length.
Value normValue1, normValue2;
if (!AddWeighted(1.0, aStartValue, 0.0, aEndValue, normValue1) ||
!AddWeighted(0.0, aStartValue, 1.0, aEndValue, normValue2)) {
if (!AddWeighted(aProperty, 1.0, aStartValue, 0.0, aEndValue,
normValue1) ||
!AddWeighted(aProperty, 0.0, aStartValue, 1.0, aEndValue,
normValue2)) {
success = PR_FALSE;
break;
}
@ -279,8 +282,10 @@ nsStyleAnimation::ComputeDistance(const Value& aStartValue,
case eUnit_Shadow: {
// Call AddWeighted to make us lists of the same length.
Value normValue1, normValue2;
if (!AddWeighted(1.0, aStartValue, 0.0, aEndValue, normValue1) ||
!AddWeighted(0.0, aStartValue, 1.0, aEndValue, normValue2)) {
if (!AddWeighted(aProperty, 1.0, aStartValue, 0.0, aEndValue,
normValue1) ||
!AddWeighted(aProperty, 0.0, aStartValue, 1.0, aEndValue,
normValue2)) {
success = PR_FALSE;
break;
}
@ -325,7 +330,8 @@ nsStyleAnimation::ComputeDistance(const Value& aStartValue,
#ifdef DEBUG
PRBool ok =
#endif
nsStyleAnimation::ComputeDistance(color1Value, color2Value,
nsStyleAnimation::ComputeDistance(eCSSProperty_color,
color1Value, color2Value,
colorDistance);
NS_ABORT_IF_FALSE(ok, "should not fail");
squareDistance += colorDistance * colorDistance;
@ -405,8 +411,8 @@ AddShadowItems(double aCoeff1, const nsCSSValue &aValue1,
#ifdef DEBUG
PRBool ok =
#endif
nsStyleAnimation::AddWeighted(aCoeff1, color1Value, aCoeff2, color2Value,
resultColorValue);
nsStyleAnimation::AddWeighted(eCSSProperty_color, aCoeff1, color1Value,
aCoeff2, color2Value, resultColorValue);
NS_ABORT_IF_FALSE(ok, "should not fail");
resultArray->Item(4).SetColorValue(resultColorValue.GetColorValue());
}
@ -425,7 +431,8 @@ AddShadowItems(double aCoeff1, const nsCSSValue &aValue1,
}
PRBool
nsStyleAnimation::AddWeighted(double aCoeff1, const Value& aValue1,
nsStyleAnimation::AddWeighted(nsCSSProperty aProperty,
double aCoeff1, const Value& aValue1,
double aCoeff2, const Value& aValue2,
Value& aResultValue)
{

View File

@ -76,9 +76,9 @@ public:
* @param aCount The number of times to add aValueToAdd.
* @return PR_TRUE on success, PR_FALSE on failure.
*/
static PRBool Add(Value& aDest, const Value& aValueToAdd,
PRUint32 aCount) {
return AddWeighted(1.0, aDest, aCount, aValueToAdd, aDest);
static PRBool Add(nsCSSProperty aProperty, Value& aDest,
const Value& aValueToAdd, PRUint32 aCount) {
return AddWeighted(aProperty, 1.0, aDest, aCount, aValueToAdd, aDest);
}
/**
@ -99,7 +99,8 @@ public:
* @param aDistance The result of the calculation.
* @return PR_TRUE on success, PR_FALSE on failure.
*/
static PRBool ComputeDistance(const Value& aStartValue,
static PRBool ComputeDistance(nsCSSProperty aProperty,
const Value& aStartValue,
const Value& aEndValue,
double& aDistance);
@ -119,13 +120,14 @@ public:
* @param [out] aResultValue The resulting interpolated value.
* @return PR_TRUE on success, PR_FALSE on failure.
*/
static PRBool Interpolate(const Value& aStartValue,
static PRBool Interpolate(nsCSSProperty aProperty,
const Value& aStartValue,
const Value& aEndValue,
double aPortion,
Value& aResultValue) {
NS_ABORT_IF_FALSE(0.0 <= aPortion && aPortion <= 1.0, "out of range");
return AddWeighted(1.0 - aPortion, aStartValue, aPortion, aEndValue,
aResultValue);
return AddWeighted(aProperty, 1.0 - aPortion, aStartValue,
aPortion, aEndValue, aResultValue);
}
/**
@ -142,7 +144,8 @@ public:
* difficulty, we might change this to restrict them to being
* positive.
*/
static PRBool AddWeighted(double aCoeff1, const Value& aValue1,
static PRBool AddWeighted(nsCSSProperty aProperty,
double aCoeff1, const Value& aValue1,
double aCoeff2, const Value& aValue2,
Value& aResultValue);

View File

@ -234,7 +234,8 @@ ElementTransitionsStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
#ifdef DEBUG
PRBool ok =
#endif
nsStyleAnimation::Interpolate(pt.mStartValue, pt.mEndValue,
nsStyleAnimation::Interpolate(pt.mProperty,
pt.mStartValue, pt.mEndValue,
valuePortion, pt.mCurrentValue);
NS_ABORT_IF_FALSE(ok, "could not interpolate values");
@ -512,8 +513,8 @@ nsTransitionManager::ConsiderStartingTransition(nsCSSProperty aProperty,
// Check that we can interpolate between these values
// (If this is ever a performance problem, we could add a
// CanInterpolate method, but it seems fine for now.)
nsStyleAnimation::Interpolate(pt.mStartValue, pt.mEndValue, 0.5,
dummyValue);
nsStyleAnimation::Interpolate(aProperty, pt.mStartValue, pt.mEndValue,
0.5, dummyValue);
PRUint32 currentIndex = nsTArray<ElementPropertyTransition>::NoIndex;
if (aElementTransitions) {
@ -575,12 +576,12 @@ nsTransitionManager::ConsiderStartingTransition(nsCSSProperty aProperty,
#ifdef DEBUG
PRBool ok =
#endif
nsStyleAnimation::ComputeDistance(pt.mStartValue, pt.mEndValue,
fullDistance);
nsStyleAnimation::ComputeDistance(aProperty, pt.mStartValue,
pt.mEndValue, fullDistance);
NS_ABORT_IF_FALSE(ok, "could not compute distance");
NS_ABORT_IF_FALSE(fullDistance >= 0.0, "distance must be positive");
if (nsStyleAnimation::ComputeDistance(endVal, pt.mEndValue,
if (nsStyleAnimation::ComputeDistance(aProperty, endVal, pt.mEndValue,
remainingDistance)) {
NS_ABORT_IF_FALSE(remainingDistance >= 0.0, "distance must be positive");
durationFraction = fullDistance / remainingDistance;