Bug 1072037, part 1 - Implement web-animations proceedure to 'set the current time' and make AnimationPlayer.startTime writeable. r=birtles, r=smaug

This commit is contained in:
Jonathan Watt 2015-03-09 16:50:39 +00:00
parent d5681f75bf
commit 39fe510f93
3 changed files with 57 additions and 2 deletions

View File

@ -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<double>& 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)
{

View File

@ -74,6 +74,8 @@ public:
Nullable<TimeDuration> GetStartTime() const { return mStartTime; }
void SetStartTime(const Nullable<TimeDuration>& aNewStartTime);
Nullable<TimeDuration> 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<double> GetStartTimeAsDouble() const;
void SetStartTimeAsDouble(const Nullable<double>& aStartTime);
Nullable<double> GetCurrentTimeAsDouble() const;
void SetCurrentTimeAsDouble(const Nullable<double>& aCurrentTime,
ErrorResult& aRv);
virtual AnimationPlayState PlayStateFromJS() const { return PlayState(); }
virtual void PlayFromJS() { Play(); }
// PauseFromJS is currently only here for symmetry with PlayFromJS but

View File

@ -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; */