1 /* 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. 3 * 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 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef MediaControlElements_h 30 #define MediaControlElements_h 31 32 #if ENABLE(VIDEO) 33 34 #include "HTMLDivElement.h" 35 #include "HTMLInputElement.h" 36 #include "HTMLMediaElement.h" 37 #include "RenderBlock.h" 38 39 // These are the shadow elements used in RenderMedia 40 41 namespace WebCore { 42 43 class Event; 44 class Frame; 45 46 // Must match WebKitSystemInterface.h 47 enum MediaControlElementType { 48 MediaFullscreenButton = 0, 49 MediaMuteButton, 50 MediaPlayButton, 51 MediaSeekBackButton, 52 MediaSeekForwardButton, 53 MediaSlider, 54 MediaSliderThumb, 55 MediaRewindButton, 56 MediaReturnToRealtimeButton, 57 MediaUnMuteButton, 58 MediaPauseButton, 59 MediaTimelineContainer, 60 MediaCurrentTimeDisplay, 61 MediaTimeRemainingDisplay, 62 MediaStatusDisplay, 63 MediaControlsPanel 64 }; 65 66 class MediaControlShadowRootElement : public HTMLDivElement { 67 public: 68 MediaControlShadowRootElement(Document*, HTMLMediaElement*); 69 isShadowNode()70 virtual bool isShadowNode() const { return true; } shadowParentNode()71 virtual Node* shadowParentNode() { return m_mediaElement; } 72 73 void updateStyle(); 74 75 private: 76 HTMLMediaElement* m_mediaElement; 77 }; 78 79 // ---------------------------- 80 81 class MediaControlElement : public HTMLDivElement { 82 public: 83 MediaControlElement(Document*, PseudoId, HTMLMediaElement*); 84 virtual void attach(); 85 virtual bool rendererIsNeeded(RenderStyle*); 86 87 virtual PassRefPtr<RenderStyle> styleForElement(); 88 void attachToParent(Element*); 89 void update(); 90 virtual void updateStyle(); 91 92 protected: 93 HTMLMediaElement* m_mediaElement; 94 PseudoId m_pseudoStyleId; 95 }; 96 97 // ---------------------------- 98 99 class MediaControlTimelineContainerElement : public MediaControlElement { 100 public: 101 MediaControlTimelineContainerElement(Document*, HTMLMediaElement*); 102 virtual bool rendererIsNeeded(RenderStyle*); 103 }; 104 105 // ---------------------------- 106 107 class MediaControlStatusDisplayElement : public MediaControlElement { 108 public: 109 MediaControlStatusDisplayElement(Document*, HTMLMediaElement*); 110 virtual void update(); 111 virtual bool rendererIsNeeded(RenderStyle*); 112 private: 113 enum StateBeingDisplayed { Nothing, Loading, LiveBroadcast }; 114 StateBeingDisplayed m_stateBeingDisplayed; 115 }; 116 117 // ---------------------------- 118 119 class MediaControlInputElement : public HTMLInputElement { 120 public: 121 MediaControlInputElement(Document*, PseudoId, const String& type, HTMLMediaElement*, MediaControlElementType); 122 virtual void attach(); 123 virtual bool rendererIsNeeded(RenderStyle*); 124 125 virtual PassRefPtr<RenderStyle> styleForElement(); 126 void attachToParent(Element*); 127 void update(); 128 void updateStyle(); 129 130 bool hitTest(const IntPoint& absPoint); displayType()131 MediaControlElementType displayType() const { return m_displayType; } 132 133 protected: updateDisplayType()134 virtual void updateDisplayType() { } 135 void setDisplayType(MediaControlElementType); 136 137 HTMLMediaElement* m_mediaElement; 138 PseudoId m_pseudoStyleId; 139 MediaControlElementType m_displayType; // some elements can show multiple types (e.g. play/pause) 140 }; 141 142 // ---------------------------- 143 144 class MediaControlMuteButtonElement : public MediaControlInputElement { 145 public: 146 MediaControlMuteButtonElement(Document*, HTMLMediaElement*); 147 virtual void defaultEventHandler(Event*); 148 virtual void updateDisplayType(); 149 }; 150 151 // ---------------------------- 152 153 class MediaControlPlayButtonElement : public MediaControlInputElement { 154 public: 155 MediaControlPlayButtonElement(Document*, HTMLMediaElement*); 156 virtual void defaultEventHandler(Event*); 157 virtual void updateDisplayType(); 158 }; 159 160 // ---------------------------- 161 162 class MediaControlSeekButtonElement : public MediaControlInputElement { 163 public: 164 MediaControlSeekButtonElement(Document*, HTMLMediaElement*, bool forward); 165 virtual void defaultEventHandler(Event*); 166 virtual void detach(); 167 void seekTimerFired(Timer<MediaControlSeekButtonElement>*); 168 169 private: 170 bool m_forward; 171 bool m_seeking; 172 bool m_capturing; 173 Timer<MediaControlSeekButtonElement> m_seekTimer; 174 }; 175 176 // ---------------------------- 177 178 class MediaControlRewindButtonElement : public MediaControlInputElement { 179 public: 180 MediaControlRewindButtonElement(Document*, HTMLMediaElement*); 181 virtual void defaultEventHandler(Event*); 182 virtual bool rendererIsNeeded(RenderStyle*); 183 }; 184 185 // ---------------------------- 186 187 class MediaControlReturnToRealtimeButtonElement : public MediaControlInputElement { 188 public: 189 MediaControlReturnToRealtimeButtonElement(Document*, HTMLMediaElement*); 190 virtual void defaultEventHandler(Event*); 191 virtual bool rendererIsNeeded(RenderStyle*); 192 }; 193 194 // ---------------------------- 195 196 class MediaControlTimelineElement : public MediaControlInputElement { 197 public: 198 MediaControlTimelineElement(Document*, HTMLMediaElement*); 199 virtual void defaultEventHandler(Event*); 200 void update(bool updateDuration = true); 201 }; 202 203 // ---------------------------- 204 205 class MediaControlFullscreenButtonElement : public MediaControlInputElement { 206 public: 207 MediaControlFullscreenButtonElement(Document*, HTMLMediaElement*); 208 virtual void defaultEventHandler(Event*); 209 virtual bool rendererIsNeeded(RenderStyle*); 210 }; 211 212 // ---------------------------- 213 214 class MediaControlTimeDisplayElement : public MediaControlElement { 215 public: 216 MediaControlTimeDisplayElement(Document*, PseudoId, HTMLMediaElement*); 217 void setVisible(bool); 218 virtual PassRefPtr<RenderStyle> styleForElement(); 219 220 private: 221 bool m_isVisible; 222 }; 223 224 // ---------------------------- 225 226 class RenderMediaControlShadowRoot : public RenderBlock { 227 public: RenderMediaControlShadowRoot(Element * e)228 RenderMediaControlShadowRoot(Element* e) : RenderBlock(e) { } setParent(RenderObject * p)229 void setParent(RenderObject* p) { RenderObject::setParent(p); } 230 }; 231 232 // ---------------------------- 233 234 235 } //namespace WebCore 236 #endif // enable(video) 237 #endif // MediaControlElements_h 238