Bug 1070745 part 4 - Add AnimationPlayer::Play and AnimationPlayer::Pause; r=dholbert

This patch introduces the basic implementation of play() and pause().

There are a lot of gaps still because we don't yet:
* Support the pending state (to be covered in bug 927349)
* Support finishing behavior (to be covered in bug 1074630)
* Have a good way of updating animation state outside of style resolution (bug
  1073336)

Also, we don't call these methods from CSS yet because the interaction between
play()/pause() and animation-play-state requires storing some extra state which
we introduce in subsequent patches in this series.

This patch introduces, temporarily, an update flag to indicate whether
play()/pause() operations need to post a restyle event. When these methods are
triggered by processing restyles we don't want to post another (unnecessary)
restyle event. In bug 1073336 we will remove the need for this.
This commit is contained in:
David Zbarsky committed 2014-10-20 13:55:43 +09:00
1 parent dab3fc5c26
commit 1313058326
3 files changed
+81 -14

No files matched your search

+1 -1
View File
@@ -165,7 +165,7 @@ public:
already_AddRefed<AnimationEffect> GetEffect();
Element* GetTarget() const {
// Currently we only implement Element.getAnimationPlayers() which only
// returns animations targetting Elements so we should this should never
// returns animations targetting Elements so this should never
// be called for an animation that targets a pseudo-element.
MOZ_ASSERT(mPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement,
"Requesting the target of an Animation that targets a"
+64 -8
View File
@@ -6,6 +6,7 @@
#include "AnimationPlayer.h"
#include "AnimationUtils.h"
#include "mozilla/dom/AnimationPlayerBinding.h"
#include "nsLayoutUtils.h" // For PostRestyleEvent (remove after bug 1073336)
namespace mozilla {
namespace dom {
@@ -34,15 +35,48 @@ AnimationPlayer::GetCurrentTime() const
}
void
AnimationPlayer::Play()
AnimationPlayer::Play(UpdateFlags aFlags)
{
// TODO
// FIXME: When we implement finishing behavior (bug 1074630) we should
// not return early if mIsPaused is false since we may still need to seek.
if (!mIsPaused) {
return;
}
mIsPaused = false;
Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTimeDuration();
if (timelineTime.IsNull()) {
// FIXME: We should just sit in the pending state in this case.
// We will introduce the pending state in Bug 927349.
return;
}
// Update start time to an appropriate offset from the current timeline time
MOZ_ASSERT(!mHoldTime.IsNull(), "Hold time should not be null when paused");
mStartTime.SetValue(timelineTime.Value() - mHoldTime.Value());
mHoldTime.SetNull();
if (aFlags == eUpdateStyle) {
MaybePostRestyle();
}
}
void
AnimationPlayer::Pause()
AnimationPlayer::Pause(UpdateFlags aFlags)
{
// TODO
if (mIsPaused) {
return;
}
mIsPaused = true;
mIsRunningOnCompositor = false;
// Bug 927349 - check for null result here and go to pending state
mHoldTime = GetCurrentTimeDuration();
mStartTime.SetNull();
if (aFlags == eUpdateStyle) {
MaybePostRestyle();
}
}
void
@@ -50,15 +84,13 @@ AnimationPlayer::PlayFromJS()
{
// TODO (flush styles etc.)
Play();
Play(eUpdateStyle);
}
void
AnimationPlayer::PauseFromJS()
{
Pause();
// TODO (flush styles etc.)
Pause(eUpdateStyle);
}
void
@@ -107,5 +139,29 @@ AnimationPlayer::GetCurrentTimeDuration() const
return result;
}
void
AnimationPlayer::FlushStyle() const
{
if (mSource && mSource->GetTarget()) {
nsIDocument* doc = mSource->GetTarget()->GetComposedDoc();
if (doc) {
doc->FlushPendingNotifications(Flush_Style);
}
}
}
void
AnimationPlayer::MaybePostRestyle() const
{
if (!mSource || !mSource->GetTarget())
return;
// FIXME: This is a bit heavy-handed but in bug 1073336 we hope to
// introduce a better means for players to update style.
nsLayoutUtils::PostRestyleEvent(mSource->GetTarget(),
eRestyle_Self,
nsChangeHint_AllReflowHints);
}
} // namespace dom
} // namespace mozilla
+16 -5
View File
@@ -43,19 +43,26 @@ public:
AnimationTimeline* GetParentObject() const { return mTimeline; }
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
// Temporary flags to control restyle behavior until bug 1073336
// provides a better solution.
enum UpdateFlags {
eNoUpdate,
eUpdateStyle
};
// AnimationPlayer methods
Animation* GetSource() const { return mSource; }
AnimationTimeline* Timeline() const { return mTimeline; }
Nullable<double> GetStartTime() const;
Nullable<double> GetCurrentTime() const;
void Play();
void Pause();
void Play(UpdateFlags aUpdateFlags);
void Pause(UpdateFlags aUpdateFlags);
bool IsRunningOnCompositor() const { return mIsRunningOnCompositor; }
// Wrapper functions for performing extra steps such as flushing
// style when calling from JS.
void PauseFromJS();
void PlayFromJS();
void PauseFromJS();
void SetSource(Animation* aSource);
void Tick();
@@ -80,13 +87,17 @@ public:
Nullable<TimeDuration> GetCurrentTimeDuration() const;
// The beginning of the delay period.
Nullable<TimeDuration> mStartTime;
Nullable<TimeDuration> mHoldTime;
Nullable<TimeDuration> mStartTime; // Timeline timescale
Nullable<TimeDuration> mHoldTime; // Player timescale
bool mIsPaused;
bool mIsRunningOnCompositor;
nsRefPtr<AnimationTimeline> mTimeline;
nsRefPtr<Animation> mSource;
protected:
void FlushStyle() const;
void MaybePostRestyle() const;
};
} // namespace dom