Bug 1078122 part 5 - Move CSSAnimationPlayer to nsAnimationManager; r=dholbert

This patch takes the CSSAnimationPlayer object, currently defined in
dom/animation/AnimationPlayer.{cpp,h}, and moves it to
layout/style/nsAnimationManager.{cpp,h} where the rest of the CSS
Animations-specific code lives.

At the same time it extends the scope of the mozilla namespace block in
nsAnimationManager.h to also include the AnimationEventInfo and EventArray types
since these classes, which don't have an ns* prefix, probably should be in the
mozilla namespace anyway.
This commit is contained in:
Brian Birtles 2014-10-20 13:55:46 +09:00
parent 0898410bf5
commit c1d26b86ba
4 changed files with 118 additions and 119 deletions

View File

@ -262,40 +262,4 @@ AnimationPlayer::SourceContentEnd() const
}
} // namespace dom
void
CSSAnimationPlayer::Play(UpdateFlags aUpdateFlags)
{
mPauseShouldStick = false;
AnimationPlayer::Play(aUpdateFlags);
}
void
CSSAnimationPlayer::Pause(UpdateFlags aUpdateFlags)
{
mPauseShouldStick = true;
AnimationPlayer::Pause(aUpdateFlags);
}
void
CSSAnimationPlayer::PlayFromStyle()
{
mIsStylePaused = false;
if (!mPauseShouldStick) {
AnimationPlayer::Play(eNoUpdate);
}
}
void
CSSAnimationPlayer::PauseFromStyle()
{
// Check if the pause state is being overridden
if (mIsStylePaused) {
return;
}
mIsStylePaused = true;
AnimationPlayer::Pause(eNoUpdate);
}
} // namespace mozilla

View File

@ -131,84 +131,6 @@ protected:
};
} // namespace dom
class CSSAnimationPlayer MOZ_FINAL : public dom::AnimationPlayer
{
public:
explicit CSSAnimationPlayer(dom::AnimationTimeline* aTimeline)
: dom::AnimationPlayer(aTimeline)
, mIsStylePaused(false)
, mPauseShouldStick(false)
{
}
virtual CSSAnimationPlayer*
AsCSSAnimationPlayer() MOZ_OVERRIDE { return this; }
virtual void Play(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
virtual void Pause(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
void PlayFromStyle();
void PauseFromStyle();
bool IsStylePaused() const { return mIsStylePaused; }
protected:
virtual ~CSSAnimationPlayer() { }
// When combining animation-play-state with play() / pause() the following
// behavior applies:
// 1. pause() is sticky and always overrides the underlying
// animation-play-state
// 2. If animation-play-state is 'paused', play() will temporarily override
// it until animation-play-state next becomes 'running'.
// 3. Calls to play() trigger finishing behavior but setting the
// animation-play-state to 'running' does not.
//
// This leads to five distinct states:
//
// A. Running
// B. Running and temporarily overriding animation-play-state: paused
// C. Paused and sticky overriding animation-play-state: running
// D. Paused and sticky overriding animation-play-state: paused
// E. Paused by animation-play-state
//
// C and D may seem redundant but they differ in how to respond to the
// sequence: call play(), set animation-play-state: paused.
//
// C will transition to A then E leaving the animation paused.
// D will transition to B then B leaving the animation running.
//
// A state transition chart is as follows:
//
// A | B | C | D | E
// ---------------------------
// play() A | B | A | B | B
// pause() C | D | C | D | D
// 'running' A | A | C | C | A
// 'paused' E | B | D | D | E
//
// The base class, AnimationPlayer already provides a boolean value,
// mIsPaused which gives us two states. To this we add a further two booleans
// to represent the states as follows.
//
// A. Running
// (!mIsPaused; !mIsStylePaused; !mPauseShouldStick)
// B. Running and temporarily overriding animation-play-state: paused
// (!mIsPaused; mIsStylePaused; !mPauseShouldStick)
// C. Paused and sticky overriding animation-play-state: running
// (mIsPaused; !mIsStylePaused; mPauseShouldStick)
// D. Paused and sticky overriding animation-play-state: paused
// (mIsPaused; mIsStylePaused; mPauseShouldStick)
// E. Paused by animation-play-state
// (mIsPaused; mIsStylePaused; !mPauseShouldStick)
//
// (That leaves 3 combinations of the boolean values that we never set because
// they don't represent valid states.)
bool mIsStylePaused;
bool mPauseShouldStick;
};
} // namespace mozilla
#endif // mozilla_dom_AnimationPlayer_h

View File

@ -9,7 +9,6 @@
#include "mozilla/EventDispatcher.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/dom/AnimationPlayer.h"
#include "nsPresContext.h"
#include "nsRuleProcessorData.h"
@ -28,6 +27,41 @@ using mozilla::dom::Animation;
using mozilla::dom::AnimationPlayer;
using mozilla::CSSAnimationPlayer;
void
CSSAnimationPlayer::Play(UpdateFlags aUpdateFlags)
{
mPauseShouldStick = false;
AnimationPlayer::Play(aUpdateFlags);
}
void
CSSAnimationPlayer::Pause(UpdateFlags aUpdateFlags)
{
mPauseShouldStick = true;
AnimationPlayer::Pause(aUpdateFlags);
}
void
CSSAnimationPlayer::PlayFromStyle()
{
mIsStylePaused = false;
if (!mPauseShouldStick) {
AnimationPlayer::Play(eNoUpdate);
}
}
void
CSSAnimationPlayer::PauseFromStyle()
{
// Check if the pause state is being overridden
if (mIsStylePaused) {
return;
}
mIsStylePaused = true;
AnimationPlayer::Pause(eNoUpdate);
}
void
nsAnimationManager::UpdateStyleAndEvents(AnimationPlayerCollection*
aCollection,

View File

@ -9,6 +9,7 @@
#include "mozilla/ContentEvents.h"
#include "AnimationCommon.h"
#include "nsCSSPseudoElements.h"
#include "mozilla/dom/AnimationPlayer.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/TimeStamp.h"
@ -18,8 +19,7 @@ class nsStyleContext;
namespace mozilla {
namespace css {
class Declaration;
}
}
} /* namespace css */
struct AnimationEventInfo {
nsRefPtr<mozilla::dom::Element> mElement;
@ -49,6 +49,85 @@ struct AnimationEventInfo {
typedef InfallibleTArray<AnimationEventInfo> EventArray;
class CSSAnimationPlayer MOZ_FINAL : public dom::AnimationPlayer
{
public:
explicit CSSAnimationPlayer(dom::AnimationTimeline* aTimeline)
: dom::AnimationPlayer(aTimeline)
, mIsStylePaused(false)
, mPauseShouldStick(false)
{
}
virtual CSSAnimationPlayer*
AsCSSAnimationPlayer() MOZ_OVERRIDE { return this; }
virtual void Play(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
virtual void Pause(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
void PlayFromStyle();
void PauseFromStyle();
bool IsStylePaused() const { return mIsStylePaused; }
protected:
virtual ~CSSAnimationPlayer() { }
// When combining animation-play-state with play() / pause() the following
// behavior applies:
// 1. pause() is sticky and always overrides the underlying
// animation-play-state
// 2. If animation-play-state is 'paused', play() will temporarily override
// it until animation-play-state next becomes 'running'.
// 3. Calls to play() trigger finishing behavior but setting the
// animation-play-state to 'running' does not.
//
// This leads to five distinct states:
//
// A. Running
// B. Running and temporarily overriding animation-play-state: paused
// C. Paused and sticky overriding animation-play-state: running
// D. Paused and sticky overriding animation-play-state: paused
// E. Paused by animation-play-state
//
// C and D may seem redundant but they differ in how to respond to the
// sequence: call play(), set animation-play-state: paused.
//
// C will transition to A then E leaving the animation paused.
// D will transition to B then B leaving the animation running.
//
// A state transition chart is as follows:
//
// A | B | C | D | E
// ---------------------------
// play() A | B | A | B | B
// pause() C | D | C | D | D
// 'running' A | A | C | C | A
// 'paused' E | B | D | D | E
//
// The base class, AnimationPlayer already provides a boolean value,
// mIsPaused which gives us two states. To this we add a further two booleans
// to represent the states as follows.
//
// A. Running
// (!mIsPaused; !mIsStylePaused; !mPauseShouldStick)
// B. Running and temporarily overriding animation-play-state: paused
// (!mIsPaused; mIsStylePaused; !mPauseShouldStick)
// C. Paused and sticky overriding animation-play-state: running
// (mIsPaused; !mIsStylePaused; mPauseShouldStick)
// D. Paused and sticky overriding animation-play-state: paused
// (mIsPaused; mIsStylePaused; mPauseShouldStick)
// E. Paused by animation-play-state
// (mIsPaused; mIsStylePaused; !mPauseShouldStick)
//
// (That leaves 3 combinations of the boolean values that we never set because
// they don't represent valid states.)
bool mIsStylePaused;
bool mPauseShouldStick;
};
} /* namespace mozilla */
class nsAnimationManager MOZ_FINAL
: public mozilla::css::CommonAnimationManager
{
@ -81,7 +160,7 @@ public:
mozilla::TimeStamp aRefreshTime,
mozilla::EnsureStyleRuleFlags aFlags);
void GetEventsForCurrentTime(mozilla::AnimationPlayerCollection* aEA,
EventArray &aEventsToDispatch);
mozilla::EventArray &aEventsToDispatch);
// nsIStyleRuleProcessor (parts)
virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
@ -164,7 +243,7 @@ private:
// The guts of DispatchEvents
void DoDispatchEvents();
EventArray mPendingEvents;
mozilla::EventArray mPendingEvents;
bool mObservingRefreshDriver;
};