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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_AnimationPlayer_h
|
|
|
|
#define mozilla_dom_AnimationPlayer_h
|
|
|
|
|
|
|
|
#include <algorithm> // for std::max
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
|
2014-08-10 00:06:46 -07:00
|
|
|
#include "mozilla/dom/Animation.h" // for Animation
|
2014-08-10 00:06:44 -07:00
|
|
|
#include "mozilla/dom/AnimationTimeline.h" // for AnimationTimeline
|
|
|
|
#include "nsCSSProperty.h" // for nsCSSProperty
|
|
|
|
|
|
|
|
// X11 has a #define for CurrentTime.
|
|
|
|
#ifdef CurrentTime
|
|
|
|
#undef CurrentTime
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct JSContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
struct ElementPropertyTransition;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class AnimationPlayer : public nsWrapperCache
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual ~AnimationPlayer() { }
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AnimationPlayer(AnimationTimeline* aTimeline)
|
|
|
|
: mIsRunningOnCompositor(false)
|
|
|
|
, mTimeline(aTimeline)
|
|
|
|
{
|
|
|
|
SetIsDOMBinding();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationPlayer)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AnimationPlayer)
|
|
|
|
|
|
|
|
AnimationTimeline* GetParentObject() const { return mTimeline; }
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// AnimationPlayer methods
|
2014-08-10 00:06:47 -07:00
|
|
|
Animation* GetSource() const { return mSource; }
|
2014-08-10 00:06:44 -07:00
|
|
|
AnimationTimeline* Timeline() const { return mTimeline; }
|
|
|
|
double StartTime() const;
|
|
|
|
double CurrentTime() const;
|
|
|
|
|
2014-08-10 00:06:47 -07:00
|
|
|
void SetSource(Animation* aSource);
|
2014-08-10 00:06:48 -07:00
|
|
|
void Tick();
|
2014-08-10 00:06:47 -07:00
|
|
|
|
2014-08-10 00:06:44 -07:00
|
|
|
// FIXME: If we succeed in moving transition-specific code to a type of
|
|
|
|
// AnimationEffect (as per the Web Animations API) we should remove these
|
|
|
|
// virtual methods.
|
|
|
|
virtual ElementPropertyTransition* AsTransition() { return nullptr; }
|
|
|
|
virtual const ElementPropertyTransition* AsTransition() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPaused() const {
|
|
|
|
return mPlayState == NS_STYLE_ANIMATION_PLAY_STATE_PAUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsRunning() const;
|
|
|
|
bool IsCurrent() const;
|
|
|
|
|
2014-08-10 00:06:50 -07:00
|
|
|
// Return the duration since the start time of the player, taking into
|
2014-08-10 00:06:44 -07:00
|
|
|
// account the pause state. May be negative.
|
|
|
|
// Returns a null value if the timeline associated with this object has a
|
|
|
|
// current timestamp that is null or if the start time of this object is
|
|
|
|
// null.
|
2014-08-10 00:06:50 -07:00
|
|
|
Nullable<TimeDuration> GetCurrentTimeDuration() const {
|
2014-08-10 00:06:44 -07:00
|
|
|
const TimeStamp& timelineTime = mTimeline->GetCurrentTimeStamp();
|
|
|
|
// FIXME: In order to support arbitrary timelines we will need to fix
|
|
|
|
// the pause logic to handle the timeline time going backwards.
|
|
|
|
MOZ_ASSERT(timelineTime.IsNull() || !IsPaused() ||
|
|
|
|
timelineTime >= mPauseStart,
|
|
|
|
"if paused, any non-null value of aTime must be at least"
|
|
|
|
" mPauseStart");
|
|
|
|
|
|
|
|
Nullable<TimeDuration> result; // Initializes to null
|
|
|
|
if (!timelineTime.IsNull() && !mStartTime.IsNull()) {
|
|
|
|
result.SetValue((IsPaused() ? mPauseStart : timelineTime) - mStartTime);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString mName;
|
|
|
|
// The beginning of the delay period.
|
|
|
|
TimeStamp mStartTime;
|
|
|
|
TimeStamp mPauseStart;
|
|
|
|
uint8_t mPlayState;
|
|
|
|
bool mIsRunningOnCompositor;
|
|
|
|
|
|
|
|
nsRefPtr<AnimationTimeline> mTimeline;
|
2014-08-10 00:06:47 -07:00
|
|
|
nsRefPtr<Animation> mSource;
|
2014-08-10 00:06:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_AnimationPlayer_h
|