Bug 755084 Part 1: Move ElementAnimations, ElementAnimation, AnimationProperty, and AnimationPropertySegment classes to the header file. r=dbaron

This commit is contained in:
David Zbarsky 2012-07-31 10:28:21 -07:00
Родитель c88b41986f
Коммит 609441e255
2 изменённых файлов: 130 добавлений и 127 удалений

Просмотреть файл

@ -14,110 +14,13 @@
using namespace mozilla;
struct AnimationPropertySegment
ElementAnimations::ElementAnimations(mozilla::dom::Element *aElement, nsIAtom *aElementProperty,
nsAnimationManager *aAnimationManager)
: CommonElementAnimationData(aElement, aElementProperty,
aAnimationManager),
mNeedsRefreshes(true)
{
float mFromKey, mToKey;
nsStyleAnimation::Value mFromValue, mToValue;
css::ComputedTimingFunction mTimingFunction;
};
struct AnimationProperty
{
nsCSSProperty mProperty;
InfallibleTArray<AnimationPropertySegment> mSegments;
};
/**
* Data about one animation (i.e., one of the values of
* 'animation-name') running on an element.
*/
struct ElementAnimation
{
ElementAnimation()
: mLastNotification(LAST_NOTIFICATION_NONE)
{
}
nsString mName; // empty string for 'none'
float mIterationCount; // NS_IEEEPositiveInfinity() means infinite
PRUint8 mDirection;
PRUint8 mFillMode;
PRUint8 mPlayState;
bool FillsForwards() const {
return mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BOTH ||
mFillMode == NS_STYLE_ANIMATION_FILL_MODE_FORWARDS;
}
bool FillsBackwards() const {
return mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BOTH ||
mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BACKWARDS;
}
bool IsPaused() const {
return mPlayState == NS_STYLE_ANIMATION_PLAY_STATE_PAUSED;
}
TimeStamp mStartTime; // with delay taken into account
TimeStamp mPauseStart;
TimeDuration mIterationDuration;
enum {
LAST_NOTIFICATION_NONE = PRUint32(-1),
LAST_NOTIFICATION_END = PRUint32(-2)
};
// One of the above constants, or an integer for the iteration
// whose start we last notified on.
PRUint32 mLastNotification;
InfallibleTArray<AnimationProperty> mProperties;
};
typedef nsAnimationManager::EventArray EventArray;
typedef nsAnimationManager::AnimationEventInfo AnimationEventInfo;
/**
* Data about all of the animations running on an element.
*/
struct ElementAnimations : public mozilla::css::CommonElementAnimationData
{
ElementAnimations(dom::Element *aElement, nsIAtom *aElementProperty,
nsAnimationManager *aAnimationManager)
: CommonElementAnimationData(aElement, aElementProperty,
aAnimationManager),
mNeedsRefreshes(true)
{
}
void EnsureStyleRuleFor(TimeStamp aRefreshTime,
EventArray &aEventsToDispatch);
bool IsForElement() const { // rather than for a pseudo-element
return mElementProperty == nsGkAtoms::animationsProperty;
}
void PostRestyleForAnimation(nsPresContext *aPresContext) {
nsRestyleHint hint = IsForElement() ? eRestyle_Self : eRestyle_Subtree;
aPresContext->PresShell()->RestyleForAnimation(mElement, hint);
}
// This style rule contains the style data for currently animating
// values. It only matches when styling with animation. When we
// style without animation, we need to not use it so that we can
// detect any new changes; if necessary we restyle immediately
// afterwards with animation.
// NOTE: If we don't need to apply any styles, mStyleRule will be
// null, but mStyleRuleRefreshTime will still be valid.
nsRefPtr<css::AnimValuesStyleRule> mStyleRule;
// The refresh time associated with mStyleRule.
TimeStamp mStyleRuleRefreshTime;
// False when we know that our current style rule is valid
// indefinitely into the future (because all of our animations are
// either completed or paused). May be invalidated by a style change.
bool mNeedsRefreshes;
InfallibleTArray<ElementAnimation> mAnimations;
};
}
static void
ElementAnimationsPropertyDtor(void *aObject,

Просмотреть файл

@ -14,9 +14,6 @@
#include "nsThreadUtils.h"
class nsCSSKeyframesRule;
struct AnimationPropertySegment;
struct ElementAnimation;
struct ElementAnimations;
namespace mozilla {
namespace css {
@ -24,6 +21,130 @@ class Declaration;
}
}
struct AnimationEventInfo {
nsRefPtr<mozilla::dom::Element> mElement;
nsAnimationEvent mEvent;
AnimationEventInfo(mozilla::dom::Element *aElement,
const nsString& aAnimationName,
PRUint32 aMessage, mozilla::TimeDuration aElapsedTime)
: mElement(aElement),
mEvent(true, aMessage, aAnimationName, aElapsedTime.ToSeconds())
{
}
// nsAnimationEvent doesn't support copy-construction, so we need
// to ourselves in order to work with nsTArray
AnimationEventInfo(const AnimationEventInfo &aOther)
: mElement(aOther.mElement),
mEvent(true, aOther.mEvent.message,
aOther.mEvent.animationName, aOther.mEvent.elapsedTime)
{
}
};
typedef InfallibleTArray<AnimationEventInfo> EventArray;
struct AnimationPropertySegment
{
float mFromKey, mToKey;
nsStyleAnimation::Value mFromValue, mToValue;
mozilla::css::ComputedTimingFunction mTimingFunction;
};
struct AnimationProperty
{
nsCSSProperty mProperty;
InfallibleTArray<AnimationPropertySegment> mSegments;
};
/**
* Data about one animation (i.e., one of the values of
* 'animation-name') running on an element.
*/
struct ElementAnimation
{
ElementAnimation()
: mLastNotification(LAST_NOTIFICATION_NONE)
{
}
nsString mName; // empty string for 'none'
float mIterationCount; // NS_IEEEPositiveInfinity() means infinite
PRUint8 mDirection;
PRUint8 mFillMode;
PRUint8 mPlayState;
bool FillsForwards() const {
return mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BOTH ||
mFillMode == NS_STYLE_ANIMATION_FILL_MODE_FORWARDS;
}
bool FillsBackwards() const {
return mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BOTH ||
mFillMode == NS_STYLE_ANIMATION_FILL_MODE_BACKWARDS;
}
bool IsPaused() const {
return mPlayState == NS_STYLE_ANIMATION_PLAY_STATE_PAUSED;
}
mozilla::TimeStamp mStartTime; // with delay taken into account
mozilla::TimeStamp mPauseStart;
mozilla::TimeDuration mIterationDuration;
enum {
LAST_NOTIFICATION_NONE = PRUint32(-1),
LAST_NOTIFICATION_END = PRUint32(-2)
};
// One of the above constants, or an integer for the iteration
// whose start we last notified on.
PRUint32 mLastNotification;
InfallibleTArray<AnimationProperty> mProperties;
};
/**
* Data about all of the animations running on an element.
*/
struct ElementAnimations : public mozilla::css::CommonElementAnimationData
{
typedef mozilla::TimeStamp TimeStamp;
typedef mozilla::TimeDuration TimeDuration;
ElementAnimations(mozilla::dom::Element *aElement, nsIAtom *aElementProperty,
nsAnimationManager *aAnimationManager);
void EnsureStyleRuleFor(TimeStamp aRefreshTime,
EventArray &aEventsToDispatch);
bool IsForElement() const { // rather than for a pseudo-element
return mElementProperty == nsGkAtoms::animationsProperty;
}
void PostRestyleForAnimation(nsPresContext *aPresContext) {
nsRestyleHint styleHint = IsForElement() ? eRestyle_Self : eRestyle_Subtree;
aPresContext->PresShell()->RestyleForAnimation(mElement, styleHint);
}
// This style rule contains the style data for currently animating
// values. It only matches when styling with animation. When we
// style without animation, we need to not use it so that we can
// detect any new changes; if necessary we restyle immediately
// afterwards with animation.
// NOTE: If we don't need to apply any styles, mStyleRule will be
// null, but mStyleRuleRefreshTime will still be valid.
nsRefPtr<mozilla::css::AnimValuesStyleRule> mStyleRule;
// The refresh time associated with mStyleRule.
TimeStamp mStyleRuleRefreshTime;
// False when we know that our current style rule is valid
// indefinitely into the future (because all of our animations are
// either completed or paused). May be invalidated by a style change.
bool mNeedsRefreshes;
InfallibleTArray<ElementAnimation> mAnimations;
};
class nsAnimationManager : public mozilla::css::CommonAnimationManager
{
public:
@ -34,27 +155,8 @@ public:
mKeyframesRules.Init(16); // FIXME: make infallible!
}
struct AnimationEventInfo {
nsRefPtr<mozilla::dom::Element> mElement;
nsAnimationEvent mEvent;
AnimationEventInfo(mozilla::dom::Element *aElement,
const nsString& aAnimationName,
PRUint32 aMessage, mozilla::TimeDuration aElapsedTime)
: mElement(aElement),
mEvent(true, aMessage, aAnimationName, aElapsedTime.ToSeconds())
{
}
// nsAnimationEvent doesn't support copy-construction, so we need
// to ourselves in order to work with nsTArray
AnimationEventInfo(const AnimationEventInfo &aOther)
: mElement(aOther.mElement),
mEvent(true, aOther.mEvent.message,
aOther.mEvent.animationName, aOther.mEvent.elapsedTime)
{
}
};
// nsIStyleRuleProcessor (parts)
virtual void RulesMatching(ElementRuleProcessorData* aData);
@ -89,8 +191,6 @@ public:
mKeyframesListIsDirty = true;
}
typedef InfallibleTArray<AnimationEventInfo> EventArray;
/**
* Dispatch any pending events. We accumulate animationend and
* animationiteration events only during refresh driver notifications