#ifndef SMILTimeContainer_h
#define SMILTimeContainer_h
#include "core/dom/QualifiedName.h"
#include "core/svg/animation/SMILTime.h"
#include "platform/Timer.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/text/StringHash.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class Document;
class SVGElement;
class SVGSMILElement;
class SVGSVGElement;
class SMILTimeContainer : public RefCounted<SMILTimeContainer> {
public:
static PassRefPtr<SMILTimeContainer> create(SVGSVGElement& owner) { return adoptRef(new SMILTimeContainer(owner)); }
~SMILTimeContainer();
void schedule(SVGSMILElement*, SVGElement*, const QualifiedName&);
void unschedule(SVGSMILElement*, SVGElement*, const QualifiedName&);
void notifyIntervalsChanged();
SMILTime elapsed() const;
bool isPaused() const;
bool isStarted() const;
void begin();
void pause();
void resume();
void setElapsed(SMILTime);
void serviceAnimations(double monotonicAnimationStartTime);
bool hasAnimations() const;
void setDocumentOrderIndexesDirty() { m_documentOrderIndexesDirty = true; }
private:
SMILTimeContainer(SVGSVGElement& owner);
enum FrameSchedulingState {
Idle,
SynchronizeAnimations,
FutureAnimationFrame,
AnimationFrame
};
bool isTimelineRunning() const;
void scheduleAnimationFrame(SMILTime fireTime);
void cancelAnimationFrame();
void wakeupTimerFired(Timer<SMILTimeContainer>*);
void updateAnimationsAndScheduleFrameIfNeeded(SMILTime elapsed, bool seekToTime = false);
SMILTime updateAnimations(SMILTime elapsed, bool seekToTime = false);
void serviceOnNextFrame();
void scheduleWakeUp(double delayTime, FrameSchedulingState);
bool hasPendingSynchronization() const;
void updateDocumentOrderIndexes();
double lastResumeTime() const { return m_resumeTime ? m_resumeTime : m_beginTime; }
Document& document() const;
double currentTime() const;
double m_beginTime;
double m_pauseTime;
double m_resumeTime;
double m_accumulatedActiveTime;
double m_presetStartTime;
FrameSchedulingState m_frameSchedulingState;
bool m_documentOrderIndexesDirty;
Timer<SMILTimeContainer> m_wakeupTimer;
typedef pair<SVGElement*, QualifiedName> ElementAttributePair;
typedef Vector<SVGSMILElement*> AnimationsVector;
typedef HashMap<ElementAttributePair, OwnPtr<AnimationsVector> > GroupedAnimationsMap;
GroupedAnimationsMap m_scheduledAnimations;
SVGSVGElement& m_ownerSVGElement;
#ifndef NDEBUG
bool m_preventScheduledAnimationsChanges;
#endif
};
}
#endif