Home | History | Annotate | Download | only in shadow
      1 /*
      2  * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
      3  * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      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  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #ifndef MediaControls_h
     28 #define MediaControls_h
     29 
     30 #include "core/html/HTMLDivElement.h"
     31 #include "core/html/shadow/MediaControlElements.h"
     32 
     33 namespace WebCore {
     34 
     35 class Document;
     36 class Event;
     37 
     38 class MediaControls FINAL : public HTMLDivElement {
     39 public:
     40     static PassRefPtrWillBeRawPtr<MediaControls> create(HTMLMediaElement&);
     41 
     42     HTMLMediaElement& mediaElement() const { return *m_mediaElement; }
     43 
     44     void reset();
     45 
     46     void show();
     47     void hide();
     48 
     49     void playbackStarted();
     50     void playbackProgressed();
     51     void playbackStopped();
     52 
     53     void beginScrubbing();
     54     void endScrubbing();
     55 
     56     void updateCurrentTimeDisplay();
     57 
     58     void updateVolume();
     59 
     60     void changedClosedCaptionsVisibility();
     61     void refreshClosedCaptionsButtonVisibility();
     62     void closedCaptionTracksChanged();
     63 
     64     void enteredFullscreen();
     65     void exitedFullscreen();
     66 
     67     void updateTextTrackDisplay();
     68 
     69     void mediaElementFocused();
     70 
     71     virtual void trace(Visitor*) OVERRIDE;
     72 
     73 private:
     74     explicit MediaControls(HTMLMediaElement&);
     75 
     76     bool initializeControls();
     77 
     78     void makeOpaque();
     79     void makeTransparent();
     80 
     81     void updatePlayState();
     82 
     83     enum HideBehaviorFlags {
     84         IgnoreVideoHover = 1 << 0,
     85         IgnoreFocus = 1 << 1,
     86         IgnoreControlsHover = 1 << 2
     87     };
     88 
     89     bool shouldHideMediaControls(unsigned behaviorFlags = 0) const;
     90     void hideMediaControlsTimerFired(Timer<MediaControls>*);
     91     void startHideMediaControlsTimer();
     92     void stopHideMediaControlsTimer();
     93 
     94     void createTextTrackDisplay();
     95     void showTextTrackDisplay();
     96     void hideTextTrackDisplay();
     97 
     98     // Node
     99     virtual bool isMediaControls() const OVERRIDE { return true; }
    100     virtual bool willRespondToMouseMoveEvents() OVERRIDE { return true; }
    101     virtual void defaultEventHandler(Event*) OVERRIDE;
    102     bool containsRelatedTarget(Event*);
    103 
    104     // Element
    105     virtual const AtomicString& shadowPseudoId() const OVERRIDE;
    106 
    107     RawPtrWillBeMember<HTMLMediaElement> m_mediaElement;
    108 
    109     // Container for the media control elements.
    110     RawPtrWillBeMember<MediaControlPanelElement> m_panel;
    111 
    112     // Container for the text track cues.
    113     RawPtrWillBeMember<MediaControlTextTrackContainerElement> m_textDisplayContainer;
    114 
    115     // Media control elements.
    116     RawPtrWillBeMember<MediaControlOverlayPlayButtonElement> m_overlayPlayButton;
    117     RawPtrWillBeMember<MediaControlOverlayEnclosureElement> m_overlayEnclosure;
    118     RawPtrWillBeMember<MediaControlPlayButtonElement> m_playButton;
    119     RawPtrWillBeMember<MediaControlCurrentTimeDisplayElement> m_currentTimeDisplay;
    120     RawPtrWillBeMember<MediaControlTimelineElement> m_timeline;
    121     RawPtrWillBeMember<MediaControlMuteButtonElement> m_muteButton;
    122     RawPtrWillBeMember<MediaControlVolumeSliderElement> m_volumeSlider;
    123     RawPtrWillBeMember<MediaControlToggleClosedCaptionsButtonElement> m_toggleClosedCaptionsButton;
    124     RawPtrWillBeMember<MediaControlFullscreenButtonElement> m_fullScreenButton;
    125     RawPtrWillBeMember<MediaControlTimeRemainingDisplayElement> m_durationDisplay;
    126     RawPtrWillBeMember<MediaControlPanelEnclosureElement> m_enclosure;
    127 
    128     Timer<MediaControls> m_hideMediaControlsTimer;
    129     bool m_isMouseOverControls : 1;
    130     bool m_isPausedForScrubbing : 1;
    131 };
    132 
    133 DEFINE_ELEMENT_TYPE_CASTS(MediaControls, isMediaControls());
    134 
    135 }
    136 
    137 #endif
    138