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