Home | History | Annotate | Download | only in rendering
      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     MediaShowClosedCaptionsButton,
     58     MediaHideClosedCaptionsButton,
     59     MediaUnMuteButton,
     60     MediaPauseButton,
     61     MediaTimelineContainer,
     62     MediaCurrentTimeDisplay,
     63     MediaTimeRemainingDisplay,
     64     MediaStatusDisplay,
     65     MediaControlsPanel,
     66     MediaVolumeSliderContainer,
     67     MediaVolumeSlider,
     68     MediaVolumeSliderThumb
     69 };
     70 
     71 HTMLMediaElement* toParentMediaElement(RenderObject*);
     72 
     73 class MediaControlShadowRootElement : public HTMLDivElement {
     74 public:
     75     MediaControlShadowRootElement(Document*, HTMLMediaElement*);
     76 
     77     virtual bool isShadowNode() const { return true; }
     78     virtual Node* shadowParentNode() { return m_mediaElement; }
     79 
     80     void updateStyle();
     81 
     82 private:
     83     HTMLMediaElement* m_mediaElement;
     84 };
     85 
     86 // ----------------------------
     87 
     88 class MediaControlElement : public HTMLDivElement {
     89 public:
     90     MediaControlElement(Document*, PseudoId, HTMLMediaElement*);
     91     virtual void attach();
     92     virtual bool rendererIsNeeded(RenderStyle*);
     93 
     94     virtual PassRefPtr<RenderStyle> styleForElement();
     95     void attachToParent(Element*);
     96     void update();
     97     virtual void updateStyle();
     98 
     99     MediaControlElementType displayType() const { return m_displayType; }
    100 
    101     HTMLMediaElement* mediaElement() const { return m_mediaElement; }
    102     virtual bool isMediaControlElement() const { return true; }
    103 
    104 protected:
    105     HTMLMediaElement* m_mediaElement;
    106     PseudoId m_pseudoStyleId;
    107     MediaControlElementType m_displayType;  // some elements can show multiple types (e.g. play/pause)
    108 };
    109 
    110 // ----------------------------
    111 
    112 class MediaControlTimelineContainerElement : public MediaControlElement {
    113 public:
    114     MediaControlTimelineContainerElement(Document*, HTMLMediaElement*);
    115     virtual bool rendererIsNeeded(RenderStyle*);
    116 };
    117 
    118 // ----------------------------
    119 
    120 class MediaControlVolumeSliderContainerElement : public MediaControlElement {
    121 public:
    122     MediaControlVolumeSliderContainerElement(Document*, HTMLMediaElement*);
    123     virtual PassRefPtr<RenderStyle> styleForElement();
    124     void setVisible(bool);
    125     bool isVisible() { return m_isVisible; }
    126     void setPosition(int x, int y);
    127     bool hitTest(const IntPoint& absPoint);
    128 
    129 private:
    130     bool m_isVisible;
    131     int m_x, m_y;
    132 };
    133 
    134 // ----------------------------
    135 
    136 class MediaControlStatusDisplayElement : public MediaControlElement {
    137 public:
    138     MediaControlStatusDisplayElement(Document*, HTMLMediaElement*);
    139     virtual void update();
    140     virtual bool rendererIsNeeded(RenderStyle*);
    141 private:
    142     enum StateBeingDisplayed { Nothing, Loading, LiveBroadcast };
    143     StateBeingDisplayed m_stateBeingDisplayed;
    144 };
    145 
    146 // ----------------------------
    147 
    148 class MediaControlInputElement : public HTMLInputElement {
    149 public:
    150     MediaControlInputElement(Document*, PseudoId, const String& type, HTMLMediaElement*);
    151     virtual void attach();
    152     virtual bool rendererIsNeeded(RenderStyle*);
    153 
    154     virtual PassRefPtr<RenderStyle> styleForElement();
    155     void attachToParent(Element*);
    156     void update();
    157     void updateStyle();
    158 
    159     bool hitTest(const IntPoint& absPoint);
    160     MediaControlElementType displayType() const { return m_displayType; }
    161 
    162     HTMLMediaElement* mediaElement() const { return m_mediaElement; }
    163     virtual bool isMediaControlElement() const { return true; }
    164 
    165 protected:
    166     virtual void updateDisplayType() { }
    167     void setDisplayType(MediaControlElementType);
    168 
    169     HTMLMediaElement* m_mediaElement;
    170     PseudoId m_pseudoStyleId;
    171     MediaControlElementType m_displayType;
    172 };
    173 
    174 // ----------------------------
    175 
    176 class MediaControlMuteButtonElement : public MediaControlInputElement {
    177 public:
    178     MediaControlMuteButtonElement(Document*, HTMLMediaElement*);
    179     virtual void defaultEventHandler(Event*);
    180     virtual void updateDisplayType();
    181 };
    182 
    183 // ----------------------------
    184 
    185 class MediaControlPlayButtonElement : public MediaControlInputElement {
    186 public:
    187     MediaControlPlayButtonElement(Document*, HTMLMediaElement*);
    188     virtual void defaultEventHandler(Event*);
    189     virtual void updateDisplayType();
    190 };
    191 
    192 // ----------------------------
    193 
    194 class MediaControlSeekButtonElement : public MediaControlInputElement {
    195 public:
    196     MediaControlSeekButtonElement(Document*, HTMLMediaElement*, bool forward);
    197     virtual void defaultEventHandler(Event*);
    198     virtual void detach();
    199     void seekTimerFired(Timer<MediaControlSeekButtonElement>*);
    200 
    201 private:
    202     bool m_forward;
    203     bool m_seeking;
    204     bool m_capturing;
    205     Timer<MediaControlSeekButtonElement> m_seekTimer;
    206 };
    207 
    208 // ----------------------------
    209 
    210 class MediaControlRewindButtonElement : public MediaControlInputElement {
    211 public:
    212     MediaControlRewindButtonElement(Document*, HTMLMediaElement*);
    213     virtual void defaultEventHandler(Event*);
    214 };
    215 
    216 // ----------------------------
    217 
    218 class MediaControlReturnToRealtimeButtonElement : public MediaControlInputElement {
    219 public:
    220     MediaControlReturnToRealtimeButtonElement(Document*, HTMLMediaElement*);
    221     virtual void defaultEventHandler(Event*);
    222 };
    223 
    224 // ----------------------------
    225 
    226 class MediaControlToggleClosedCaptionsButtonElement : public MediaControlInputElement {
    227 public:
    228     MediaControlToggleClosedCaptionsButtonElement(Document*, HTMLMediaElement*);
    229     virtual void defaultEventHandler(Event*);
    230     virtual void updateDisplayType();
    231 };
    232 
    233 // ----------------------------
    234 
    235 class MediaControlTimelineElement : public MediaControlInputElement {
    236 public:
    237     MediaControlTimelineElement(Document*, HTMLMediaElement*);
    238     virtual void defaultEventHandler(Event*);
    239     void update(bool updateDuration = true);
    240 };
    241 
    242 // ----------------------------
    243 
    244 class MediaControlVolumeSliderElement : public MediaControlInputElement {
    245 public:
    246     MediaControlVolumeSliderElement(Document*, HTMLMediaElement*);
    247     virtual void defaultEventHandler(Event*);
    248     virtual void update();
    249 };
    250 
    251 // ----------------------------
    252 
    253 class MediaControlFullscreenButtonElement : public MediaControlInputElement {
    254 public:
    255     MediaControlFullscreenButtonElement(Document*, HTMLMediaElement*);
    256     virtual void defaultEventHandler(Event*);
    257 };
    258 
    259 // ----------------------------
    260 
    261 class MediaControlTimeDisplayElement : public MediaControlElement {
    262 public:
    263     MediaControlTimeDisplayElement(Document*, PseudoId, HTMLMediaElement*);
    264     void setVisible(bool);
    265     virtual PassRefPtr<RenderStyle> styleForElement();
    266 
    267     void setCurrentValue(float);
    268     float currentValue() const { return m_currentValue; }
    269 
    270 private:
    271     float m_currentValue;
    272     bool m_isVisible;
    273 };
    274 
    275 // ----------------------------
    276 
    277 class RenderMediaControlShadowRoot : public RenderBlock {
    278 public:
    279     RenderMediaControlShadowRoot(Element* e) : RenderBlock(e) { }
    280     void setParent(RenderObject* p) { RenderObject::setParent(p); }
    281 };
    282 
    283 // ----------------------------
    284 
    285 
    286 } //namespace WebCore
    287 #endif // enable(video)
    288 #endif // MediaControlElements_h
    289