Bug 880596 part 7 - Move ElementAnimation to AnimationCommon; r=dbaron

This patch relocates ElementAnimation from nsAnimationManager.{h,cpp} to
AnimationCommon.{h,cpp} and in the process moves it into the mozilla::css
namespace.
This commit is contained in:
Brian Birtles 2014-04-03 14:57:28 +09:00
parent c4ffbc205d
commit 095840cb6d
5 changed files with 107 additions and 106 deletions

View File

@ -360,6 +360,30 @@ ComputedTimingFunction::GetValue(double aPortion) const
}
}
bool
ElementAnimation::IsRunningAt(TimeStamp aTime) const
{
if (IsPaused() || mIterationDuration.ToMilliseconds() <= 0.0 ||
mStartTime.IsNull()) {
return false;
}
double iterationsElapsed = ElapsedDurationAt(aTime) / mIterationDuration;
return 0.0 <= iterationsElapsed && iterationsElapsed < mIterationCount;
}
bool
ElementAnimation::HasAnimationOfProperty(nsCSSProperty aProperty) const
{
for (uint32_t propIdx = 0, propEnd = mProperties.Length();
propIdx != propEnd; ++propIdx) {
if (aProperty == mProperties[propIdx].mProperty) {
return true;
}
}
return false;
}
bool
CommonElementAnimationData::CanAnimatePropertyOnCompositor(const dom::Element *aElement,
nsCSSProperty aProperty,

View File

@ -203,6 +203,81 @@ private:
uint32_t mSteps;
};
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()
: mIsRunningOnCompositor(false)
, mLastNotification(LAST_NOTIFICATION_NONE)
{
}
nsString mName; // empty string for 'none'
float mIterationCount; // NS_IEEEPositiveInfinity() means infinite
uint8_t mDirection;
uint8_t mFillMode;
uint8_t 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;
}
bool HasAnimationOfProperty(nsCSSProperty aProperty) const;
bool IsRunningAt(mozilla::TimeStamp aTime) const;
// Return the duration, at aTime (or, if paused, mPauseStart), since
// the *end* of the delay period. May be negative.
mozilla::TimeDuration ElapsedDurationAt(mozilla::TimeStamp aTime) const {
NS_ABORT_IF_FALSE(!IsPaused() || aTime >= mPauseStart,
"if paused, aTime must be at least mPauseStart");
return (IsPaused() ? mPauseStart : aTime) - mStartTime - mDelay;
}
// The beginning of the delay period. This is also used by
// ElementPropertyTransition in its IsRemovedSentinel and
// SetRemovedSentinel methods.
mozilla::TimeStamp mStartTime;
mozilla::TimeStamp mPauseStart;
mozilla::TimeDuration mDelay;
mozilla::TimeDuration mIterationDuration;
bool mIsRunningOnCompositor;
enum {
LAST_NOTIFICATION_NONE = uint32_t(-1),
LAST_NOTIFICATION_END = uint32_t(-2)
};
// One of the above constants, or an integer for the iteration
// whose start we last notified on.
uint32_t mLastNotification;
InfallibleTArray<AnimationProperty> mProperties;
};
struct CommonElementAnimationData : public PRCList
{
CommonElementAnimationData(dom::Element *aElement, nsIAtom *aElementProperty,

View File

@ -325,31 +325,6 @@ ElementAnimations::EnsureStyleRuleFor(TimeStamp aRefreshTime,
}
}
bool
ElementAnimation::IsRunningAt(TimeStamp aTime) const
{
if (IsPaused() || mIterationDuration.ToMilliseconds() <= 0.0 ||
mStartTime.IsNull()) {
return false;
}
double iterationsElapsed = ElapsedDurationAt(aTime) / mIterationDuration;
return 0.0 <= iterationsElapsed && iterationsElapsed < mIterationCount;
}
bool
ElementAnimation::HasAnimationOfProperty(nsCSSProperty aProperty) const
{
for (uint32_t propIdx = 0, propEnd = mProperties.Length();
propIdx != propEnd; ++propIdx) {
if (aProperty == mProperties[propIdx].mProperty) {
return true;
}
}
return false;
}
bool
ElementAnimations::HasAnimationOfProperty(nsCSSProperty aProperty) const

View File

@ -48,81 +48,6 @@ struct AnimationEventInfo {
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()
: mIsRunningOnCompositor(false)
, mLastNotification(LAST_NOTIFICATION_NONE)
{
}
nsString mName; // empty string for 'none'
float mIterationCount; // NS_IEEEPositiveInfinity() means infinite
uint8_t mDirection;
uint8_t mFillMode;
uint8_t 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;
}
bool HasAnimationOfProperty(nsCSSProperty aProperty) const;
bool IsRunningAt(mozilla::TimeStamp aTime) const;
// Return the duration, at aTime (or, if paused, mPauseStart), since
// the *end* of the delay period. May be negative.
mozilla::TimeDuration ElapsedDurationAt(mozilla::TimeStamp aTime) const {
NS_ABORT_IF_FALSE(!IsPaused() || aTime >= mPauseStart,
"if paused, aTime must be at least mPauseStart");
return (IsPaused() ? mPauseStart : aTime) - mStartTime - mDelay;
}
// The beginning of the delay period. This is also used by
// ElementPropertyTransition in its IsRemovedSentinel and
// SetRemovedSentinel methods.
mozilla::TimeStamp mStartTime;
mozilla::TimeStamp mPauseStart;
mozilla::TimeDuration mDelay;
mozilla::TimeDuration mIterationDuration;
bool mIsRunningOnCompositor;
enum {
LAST_NOTIFICATION_NONE = uint32_t(-1),
LAST_NOTIFICATION_END = uint32_t(-2)
};
// One of the above constants, or an integer for the iteration
// whose start we last notified on.
uint32_t mLastNotification;
InfallibleTArray<AnimationProperty> mProperties;
};
/**
* Data about all of the animations running on an element.
*/
@ -153,7 +78,8 @@ struct ElementAnimations MOZ_FINAL
TimeDuration aIterationDuration,
double aIterationCount,
uint32_t aDirection,
ElementAnimation* aAnimation = nullptr,
mozilla::css::ElementAnimation*
aAnimation = nullptr,
ElementAnimations* aEa = nullptr,
EventArray* aEventsToDispatch = nullptr);
@ -201,7 +127,7 @@ struct ElementAnimations MOZ_FINAL
// either completed or paused). May be invalidated by a style change.
bool mNeedsRefreshes;
InfallibleTArray<ElementAnimation> mAnimations;
InfallibleTArray<mozilla::css::ElementAnimation> mAnimations;
};
class nsAnimationManager MOZ_FINAL
@ -310,8 +236,10 @@ protected:
private:
void BuildAnimations(nsStyleContext* aStyleContext,
InfallibleTArray<ElementAnimation>& aAnimations);
bool BuildSegment(InfallibleTArray<AnimationPropertySegment>& aSegments,
InfallibleTArray<mozilla::css::ElementAnimation>&
aAnimations);
bool BuildSegment(InfallibleTArray<mozilla::css::AnimationPropertySegment>&
aSegments,
nsCSSProperty aProperty, const nsAnimation& aAnimation,
float aFromKey, nsStyleContext* aFromContext,
mozilla::css::Declaration* aFromDeclaration,

View File

@ -12,7 +12,6 @@
#include "mozilla/MemoryReporting.h"
#include "AnimationCommon.h"
#include "nsCSSPseudoElements.h"
#include "nsAnimationManager.h"
class nsStyleContext;
class nsPresContext;
@ -24,7 +23,7 @@ struct ElementDependentRuleProcessorData;
* Per-Element data *
*****************************************************************************/
struct ElementPropertyTransition : public ElementAnimation
struct ElementPropertyTransition : public mozilla::css::ElementAnimation
{
// This is the start value to be used for a check for whether a
// transition is being reversed. Normally the same as