mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Add support for animation of nsStyleCoord and nsStyleSides values to nsStyleAnimation. (Bug 504652) r=dbaron sr=bzbarsky
This commit is contained in:
parent
3affc2ba0f
commit
fe5b083fc3
@ -1119,8 +1119,8 @@ CSS_PROP_POSITION(
|
||||
mOffset.mBottom,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mOffset),
|
||||
eStyleAnimType_Sides_Bottom)
|
||||
CSS_PROP_BORDER(
|
||||
-moz-box-shadow,
|
||||
box_shadow,
|
||||
@ -1210,8 +1210,8 @@ CSS_PROP_COLUMN(
|
||||
mColumnWidth,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleColumn, mColumnWidth),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_COLUMN(
|
||||
-moz-column-gap,
|
||||
_moz_column_gap,
|
||||
@ -1221,8 +1221,8 @@ CSS_PROP_COLUMN(
|
||||
mColumnGap,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleColumn, mColumnGap),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_SHORTHAND(
|
||||
-moz-column-rule,
|
||||
_moz_column_rule,
|
||||
@ -1494,8 +1494,8 @@ CSS_PROP_POSITION(
|
||||
mHeight,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mHeight),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_LIST(
|
||||
-moz-image-region,
|
||||
image_region,
|
||||
@ -1527,8 +1527,8 @@ CSS_PROP_POSITION(
|
||||
mOffset.mLeft,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mOffset),
|
||||
eStyleAnimType_Sides_Left)
|
||||
CSS_PROP_TEXT(
|
||||
letter-spacing,
|
||||
letter_spacing,
|
||||
@ -1538,8 +1538,8 @@ CSS_PROP_TEXT(
|
||||
mLetterSpacing,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleText, mLetterSpacing),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_TEXT(
|
||||
line-height,
|
||||
line_height,
|
||||
@ -1549,8 +1549,8 @@ CSS_PROP_TEXT(
|
||||
mLineHeight,
|
||||
eCSSType_Value,
|
||||
kLineHeightKTable,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleText, mLineHeight),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_SHORTHAND(
|
||||
list-style,
|
||||
list_style,
|
||||
@ -1603,8 +1603,8 @@ CSS_PROP_MARGIN(
|
||||
mMargin.mBottom,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleMargin, mMargin),
|
||||
eStyleAnimType_Sides_Bottom)
|
||||
CSS_PROP_SHORTHAND(
|
||||
-moz-margin-end,
|
||||
margin_end,
|
||||
@ -1638,8 +1638,8 @@ CSS_PROP_MARGIN(
|
||||
mMargin.mLeft,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleMargin, mMargin),
|
||||
eStyleAnimType_Sides_Left)
|
||||
CSS_PROP_MARGIN(
|
||||
margin-left-ltr-source,
|
||||
margin_left_ltr_source,
|
||||
@ -1680,8 +1680,8 @@ CSS_PROP_MARGIN(
|
||||
mMargin.mRight,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleMargin, mMargin),
|
||||
eStyleAnimType_Sides_Right)
|
||||
CSS_PROP_MARGIN(
|
||||
margin-right-ltr-source,
|
||||
margin_right_ltr_source,
|
||||
@ -1734,8 +1734,8 @@ CSS_PROP_MARGIN(
|
||||
mMargin.mTop,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleMargin, mMargin),
|
||||
eStyleAnimType_Sides_Top)
|
||||
CSS_PROP_CONTENT(
|
||||
marker-offset,
|
||||
marker_offset,
|
||||
@ -1745,8 +1745,8 @@ CSS_PROP_CONTENT(
|
||||
mMarkerOffset,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleContent, mMarkerOffset),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_BACKENDONLY(
|
||||
marks,
|
||||
marks,
|
||||
@ -1765,8 +1765,8 @@ CSS_PROP_POSITION(
|
||||
mMaxHeight,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mMaxHeight),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_POSITION(
|
||||
max-width,
|
||||
max_width,
|
||||
@ -1776,8 +1776,8 @@ CSS_PROP_POSITION(
|
||||
mMaxWidth,
|
||||
eCSSType_Value,
|
||||
kWidthKTable,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mMaxWidth),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_POSITION(
|
||||
min-height,
|
||||
min_height,
|
||||
@ -1787,8 +1787,8 @@ CSS_PROP_POSITION(
|
||||
mMinHeight,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mMinHeight),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_POSITION(
|
||||
min-width,
|
||||
min_width,
|
||||
@ -1798,8 +1798,8 @@ CSS_PROP_POSITION(
|
||||
mMinWidth,
|
||||
eCSSType_Value,
|
||||
kWidthKTable,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mMinWidth),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_DISPLAY(
|
||||
opacity,
|
||||
opacity,
|
||||
@ -1856,8 +1856,8 @@ CSS_PROP_OUTLINE(
|
||||
mOutlineWidth,
|
||||
eCSSType_Value,
|
||||
kBorderWidthKTable,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleOutline, mOutlineWidth),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_OUTLINE(
|
||||
outline-offset,
|
||||
outline_offset,
|
||||
@ -1910,8 +1910,8 @@ CSS_PROP_PADDING(
|
||||
mPadding.mBottom,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePadding, mPadding),
|
||||
eStyleAnimType_Sides_Bottom)
|
||||
CSS_PROP_SHORTHAND(
|
||||
-moz-padding-end,
|
||||
padding_end,
|
||||
@ -1945,8 +1945,8 @@ CSS_PROP_PADDING(
|
||||
mPadding.mLeft,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePadding, mPadding),
|
||||
eStyleAnimType_Sides_Left)
|
||||
CSS_PROP_PADDING(
|
||||
padding-left-ltr-source,
|
||||
padding_left_ltr_source,
|
||||
@ -1987,8 +1987,8 @@ CSS_PROP_PADDING(
|
||||
mPadding.mRight,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePadding, mPadding),
|
||||
eStyleAnimType_Sides_Right)
|
||||
CSS_PROP_PADDING(
|
||||
padding-right-ltr-source,
|
||||
padding_right_ltr_source,
|
||||
@ -2041,8 +2041,8 @@ CSS_PROP_PADDING(
|
||||
mPadding.mTop,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePadding, mPadding),
|
||||
eStyleAnimType_Sides_Top)
|
||||
CSS_PROP_BACKENDONLY(
|
||||
page,
|
||||
page,
|
||||
@ -2175,8 +2175,8 @@ CSS_PROP_POSITION(
|
||||
mOffset.mRight,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mOffset),
|
||||
eStyleAnimType_Sides_Right)
|
||||
CSS_PROP_BACKENDONLY(
|
||||
size,
|
||||
size,
|
||||
@ -2282,8 +2282,8 @@ CSS_PROP_TEXT(
|
||||
mTextIndent,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleText, mTextIndent),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_TEXT(
|
||||
text-shadow,
|
||||
text_shadow,
|
||||
@ -2339,8 +2339,8 @@ CSS_PROP_POSITION(
|
||||
mOffset.mTop,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mOffset),
|
||||
eStyleAnimType_Sides_Top)
|
||||
CSS_PROP_SHORTHAND(
|
||||
-moz-transition,
|
||||
transition,
|
||||
@ -2457,8 +2457,8 @@ CSS_PROP_TEXTRESET(
|
||||
mVerticalAlign,
|
||||
eCSSType_Value,
|
||||
kVerticalAlignKTable,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleTextReset, mVerticalAlign),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_VISIBILITY(
|
||||
visibility,
|
||||
visibility,
|
||||
@ -2517,8 +2517,8 @@ CSS_PROP_POSITION(
|
||||
mWidth,
|
||||
eCSSType_Value,
|
||||
kWidthKTable,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStylePosition, mWidth),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_UIRESET(
|
||||
-moz-window-shadow,
|
||||
_moz_window_shadow,
|
||||
@ -2940,8 +2940,8 @@ CSS_PROP_SVG(
|
||||
mStrokeDashoffset,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleSVG, mStrokeDashoffset),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_SVG(
|
||||
stroke-linecap,
|
||||
stroke_linecap,
|
||||
@ -2995,8 +2995,8 @@ CSS_PROP_SVG(
|
||||
mStrokeWidth,
|
||||
eCSSType_Value,
|
||||
nsnull,
|
||||
CSS_PROP_NO_OFFSET,
|
||||
eStyleAnimType_None)
|
||||
offsetof(nsStyleSVG, mStrokeWidth),
|
||||
eStyleAnimType_Coord)
|
||||
CSS_PROP_SVG(
|
||||
text-anchor,
|
||||
text_anchor,
|
||||
|
@ -69,7 +69,18 @@
|
||||
* Types of animatable values.
|
||||
*/
|
||||
enum nsStyleAnimType {
|
||||
eStyleAnimType_None /* property not animatable */
|
||||
// nsStyleCoord with animatable values
|
||||
eStyleAnimType_Coord,
|
||||
|
||||
// same as Coord, except for one side of an nsStyleSides
|
||||
// listed in the same order as the NS_STYLE_* constants
|
||||
eStyleAnimType_Sides_Top,
|
||||
eStyleAnimType_Sides_Right,
|
||||
eStyleAnimType_Sides_Bottom,
|
||||
eStyleAnimType_Sides_Left,
|
||||
|
||||
// property not animatable
|
||||
eStyleAnimType_None
|
||||
};
|
||||
|
||||
class nsCSSProps {
|
||||
|
@ -21,6 +21,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Daniel Holbert <dholbert@mozilla.com>, Mozilla Corporation
|
||||
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -51,6 +52,7 @@
|
||||
#include "nsICSSLoader.h"
|
||||
#include "nsCSSDataBlock.h"
|
||||
#include "nsCSSDeclaration.h"
|
||||
#include "prlog.h"
|
||||
|
||||
// HELPER METHODS
|
||||
// --------------
|
||||
@ -293,27 +295,98 @@ nsStyleAnimation::ComputeValue(nsCSSProperty aProperty,
|
||||
return ExtractComputedValue(aProperty, tmpStyleContext, aComputedValue);
|
||||
}
|
||||
|
||||
inline const void*
|
||||
StyleDataAtOffset(const void* aStyleStruct, ptrdiff_t aOffset)
|
||||
{
|
||||
return reinterpret_cast<const char*>(aStyleStruct) + aOffset;
|
||||
}
|
||||
|
||||
inline void*
|
||||
StyleDataAtOffset(void* aStyleStruct, ptrdiff_t aOffset)
|
||||
{
|
||||
return reinterpret_cast<char*>(aStyleStruct) + aOffset;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsStyleAnimation::ExtractComputedValue(nsCSSProperty aProperty,
|
||||
nsStyleContext* aStyleContext,
|
||||
nsStyleCoord& aComputedValue)
|
||||
{
|
||||
// XXXdholbert This is a simple implementation that only supports "font-size"
|
||||
// and "stroke-width for now, so that we can test the rest of the
|
||||
// functionality. A full implementation will require modifications to
|
||||
// nsCSSPropList.h, as described in bug 504652 comment 0.
|
||||
switch(aProperty) {
|
||||
case eCSSProperty_font_size: {
|
||||
const nsStyleFont* styleFont = aStyleContext->GetStyleFont();
|
||||
aComputedValue.SetCoordValue(styleFont->mFont.size);
|
||||
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
||||
aProperty < eCSSProperty_COUNT_no_shorthands,
|
||||
"bad property");
|
||||
const void* styleStruct =
|
||||
aStyleContext->GetStyleData(nsCSSProps::kSIDTable[aProperty]);
|
||||
ptrdiff_t ssOffset = nsCSSProps::kStyleStructOffsetTable[aProperty];
|
||||
NS_ABORT_IF_FALSE(0 <= ssOffset, "must be dealing with animatable property");
|
||||
nsStyleAnimType animType = nsCSSProps::kAnimTypeTable[aProperty];
|
||||
switch (animType) {
|
||||
case eStyleAnimType_Coord:
|
||||
aComputedValue = *static_cast<const nsStyleCoord*>(
|
||||
StyleDataAtOffset(styleStruct, ssOffset));
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eCSSProperty_stroke_width: {
|
||||
const nsStyleSVG* styleSVG = aStyleContext->GetStyleSVG();
|
||||
aComputedValue = styleSVG->mStrokeWidth;
|
||||
case eStyleAnimType_Sides_Top:
|
||||
case eStyleAnimType_Sides_Right:
|
||||
case eStyleAnimType_Sides_Bottom:
|
||||
case eStyleAnimType_Sides_Left:
|
||||
PR_STATIC_ASSERT(0 == NS_SIDE_TOP);
|
||||
PR_STATIC_ASSERT(eStyleAnimType_Sides_Right - eStyleAnimType_Sides_Top
|
||||
== NS_SIDE_RIGHT);
|
||||
PR_STATIC_ASSERT(eStyleAnimType_Sides_Bottom - eStyleAnimType_Sides_Top
|
||||
== NS_SIDE_BOTTOM);
|
||||
PR_STATIC_ASSERT(eStyleAnimType_Sides_Left - eStyleAnimType_Sides_Top
|
||||
== NS_SIDE_LEFT);
|
||||
aComputedValue = static_cast<const nsStyleSides*>(
|
||||
StyleDataAtOffset(styleStruct, ssOffset))->
|
||||
Get(animType - eStyleAnimType_Sides_Top);
|
||||
return PR_TRUE;
|
||||
}
|
||||
default:
|
||||
return PR_FALSE;
|
||||
case eStyleAnimType_None:
|
||||
NS_NOTREACHED("shouldn't use on non-animatable properties");
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsStyleAnimation::StoreComputedValue(nsCSSProperty aProperty,
|
||||
nsPresContext* aPresContext,
|
||||
void* aStyleStruct,
|
||||
const nsStyleCoord& aComputedValue)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
||||
aProperty < eCSSProperty_COUNT_no_shorthands,
|
||||
"bad property");
|
||||
ptrdiff_t ssOffset = nsCSSProps::kStyleStructOffsetTable[aProperty];
|
||||
NS_ABORT_IF_FALSE(0 <= ssOffset, "must be dealing with animatable property");
|
||||
nsStyleAnimType animType = nsCSSProps::kAnimTypeTable[aProperty];
|
||||
switch (animType) {
|
||||
case eStyleAnimType_Coord:
|
||||
*static_cast<nsStyleCoord*>(StyleDataAtOffset(aStyleStruct, ssOffset)) =
|
||||
aComputedValue;
|
||||
return PR_TRUE;
|
||||
case eStyleAnimType_Sides_Top:
|
||||
case eStyleAnimType_Sides_Right:
|
||||
case eStyleAnimType_Sides_Bottom:
|
||||
case eStyleAnimType_Sides_Left: {
|
||||
PR_STATIC_ASSERT(0 == NS_SIDE_TOP);
|
||||
PR_STATIC_ASSERT(eStyleAnimType_Sides_Right - eStyleAnimType_Sides_Top
|
||||
== NS_SIDE_RIGHT);
|
||||
PR_STATIC_ASSERT(eStyleAnimType_Sides_Bottom - eStyleAnimType_Sides_Top
|
||||
== NS_SIDE_BOTTOM);
|
||||
PR_STATIC_ASSERT(eStyleAnimType_Sides_Left - eStyleAnimType_Sides_Top
|
||||
== NS_SIDE_LEFT);
|
||||
static_cast<nsStyleSides*>(StyleDataAtOffset(aStyleStruct, ssOffset))->
|
||||
Set(animType - eStyleAnimType_Sides_Top, aComputedValue);
|
||||
|
||||
nsStyleStructID sid = nsCSSProps::kSIDTable[aProperty];
|
||||
if (sid == eStyleStruct_Margin) {
|
||||
static_cast<nsStyleMargin*>(aStyleStruct)->RecalcData();
|
||||
} else if (sid == eStyleStruct_Padding) {
|
||||
static_cast<nsStylePadding*>(aStyleStruct)->RecalcData();
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eStyleAnimType_None:
|
||||
NS_NOTREACHED("shouldn't use on non-animatable properties");
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Daniel Holbert <dholbert@mozilla.com>, Mozilla Corporation
|
||||
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -47,6 +48,7 @@
|
||||
|
||||
class nsCSSDeclaration;
|
||||
class nsIContent;
|
||||
class nsPresContext;
|
||||
class nsStyleCoord;
|
||||
class nsStyleContext;
|
||||
|
||||
@ -150,6 +152,21 @@ public:
|
||||
static PRBool ExtractComputedValue(nsCSSProperty aProperty,
|
||||
nsStyleContext* aStyleContext,
|
||||
nsStyleCoord& aComputedValue);
|
||||
|
||||
/**
|
||||
* Sets the computed value for the given property in the given style
|
||||
* struct.
|
||||
*
|
||||
* @param aProperty The property whose value we're setting.
|
||||
* @param aPresContext The pres context associated with aStyleStruct.
|
||||
* @param aStyleStruct The style struct in which to set the value.
|
||||
* @param aComputedValue The computed value.
|
||||
* @return PR_TRUE on success, PR_FALSE on failure.
|
||||
*/
|
||||
static PRBool StoreComputedValue(nsCSSProperty aProperty,
|
||||
nsPresContext* aPresContext,
|
||||
void* aStyleStruct,
|
||||
const nsStyleCoord& aComputedValue);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user