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
38namespace WebCore {
39
40// ----------------------------
41
42class MediaControlPanelElement final : public MediaControlDivElement {
43 WTF_MAKE_ISO_ALLOCATED(MediaControlPanelElement);
44public:
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
59private:
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
86class MediaControlPanelEnclosureElement final : public MediaControlDivElement {
87 WTF_MAKE_ISO_ALLOCATED(MediaControlPanelEnclosureElement);
88public:
89 static Ref<MediaControlPanelEnclosureElement> create(Document&);
90
91private:
92 explicit MediaControlPanelEnclosureElement(Document&);
93};
94
95// ----------------------------
96
97class MediaControlOverlayEnclosureElement final : public MediaControlDivElement {
98 WTF_MAKE_ISO_ALLOCATED(MediaControlOverlayEnclosureElement);
99public:
100 static Ref<MediaControlOverlayEnclosureElement> create(Document&);
101
102private:
103 explicit MediaControlOverlayEnclosureElement(Document&);
104};
105
106// ----------------------------
107
108class MediaControlTimelineContainerElement final : public MediaControlDivElement {
109 WTF_MAKE_ISO_ALLOCATED(MediaControlTimelineContainerElement);
110public:
111 static Ref<MediaControlTimelineContainerElement> create(Document&);
112
113 void setTimeDisplaysHidden(bool);
114
115private:
116 explicit MediaControlTimelineContainerElement(Document&);
117
118 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
119};
120
121// ----------------------------
122
123class MediaControlVolumeSliderContainerElement final : public MediaControlDivElement {
124 WTF_MAKE_ISO_ALLOCATED(MediaControlVolumeSliderContainerElement);
125public:
126 static Ref<MediaControlVolumeSliderContainerElement> create(Document&);
127
128#if !PLATFORM(IOS_FAMILY)
129 bool willRespondToMouseMoveEvents() override { return true; }
130#endif
131
132private:
133 explicit MediaControlVolumeSliderContainerElement(Document&);
134
135 void defaultEventHandler(Event&) override;
136
137 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
138};
139
140// ----------------------------
141
142class MediaControlStatusDisplayElement final : public MediaControlDivElement {
143 WTF_MAKE_ISO_ALLOCATED(MediaControlStatusDisplayElement);
144public:
145 static Ref<MediaControlStatusDisplayElement> create(Document&);
146
147 void update();
148
149private:
150 explicit MediaControlStatusDisplayElement(Document&);
151
152 enum StateBeingDisplayed { Nothing, Loading, LiveBroadcast };
153 StateBeingDisplayed m_stateBeingDisplayed;
154};
155
156// ----------------------------
157
158class MediaControlPanelMuteButtonElement final : public MediaControlMuteButtonElement {
159 WTF_MAKE_ISO_ALLOCATED(MediaControlPanelMuteButtonElement);
160public:
161 static Ref<MediaControlPanelMuteButtonElement> create(Document&, MediaControls*);
162
163#if !PLATFORM(IOS_FAMILY)
164 bool willRespondToMouseMoveEvents() override { return true; }
165#endif
166
167private:
168 explicit MediaControlPanelMuteButtonElement(Document&, MediaControls*);
169
170 void defaultEventHandler(Event&) override;
171
172 MediaControls* m_controls;
173};
174
175// ----------------------------
176
177class MediaControlVolumeSliderMuteButtonElement final : public MediaControlMuteButtonElement {
178 WTF_MAKE_ISO_ALLOCATED(MediaControlVolumeSliderMuteButtonElement);
179public:
180 static Ref<MediaControlVolumeSliderMuteButtonElement> create(Document&);
181
182private:
183 explicit MediaControlVolumeSliderMuteButtonElement(Document&);
184};
185
186
187// ----------------------------
188
189class MediaControlPlayButtonElement final : public MediaControlInputElement {
190 WTF_MAKE_ISO_ALLOCATED(MediaControlPlayButtonElement);
191public:
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
200private:
201 explicit MediaControlPlayButtonElement(Document&);
202
203 void defaultEventHandler(Event&) override;
204};
205
206// ----------------------------
207
208class MediaControlOverlayPlayButtonElement final : public MediaControlInputElement {
209 WTF_MAKE_ISO_ALLOCATED(MediaControlOverlayPlayButtonElement);
210public:
211 static Ref<MediaControlOverlayPlayButtonElement> create(Document&);
212
213 void updateDisplayType() override;
214
215private:
216 explicit MediaControlOverlayPlayButtonElement(Document&);
217
218 void defaultEventHandler(Event&) override;
219};
220
221// ----------------------------
222
223class MediaControlSeekForwardButtonElement final : public MediaControlSeekButtonElement {
224 WTF_MAKE_ISO_ALLOCATED(MediaControlSeekForwardButtonElement);
225public:
226 static Ref<MediaControlSeekForwardButtonElement> create(Document&);
227
228private:
229 explicit MediaControlSeekForwardButtonElement(Document&);
230
231 bool isForwardButton() const override { return true; }
232};
233
234// ----------------------------
235
236class MediaControlSeekBackButtonElement final : public MediaControlSeekButtonElement {
237 WTF_MAKE_ISO_ALLOCATED(MediaControlSeekBackButtonElement);
238public:
239 static Ref<MediaControlSeekBackButtonElement> create(Document&);
240
241private:
242 explicit MediaControlSeekBackButtonElement(Document&);
243
244 bool isForwardButton() const override { return false; }
245};
246
247// ----------------------------
248
249class MediaControlRewindButtonElement final : public MediaControlInputElement {
250 WTF_MAKE_ISO_ALLOCATED(MediaControlRewindButtonElement);
251public:
252 static Ref<MediaControlRewindButtonElement> create(Document&);
253
254#if !PLATFORM(IOS_FAMILY)
255 bool willRespondToMouseClickEvents() override { return true; }
256#endif
257
258private:
259 explicit MediaControlRewindButtonElement(Document&);
260
261 void defaultEventHandler(Event&) override;
262};
263
264// ----------------------------
265
266class MediaControlReturnToRealtimeButtonElement final : public MediaControlInputElement {
267 WTF_MAKE_ISO_ALLOCATED(MediaControlReturnToRealtimeButtonElement);
268public:
269 static Ref<MediaControlReturnToRealtimeButtonElement> create(Document&);
270
271#if !PLATFORM(IOS_FAMILY)
272 bool willRespondToMouseClickEvents() override { return true; }
273#endif
274
275private:
276 explicit MediaControlReturnToRealtimeButtonElement(Document&);
277
278 void defaultEventHandler(Event&) override;
279};
280
281// ----------------------------
282
283class MediaControlToggleClosedCaptionsButtonElement final : public MediaControlInputElement {
284 WTF_MAKE_ISO_ALLOCATED(MediaControlToggleClosedCaptionsButtonElement);
285public:
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
294private:
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
306class MediaControlClosedCaptionsContainerElement final : public MediaControlDivElement {
307 WTF_MAKE_ISO_ALLOCATED(MediaControlClosedCaptionsContainerElement);
308public:
309 static Ref<MediaControlClosedCaptionsContainerElement> create(Document&);
310
311#if !PLATFORM(IOS_FAMILY)
312 bool willRespondToMouseClickEvents() override { return true; }
313#endif
314
315private:
316 MediaControlClosedCaptionsContainerElement(Document&);
317};
318
319// ----------------------------
320
321class MediaControlClosedCaptionsTrackListElement final : public MediaControlDivElement {
322 WTF_MAKE_ISO_ALLOCATED(MediaControlClosedCaptionsTrackListElement);
323public:
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
332private:
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
350class MediaControlTimelineElement final : public MediaControlInputElement {
351 WTF_MAKE_ISO_ALLOCATED(MediaControlTimelineElement);
352public:
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
362private:
363 explicit MediaControlTimelineElement(Document&, MediaControls*);
364
365 void defaultEventHandler(Event&) override;
366
367 MediaControls* m_controls;
368};
369
370// ----------------------------
371
372class MediaControlFullscreenButtonElement final : public MediaControlInputElement {
373 WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenButtonElement);
374public:
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
383private:
384 explicit MediaControlFullscreenButtonElement(Document&);
385
386 void defaultEventHandler(Event&) override;
387};
388
389// ----------------------------
390
391class MediaControlPanelVolumeSliderElement final : public MediaControlVolumeSliderElement {
392 WTF_MAKE_ISO_ALLOCATED(MediaControlPanelVolumeSliderElement);
393public:
394 static Ref<MediaControlPanelVolumeSliderElement> create(Document&);
395
396private:
397 explicit MediaControlPanelVolumeSliderElement(Document&);
398};
399// ----------------------------
400
401class MediaControlFullscreenVolumeSliderElement final : public MediaControlVolumeSliderElement {
402 WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenVolumeSliderElement);
403public:
404 static Ref<MediaControlFullscreenVolumeSliderElement> create(Document&);
405
406private:
407 explicit MediaControlFullscreenVolumeSliderElement(Document&);
408};
409
410// ----------------------------
411
412class MediaControlFullscreenVolumeMinButtonElement final : public MediaControlInputElement {
413 WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenVolumeMinButtonElement);
414public:
415 static Ref<MediaControlFullscreenVolumeMinButtonElement> create(Document&);
416
417#if !PLATFORM(IOS_FAMILY)
418 bool willRespondToMouseClickEvents() override { return true; }
419#endif
420
421private:
422 explicit MediaControlFullscreenVolumeMinButtonElement(Document&);
423 void defaultEventHandler(Event&) override;
424};
425
426// ----------------------------
427
428class MediaControlFullscreenVolumeMaxButtonElement final : public MediaControlInputElement {
429 WTF_MAKE_ISO_ALLOCATED(MediaControlFullscreenVolumeMaxButtonElement);
430public:
431 static Ref<MediaControlFullscreenVolumeMaxButtonElement> create(Document&);
432
433#if !PLATFORM(IOS_FAMILY)
434 bool willRespondToMouseClickEvents() override { return true; }
435#endif
436
437private:
438 explicit MediaControlFullscreenVolumeMaxButtonElement(Document&);
439
440 void defaultEventHandler(Event&) override;
441};
442
443
444// ----------------------------
445
446class MediaControlTimeRemainingDisplayElement final : public MediaControlTimeDisplayElement {
447 WTF_MAKE_ISO_ALLOCATED(MediaControlTimeRemainingDisplayElement);
448public:
449 static Ref<MediaControlTimeRemainingDisplayElement> create(Document&);
450
451private:
452 explicit MediaControlTimeRemainingDisplayElement(Document&);
453};
454
455// ----------------------------
456
457class MediaControlCurrentTimeDisplayElement final : public MediaControlTimeDisplayElement {
458 WTF_MAKE_ISO_ALLOCATED(MediaControlCurrentTimeDisplayElement);
459public:
460 static Ref<MediaControlCurrentTimeDisplayElement> create(Document&);
461
462private:
463 explicit MediaControlCurrentTimeDisplayElement(Document&);
464};
465
466// ----------------------------
467
468#if ENABLE(VIDEO_TRACK)
469
470class 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);
478public:
479 static Ref<MediaControlTextTrackContainerElement> create(Document&);
480
481 void updateDisplay();
482 void updateSizes(bool forceUpdate = false);
483 void enteredFullscreen();
484 void exitedFullscreen();
485
486private:
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)
521