Home | History | Annotate | Download | only in shadow
      1 /*
      2  * Copyright (C) 2008, 2009, 2010 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 class MediaControls;
     46 
     47 // Must match WebKitSystemInterface.h
     48 enum MediaControlElementType {
     49     MediaFullscreenButton = 0,
     50     MediaMuteButton,
     51     MediaPlayButton,
     52     MediaSeekBackButton,
     53     MediaSeekForwardButton,
     54     MediaSlider,
     55     MediaSliderThumb,
     56     MediaRewindButton,
     57     MediaReturnToRealtimeButton,
     58     MediaShowClosedCaptionsButton,
     59     MediaHideClosedCaptionsButton,
     60     MediaUnMuteButton,
     61     MediaPauseButton,
     62     MediaTimelineContainer,
     63     MediaCurrentTimeDisplay,
     64     MediaTimeRemainingDisplay,
     65     MediaStatusDisplay,
     66     MediaControlsPanel,
     67     MediaVolumeSliderContainer,
     68     MediaVolumeSlider,
     69     MediaVolumeSliderThumb,
     70     MediaVolumeSliderMuteButton,
     71 };
     72 
     73 HTMLMediaElement* toParentMediaElement(RenderObject*);
     74 
     75 // ----------------------------
     76 
     77 class MediaControlElement : public HTMLDivElement {
     78 public:
     79     void hide();
     80     void show();
     81 
     82     virtual MediaControlElementType displayType() const = 0;
     83 
     84     HTMLMediaElement* mediaElement() const { return m_mediaElement; }
     85 
     86 protected:
     87     MediaControlElement(HTMLMediaElement*);
     88 
     89 private:
     90     virtual bool isMediaControlElement() const { return true; }
     91 
     92     HTMLMediaElement* m_mediaElement;
     93 };
     94 
     95 // ----------------------------
     96 
     97 class MediaControlPanelElement : public MediaControlElement {
     98 public:
     99     static PassRefPtr<MediaControlPanelElement> create(HTMLMediaElement*);
    100 
    101 private:
    102     MediaControlPanelElement(HTMLMediaElement*);
    103     virtual MediaControlElementType displayType() const;
    104     virtual const AtomicString& shadowPseudoId() const;
    105 };
    106 
    107 // ----------------------------
    108 
    109 class MediaControlTimelineContainerElement : public MediaControlElement {
    110 public:
    111     static PassRefPtr<MediaControlTimelineContainerElement> create(HTMLMediaElement*);
    112 
    113 private:
    114     MediaControlTimelineContainerElement(HTMLMediaElement*);
    115     virtual const AtomicString& shadowPseudoId() const;
    116 
    117     virtual MediaControlElementType displayType() const;
    118 };
    119 
    120 // ----------------------------
    121 
    122 class MediaControlVolumeSliderContainerElement : public MediaControlElement {
    123 public:
    124     static PassRefPtr<MediaControlVolumeSliderContainerElement> create(HTMLMediaElement*);
    125 
    126 private:
    127     MediaControlVolumeSliderContainerElement(HTMLMediaElement*);
    128     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    129     virtual void defaultEventHandler(Event*);
    130     virtual MediaControlElementType displayType() const;
    131     virtual const AtomicString& shadowPseudoId() const;
    132 };
    133 
    134 // ----------------------------
    135 
    136 class MediaControlStatusDisplayElement : public MediaControlElement {
    137 public:
    138     static PassRefPtr<MediaControlStatusDisplayElement> create(HTMLMediaElement*);
    139 
    140     void update();
    141 
    142 private:
    143     MediaControlStatusDisplayElement(HTMLMediaElement*);
    144 
    145     virtual MediaControlElementType displayType() const;
    146     virtual const AtomicString& shadowPseudoId() const;
    147 
    148     enum StateBeingDisplayed { Nothing, Loading, LiveBroadcast };
    149     StateBeingDisplayed m_stateBeingDisplayed;
    150 };
    151 
    152 // ----------------------------
    153 
    154 class MediaControlInputElement : public HTMLInputElement {
    155 public:
    156     void hide();
    157     void show();
    158 
    159     MediaControlElementType displayType() const { return m_displayType; }
    160 
    161     HTMLMediaElement* mediaElement() const { return m_mediaElement; }
    162 
    163 protected:
    164     MediaControlInputElement(HTMLMediaElement*, MediaControlElementType);
    165 
    166     void setDisplayType(MediaControlElementType);
    167 
    168 private:
    169     virtual bool isMediaControlElement() const { return true; }
    170 
    171     virtual void updateDisplayType() { }
    172 
    173     HTMLMediaElement* m_mediaElement;
    174     MediaControlElementType m_displayType;
    175 };
    176 
    177 // ----------------------------
    178 
    179 class MediaControlMuteButtonElement : public MediaControlInputElement {
    180 public:
    181     void changedMute();
    182 
    183 protected:
    184     MediaControlMuteButtonElement(HTMLMediaElement*, MediaControlElementType);
    185     virtual void defaultEventHandler(Event*);
    186 
    187 
    188 private:
    189     virtual void updateDisplayType();
    190 };
    191 
    192 // ----------------------------
    193 
    194 class MediaControlPanelMuteButtonElement : public MediaControlMuteButtonElement {
    195 public:
    196     static PassRefPtr<MediaControlPanelMuteButtonElement> create(HTMLMediaElement*, MediaControls*);
    197 
    198 private:
    199     MediaControlPanelMuteButtonElement(HTMLMediaElement*, MediaControls*);
    200 
    201     virtual void defaultEventHandler(Event*);
    202     virtual const AtomicString& shadowPseudoId() const;
    203 
    204     MediaControls* m_controls;
    205 };
    206 
    207 // ----------------------------
    208 
    209 class MediaControlVolumeSliderMuteButtonElement : public MediaControlMuteButtonElement {
    210 public:
    211     static PassRefPtr<MediaControlVolumeSliderMuteButtonElement> create(HTMLMediaElement*);
    212 
    213 private:
    214     MediaControlVolumeSliderMuteButtonElement(HTMLMediaElement*);
    215 
    216     virtual const AtomicString& shadowPseudoId() const;
    217 };
    218 
    219 
    220 // ----------------------------
    221 
    222 class MediaControlPlayButtonElement : public MediaControlInputElement {
    223 public:
    224     static PassRefPtr<MediaControlPlayButtonElement> create(HTMLMediaElement*);
    225 
    226     virtual void defaultEventHandler(Event*);
    227     virtual void updateDisplayType();
    228 
    229 private:
    230     MediaControlPlayButtonElement(HTMLMediaElement*);
    231 
    232     virtual const AtomicString& shadowPseudoId() const;
    233 };
    234 
    235 // ----------------------------
    236 
    237 class MediaControlSeekButtonElement : public MediaControlInputElement {
    238 public:
    239     virtual void defaultEventHandler(Event*);
    240 
    241 protected:
    242     MediaControlSeekButtonElement(HTMLMediaElement*, MediaControlElementType);
    243 
    244 private:
    245     virtual bool isForwardButton() const = 0;
    246 
    247     virtual void detach();
    248     void seekTimerFired(Timer<MediaControlSeekButtonElement>*);
    249 
    250     bool m_seeking;
    251     bool m_capturing;
    252     Timer<MediaControlSeekButtonElement> m_seekTimer;
    253 };
    254 
    255 // ----------------------------
    256 
    257 class MediaControlSeekForwardButtonElement : public MediaControlSeekButtonElement {
    258 public:
    259     static PassRefPtr<MediaControlSeekForwardButtonElement> create(HTMLMediaElement*);
    260 
    261 private:
    262     MediaControlSeekForwardButtonElement(HTMLMediaElement*);
    263 
    264     virtual bool isForwardButton() const { return true; }
    265     virtual const AtomicString& shadowPseudoId() const;
    266 };
    267 
    268 // ----------------------------
    269 
    270 class MediaControlSeekBackButtonElement : public MediaControlSeekButtonElement {
    271 public:
    272     static PassRefPtr<MediaControlSeekBackButtonElement> create(HTMLMediaElement*);
    273 
    274 private:
    275     MediaControlSeekBackButtonElement(HTMLMediaElement*);
    276 
    277     virtual bool isForwardButton() const { return false; }
    278     virtual const AtomicString& shadowPseudoId() const;
    279 };
    280 
    281 // ----------------------------
    282 
    283 class MediaControlRewindButtonElement : public MediaControlInputElement {
    284 public:
    285     static PassRefPtr<MediaControlRewindButtonElement> create(HTMLMediaElement*);
    286 
    287     virtual void defaultEventHandler(Event*);
    288 
    289 private:
    290     MediaControlRewindButtonElement(HTMLMediaElement*);
    291 
    292     virtual const AtomicString& shadowPseudoId() const;
    293 };
    294 
    295 // ----------------------------
    296 
    297 class MediaControlReturnToRealtimeButtonElement : public MediaControlInputElement {
    298 public:
    299     static PassRefPtr<MediaControlReturnToRealtimeButtonElement> create(HTMLMediaElement*);
    300 
    301     virtual void defaultEventHandler(Event*);
    302 
    303 private:
    304     MediaControlReturnToRealtimeButtonElement(HTMLMediaElement*);
    305 
    306     virtual const AtomicString& shadowPseudoId() const;
    307 };
    308 
    309 // ----------------------------
    310 
    311 class MediaControlToggleClosedCaptionsButtonElement : public MediaControlInputElement {
    312 public:
    313     static PassRefPtr<MediaControlToggleClosedCaptionsButtonElement> create(HTMLMediaElement*);
    314 
    315     virtual void defaultEventHandler(Event*);
    316     virtual void updateDisplayType();
    317 
    318 private:
    319     MediaControlToggleClosedCaptionsButtonElement(HTMLMediaElement*);
    320 
    321     virtual const AtomicString& shadowPseudoId() const;
    322 };
    323 
    324 // ----------------------------
    325 
    326 class MediaControlTimelineElement : public MediaControlInputElement {
    327 public:
    328     static PassRefPtr<MediaControlTimelineElement> create(HTMLMediaElement*, MediaControls*);
    329 
    330     virtual void defaultEventHandler(Event*);
    331     void setPosition(float);
    332     void setDuration(float);
    333 
    334 private:
    335     MediaControlTimelineElement(HTMLMediaElement*, MediaControls*);
    336 
    337     virtual const AtomicString& shadowPseudoId() const;
    338 
    339     MediaControls* m_controls;
    340 };
    341 
    342 // ----------------------------
    343 
    344 class MediaControlVolumeSliderElement : public MediaControlInputElement {
    345 public:
    346     static PassRefPtr<MediaControlVolumeSliderElement> create(HTMLMediaElement*);
    347 
    348     virtual void defaultEventHandler(Event*);
    349     void setVolume(float);
    350 
    351 protected:
    352     MediaControlVolumeSliderElement(HTMLMediaElement*);
    353 
    354 private:
    355     virtual const AtomicString& shadowPseudoId() const;
    356 };
    357 
    358 // ----------------------------
    359 
    360 class MediaControlFullscreenButtonElement : public MediaControlInputElement {
    361 public:
    362     static PassRefPtr<MediaControlFullscreenButtonElement> create(HTMLMediaElement*, MediaControls*);
    363 
    364     virtual void defaultEventHandler(Event*);
    365 
    366 private:
    367     MediaControlFullscreenButtonElement(HTMLMediaElement*, MediaControls*);
    368 
    369     virtual const AtomicString& shadowPseudoId() const;
    370 
    371     MediaControls* m_controls;
    372 };
    373 
    374 // ----------------------------
    375 
    376 class MediaControlFullscreenVolumeSliderElement : public MediaControlVolumeSliderElement {
    377 public:
    378     static PassRefPtr<MediaControlFullscreenVolumeSliderElement> create(HTMLMediaElement*);
    379 
    380 private:
    381     MediaControlFullscreenVolumeSliderElement(HTMLMediaElement*);
    382 
    383     virtual const AtomicString& shadowPseudoId() const;
    384 };
    385 
    386 // ----------------------------
    387 
    388 class MediaControlFullscreenVolumeMinButtonElement : public MediaControlInputElement {
    389 public:
    390     static PassRefPtr<MediaControlFullscreenVolumeMinButtonElement> create(HTMLMediaElement*);
    391 
    392     virtual void defaultEventHandler(Event*);
    393 
    394 private:
    395     MediaControlFullscreenVolumeMinButtonElement(HTMLMediaElement*);
    396 
    397     virtual const AtomicString& shadowPseudoId() const;
    398 };
    399 
    400 // ----------------------------
    401 
    402 class MediaControlFullscreenVolumeMaxButtonElement : public MediaControlInputElement {
    403 public:
    404     static PassRefPtr<MediaControlFullscreenVolumeMaxButtonElement> create(HTMLMediaElement*);
    405 
    406     virtual void defaultEventHandler(Event*);
    407 
    408 private:
    409     MediaControlFullscreenVolumeMaxButtonElement(HTMLMediaElement*);
    410 
    411     virtual const AtomicString& shadowPseudoId() const;
    412 };
    413 
    414 // ----------------------------
    415 
    416 class MediaControlTimeDisplayElement : public MediaControlElement {
    417 public:
    418     void setCurrentValue(float);
    419     float currentValue() const { return m_currentValue; }
    420 
    421 protected:
    422     MediaControlTimeDisplayElement(HTMLMediaElement*);
    423 
    424 private:
    425     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    426 
    427     float m_currentValue;
    428 };
    429 
    430 // ----------------------------
    431 
    432 class MediaControlTimeRemainingDisplayElement : public MediaControlTimeDisplayElement {
    433 public:
    434     static PassRefPtr<MediaControlTimeRemainingDisplayElement> create(HTMLMediaElement*);
    435 
    436 private:
    437     MediaControlTimeRemainingDisplayElement(HTMLMediaElement*);
    438 
    439     virtual MediaControlElementType displayType() const;
    440     virtual const AtomicString& shadowPseudoId() const;
    441 };
    442 
    443 // ----------------------------
    444 
    445 class MediaControlCurrentTimeDisplayElement : public MediaControlTimeDisplayElement {
    446 public:
    447     static PassRefPtr<MediaControlCurrentTimeDisplayElement> create(HTMLMediaElement*);
    448 
    449 private:
    450     MediaControlCurrentTimeDisplayElement(HTMLMediaElement*);
    451 
    452     virtual MediaControlElementType displayType() const;
    453     virtual const AtomicString& shadowPseudoId() const;
    454 };
    455 
    456 // ----------------------------
    457 
    458 } // namespace WebCore
    459 
    460 #endif // ENABLE(VIDEO)
    461 
    462 #endif // MediaControlElements_h
    463