Bug 1078119 - Rename AnimationTimeline/AnimationPlayer GetCurrentTimeDuration; r=bz
This patch performs the following renaming:
AnimationPlayer::GetCurrentTime -> GetCurrentTimeAsDouble
AnimationPlayer::GetCurrentTimeDuration -> GetCurrentTime
AnimationTimeline::GetCurrentTime -> GetCurrentTimeAsDouble
AnimationTimeline::GetCurrentTimeDuration -> GetCurrentTime
--- a/dom/animation/AnimationPlayer.cpp
+++ b/dom/animation/AnimationPlayer.cpp
@@ -23,26 +23,35 @@ AnimationPlayer::WrapObject(JSContext* a
}
Nullable<double>
AnimationPlayer::GetStartTime() const
{
return AnimationUtils::TimeDurationToDouble(mStartTime);
}
-Nullable<double>
+Nullable<TimeDuration>
AnimationPlayer::GetCurrentTime() const
{
- return AnimationUtils::TimeDurationToDouble(GetCurrentTimeDuration());
+ Nullable<TimeDuration> result;
+ if (!mHoldTime.IsNull()) {
+ result = mHoldTime;
+ } else {
+ Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTime();
+ if (!timelineTime.IsNull() && !mStartTime.IsNull()) {
+ result.SetValue(timelineTime.Value() - mStartTime.Value());
+ }
+ }
+ return result;
}
AnimationPlayState
AnimationPlayer::PlayState() const
{
- Nullable<TimeDuration> currentTime = GetCurrentTimeDuration();
+ Nullable<TimeDuration> currentTime = GetCurrentTime();
if (currentTime.IsNull()) {
return AnimationPlayState::Idle;
}
if (mIsPaused) {
return AnimationPlayState::Paused;
}
@@ -60,17 +69,17 @@ AnimationPlayer::Play(UpdateFlags aFlags
// not return early if mIsPaused is false since we may still need to seek.
// (However, we will need to pass a flag so that when we start playing due to
// a change in animation-play-state we *don't* trigger finishing behavior.)
if (!mIsPaused) {
return;
}
mIsPaused = false;
- Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTimeDuration();
+ Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTime();
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");
@@ -87,24 +96,30 @@ AnimationPlayer::Pause(UpdateFlags aFlag
{
if (mIsPaused) {
return;
}
mIsPaused = true;
mIsRunningOnCompositor = false;
// Bug 927349 - check for null result here and go to pending state
- mHoldTime = GetCurrentTimeDuration();
+ mHoldTime = GetCurrentTime();
mStartTime.SetNull();
if (aFlags == eUpdateStyle) {
MaybePostRestyle();
}
}
+Nullable<double>
+AnimationPlayer::GetCurrentTimeAsDouble() const
+{
+ return AnimationUtils::TimeDurationToDouble(GetCurrentTime());
+}
+
AnimationPlayState
AnimationPlayer::PlayStateFromJS() const
{
// FIXME: Once we introduce CSSTransitionPlayer, this should move to an
// override of PlayStateFromJS in CSSAnimationPlayer and CSSTransitionPlayer
// and we should skip it in the general case.
FlushStyle();
@@ -137,54 +152,39 @@ AnimationPlayer::PauseFromJS()
void
AnimationPlayer::SetSource(Animation* aSource)
{
if (mSource) {
mSource->SetParentTime(Nullable<TimeDuration>());
}
mSource = aSource;
if (mSource) {
- mSource->SetParentTime(GetCurrentTimeDuration());
+ mSource->SetParentTime(GetCurrentTime());
}
}
void
AnimationPlayer::Tick()
{
if (mSource) {
- mSource->SetParentTime(GetCurrentTimeDuration());
+ mSource->SetParentTime(GetCurrentTime());
}
}
bool
AnimationPlayer::IsRunning() const
{
if (IsPaused() || !GetSource() || GetSource()->IsFinishedTransition()) {
return false;
}
ComputedTiming computedTiming = GetSource()->GetComputedTiming();
return computedTiming.mPhase == ComputedTiming::AnimationPhase_Active;
}
-Nullable<TimeDuration>
-AnimationPlayer::GetCurrentTimeDuration() const
-{
- Nullable<TimeDuration> result;
- if (!mHoldTime.IsNull()) {
- result = mHoldTime;
- } else {
- Nullable<TimeDuration> timelineTime = mTimeline->GetCurrentTimeDuration();
- if (!timelineTime.IsNull() && !mStartTime.IsNull()) {
- result.SetValue(timelineTime.Value() - mStartTime.Value());
- }
- }
- return result;
-}
-
void
AnimationPlayer::FlushStyle() const
{
if (mSource && mSource->GetTarget()) {
nsIDocument* doc = mSource->GetTarget()->GetComposedDoc();
if (doc) {
doc->FlushPendingNotifications(Flush_Style);
}
--- a/dom/animation/AnimationPlayer.h
+++ b/dom/animation/AnimationPlayer.h
@@ -55,24 +55,27 @@ public:
eNoUpdate,
eUpdateStyle
};
// AnimationPlayer methods
Animation* GetSource() const { return mSource; }
AnimationTimeline* Timeline() const { return mTimeline; }
Nullable<double> GetStartTime() const;
- Nullable<double> GetCurrentTime() const;
+ Nullable<TimeDuration> GetCurrentTime() const;
AnimationPlayState PlayState() const;
virtual void Play(UpdateFlags aUpdateFlags);
virtual void Pause(UpdateFlags aUpdateFlags);
bool IsRunningOnCompositor() const { return mIsRunningOnCompositor; }
- // Wrapper functions for performing extra steps such as flushing
- // style when calling from JS.
+ // Wrapper functions for AnimationPlayer DOM methods when called
+ // from script. We often use the same methods internally and from
+ // script but when called from script we perform extra steps such
+ // as flushing style or converting the return type.
+ Nullable<double> GetCurrentTimeAsDouble() const;
AnimationPlayState PlayStateFromJS() const;
void PlayFromJS();
void PauseFromJS();
void SetSource(Animation* aSource);
void Tick();
const nsString& Name() const {
@@ -85,20 +88,16 @@ public:
bool HasCurrentSource() const {
return GetSource() && GetSource()->IsCurrent();
}
bool HasInEffectSource() const {
return GetSource() && GetSource()->IsInEffect();
}
- // Return the duration since the start time of the player, taking into
- // account the pause state. May be negative or null.
- Nullable<TimeDuration> GetCurrentTimeDuration() const;
-
// The beginning of the delay period.
Nullable<TimeDuration> mStartTime; // Timeline timescale
bool mIsRunningOnCompositor;
nsRefPtr<AnimationTimeline> mTimeline;
nsRefPtr<Animation> mSource;
protected:
--- a/dom/animation/AnimationTimeline.cpp
+++ b/dom/animation/AnimationTimeline.cpp
@@ -21,20 +21,26 @@ NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Ani
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AnimationTimeline, Release)
JSObject*
AnimationTimeline::WrapObject(JSContext* aCx)
{
return AnimationTimelineBinding::Wrap(aCx, this);
}
-Nullable<double>
+Nullable<TimeDuration>
AnimationTimeline::GetCurrentTime() const
{
- return AnimationUtils::TimeDurationToDouble(GetCurrentTimeDuration());
+ return ToTimelineTime(GetCurrentTimeStamp());
+}
+
+Nullable<double>
+AnimationTimeline::GetCurrentTimeAsDouble() const
+{
+ return AnimationUtils::TimeDurationToDouble(GetCurrentTime());
}
TimeStamp
AnimationTimeline::GetCurrentTimeStamp() const
{
// Always return the same object to benefit from return-value optimization.
TimeStamp result = mLastCurrentTime;
@@ -64,22 +70,16 @@ AnimationTimeline::GetCurrentTimeStamp()
// mLastCurrentTime.IsNull() || result >= mLastCurrentTime
// but due to bug 1043078 this will not be the case when the refresh driver
// is restored from test control.
mLastCurrentTime = result;
return result;
}
Nullable<TimeDuration>
-AnimationTimeline::GetCurrentTimeDuration() const
-{
- return ToTimelineTime(GetCurrentTimeStamp());
-}
-
-Nullable<TimeDuration>
AnimationTimeline::ToTimelineTime(const TimeStamp& aTimeStamp) const
{
Nullable<TimeDuration> result; // Initializes to null
if (aTimeStamp.IsNull()) {
return result;
}
nsRefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
--- a/dom/animation/AnimationTimeline.h
+++ b/dom/animation/AnimationTimeline.h
@@ -27,20 +27,22 @@ public:
}
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationTimeline)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AnimationTimeline)
nsISupports* GetParentObject() const { return mDocument; }
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
- // WebIDL API
- Nullable<double> GetCurrentTime() const;
+ // AnimationTimeline methods
+ Nullable<TimeDuration> GetCurrentTime() const;
- Nullable<TimeDuration> GetCurrentTimeDuration() const;
+ // Wrapper functions for AnimationTimeline DOM methods when called from
+ // script.
+ Nullable<double> GetCurrentTimeAsDouble() const;
Nullable<TimeDuration> ToTimelineTime(const TimeStamp& aTimeStamp) const;
TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const;
protected:
TimeStamp GetCurrentTimeStamp() const;
virtual ~AnimationTimeline() { }
--- a/dom/webidl/AnimationPlayer.webidl
+++ b/dom/webidl/AnimationPlayer.webidl
@@ -16,16 +16,17 @@ enum AnimationPlayState { "idle", "pendi
interface AnimationPlayer {
// Bug 1049975
// attribute AnimationNode? source;
[Pure]
readonly attribute Animation? source;
readonly attribute AnimationTimeline timeline;
[Pure]
readonly attribute double? startTime;
+ [BinaryName="currentTimeAsDouble"]
readonly attribute double? currentTime;
/* Not yet implemented
attribute double playbackRate; */
[BinaryName="playStateFromJS"]
readonly attribute AnimationPlayState playState;
/*
readonly attribute Promise ready;
--- a/dom/webidl/AnimationTimeline.webidl
+++ b/dom/webidl/AnimationTimeline.webidl
@@ -7,12 +7,14 @@
* http://dev.w3.org/fxtf/web-animations/#the-animationtimeline-interface
*
* Copyright © 2014 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
[Pref="dom.animations-api.core.enabled"]
interface AnimationTimeline {
+ [BinaryName="currentTimeAsDouble"]
readonly attribute double? currentTime;
+ // Not yet implemented:
// AnimationPlayer play (optional TimedItem? source = null);
// sequence<AnimationPlayer> getAnimationPlayers ();
};
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -418,17 +418,17 @@ nsAnimationManager::BuildAnimations(nsSt
dom::AnimationTimeline* aTimeline,
AnimationPlayerPtrArray& aPlayers)
{
NS_ABORT_IF_FALSE(aPlayers.IsEmpty(), "expect empty array");
ResolvedStyleCache resolvedStyles;
const nsStyleDisplay *disp = aStyleContext->StyleDisplay();
- Nullable<TimeDuration> now = aTimeline->GetCurrentTimeDuration();
+ Nullable<TimeDuration> now = aTimeline->GetCurrentTime();
for (size_t animIdx = 0, animEnd = disp->mAnimationNameCount;
animIdx != animEnd; ++animIdx) {
const StyleAnimation& src = disp->mAnimations[animIdx];
// CSS Animations whose animation-name does not match a @keyframes rule do
// not generate animation events. This includes when the animation-name is
// "none" which is represented by an empty name in the StyleAnimation.
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -528,17 +528,17 @@ nsTransitionManager::ConsiderStartingTra
AnimationPropertySegment& segment = *prop.mSegments.AppendElement();
segment.mFromValue = startValue;
segment.mToValue = endValue;
segment.mFromKey = 0;
segment.mToKey = 1;
segment.mTimingFunction.Init(tf);
nsRefPtr<dom::AnimationPlayer> player = new dom::AnimationPlayer(timeline);
- player->mStartTime = timeline->GetCurrentTimeDuration();
+ player->mStartTime = timeline->GetCurrentTime();
player->SetSource(pt);
if (!aElementTransitions) {
aElementTransitions =
GetElementTransitions(aElement, aNewStyleContext->GetPseudoType(),
true);
if (!aElementTransitions) {
NS_WARNING("allocating CommonAnimationManager failed");