Skip to content

Commit

Permalink
Bug 1216843 - Part 3: Use nsCSSValue instead of nscolor to store over…
Browse files Browse the repository at this point in the history
… 1.0 color components as an accumulated value so that we can correctly calculate intermediate values in interpolation. r=dholbert

MozReview-Commit-ID: GYdqYZA4xXf
  • Loading branch information
Hiroyuki Ikezoe committed Sep 13, 2016
1 parent f98523c commit 447019c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
31 changes: 15 additions & 16 deletions layout/style/StyleAnimationValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ StyleAnimationValue::ComputeDistance(nsCSSPropertyID aProperty,
// colors are premultiplied, but things work better when they are,
// so use premultiplication. Spec issue is still open per
// http://lists.w3.org/Archives/Public/www-style/2009Jul/0050.html
nscolor startColor = aStartValue.GetColorValue();
nscolor endColor = aEndValue.GetColorValue();
nscolor startColor = aStartValue.GetCSSValueValue()->GetColorValue();
nscolor endColor = aEndValue.GetCSSValueValue()->GetColorValue();

// Get a color component on a 0-1 scale, which is much easier to
// deal with when working with alpha.
Expand Down Expand Up @@ -1268,7 +1268,8 @@ AddShadowItems(double aCoeff1, const nsCSSValue &aValue1,
aCoeff2, color2Value,
resultColorValue);
MOZ_ASSERT(ok, "should not fail");
resultArray->Item(4).SetColorValue(resultColorValue.GetColorValue());
resultArray->Item(4).SetColorValue(
resultColorValue.GetCSSValueValue()->GetColorValue());
}

MOZ_ASSERT(inset1 == inset2, "should match");
Expand Down Expand Up @@ -2408,8 +2409,8 @@ StyleAnimationValue::AddWeighted(nsCSSPropertyID aProperty,
return true;
}
case eUnit_Color: {
nscolor color1 = aValue1.GetColorValue();
nscolor color2 = aValue2.GetColorValue();
nscolor color1 = aValue1.GetCSSValueValue()->GetColorValue();
nscolor color2 = aValue2.GetCSSValueValue()->GetColorValue();
nscolor resultColor;

// We are using AddWeighted() with a zero aCoeff2 for colors to
Expand Down Expand Up @@ -3118,21 +3119,20 @@ StyleAnimationValue::UncomputeValue(nsCSSPropertyID aProperty,
aSpecifiedValue.
SetFloatValue(aComputedValue.GetFloatValue(), eCSSUnit_Number);
break;
case eUnit_Color:
// colors can be alone, or part of a paint server
aSpecifiedValue.SetColorValue(aComputedValue.GetColorValue());
break;
case eUnit_CurrentColor:
aSpecifiedValue.SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
break;
case eUnit_Calc:
case eUnit_Color:
case eUnit_ObjectPosition:
case eUnit_URL:
case eUnit_DiscreteCSSValue: {
nsCSSValue* val = aComputedValue.GetCSSValueValue();
// Sanity-check that the underlying unit in the nsCSSValue is what we
// expect for our StyleAnimationValue::Unit:
MOZ_ASSERT((unit == eUnit_Calc && val->GetUnit() == eCSSUnit_Calc) ||
(unit == eUnit_Color &&
nsCSSValue::IsNumericColorUnit(val->GetUnit())) ||
(unit == eUnit_ObjectPosition &&
val->GetUnit() == eCSSUnit_Array) ||
(unit == eUnit_URL && val->GetUnit() == eCSSUnit_URL) ||
Expand Down Expand Up @@ -4356,7 +4356,8 @@ StyleAnimationValue::StyleAnimationValue(float aFloat, FloatConstructorType)
StyleAnimationValue::StyleAnimationValue(nscolor aColor, ColorConstructorType)
{
mUnit = eUnit_Color;
mValue.mColor = aColor;
mValue.mCSSValue = new nsCSSValue();
mValue.mCSSValue->SetColorValue(aColor);
}

StyleAnimationValue&
Expand Down Expand Up @@ -4389,10 +4390,8 @@ StyleAnimationValue::operator=(const StyleAnimationValue& aOther)
mValue.mFloat = aOther.mValue.mFloat;
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
break;
case eUnit_Color:
mValue.mColor = aOther.mValue.mColor;
break;
case eUnit_Calc:
case eUnit_Color:
case eUnit_ObjectPosition:
case eUnit_URL:
case eUnit_DiscreteCSSValue:
Expand Down Expand Up @@ -4514,7 +4513,8 @@ StyleAnimationValue::SetColorValue(nscolor aColor)
{
FreeValue();
mUnit = eUnit_Color;
mValue.mColor = aColor;
mValue.mCSSValue = new nsCSSValue();
mValue.mCSSValue->SetColorValue(aColor);
}

void
Expand Down Expand Up @@ -4668,9 +4668,8 @@ StyleAnimationValue::operator==(const StyleAnimationValue& aOther) const
case eUnit_Percent:
case eUnit_Float:
return mValue.mFloat == aOther.mValue.mFloat;
case eUnit_Color:
return mValue.mColor == aOther.mValue.mColor;
case eUnit_Calc:
case eUnit_Color:
case eUnit_ObjectPosition:
case eUnit_URL:
case eUnit_DiscreteCSSValue:
Expand Down
11 changes: 4 additions & 7 deletions layout/style/StyleAnimationValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ class StyleAnimationValue {
eUnit_Coord,
eUnit_Percent,
eUnit_Float,
eUnit_Color,
eUnit_Color, // nsCSSValue* (never null), always with an nscolor or
// an nsCSSValueFloatColor
eUnit_CurrentColor,
eUnit_Calc, // nsCSSValue* (never null), always with a single
// calc() expression that's either length or length+percent
Expand All @@ -332,7 +333,6 @@ class StyleAnimationValue {
int32_t mInt;
nscoord mCoord;
float mFloat;
nscolor mColor;
nsCSSValue* mCSSValue;
nsCSSValuePair* mCSSValuePair;
nsCSSValueTriplet* mCSSValueTriplet;
Expand Down Expand Up @@ -372,10 +372,6 @@ class StyleAnimationValue {
NS_ASSERTION(mUnit == eUnit_Float, "unit mismatch");
return mValue.mFloat;
}
nscolor GetColorValue() const {
NS_ASSERTION(mUnit == eUnit_Color, "unit mismatch");
return mValue.mColor;
}
nsCSSValue* GetCSSValueValue() const {
NS_ASSERTION(IsCSSValueUnit(mUnit), "unit mismatch");
return mValue.mCSSValue;
Expand Down Expand Up @@ -511,7 +507,8 @@ class StyleAnimationValue {
aUnit == eUnit_Integer;
}
static bool IsCSSValueUnit(Unit aUnit) {
return aUnit == eUnit_Calc ||
return aUnit == eUnit_Color ||
aUnit == eUnit_Calc ||
aUnit == eUnit_ObjectPosition ||
aUnit == eUnit_URL ||
aUnit == eUnit_DiscreteCSSValue;
Expand Down
5 changes: 3 additions & 2 deletions layout/style/nsStyleContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,8 @@ ExtractColor(nsCSSPropertyID aProperty,
StyleAnimationValue val;
ExtractAnimationValue(aProperty, aStyleContext, val);
return val.GetUnit() == StyleAnimationValue::eUnit_CurrentColor
? aStyleContext->StyleColor()->mColor : val.GetColorValue();
? aStyleContext->StyleColor()->mColor
: val.GetCSSValueValue()->GetColorValue();
}

static nscolor
Expand All @@ -1494,7 +1495,7 @@ ExtractColorLenient(nsCSSPropertyID aProperty,
StyleAnimationValue val;
ExtractAnimationValue(aProperty, aStyleContext, val);
if (val.GetUnit() == StyleAnimationValue::eUnit_Color) {
return val.GetColorValue();
return val.GetCSSValueValue()->GetColorValue();
} else if (val.GetUnit() == StyleAnimationValue::eUnit_CurrentColor) {
return aStyleContext->StyleColor()->mColor;
}
Expand Down

0 comments on commit 447019c

Please sign in to comment.