cf0560efa9458f4908bfa09b37dbc945faae593e
[WebKit-https.git] / Source / WebCore / html / shadow / MediaControlElements.h
1 /*
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 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 #pragma once
31
32 #if ENABLE(VIDEO)
33
34 #include "MediaControlElementTypes.h"
35 #include "TextTrackRepresentation.h"
36
37 namespace WebCore {
38
39 // ----------------------------
40
41 class MediaControlPanelElement final : public MediaControlDivElement {
42     WTF_MAKE_ISO_ALLOCATED(MediaControlPanelElement);
43 public:
44     static Ref<MediaControlPanelElement> create(Document&);
45
46     void setCanBeDragged(bool);
47     void setIsDisplayed(bool);
48
49     void resetPosition();
50     void makeOpaque();
51     void makeTransparent();
52
53 #if !PLATFORM(IOS_FAMILY)
54     bool willRespondToMouseMoveEvents() override { return true; }
55     bool willRespondToMouseClickEvents() override { return true; }
56 #endif
57
58 private:
59     explicit MediaControlPanelElement(Document&);
60
61     void defaultEventHandler(Event&) override;
62
63     void startDrag(const LayoutPoint& eventLocation);
64     void continueDrag(const LayoutPoint& eventLocation);
65     void endDrag();
66
67     void startTimer();
68     void stopTimer();
69     void transitionTimerFired();
70
71     void setPosition(const LayoutPoint&);
72
73     bool m_canBeDragged;
74     bool m_isBeingDragged;
75     bool m_isDisplayed;
76     bool m_opaque;
77     LayoutPoint m_lastDragEventLocation;
78     LayoutPoint m_cumulativeDragOffset;
79
80     Timer m_transitionTimer;
81 };
82
83 // ----------------------------
84
85 class MediaControlPanelEnclosureElement final : public MediaControlDivElement {
86     WTF_MAKE_ISO_ALLOCATED(MediaControlPanelEnclosureElement);
87 public:
88     static Ref<MediaControlPanelEnclosureElement> create(Document&);
89
90 private:
91     explicit MediaControlPanelEnclosureElement(Document&);
92 };
93
94 // ----------------------------
95
96 class MediaControlOverlayEnclosureElement final : public MediaControlDivElement {
97     WTF_MAKE_ISO_ALLOCATED(MediaControlOverlayEnclosureElement);
98 public:
99     static Ref<MediaControlOverlayEnclosureElement> create(Document&);
100
101 private:
102     explicit MediaControlOverlayEnclosureElement(Document&);
103 };
104
105 // ----------------------------
106
107 class MediaControlTimelineContainerElement final : public MediaControlDivElement {
108     WTF_MAKE_ISO_ALLOCATED(MediaControlTimelineContainerElement);
109 public:
110     static Ref<MediaControlTimelineContainerElement> create(Document&);
111
112     void setTimeDisplaysHidden(bool);
113
114 private:
115     explicit MediaControlTimelineContainerElement(Document&);
116
117     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
118 };
119
120 // ----------------------------
121
122 class MediaControlVolumeSliderContainerElement final : public MediaControlDivElement {
123     WTF_MAKE_ISO_ALLOCATED(MediaControlVolumeSliderContainerElement);
124 public:
125     static Ref<MediaControlVolumeSliderContainerElement> create(Document&);
126
127 #if !PLATFORM(IOS_FAMILY)
128     bool willRespondToMouseMoveEvents() override { return true; }
129 #endif
130
131 private:
132     explicit MediaControlVolumeSliderContainerElement(Document&);
133
134     void defaultEventHandler(Event&) override;
135
136     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
137 };
138
139 // ----------------------------
140
141 class MediaControlStatusDisplayElement final : public MediaControlDivElement {
142     WTF_MAKE_ISO_ALLOCATED(MediaControlStatusDisplayElement);
143 public:
144     static Ref<MediaControlStatusDisplayElement> create(Document&);
145
146     void update();
147
148 private:
149     explicit MediaControlStatusDisplayElement(Document&);
150
151     enum StateBeingDisplayed { Nothing, Loading, LiveBroadcast };
152     StateBeingDisplayed m_stateBeingDisplayed;
153 };
154
155 // ----------------------------
156
157 class MediaControlPanelMuteButtonElement final : public MediaControlMuteButtonElement {
158     WTF_MAKE_ISO_ALLOCATED(MediaControlPanelMuteButtonElement);
159 public:
160     static Ref<MediaControlPanelMuteButtonElement> create(Document&, MediaControls*);
161
162 #if !PLATFORM(IOS_FAMILY)
163     bool willRespondToMouseMoveEvents() override { return true; }
164 #endif
165
166 private:
167     explicit MediaControlPanelMuteButtonElement(Document&, MediaControls*);
168
169     void defaultEventHandler(Event&) override;
170
171     MediaControls* m_controls;
172 };
173
174 // ----------------------------
175
176 class MediaControlVolumeSliderMuteButtonElement final : public MediaControlMuteButtonElement {
177     WTF_MAKE_ISO_ALLOCATED(MediaControlVolumeSliderMuteButtonElement);
178 public:
179     static Ref<MediaControlVolumeSliderMuteButtonElement> create(Document&);
180
181 private:
182     explicit MediaControlVolumeSliderMuteButtonElement(Document&);
183 };
184
185
186 // ----------------------------
187
188 class MediaControlPlayButtonElement final : public MediaControlInputElement {
189     WTF_MAKE_ISO_ALLOCATED(MediaControlPlayButtonElement);
190 public:
191     static Ref<MediaControlPlayButtonElement> create(Document&);
192
193 #if !PLATFORM(IOS_FAMILY)
194     bool willRespondToMouseClickEvents() override { return true; }
195 #endif
196
197     void updateDisplayType() override;
198
199 private:
200     explicit MediaControlPlayButtonElement(Document&);
201
202     void defaultEventHandler(Event&) override;
203 };
204
205 // ----------------------------
206
207 class MediaControlOverlayPlayButtonElement final : public MediaControlInputElement {
208     WTF_MAKE_ISO_ALLOCATED(MediaControlOverlayPlayButtonElement);
209 public:
210     static Ref<MediaControlOverlayPlayButtonElement> create(Document&);
211
212     void updateDisplayType() override;
213
214 private:
215     explicit MediaControlOverlayPlayButtonElement(Document&);
216
217     void defaultEventHandler(Event&) override;
218 };
219
220 // ----------------------------
221
222 class MediaControlSeekForwardButtonElement final : public MediaControlSeekButtonElement {
223     WTF_MAKE_ISO_ALLOCATED(MediaControlSeekForwardButtonElement);
224 public:
225     static Ref<MediaControlSeekForwardButtonElement> create(Document&);
226
227 private:
228     explicit MediaControlSeekForwardButtonElement(Document&);
229
230     bool isForwardButton() const override { return true; }
231 };
232
233 // ----------------------------
234
235 class MediaControlSeekBackButtonElement final : public MediaControlSeekButtonElement {
236     WTF_MAKE_ISO_ALLOCATED(MediaControlSeekBackButtonElement);
237 public:
238     static Ref<MediaControlSeekBackButtonElement> create(Document&);
239
240 private:
241     explicit MediaControlSeekBackButtonElement(Document&);
242
243     bool isForwardButton() const override { return false; }
244 };
245
246 // ----------------------------
247
248 class MediaControlRewindButtonElement final : public MediaControlInputElement {
249     WTF_MAKE_ISO_ALLOCATED(MediaControlRewindButtonElement);
250 public:
251     static Ref<MediaControlRewindButtonElement> create(Document&);
252
253 #if !PLATFORM(IOS_FAMILY)
254     bool willRespondToMouseClickEvents() override { return true; }
255 #endif
256
257 private:
258     explicit MediaControlRewindButtonElement(Document&);
259
260     void defaultEventHandler(Event&) override;
261 };
262
263 // ----------------------------
264
265 class MediaControlReturnToRealtimeButtonElement final : public MediaControlInputElement {
266     WTF_MAKE_ISO_ALLOCATED(MediaControlReturnToRealtimeButtonElement);
267 public:
268     static Ref<MediaControlReturnToRealtimeButtonElement> create(Document&);
269
270 #if !PLATFORM(IOS_FAMILY)
271     bool willRespondToMouseClickEvents() override { return true; }
272 #endif
273
274 private:
275     explicit MediaControlReturnToRealtimeButtonElement(Document&);
276
277     void defaultEventHandler(Event&) override;
278 };
279
280 // ----------------------------
281
282 class MediaControlToggleClosedCaptionsButtonElement final : public MediaControlInputElement {
283     WTF_MAKE_ISO_ALLOCATED(MediaControlToggleClosedCaptionsButtonElement);
284 public:
285     static Ref<MediaControlToggleClosedCaptionsButtonElement> create(Document&, MediaControls*);
286
287 #if !PLATFORM(IOS_FAMILY)
288     bool willRespondToMouseClickEvents() override { return true; }
289 #endif
290
291     void updateDisplayType() override;
292
293 private:
294     explicit MediaControlToggleClosedCaptionsButtonElement(Document&, MediaControls*);
295
296     void defaultEventHandler(Event&) override;
297
298 #if PLATFORM(COCOA) || PLATFORM(WIN) || PLATFORM(GTK)
299     MediaControls* m_controls;
300 #endif
301 };
302
303 // ----------------------------
304
305 class MediaControlClosedCaptionsContainerElement final : public MediaControlDivElement {
306     WTF_MAKE_ISO_ALLOCATED(MediaControlClosedCaptionsContainerElement);
307 public:
308     static Ref<MediaControlClosedCaptionsContainerElement> create(Document&);
309
310 #if !PLATFORM(IOS_FAMILY)
311     bool willRespondToMouseClickEvents() override { return true; }
312 #endif
313
314 private:
315     MediaControlClosedCaptionsContainerElement(Document&);
316 };
317
318 // ----------------------------
319
320 class MediaControlClosedCaptionsTrackListElement final : public MediaControlDivElement {
321     WTF_MAKE_ISO_ALLOCATED(MediaControlClosedCaptionsTrackListElement);
322 public:
323     static Ref<MediaControlClosedCaptionsTrackListElement> create(Document&, MediaControls*);
324
325 #if !PLATFORM(IOS_FAMILY)
326     bool willRespondToMouseClickEvents() override { return true; }
327 #endif
328
329     void updateDisplay();
330
331 private:
332     MediaControlClosedCaptionsTrackListElement(Document&, MediaControls*);
333
334     void rebuildTrackListMenu();
335
336     void defaultEventHandler(Event&) override;
337
338     typedef Vector<RefPtr<Element>> TrackMenuItems;
339     TrackMenuItems m_menuItems;
340 #if ENABLE(VIDEO_TRACK)
341     typedef HashMap<RefPtr<Element>, RefPtr<TextTrack>> MenuItemToTrackMap;
342     MenuItemToTrackMap m_menuToTrackMap;
343 #endif
344     MediaControls* m_controls;
345 };
346
347 // ----------------------------
348
349 class MediaControlTimelineElement final : public MediaControlInputElement {
350     WTF_MAKE_ISO_ALLOCATED(MediaControlTimelineElement);
351 public:
352     static Ref<MediaControlTimelineElement> create(Document&, MediaControls*);
353
354 #if !PLATFORM(IOS_FAMILY)
355     bool willRespondToMouseClickEvents() override;
356 #endif
357
358     void setPosition(double);
359     void setDuration(double);
360
361 private:
362     explicit MediaControlTimelineElement(Document&, MediaControls*);
363
364     void defaultEventHandler(Event&) override;
365
366     MediaControls* m_controls;
367 };
368
369 // ----------------------------
370
371 class MediaControlFullscreenButtonElement final : public MediaControlInputElement {
372     WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenButtonElement);
373 public:
374     static Ref<MediaControlFullscreenButtonElement> create(Document&);
375
376 #if !PLATFORM(IOS_FAMILY)
377     bool willRespondToMouseClickEvents() override { return true; }
378 #endif
379
380     void setIsFullscreen(bool);
381
382 private:
383     explicit MediaControlFullscreenButtonElement(Document&);
384
385     void defaultEventHandler(Event&) override;
386 };
387
388 // ----------------------------
389
390 class MediaControlPanelVolumeSliderElement final : public MediaControlVolumeSliderElement {
391     WTF_MAKE_ISO_ALLOCATED(MediaControlPanelVolumeSliderElement);
392 public:
393     static Ref<MediaControlPanelVolumeSliderElement> create(Document&);
394
395 private:
396     explicit MediaControlPanelVolumeSliderElement(Document&);
397 };
398 // ----------------------------
399
400 class MediaControlFullscreenVolumeSliderElement final : public MediaControlVolumeSliderElement {
401     WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenVolumeSliderElement);
402 public:
403     static Ref<MediaControlFullscreenVolumeSliderElement> create(Document&);
404
405 private:
406     explicit MediaControlFullscreenVolumeSliderElement(Document&);
407 };
408
409 // ----------------------------
410
411 class MediaControlFullscreenVolumeMinButtonElement final : public MediaControlInputElement {
412     WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenVolumeMinButtonElement);
413 public:
414     static Ref<MediaControlFullscreenVolumeMinButtonElement> create(Document&);
415
416 #if !PLATFORM(IOS_FAMILY)
417     bool willRespondToMouseClickEvents() override { return true; }
418 #endif
419
420 private:
421     explicit MediaControlFullscreenVolumeMinButtonElement(Document&);
422     void defaultEventHandler(Event&) override;
423 };
424
425 // ----------------------------
426
427 class MediaControlFullscreenVolumeMaxButtonElement final : public MediaControlInputElement {
428     WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenVolumeMaxButtonElement);
429 public:
430     static Ref<MediaControlFullscreenVolumeMaxButtonElement> create(Document&);
431
432 #if !PLATFORM(IOS_FAMILY)
433     bool willRespondToMouseClickEvents() override { return true; }
434 #endif
435
436 private:
437     explicit MediaControlFullscreenVolumeMaxButtonElement(Document&);
438
439     void defaultEventHandler(Event&) override;
440 };
441
442
443 // ----------------------------
444
445 class MediaControlTimeRemainingDisplayElement final : public MediaControlTimeDisplayElement {
446     WTF_MAKE_ISO_ALLOCATED(MediaControlTimeRemainingDisplayElement);
447 public:
448     static Ref<MediaControlTimeRemainingDisplayElement> create(Document&);
449
450 private:
451     explicit MediaControlTimeRemainingDisplayElement(Document&);
452 };
453
454 // ----------------------------
455
456 class MediaControlCurrentTimeDisplayElement final : public MediaControlTimeDisplayElement {
457     WTF_MAKE_ISO_ALLOCATED(MediaControlCurrentTimeDisplayElement);
458 public:
459     static Ref<MediaControlCurrentTimeDisplayElement> create(Document&);
460
461 private:
462     explicit MediaControlCurrentTimeDisplayElement(Document&);
463 };
464
465 // ----------------------------
466
467 #if ENABLE(VIDEO_TRACK)
468
469 class MediaControlTextTrackContainerElement final : public MediaControlDivElement, public TextTrackRepresentationClient {
470     WTF_MAKE_ISO_ALLOCATED(MediaControlTextTrackContainerElement);
471 public:
472     static Ref<MediaControlTextTrackContainerElement> create(Document&);
473
474     void updateDisplay();
475     void updateSizes(bool forceUpdate = false);
476     void enteredFullscreen();
477     void exitedFullscreen();
478
479 private:
480     void updateTimerFired();
481     void updateActiveCuesFontSize();
482     void updateTextStrokeStyle();
483     
484     explicit MediaControlTextTrackContainerElement(Document&);
485
486     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
487
488     RefPtr<Image> createTextTrackRepresentationImage() override;
489     void textTrackRepresentationBoundsChanged(const IntRect&) override;
490     void updateTextTrackRepresentation();
491     void clearTextTrackRepresentation();
492     void updateStyleForTextTrackRepresentation();
493     std::unique_ptr<TextTrackRepresentation> m_textTrackRepresentation;
494
495     Timer m_updateTimer;
496     IntRect m_videoDisplaySize;
497     int m_fontSize;
498     bool m_fontSizeIsImportant;
499     bool m_updateTextTrackRepresentationStyle;
500 };
501
502 #endif
503
504 } // namespace WebCore
505
506 #endif // ENABLE(VIDEO)