#ifndef AnimationPlayer_h
#define AnimationPlayer_h
#include "core/animation/TimedItem.h"
#include "core/events/EventTarget.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class DocumentTimeline;
class ExceptionState;
class AnimationPlayer FINAL : public RefCounted<AnimationPlayer>, public EventTargetWithInlineData {
REFCOUNTED_EVENT_TARGET(AnimationPlayer);
public:
enum UpdateReason {
UpdateOnDemand,
UpdateForAnimationFrame
};
~AnimationPlayer();
static PassRefPtr<AnimationPlayer> create(DocumentTimeline&, TimedItem*);
bool update(UpdateReason);
double timeToEffectChange();
void cancel();
double currentTime();
void setCurrentTime(double newCurrentTime);
bool paused() const { return m_paused && !m_isPausedForTesting; }
void pause();
void play();
void reverse();
void finish(ExceptionState&);
bool finished() { return limited(currentTime()); }
DEFINE_ATTRIBUTE_EVENT_LISTENER(finish);
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ExecutionContext* executionContext() const OVERRIDE;
double playbackRate() const { return m_playbackRate; }
void setPlaybackRate(double);
const DocumentTimeline* timeline() const { return m_timeline; }
DocumentTimeline* timeline() { return m_timeline; }
void timelineDestroyed() { m_timeline = 0; }
bool hasStartTime() const { return !isNull(m_startTime); }
double startTime() const { return m_startTime; }
void setStartTime(double);
const TimedItem* source() const { return m_content.get(); }
TimedItem* source() { return m_content.get(); }
TimedItem* source(bool& isNull) { isNull = !m_content; return m_content.get(); }
void setSource(TimedItem*);
double timeLag() { return currentTimeWithoutLag() - currentTime(); }
void pauseForTesting(double pauseTime);
void unpause();
void setOutdated();
bool outdated() { return m_outdated; }
bool maybeStartAnimationOnCompositor();
void cancelAnimationOnCompositor();
bool hasActiveAnimationsOnCompositor();
class SortInfo {
public:
friend class AnimationPlayer;
bool operator<(const SortInfo& other) const;
private:
SortInfo(unsigned sequenceNumber, double startTime)
: m_sequenceNumber(sequenceNumber)
, m_startTime(startTime)
{ }
unsigned m_sequenceNumber;
double m_startTime;
};
const SortInfo& sortInfo() const { return m_sortInfo; }
static bool hasLowerPriority(AnimationPlayer* player1, AnimationPlayer* player2)
{
return player1->sortInfo() < player2->sortInfo();
}
private:
AnimationPlayer(DocumentTimeline&, TimedItem*);
double sourceEnd() const;
bool limited(double currentTime) const;
double currentTimeWithoutLag() const;
double currentTimeWithLag() const;
void updateTimingState(double newCurrentTime);
void updateCurrentTimingState();
double m_playbackRate;
double m_startTime;
double m_holdTime;
double m_storedTimeLag;
SortInfo m_sortInfo;
RefPtr<TimedItem> m_content;
DocumentTimeline* m_timeline;
bool m_paused;
bool m_held;
bool m_isPausedForTesting;
bool m_outdated;
bool m_finished;
};
}
#endif