2014-08-10 00:06:44 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "AnimationPlayer.h"
|
|
|
|
#include "mozilla/dom/AnimationPlayerBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-08-10 00:06:47 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AnimationPlayer, mTimeline, mSource)
|
2014-08-10 00:06:44 -07:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AnimationPlayer, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AnimationPlayer, Release)
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
AnimationPlayer::WrapObject(JSContext* aCx)
|
|
|
|
{
|
|
|
|
return dom::AnimationPlayerBinding::Wrap(aCx, this);
|
|
|
|
}
|
|
|
|
|
2014-08-29 23:11:56 -07:00
|
|
|
Nullable<double>
|
|
|
|
AnimationPlayer::GetStartTime() const
|
2014-08-10 00:06:44 -07:00
|
|
|
{
|
2014-08-29 23:11:56 -07:00
|
|
|
return mTimeline->ToTimelineTime(mStartTime);
|
2014-08-10 00:06:44 -07:00
|
|
|
}
|
|
|
|
|
2014-08-29 23:11:56 -07:00
|
|
|
Nullable<double>
|
|
|
|
AnimationPlayer::GetCurrentTime() const
|
2014-08-10 00:06:44 -07:00
|
|
|
{
|
2014-08-29 23:11:56 -07:00
|
|
|
Nullable<double> result;
|
2014-08-10 00:06:50 -07:00
|
|
|
Nullable<TimeDuration> currentTime = GetCurrentTimeDuration();
|
2014-08-10 00:06:44 -07:00
|
|
|
|
|
|
|
// The current time is currently only going to be null when don't have a
|
|
|
|
// refresh driver (e.g. because we are in a display:none iframe).
|
|
|
|
//
|
|
|
|
// Web Animations says that in this case we should use a timeline time of
|
|
|
|
// 0 (the "effective timeline time") and calculate the current time from that.
|
|
|
|
// Doing that, however, requires storing the start time as an offset rather
|
|
|
|
// than a timestamp so for now we just return 0.
|
|
|
|
//
|
|
|
|
// FIXME: Store player start time and pause start as offsets rather than
|
|
|
|
// timestamps and return the appropriate current time when the timeline time
|
|
|
|
// is null.
|
|
|
|
if (currentTime.IsNull()) {
|
2014-08-29 23:11:56 -07:00
|
|
|
result.SetValue(0.0);
|
|
|
|
} else {
|
|
|
|
result.SetValue(currentTime.Value().ToMilliseconds());
|
2014-08-10 00:06:44 -07:00
|
|
|
}
|
|
|
|
|
2014-08-29 23:11:56 -07:00
|
|
|
return result;
|
2014-08-10 00:06:44 -07:00
|
|
|
}
|
|
|
|
|
2014-08-10 00:06:47 -07:00
|
|
|
void
|
|
|
|
AnimationPlayer::SetSource(Animation* aSource)
|
|
|
|
{
|
2014-08-10 00:06:48 -07:00
|
|
|
if (mSource) {
|
|
|
|
mSource->SetParentTime(Nullable<TimeDuration>());
|
|
|
|
}
|
2014-08-10 00:06:47 -07:00
|
|
|
mSource = aSource;
|
2014-08-10 00:06:48 -07:00
|
|
|
if (mSource) {
|
2014-08-10 00:06:50 -07:00
|
|
|
mSource->SetParentTime(GetCurrentTimeDuration());
|
2014-08-10 00:06:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AnimationPlayer::Tick()
|
|
|
|
{
|
|
|
|
if (mSource) {
|
2014-08-10 00:06:50 -07:00
|
|
|
mSource->SetParentTime(GetCurrentTimeDuration());
|
2014-08-10 00:06:48 -07:00
|
|
|
}
|
2014-08-10 00:06:47 -07:00
|
|
|
}
|
|
|
|
|
2014-08-10 00:06:44 -07:00
|
|
|
bool
|
|
|
|
AnimationPlayer::IsRunning() const
|
|
|
|
{
|
2014-08-10 00:06:51 -07:00
|
|
|
if (IsPaused() || !GetSource() || GetSource()->IsFinishedTransition()) {
|
2014-08-10 00:06:44 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-10 00:06:50 -07:00
|
|
|
ComputedTiming computedTiming = GetSource()->GetComputedTiming();
|
2014-08-10 00:06:44 -07:00
|
|
|
return computedTiming.mPhase == ComputedTiming::AnimationPhase_Active;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AnimationPlayer::IsCurrent() const
|
|
|
|
{
|
2014-08-10 00:06:51 -07:00
|
|
|
return GetSource() && GetSource()->IsCurrent();
|
2014-08-10 00:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|