fix logic
[personal-kdelibs.git] / khtml / html / HTMLMediaElement.h
blobb095585490ec4461d1d4533a025e9231cf1356c4
1 /*
2 * Copyright (C) 2007, 2008 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
6 * are met:
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
29 #include "HTMLElement.h"
30 #include "ExceptionCode.h"
31 #include <wtf/OwnPtr.h>
32 #include <wtf/PassRefPtr.h>
34 namespace khtml {
36 class MediaError;
37 class TimeRanges;
39 // dummy
40 class MediaPlayer
42 public:
43 QRect naturalSize() const { return QRect(); }
44 float duration() const { return 0; }
45 float rate() const { return 0; }
46 void setRate(float) { }
47 void setVolume(float) { }
48 float currentTime() const { return 0; }
49 float maxTimeSeekable() { return 0; }
50 float maxTimeBuffered() { return 0; }
53 class HTMLMediaElement : public HTMLElement {
54 public:
55 HTMLMediaElement(Document*);
56 virtual ~HTMLMediaElement();
58 virtual void attributeChanged(NodeImpl::Id attrId);
60 virtual bool isVideo() const { return false; }
62 void scheduleLoad();
64 // DOM API
65 // error state
66 PassRefPtr<MediaError> error() const;
68 // network state
69 String src() const;
70 void setSrc(const String&);
71 String currentSrc() const;
73 enum NetworkState { EMPTY, LOADING, LOADED_METADATA, LOADED_FIRST_FRAME, LOADED };
74 NetworkState networkState() const;
75 float bufferingRate();
76 PassRefPtr<TimeRanges> buffered() const;
77 void load(ExceptionCode&);
79 // ready state
80 enum ReadyState { DATA_UNAVAILABLE, CAN_SHOW_CURRENT_FRAME, CAN_PLAY, CAN_PLAY_THROUGH };
81 ReadyState readyState() const;
82 bool seeking() const;
84 // playback state
85 float currentTime() const;
86 void setCurrentTime(float, ExceptionCode&);
87 float duration() const;
88 bool paused() const;
89 float defaultPlaybackRate() const;
90 void setDefaultPlaybackRate(float, ExceptionCode&);
91 float playbackRate() const;
92 void setPlaybackRate(float, ExceptionCode&);
93 PassRefPtr<TimeRanges> played() const;
94 PassRefPtr<TimeRanges> seekable() const;
95 bool ended() const;
96 bool autoplay() const;
97 void setAutoplay(bool b);
98 void play(ExceptionCode&);
99 void pause(ExceptionCode&);
101 // looping
102 float start() const;
103 void setStart(float time);
104 float end() const;
105 void setEnd(float time);
106 float loopStart() const;
107 void setLoopStart(float time);
108 float loopEnd() const;
109 void setLoopEnd(float time);
110 unsigned playCount() const;
111 void setPlayCount(unsigned, ExceptionCode&);
112 unsigned currentLoop() const;
113 void setCurrentLoop(unsigned);
115 // controls
116 bool controls() const;
117 void setControls(bool);
118 float volume() const;
119 void setVolume(float, ExceptionCode&);
120 bool muted() const;
121 void setMuted(bool);
123 protected:
124 float getTimeOffsetAttribute(NodeImpl::Id name, float valueOnError) const;
125 void setTimeOffsetAttribute(NodeImpl::Id name, float value);
127 void checkIfSeekNeeded();
129 void setReadyState(ReadyState);
131 private:
132 void updateVolume();
133 void updatePlayState();
134 bool endedPlayback() const;
136 protected:
137 float m_defaultPlaybackRate;
138 NetworkState m_networkState;
139 ReadyState m_readyState;
140 String m_currentSrc;
142 RefPtr<MediaError> m_error;
144 bool m_begun;
145 bool m_loadedFirstFrame;
146 bool m_autoplaying;
148 unsigned m_currentLoop;
149 float m_volume;
150 bool m_muted;
152 bool m_paused;
153 bool m_seeking;
155 float m_currentTimeDuringSeek;
157 unsigned m_previousProgress;
158 double m_previousProgressTime;
159 bool m_sentStalledEvent;
161 float m_bufferingRate;
163 OwnPtr<MediaPlayer> m_player;
166 } //namespace
168 #endif