From 39fe510f93d33f034133d7e8e4c41eea3a31aa0e Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Mon, 9 Mar 2015 16:50:39 +0000 Subject: [PATCH] Bug 1072037, part 1 - Implement web-animations proceedure to 'set the current time' and make AnimationPlayer.startTime writeable. r=birtles, r=smaug --- dom/animation/AnimationPlayer.cpp | 51 +++++++++++++++++++++++++++++++ dom/animation/AnimationPlayer.h | 4 +++ dom/webidl/AnimationPlayer.webidl | 4 +-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/dom/animation/AnimationPlayer.cpp b/dom/animation/AnimationPlayer.cpp index 769a9588ff2b..f94af0df5254 100644 --- a/dom/animation/AnimationPlayer.cpp +++ b/dom/animation/AnimationPlayer.cpp @@ -95,6 +95,43 @@ AnimationPlayer::GetCurrentTime() const return result; } +// Implements http://w3c.github.io/web-animations/#silently-set-the-current-time +void +AnimationPlayer::SilentlySetCurrentTime(const TimeDuration& aSeekTime) +{ + if (!mHoldTime.IsNull() || + !mTimeline || + mTimeline->GetCurrentTime().IsNull() + /*or, once supported, playback rate is 0, or have pending pause task*/) { + mHoldTime.SetValue(aSeekTime); + if (!mTimeline || mTimeline->GetCurrentTime().IsNull()) { + mStartTime.SetNull(); + } + } else { + // once playback rate is supported, need to account for that here + mStartTime.SetValue(mTimeline->GetCurrentTime().Value() - aSeekTime); + } + + // Once AnimationPlayers store a previous current time, set that to + // unresolved. +} + +// Implements http://w3c.github.io/web-animations/#set-the-current-time +void +AnimationPlayer::SetCurrentTime(const TimeDuration& aSeekTime) +{ + SilentlySetCurrentTime(aSeekTime); + + // Once pending pause tasks are supported, cancel that here. + + UpdateSourceContent(); + PostUpdate(); + + // FIXME: Once bug 1074630 is fixed, run the procedure to update a player's + // finished state for player: + // http://w3c.github.io/web-animations/#update-a-players-finished-state +} + AnimationPlayState AnimationPlayer::PlayState() const { @@ -170,6 +207,20 @@ AnimationPlayer::GetCurrentTimeAsDouble() const return AnimationUtils::TimeDurationToDouble(GetCurrentTime()); } +void +AnimationPlayer::SetCurrentTimeAsDouble(const Nullable& aCurrentTime, + ErrorResult& aRv) +{ + if (aCurrentTime.IsNull()) { + if (!GetCurrentTime().IsNull()) { + aRv.Throw(NS_ERROR_DOM_TYPE_ERR); + } + return; + } + + return SetCurrentTime(TimeDuration::FromMilliseconds(aCurrentTime.Value())); +} + void AnimationPlayer::SetSource(Animation* aSource) { diff --git a/dom/animation/AnimationPlayer.h b/dom/animation/AnimationPlayer.h index ada80de09f06..cc1259fb297a 100644 --- a/dom/animation/AnimationPlayer.h +++ b/dom/animation/AnimationPlayer.h @@ -74,6 +74,8 @@ public: Nullable GetStartTime() const { return mStartTime; } void SetStartTime(const Nullable& aNewStartTime); Nullable GetCurrentTime() const; + void SilentlySetCurrentTime(const TimeDuration& aNewCurrentTime); + void SetCurrentTime(const TimeDuration& aNewCurrentTime); AnimationPlayState PlayState() const; virtual Promise* GetReady(ErrorResult& aRv); virtual void Play(); @@ -87,6 +89,8 @@ public: Nullable GetStartTimeAsDouble() const; void SetStartTimeAsDouble(const Nullable& aStartTime); Nullable GetCurrentTimeAsDouble() const; + void SetCurrentTimeAsDouble(const Nullable& aCurrentTime, + ErrorResult& aRv); virtual AnimationPlayState PlayStateFromJS() const { return PlayState(); } virtual void PlayFromJS() { Play(); } // PauseFromJS is currently only here for symmetry with PlayFromJS but diff --git a/dom/webidl/AnimationPlayer.webidl b/dom/webidl/AnimationPlayer.webidl index 5d43903fa72e..cb027f8e39e7 100644 --- a/dom/webidl/AnimationPlayer.webidl +++ b/dom/webidl/AnimationPlayer.webidl @@ -21,8 +21,8 @@ interface AnimationPlayer { readonly attribute AnimationTimeline timeline; [BinaryName="startTimeAsDouble"] attribute double? startTime; - [BinaryName="currentTimeAsDouble"] - readonly attribute double? currentTime; + [SetterThrows, BinaryName="currentTimeAsDouble"] + attribute double? currentTime; /* Not yet implemented attribute double playbackRate; */