2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef HTMLMediaElement_h
27 #define HTMLMediaElement_h
31 #include "HTMLElement.h"
34 #include "StringHash.h"
35 #include "VoidCallback.h"
36 #include "wtf/HashMap.h"
37 #include "wtf/HashSet.h"
38 #include "wtf/RefPtr.h"
39 #include "wtf/Vector.h"
46 class HTMLMediaElement : public HTMLElement, public MovieClient {
48 HTMLMediaElement(const QualifiedName&, Document*);
49 virtual ~HTMLMediaElement();
51 bool checkDTD(const Node* newChild);
53 void attributeChanged(Attribute*, bool preserveDecls);
55 virtual bool rendererIsNeeded(RenderStyle*) { return false; }
56 virtual void insertedIntoDocument();
57 virtual void removedFromDocument();
59 Movie* movie() const { return m_movie; }
61 virtual bool isVideo() const { return false; }
67 PassRefPtr<MediaError> error() const;
71 void setSrc(const String&);
72 String currentSrc() const;
74 enum NetworkState { EMPTY, LOADING, LOADED_METADATA, LOADED_FIRST_FRAME, LOADED };
75 NetworkState networkState() const;
76 float bufferingRate();
77 PassRefPtr<TimeRanges> buffered() const;
78 void load(ExceptionCode&);
81 enum ReadyState { DATA_UNAVAILABLE, CAN_SHOW_CURRENT_FRAME, CAN_PLAY, CAN_PLAY_THROUGH };
82 ReadyState readyState() const;
86 float currentTime() const;
87 void setCurrentTime(float, ExceptionCode&);
88 float duration() const;
90 float defaultPlaybackRate() const;
91 void setDefaultPlaybackRate(float, ExceptionCode&);
92 float playbackRate() const;
93 void setPlaybackRate(float, ExceptionCode&);
94 PassRefPtr<TimeRanges> played() const;
95 PassRefPtr<TimeRanges> seekable() const;
97 bool autoplay() const;
98 void setAutoplay(bool b);
99 void play(ExceptionCode&);
100 void pause(ExceptionCode&);
104 void setStart(float time);
106 void setEnd(float time);
107 float loopStart() const;
108 void setLoopStart(float time);
109 float loopEnd() const;
110 void setLoopEnd(float time);
111 unsigned loopCount() const;
112 void setLoopCount(unsigned, ExceptionCode&);
113 unsigned currentLoop() const;
114 void setCurrentLoop(unsigned);
117 void addCuePoint(float time, VoidCallback* callback, bool pause);
118 void removeCuePoint(float time, VoidCallback* callback);
121 bool controls() const;
122 void setControls(bool);
123 float volume() const;
124 void setVolume(float, ExceptionCode&);
129 float getTimeOffsetAttribute(const QualifiedName&, float valueOnError) const;
130 void setTimeOffsetAttribute(const QualifiedName&, float value);
132 virtual void willSaveToCache();
133 virtual void didRestoreFromCache();
135 void initAndDispatchProgressEvent(const AtomicString& eventName);
136 void dispatchEventAsync(const AtomicString& eventName);
138 void setReadyState(ReadyState);
140 private: // MovieObserver
141 virtual void movieNetworkStateChanged(Movie*);
142 virtual void movieReadyStateChanged(Movie*);
143 virtual void movieVolumeChanged(Movie*);
144 virtual void movieDidEnd(Movie*);
145 virtual void movieCuePointReached(Movie*, float cueTime);
148 void loadTimerFired(Timer<HTMLMediaElement>*);
149 void asyncEventTimerFired(Timer<HTMLMediaElement>*);
150 void progressEventTimerFired(Timer<HTMLMediaElement>*);
151 void seek(float time, ExceptionCode& ec);
152 void checkIfSeekNeeded();
155 float effectiveStart() const;
156 float effectiveEnd() const;
157 float effectiveLoopStart() const;
158 float effectiveLoopEnd() const;
159 bool activelyPlaying() const;
160 bool endedPlayback() const;
163 Timer<HTMLMediaElement> m_loadTimer;
164 Timer<HTMLMediaElement> m_asyncEventTimer;
165 Timer<HTMLMediaElement> m_progressEventTimer;
166 HashSet<String> m_asyncEventsToDispatch;
168 float m_defaultPlaybackRate;
169 NetworkState m_networkState;
170 ReadyState m_readyState;
173 RefPtr<MediaError> m_error;
176 bool m_loadedFirstFrame;
179 bool m_wasPlayingBeforeMovingToPageCache;
181 unsigned m_currentLoop;
187 unsigned m_previousProgress;
188 double m_previousProgressTime;
189 bool m_sentStalledEvent;
191 float m_bufferingRate;
193 unsigned m_loadNestingLevel;
194 unsigned m_terminateLoadBelowNestingLevel;
196 struct CallbackEntry {
197 CallbackEntry() : m_voidCallback(0), m_pause(false) { }
198 CallbackEntry(VoidCallback* voidCallback, bool pause) {
199 m_voidCallback = voidCallback;
202 RefPtr<VoidCallback> m_voidCallback;
205 typedef Vector<CallbackEntry> CallbackVector;
206 HashMap<float, CallbackVector*> m_cuePoints;