File indexing completed on 2024-05-05 16:10:15
0001 /* 0002 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 0003 * (C) 2009 Michael Howell <mhowell123@gmail.com>. 0004 * 0005 * Redistribution and use in source and binary forms, with or without 0006 * modification, are permitted provided that the following conditions 0007 * are met: 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 0014 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 0015 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 0017 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 0018 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 0019 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 0020 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 0021 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 0022 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0025 */ 0026 0027 #ifndef HTMLMediaElement_h 0028 #define HTMLMediaElement_h 0029 0030 #include "html_elementimpl.h" 0031 #include "HTMLElement.h" 0032 #include "ExceptionCode.h" 0033 #include <wtf/PassRefPtr.h> 0034 #include <QPointer> 0035 0036 namespace khtml 0037 { 0038 0039 class MediaError; 0040 class TimeRanges; 0041 class RenderMedia; 0042 class MediaPlayer; 0043 0044 class HTMLMediaElement : public HTMLElement 0045 { 0046 public: 0047 HTMLMediaElement(Document *); 0048 virtual ~HTMLMediaElement(); 0049 0050 void attach() override; 0051 void close() override; 0052 0053 // virtual void parseAttribute(AttributeImpl *token); 0054 using DOM::ElementImpl::attributeChanged; 0055 void attributeChanged(NodeImpl::Id attrId) override; 0056 0057 virtual bool isVideo() const 0058 { 0059 return false; 0060 } 0061 0062 void scheduleLoad(); 0063 0064 // DOM API 0065 // error state 0066 PassRefPtr<MediaError> error() const; 0067 0068 // network state 0069 String src() const; 0070 void setSrc(const String &); 0071 String currentSrc() const; 0072 0073 enum NetworkState { NETWORK_EMPTY, NETWORK_IDLE, NETWORK_LOADING, NETWORK_NO_SOURCE }; 0074 NetworkState networkState() const; 0075 bool autobuffer() const; 0076 void setAutobuffer(bool b); 0077 PassRefPtr<TimeRanges> buffered() const; 0078 void load(ExceptionCode &); 0079 String canPlayType(String type); 0080 0081 // ready state 0082 enum ReadyState { HAVE_NOTHING, HAVE_METADATA, HAVE_CURRENT_DATA, HAVE_FUTURE_DATA, HAVE_ENOUGH_DATA }; 0083 ReadyState readyState() const; 0084 bool seeking() const; 0085 0086 // playback state 0087 float currentTime() const; 0088 void setCurrentTime(float, ExceptionCode &); 0089 float startTime() const; 0090 float duration() const; 0091 bool paused() const; 0092 float defaultPlaybackRate() const; 0093 void setDefaultPlaybackRate(float, ExceptionCode &); 0094 float playbackRate() const; 0095 void setPlaybackRate(float, ExceptionCode &); 0096 PassRefPtr<TimeRanges> played() const; 0097 PassRefPtr<TimeRanges> seekable() const; 0098 bool ended() const; 0099 bool autoplay() const; 0100 void setAutoplay(bool b); 0101 bool loop() const; 0102 void setLoop(bool b); 0103 void play(ExceptionCode &); 0104 void pause(ExceptionCode &); 0105 0106 // controls 0107 bool controls() const; 0108 void setControls(bool); 0109 float volume() const; 0110 void setVolume(float, ExceptionCode &); 0111 bool muted() const; 0112 void setMuted(bool); 0113 0114 String pickMedia(); 0115 0116 protected: 0117 void checkIfSeekNeeded(); 0118 0119 void setReadyState(ReadyState); 0120 0121 private: 0122 void loadResource(String &url); 0123 void updateLoadState(); 0124 0125 void updateVolume(); 0126 void updatePlayState(); 0127 bool endedPlayback() const; 0128 0129 protected: 0130 float m_defaultPlaybackRate; 0131 NetworkState m_networkState; 0132 ReadyState m_readyState; 0133 String m_currentSrc; 0134 0135 RefPtr<MediaError> m_error; 0136 0137 bool m_begun; 0138 bool m_loadedFirstFrame; 0139 bool m_autoplaying; 0140 bool m_autobuffer; 0141 0142 float m_volume; 0143 bool m_muted; 0144 0145 bool m_paused; 0146 bool m_seeking; 0147 0148 float m_currentTimeDuringSeek; 0149 0150 unsigned m_previousProgress; 0151 double m_previousProgressTime; 0152 bool m_sentStalledEvent; 0153 0154 QPointer<MediaPlayer> m_player; 0155 }; 0156 0157 } //namespace 0158 0159 #endif