#ifndef MediaController_h
#define MediaController_h
#include "bindings/v8/ScriptWrappable.h"
#include "core/events/Event.h"
#include "core/events/EventTarget.h"
#include "core/html/HTMLMediaElement.h"
#include "platform/Timer.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/Vector.h"
namespace WebCore {
class Clock;
class Event;
class ExceptionState;
class ExecutionContext;
class MediaController FINAL : public RefCounted<MediaController>, public ScriptWrappable, public EventTargetWithInlineData {
REFCOUNTED_EVENT_TARGET(MediaController);
public:
static PassRefPtr<MediaController> create(ExecutionContext*);
virtual ~MediaController();
void addMediaElement(HTMLMediaElement*);
void removeMediaElement(HTMLMediaElement*);
bool containsMediaElement(HTMLMediaElement*) const;
PassRefPtr<TimeRanges> buffered() const;
PassRefPtr<TimeRanges> seekable() const;
PassRefPtr<TimeRanges> played();
double duration() const;
double currentTime() const;
void setCurrentTime(double, ExceptionState&);
bool paused() const { return m_paused; }
void play();
void pause();
void unpause();
double defaultPlaybackRate() const { return m_defaultPlaybackRate; }
void setDefaultPlaybackRate(double, ExceptionState&);
double playbackRate() const;
void setPlaybackRate(double, ExceptionState&);
double volume() const { return m_volume; }
void setVolume(double, ExceptionState&);
bool muted() const { return m_muted; }
void setMuted(bool);
typedef HTMLMediaElement::ReadyState ReadyState;
ReadyState readyState() const { return m_readyState; }
enum PlaybackState { WAITING, PLAYING, ENDED };
const AtomicString& playbackState() const;
bool isRestrained() const;
bool isBlocked() const;
void clearExecutionContext() { m_executionContext = 0; }
private:
MediaController(ExecutionContext*);
void reportControllerState();
void updateReadyState();
void updatePlaybackState();
void updateMediaElements();
void bringElementUpToSpeed(HTMLMediaElement*);
void scheduleEvent(const AtomicString& eventName);
void asyncEventTimerFired(Timer<MediaController>*);
void clearPositionTimerFired(Timer<MediaController>*);
bool hasEnded() const;
void scheduleTimeupdateEvent();
void timeupdateTimerFired(Timer<MediaController>*);
void startTimeupdateTimer();
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ExecutionContext* executionContext() const OVERRIDE { return m_executionContext; }
friend class HTMLMediaElement;
friend class MediaControllerEventListener;
Vector<HTMLMediaElement*> m_mediaElements;
bool m_paused;
double m_defaultPlaybackRate;
double m_volume;
mutable double m_position;
bool m_muted;
ReadyState m_readyState;
PlaybackState m_playbackState;
WillBePersistentHeapVector<RefPtrWillBeMember<Event> > m_pendingEvents;
Timer<MediaController> m_asyncEventTimer;
mutable Timer<MediaController> m_clearPositionTimer;
OwnPtr<Clock> m_clock;
ExecutionContext* m_executionContext;
Timer<MediaController> m_timeupdateTimer;
double m_previousTimeupdateTime;
};
}
#endif