1 /*
2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef RenderMedia_h
27 #define RenderMedia_h
28
29 #if ENABLE(VIDEO)
30
31 #include "RenderReplaced.h"
32 #include "Timer.h"
33
34 namespace WebCore {
35
36 class HTMLInputElement;
37 class HTMLMediaElement;
38 class MediaControlMuteButtonElement;
39 class MediaControlPlayButtonElement;
40 class MediaControlSeekButtonElement;
41 class MediaControlRewindButtonElement;
42 class MediaControlReturnToRealtimeButtonElement;
43 class MediaControlTimelineElement;
44 class MediaControlFullscreenButtonElement;
45 class MediaControlTimeDisplayElement;
46 class MediaControlStatusDisplayElement;
47 class MediaControlTimelineContainerElement;
48 class MediaControlElement;
49 class MediaPlayer;
50
51 class RenderMedia : public RenderReplaced {
52 public:
53 RenderMedia(HTMLMediaElement*);
54 RenderMedia(HTMLMediaElement*, const IntSize& intrinsicSize);
55 virtual ~RenderMedia();
56
children()57 const RenderObjectChildList* children() const { return &m_children; }
children()58 RenderObjectChildList* children() { return &m_children; }
59
60 HTMLMediaElement* mediaElement() const;
61 MediaPlayer* player() const;
62
63 static String formatTime(float time);
64
65 bool shouldShowTimeDisplayControls() const;
66
67 void updateFromElement();
68 void updatePlayer();
69 void updateControls();
70 void updateTimeDisplay();
71
72 void forwardEvent(Event*);
73
74 protected:
75 virtual void layout();
76
77 private:
virtualChildren()78 virtual RenderObjectChildList* virtualChildren() { return children(); }
virtualChildren()79 virtual const RenderObjectChildList* virtualChildren() const { return children(); }
80
81 virtual void destroy();
82
renderName()83 virtual const char* renderName() const { return "RenderMedia"; }
isMedia()84 virtual bool isMedia() const { return true; }
85
86 virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
87 virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
88 virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
89
90 void createControlsShadowRoot();
91 void destroyControlsShadowRoot();
92 void createPanel();
93 void createMuteButton();
94 void createPlayButton();
95 void createSeekBackButton();
96 void createSeekForwardButton();
97 void createRewindButton();
98 void createReturnToRealtimeButton();
99 void createStatusDisplay();
100 void createTimelineContainer();
101 void createTimeline();
102 void createCurrentTimeDisplay();
103 void createTimeRemainingDisplay();
104 void createFullscreenButton();
105
106 void timeUpdateTimerFired(Timer<RenderMedia>*);
107
108 void updateControlVisibility();
109 void changeOpacity(HTMLElement*, float opacity);
110 void opacityAnimationTimerFired(Timer<RenderMedia>*);
111
112 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
113
114 RefPtr<HTMLElement> m_controlsShadowRoot;
115 RefPtr<MediaControlElement> m_panel;
116 RefPtr<MediaControlMuteButtonElement> m_muteButton;
117 RefPtr<MediaControlPlayButtonElement> m_playButton;
118 RefPtr<MediaControlSeekButtonElement> m_seekBackButton;
119 RefPtr<MediaControlSeekButtonElement> m_seekForwardButton;
120 RefPtr<MediaControlRewindButtonElement> m_rewindButton;
121 RefPtr<MediaControlReturnToRealtimeButtonElement> m_returnToRealtimeButton;
122 RefPtr<MediaControlTimelineElement> m_timeline;
123 RefPtr<MediaControlFullscreenButtonElement> m_fullscreenButton;
124 RefPtr<MediaControlTimelineContainerElement> m_timelineContainer;
125 RefPtr<MediaControlTimeDisplayElement> m_currentTimeDisplay;
126 RefPtr<MediaControlTimeDisplayElement> m_timeRemainingDisplay;
127 RefPtr<MediaControlStatusDisplayElement> m_statusDisplay;
128 RenderObjectChildList m_children;
129 Node* m_lastUnderNode;
130 Node* m_nodeUnderMouse;
131
132 Timer<RenderMedia> m_timeUpdateTimer;
133 Timer<RenderMedia> m_opacityAnimationTimer;
134 bool m_mouseOver;
135 double m_opacityAnimationStartTime;
136 double m_opacityAnimationDuration;
137 float m_opacityAnimationFrom;
138 float m_opacityAnimationTo;
139 };
140
toRenderMedia(RenderObject * object)141 inline RenderMedia* toRenderMedia(RenderObject* object)
142 {
143 ASSERT(!object || object->isMedia());
144 return static_cast<RenderMedia*>(object);
145 }
146
147 // This will catch anyone doing an unnecessary cast.
148 void toRenderMedia(const RenderMedia*);
149
150 } // namespace WebCore
151
152 #endif
153 #endif // RenderMedia_h
154