Bug 520486 (patch 1): Extend nsStyleAnimation to support enumerated values. r=dbaron

This commit is contained in:
Daniel Holbert 2009-10-21 14:57:57 -07:00
parent 3cb73212d1
commit 03220db402
4 changed files with 91 additions and 43 deletions

View File

@ -1359,8 +1359,8 @@ CSS_PROP_DISPLAY(
mDisplay,
eCSSType_Value,
kDisplayKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleDisplay, mDisplay),
eStyleAnimType_EnumU8)
CSS_PROP_BACKENDONLY(
elevation,
elevation,
@ -1463,8 +1463,8 @@ CSS_PROP_FONT(
mStyle,
eCSSType_Value,
kFontStyleKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleFont, mFont.style),
eStyleAnimType_EnumU8)
CSS_PROP_FONT(
font-variant,
font_variant,
@ -1474,8 +1474,8 @@ CSS_PROP_FONT(
mVariant,
eCSSType_Value,
kFontVariantKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleFont, mFont.variant),
eStyleAnimType_EnumU8)
CSS_PROP_FONT(
font-weight,
font_weight,
@ -2146,8 +2146,8 @@ CSS_PROP_VISIBILITY(
mPointerEvents,
eCSSType_Value,
kPointerEventsKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleVisibility, mPointerEvents),
eStyleAnimType_EnumU8)
CSS_PROP_DISPLAY(
position,
position,
@ -2284,8 +2284,8 @@ CSS_PROP_TEXTRESET(
mDecoration,
eCSSType_Value,
kTextDecorationKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleTextReset, mTextDecoration),
eStyleAnimType_EnumU8)
CSS_PROP_TEXT(
text-indent,
text_indent,
@ -2481,8 +2481,8 @@ CSS_PROP_VISIBILITY(
mVisibility,
eCSSType_Value,
kVisibilityKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None) // reflow for collapse
offsetof(nsStyleVisibility, mVisible),
eStyleAnimType_EnumU8) // reflow for collapse
CSS_PROP_BACKENDONLY(
voice-family,
voice_family,
@ -2717,8 +2717,8 @@ CSS_PROP_SVG(
mClipRule,
eCSSType_Value,
kFillRuleKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mClipRule),
eStyleAnimType_EnumU8)
CSS_PROP_SVG(
color-interpolation,
color_interpolation,
@ -2728,8 +2728,8 @@ CSS_PROP_SVG(
mColorInterpolation,
eCSSType_Value,
kColorInterpolationKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mColorInterpolation),
eStyleAnimType_EnumU8)
CSS_PROP_SVG(
color-interpolation-filters,
color_interpolation_filters,
@ -2739,8 +2739,8 @@ CSS_PROP_SVG(
mColorInterpolationFilters,
eCSSType_Value,
kColorInterpolationKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mColorInterpolationFilters),
eStyleAnimType_EnumU8)
CSS_PROP_SVGRESET(
dominant-baseline,
dominant_baseline,
@ -2750,8 +2750,8 @@ CSS_PROP_SVGRESET(
mDominantBaseline,
eCSSType_Value,
kDominantBaselineKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVGReset, mDominantBaseline),
eStyleAnimType_EnumU8)
CSS_PROP_SVG(
fill,
fill,
@ -2783,8 +2783,8 @@ CSS_PROP_SVG(
mFillRule,
eCSSType_Value,
kFillRuleKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mFillRule),
eStyleAnimType_EnumU8)
CSS_PROP_SVGRESET(
filter,
filter,
@ -2827,8 +2827,8 @@ CSS_PROP_SVG(
mImageRendering,
eCSSType_Value,
kImageRenderingKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mImageRendering),
eStyleAnimType_EnumU8)
CSS_PROP_SVGRESET(
lighting-color,
lighting_color,
@ -2898,8 +2898,8 @@ CSS_PROP_SVG(
mShapeRendering,
eCSSType_Value,
kShapeRenderingKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mShapeRendering),
eStyleAnimType_EnumU8)
CSS_PROP_SVGRESET(
stop-color,
stop_color,
@ -2964,8 +2964,8 @@ CSS_PROP_SVG(
mStrokeLinecap,
eCSSType_Value,
kStrokeLinecapKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mStrokeLinecap),
eStyleAnimType_EnumU8)
CSS_PROP_SVG(
stroke-linejoin,
stroke_linejoin,
@ -2975,8 +2975,8 @@ CSS_PROP_SVG(
mStrokeLinejoin,
eCSSType_Value,
kStrokeLinejoinKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mStrokeLinejoin),
eStyleAnimType_EnumU8)
CSS_PROP_SVG(
stroke-miterlimit,
stroke_miterlimit,
@ -3019,8 +3019,8 @@ CSS_PROP_SVG(
mTextAnchor,
eCSSType_Value,
kTextAnchorKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mTextAnchor),
eStyleAnimType_EnumU8)
CSS_PROP_SVG(
text-rendering,
text_rendering,
@ -3030,8 +3030,8 @@ CSS_PROP_SVG(
mTextRendering,
eCSSType_Value,
kTextRenderingKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
offsetof(nsStyleSVG, mTextRendering),
eStyleAnimType_EnumU8)
#endif /* !defined (CSS_PROP_LIST_EXCLUDE_INTERNAL) */
#endif

View File

@ -86,6 +86,12 @@ enum nsStyleAnimType {
// nscoord values
eStyleAnimType_nscoord,
// enumerated values (stored in a PRUint8)
// In order for a property to use this unit, _all_ of its enumerated values
// must be listed in its keyword table, so that any enumerated value can be
// converted into a string via a nsCSSValue of type eCSSUnit_Enumerated.
eStyleAnimType_EnumU8,
// float values
eStyleAnimType_float,

View File

@ -125,6 +125,11 @@ nsStyleAnimation::ComputeDistance(const Value& aStartValue,
PRBool success = PR_TRUE;
switch (commonUnit) {
case eUnit_Null:
case eUnit_None:
case eUnit_Enumerated:
success = PR_FALSE;
break;
case eUnit_Coord: {
nscoord startCoord = aStartValue.GetCoordValue();
nscoord endCoord = aEndValue.GetCoordValue();
@ -289,10 +294,6 @@ nsStyleAnimation::ComputeDistance(const Value& aStartValue,
aDistance = sqrt(distance);
break;
}
case eUnit_Null:
case eUnit_None:
success = PR_FALSE;
break;
default:
NS_NOTREACHED("Can't compute distance using the given common unit");
success = PR_FALSE;
@ -392,6 +393,11 @@ nsStyleAnimation::AddWeighted(double aCoeff1, const Value& aValue1,
PRBool success = PR_TRUE;
switch (commonUnit) {
case eUnit_Null:
case eUnit_None:
case eUnit_Enumerated:
success = PR_FALSE;
break;
case eUnit_Coord: {
aResultValue.SetCoordValue(NSToCoordRound(
aCoeff1 * aValue1.GetCoordValue() +
@ -551,10 +557,6 @@ nsStyleAnimation::AddWeighted(double aCoeff1, const Value& aValue1,
PR_TRUE);
break;
}
case eUnit_Null:
case eUnit_None:
success = PR_FALSE;
break;
default:
NS_NOTREACHED("Can't interpolate using the given common unit");
success = PR_FALSE;
@ -674,6 +676,12 @@ nsStyleAnimation::UncomputeValue(nsCSSProperty aProperty,
static_cast<nsCSSValue*>(aSpecifiedValue)->SetNoneValue();
}
break;
case eUnit_Enumerated:
NS_ABORT_IF_FALSE(nsCSSProps::kTypeTable[aProperty] == eCSSType_Value,
"type mismatch");
static_cast<nsCSSValue*>(aSpecifiedValue)->
SetIntValue(aComputedValue.GetIntValue(), eCSSUnit_Enumerated);
break;
case eUnit_Coord: {
NS_ABORT_IF_FALSE(nsCSSProps::kTypeTable[aProperty] == eCSSType_Value,
"type mismatch");
@ -817,8 +825,10 @@ StyleCoordToValue(const nsStyleCoord& aCoord, nsStyleAnimation::Value& aValue)
case eStyleUnit_Coord:
aValue.SetCoordValue(aCoord.GetCoordValue());
break;
case eStyleUnit_Integer:
case eStyleUnit_Enumerated:
aValue.SetIntValue(aCoord.GetIntValue(),
nsStyleAnimation::eUnit_Enumerated);
case eStyleUnit_Integer:
return PR_FALSE;
}
return PR_TRUE;
@ -964,6 +974,10 @@ nsStyleAnimation::ExtractComputedValue(nsCSSProperty aProperty,
aComputedValue.SetCoordValue(*static_cast<const nscoord*>(
StyleDataAtOffset(styleStruct, ssOffset)));
return PR_TRUE;
case eStyleAnimType_EnumU8:
aComputedValue.SetIntValue(*static_cast<const PRUint8*>(
StyleDataAtOffset(styleStruct, ssOffset)), eUnit_Enumerated);
return PR_TRUE;
case eStyleAnimType_float:
aComputedValue.SetFloatValue(*static_cast<const float*>(
StyleDataAtOffset(styleStruct, ssOffset)));
@ -1048,6 +1062,12 @@ nsStyleAnimation::ExtractComputedValue(nsCSSProperty aProperty,
return PR_FALSE;
}
nsStyleAnimation::Value::Value(PRInt32 aInt, EnumeratedConstructorType)
{
mUnit = eUnit_Enumerated;
mValue.mInt = aInt;
}
nsStyleAnimation::Value::Value(nscoord aLength, CoordConstructorType)
{
mUnit = eUnit_Coord;
@ -1084,6 +1104,9 @@ nsStyleAnimation::Value::operator=(const Value& aOther)
case eUnit_Auto:
case eUnit_None:
break;
case eUnit_Enumerated:
mValue.mInt = aOther.mValue.mInt;
break;
case eUnit_Coord:
mValue.mCoord = aOther.mValue.mCoord;
break;
@ -1124,6 +1147,14 @@ nsStyleAnimation::Value::SetNoneValue()
mUnit = eUnit_None;
}
void
nsStyleAnimation::Value::SetIntValue(PRInt32 aInt, Unit aUnit)
{
FreeValue();
mUnit = aUnit;
mValue.mInt = aInt;
}
void
nsStyleAnimation::Value::SetCoordValue(nscoord aLength)
{
@ -1192,6 +1223,8 @@ nsStyleAnimation::Value::operator==(const Value& aOther) const
case eUnit_Auto:
case eUnit_None:
return PR_TRUE;
case eUnit_Enumerated:
return mValue.mInt == aOther.mValue.mInt;
case eUnit_Coord:
return mValue.mCoord == aOther.mValue.mCoord;
case eUnit_Percent:

View File

@ -221,6 +221,7 @@ public:
eUnit_Normal,
eUnit_Auto,
eUnit_None,
eUnit_Enumerated,
eUnit_Coord,
eUnit_Percent,
eUnit_Float,
@ -233,6 +234,7 @@ public:
private:
Unit mUnit;
union {
PRInt32 mInt;
nscoord mCoord;
float mFloat;
nscolor mColor;
@ -250,6 +252,10 @@ public:
return mUnit == eUnit_Null;
}
PRInt32 GetIntValue() const {
NS_ASSERTION(mUnit == eUnit_Enumerated, "unit mismatch");
return mValue.mInt;
}
nscoord GetCoordValue() const {
NS_ASSERTION(mUnit == eUnit_Coord, "unit mismatch");
return mValue.mCoord;
@ -277,6 +283,8 @@ public:
"must be valueless unit");
}
Value(const Value& aOther) : mUnit(eUnit_Null) { *this = aOther; }
enum EnumeratedConstructorType { EnumeratedConstructor };
Value(PRInt32 aInt, EnumeratedConstructorType);
enum CoordConstructorType { CoordConstructor };
Value(nscoord aLength, CoordConstructorType);
enum PercentConstructorType { PercentConstructor };
@ -291,6 +299,7 @@ public:
void SetNormalValue();
void SetAutoValue();
void SetNoneValue();
void SetIntValue(PRInt32 aInt, Unit aUnit);
void SetCoordValue(nscoord aCoord);
void SetPercentValue(float aPercent);
void SetFloatValue(float aFloat);