--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -684,16 +684,40 @@ AddTransformTranslate(double aCoeff1, co
aValue1.IsCalcUnit())
? eCSSUnit_Calc
: aValue1.GetUnit(),
aCoeff1, aValue1,
aCoeff2, aValue2,
aResult);
}
+// Unclamped AddWeightedColors.
+static RGBAColorData
+AddWeightedColors(double aCoeff1, const RGBAColorData& aValue1,
+ double aCoeff2, const RGBAColorData& aValue2)
+{
+ float factor1 = aValue1.mA * aCoeff1;
+ float factor2 = aValue2.mA * aCoeff2;
+ float resultA = factor1 + factor2;
+ if (resultA <= 0.0) {
+ return {0, 0, 0, 0};
+ }
+
+ if (resultA > 1.0) {
+ resultA = 1.0;
+ }
+
+ float resultFactor = 1.0f / resultA;
+ return RGBAColorData(
+ (aValue1.mR * factor1 + aValue2.mR * factor2) * resultFactor,
+ (aValue1.mG * factor1 + aValue2.mG * factor2) * resultFactor,
+ (aValue1.mB * factor1 + aValue2.mB * factor2) * resultFactor,
+ resultA);
+}
+
// CLASS METHODS
// -------------
static RGBAColorData
ExtractColor(const nsCSSValue& aValue)
{
MOZ_ASSERT(aValue.IsNumericColorUnit(), "The unit should be color");
// PercentageRGBColor and PercentageRGBAColor component value might be
@@ -740,20 +764,33 @@ ExtractComplexColor(const StyleAnimation
StyleAnimationValue
StyleAnimationValue::Add(nsCSSPropertyID aProperty,
const StyleAnimationValue& aA,
StyleAnimationValue&& aB)
{
StyleAnimationValue result(Move(aB));
- Unused << AddWeighted(aProperty,
- 1.0, result,
- 1, aA,
- result);
+ Unit commonUnit =
+ GetCommonUnit(aProperty, result.GetUnit(), aA.GetUnit());
+ switch (commonUnit) {
+ case eUnit_Color: {
+ RGBAColorData color1 = ExtractColor(result);
+ RGBAColorData color2 = ExtractColor(aA);
+ result.mValue.mCSSValue->SetRGBAColorValue(
+ AddWeightedColors(1.0, color1, 1, color2));
+ break;
+ }
+ default:
+ Unused << AddWeighted(aProperty,
+ 1.0, result,
+ 1, aA,
+ result);
+ break;
+ }
return result;
}
double
StyleAnimationValue::ComputeColorDistance(const RGBAColorData& aStartColor,
const RGBAColorData& aEndColor)
{
@@ -1883,40 +1920,16 @@ AddCSSValuePercentNumber(const uint32_t
// aCoeff2 is 0, then we'll return the value halfway between 1 and
// aValue1, rather than the value halfway between 0 and aValue1.
// Note that we do something similar in AddTransformScale().
float result = (n1 - aInitialVal) * aCoeff1 + (n2 - aInitialVal) * aCoeff2;
aResult.SetFloatValue(RestrictValue(aValueRestrictions, result + aInitialVal),
eCSSUnit_Number);
}
-// Unclamped AddWeightedColors.
-static RGBAColorData
-AddWeightedColors(double aCoeff1, const RGBAColorData& aValue1,
- double aCoeff2, const RGBAColorData& aValue2)
-{
- float factor1 = aValue1.mA * aCoeff1;
- float factor2 = aValue2.mA * aCoeff2;
- float resultA = factor1 + factor2;
- if (resultA <= 0.0) {
- return {0, 0, 0, 0};
- }
-
- if (resultA > 1.0) {
- resultA = 1.0;
- }
-
- float resultFactor = 1.0f / resultA;
- return RGBAColorData(
- (aValue1.mR * factor1 + aValue2.mR * factor2) * resultFactor,
- (aValue1.mG * factor1 + aValue2.mG * factor2) * resultFactor,
- (aValue1.mB * factor1 + aValue2.mB * factor2) * resultFactor,
- resultA);
-}
-
// Multiplies |aValue| color by |aDilutionRation|.
static nscolor
DiluteColor(const RGBAColorData& aValue, double aDilutionRatio)
{
MOZ_ASSERT(aDilutionRatio >= 0.0 && aDilutionRatio <= 1.0,
"Dilution ratio should be in [0, 1]");
float resultA = aValue.mA * aDilutionRatio;
return resultA <= 0.0 ? NS_RGBA(0, 0, 0, 0)
@@ -3274,20 +3287,18 @@ StyleAnimationValue::Accumulate(nsCSSPro
if (resultList) {
result.SetAndAdoptCSSValueListValue(resultList.release(), eUnit_Shadow);
}
break;
}
case eUnit_Color: {
RGBAColorData color1 = ExtractColor(result);
RGBAColorData color2 = ExtractColor(aA);
- auto resultColor = MakeUnique<nsCSSValue>();
- resultColor->SetRGBAColorValue(
+ result.mValue.mCSSValue->SetRGBAColorValue(
AddWeightedColors(1.0, color1, aCount, color2));
- result.SetAndAdoptCSSValueValue(resultColor.release(), eUnit_Color);
break;
}
case eUnit_Transform: {
const nsCSSValueList* listA =
aA.GetCSSValueSharedListValue()->mHead;
const nsCSSValueList* listB =
result.GetCSSValueSharedListValue()->mHead;