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 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 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#if ENABLE(VIDEO)
31
32#include "Chrome.h"
33#include "HTMLDivElement.h"
34#include "MediaControlElements.h"
35#include "MouseEvent.h"
36#include "Page.h"
37#include "RenderTheme.h"
38#include "Text.h"
39#include <wtf/RefPtr.h>
40
41#if ENABLE(VIDEO_TRACK)
42#include "TextTrackCue.h"
43#endif
44
45namespace WebCore {
46
47class Document;
48class Event;
49class Page;
50class MediaPlayer;
51
52class RenderBox;
53class RenderMedia;
54
55// An abstract class with the media control elements that all ports support.
56class MediaControls : public HTMLDivElement {
57  public:
58    virtual ~MediaControls() {}
59
60    // This function is to be implemented in your port-specific media
61    // controls implementation since it will return a child instance.
62    static PassRefPtr<MediaControls> create(Document&);
63
64    virtual void setMediaController(MediaControllerInterface*);
65
66    virtual void reset();
67    virtual void reportedError();
68    virtual void loadedMetadata();
69
70    virtual void show();
71    virtual void hide();
72    virtual void makeOpaque();
73    virtual void makeTransparent();
74    virtual bool shouldHideControls();
75
76    virtual void bufferingProgressed();
77    virtual void playbackStarted();
78    virtual void playbackProgressed();
79    virtual void playbackStopped();
80
81    virtual void updateStatusDisplay() { };
82    virtual void updateCurrentTimeDisplay();
83    virtual void showVolumeSlider();
84
85    virtual void changedMute();
86    virtual void changedVolume();
87
88    virtual void changedClosedCaptionsVisibility();
89    virtual void refreshClosedCaptionsButtonVisibility();
90    virtual void toggleClosedCaptionTrackList() { }
91    virtual void closedCaptionTracksChanged();
92
93    virtual void enteredFullscreen();
94    virtual void exitedFullscreen();
95
96#if !PLATFORM(IOS)
97    virtual bool willRespondToMouseMoveEvents() override { return true; }
98#endif
99
100    virtual void hideFullscreenControlsTimerFired(Timer<MediaControls>&);
101    virtual void startHideFullscreenControlsTimer();
102    virtual void stopHideFullscreenControlsTimer();
103
104#if ENABLE(VIDEO_TRACK)
105    virtual void createTextTrackDisplay();
106    virtual void showTextTrackDisplay();
107    virtual void hideTextTrackDisplay();
108    virtual void updateTextTrackDisplay();
109    virtual void textTrackPreferencesChanged();
110#endif
111
112protected:
113    explicit MediaControls(Document&);
114
115    virtual void defaultEventHandler(Event*) override;
116
117    virtual bool containsRelatedTarget(Event*);
118
119    void setSliderVolume();
120
121    MediaControllerInterface* m_mediaController;
122
123    // Container for the media control elements.
124    MediaControlPanelElement* m_panel;
125
126    // Container for the text track cues.
127#if ENABLE(VIDEO_TRACK)
128    MediaControlTextTrackContainerElement* m_textDisplayContainer;
129#endif
130
131    // Media control elements.
132    MediaControlPlayButtonElement* m_playButton;
133    MediaControlCurrentTimeDisplayElement* m_currentTimeDisplay;
134    MediaControlTimelineElement* m_timeline;
135    MediaControlPanelMuteButtonElement* m_panelMuteButton;
136    MediaControlPanelVolumeSliderElement* m_volumeSlider;
137    MediaControlToggleClosedCaptionsButtonElement* m_toggleClosedCaptionsButton;
138    MediaControlFullscreenButtonElement* m_fullScreenButton;
139
140    Timer<MediaControls> m_hideFullscreenControlsTimer;
141    bool m_isFullscreen;
142    bool m_isMouseOverControls;
143
144private:
145    virtual bool isMediaControls() const override { return true; }
146
147    virtual const AtomicString& shadowPseudoId() const override;
148};
149
150inline MediaControls* toMediaControls(Node* node)
151{
152    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isMediaControls());
153    return static_cast<MediaControls*>(node);
154}
155
156// This will catch anyone doing an unneccessary cast.
157void toMediaControls(const MediaControls*);
158
159}
160
161#endif
162
163#endif
164