blob: 771f820810eccd6efac4a3e7cad5887d38b785ae [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 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 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef MediaControlElementTypes_h
31#define MediaControlElementTypes_h
32
33#include "core/html/HTMLDivElement.h"
34#include "core/html/HTMLInputElement.h"
35#include "core/html/HTMLMediaElement.h"
36#include "core/html/MediaControllerInterface.h"
37#include "core/rendering/RenderBlock.h"
38
39namespace WebCore {
40
41// Must match WebKitSystemInterface.h
42enum MediaControlElementType {
43 MediaEnterFullscreenButton = 0,
44 MediaMuteButton,
45 MediaPlayButton,
46 MediaSeekBackButton,
47 MediaSeekForwardButton,
48 MediaSlider,
49 MediaSliderThumb,
50 MediaRewindButton,
51 MediaReturnToRealtimeButton,
52 MediaShowClosedCaptionsButton,
53 MediaHideClosedCaptionsButton,
54 MediaUnMuteButton,
55 MediaPauseButton,
56 MediaTimelineContainer,
57 MediaCurrentTimeDisplay,
58 MediaTimeRemainingDisplay,
59 MediaStatusDisplay,
60 MediaControlsPanel,
61 MediaVolumeSliderContainer,
62 MediaVolumeSlider,
63 MediaVolumeSliderThumb,
64 MediaFullScreenVolumeSlider,
65 MediaFullScreenVolumeSliderThumb,
66 MediaVolumeSliderMuteButton,
67 MediaTextTrackDisplayContainer,
68 MediaTextTrackDisplay,
69 MediaExitFullscreenButton,
70 MediaOverlayPlayButton,
71 MediaClosedCaptionsContainer,
72 MediaClosedCaptionsTrackList,
73};
74
75HTMLMediaElement* toParentMediaElement(Node*);
76inline HTMLMediaElement* toParentMediaElement(RenderObject* renderer) { return toParentMediaElement(renderer->node()); }
77
78MediaControlElementType mediaControlElementType(Node*);
79
80const AtomicString& trackIndexAttributeName();
81int trackListIndexForElement(Element*);
82
83// ----------------------------
84
85class MediaControlElement {
86public:
87 virtual void hide();
88 virtual void show();
89 virtual bool isShowing() const;
90
91 virtual MediaControlElementType displayType() { return m_displayType; }
92 virtual const AtomicString& shadowPseudoId() const = 0;
93
94 virtual void setMediaController(MediaControllerInterface* controller) { m_mediaController = controller; }
95 virtual MediaControllerInterface* mediaController() const { return m_mediaController; }
96
97protected:
98 explicit MediaControlElement(MediaControlElementType, HTMLElement*);
99 ~MediaControlElement() { }
100
101 virtual void setDisplayType(MediaControlElementType);
102 virtual bool isMediaControlElement() const { return true; }
103
104private:
105 MediaControllerInterface* m_mediaController;
106 MediaControlElementType m_displayType;
107 HTMLElement* m_element;
108};
109
110// ----------------------------
111
112class MediaControlDivElement : public HTMLDivElement, public MediaControlElement {
113protected:
114 virtual bool isMediaControlElement() const OVERRIDE { return MediaControlElement::isMediaControlElement(); }
115 explicit MediaControlDivElement(Document*, MediaControlElementType);
116};
117
118// ----------------------------
119
120class MediaControlInputElement : public HTMLInputElement, public MediaControlElement {
121protected:
122 virtual bool isMediaControlElement() const OVERRIDE { return MediaControlElement::isMediaControlElement(); }
123 explicit MediaControlInputElement(Document*, MediaControlElementType);
124
125private:
126 virtual void updateDisplayType() { }
127};
128
129// ----------------------------
130
131class MediaControlTimeDisplayElement : public MediaControlDivElement {
132public:
133 void setCurrentValue(double);
134 double currentValue() const { return m_currentValue; }
135
136protected:
137 explicit MediaControlTimeDisplayElement(Document*, MediaControlElementType);
138
139private:
140 double m_currentValue;
141};
142
143// ----------------------------
144
145class MediaControlMuteButtonElement : public MediaControlInputElement {
146public:
147 void changedMute();
148
149 virtual bool willRespondToMouseClickEvents() OVERRIDE { return true; }
150
151protected:
152 explicit MediaControlMuteButtonElement(Document*, MediaControlElementType);
153
154 virtual void defaultEventHandler(Event*) OVERRIDE;
155
156private:
157 virtual void updateDisplayType() OVERRIDE;
158};
159
160// ----------------------------
161
162class MediaControlSeekButtonElement : public MediaControlInputElement {
163public:
164 virtual bool willRespondToMouseClickEvents() OVERRIDE { return true; }
165
166protected:
167 explicit MediaControlSeekButtonElement(Document*, MediaControlElementType);
168
169 virtual void defaultEventHandler(Event*) OVERRIDE;
170 virtual bool isForwardButton() const = 0;
171
172private:
173 void setActive(bool /*flag*/ = true, bool /*pause*/ = false);
174
175 void startTimer();
176 void stopTimer();
177 double nextRate() const;
178 void seekTimerFired(Timer<MediaControlSeekButtonElement>*);
179
180 enum ActionType { Nothing, Play, Pause };
181 ActionType m_actionOnStop;
182 enum SeekType { Skip, Scan };
183 SeekType m_seekType;
184 Timer<MediaControlSeekButtonElement> m_seekTimer;
185};
186
187// ----------------------------
188
189class MediaControlVolumeSliderElement : public MediaControlInputElement {
190public:
191 virtual bool willRespondToMouseMoveEvents() OVERRIDE;
192 virtual bool willRespondToMouseClickEvents() OVERRIDE;
193 void setVolume(double);
194 void setClearMutedOnUserInteraction(bool);
195
196protected:
197 explicit MediaControlVolumeSliderElement(Document*);
198
199 virtual void defaultEventHandler(Event*) OVERRIDE;
200
201private:
202 bool m_clearMutedOnUserInteraction;
203};
204
205} // namespace WebCore
206
207#endif // MediaControlElementTypes_h