• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010 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 "RenderImage.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 MediaControlToggleClosedCaptionsButtonElement;
44 class MediaControlTimelineElement;
45 class MediaControlVolumeSliderElement;
46 class MediaControlFullscreenButtonElement;
47 class MediaControlTimeDisplayElement;
48 class MediaControlStatusDisplayElement;
49 class MediaControlTimelineContainerElement;
50 class MediaControlVolumeSliderContainerElement;
51 class MediaControlElement;
52 class MediaPlayer;
53 
54 class RenderMedia : public RenderImage {
55 public:
56     RenderMedia(HTMLMediaElement*);
57     RenderMedia(HTMLMediaElement*, const IntSize& intrinsicSize);
58     virtual ~RenderMedia();
59 
children()60     const RenderObjectChildList* children() const { return &m_children; }
children()61     RenderObjectChildList* children() { return &m_children; }
62 
63     HTMLMediaElement* mediaElement() const;
64     MediaPlayer* player() const;
65 
66     bool shouldShowTimeDisplayControls() const;
67 
68     void updateFromElement();
69     void updatePlayer();
70     void updateControls();
71     void updateTimeDisplay();
72 
73     void forwardEvent(Event*);
74 
75 protected:
76     virtual void layout();
77 
78 private:
virtualChildren()79     virtual RenderObjectChildList* virtualChildren() { return children(); }
virtualChildren()80     virtual const RenderObjectChildList* virtualChildren() const { return children(); }
81 
82     virtual void destroy();
83 
renderName()84     virtual const char* renderName() const { return "RenderMedia"; }
isMedia()85     virtual bool isMedia() const { return true; }
isImage()86     virtual bool isImage() const { return false; }
87 
88     virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
89     virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
90     virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
91 
92     void createControlsShadowRoot();
93     void destroyControlsShadowRoot();
94     void createPanel();
95     void createMuteButton();
96     void createPlayButton();
97     void createSeekBackButton();
98     void createSeekForwardButton();
99     void createRewindButton();
100     void createReturnToRealtimeButton();
101     void createToggleClosedCaptionsButton();
102     void createStatusDisplay();
103     void createTimelineContainer();
104     void createTimeline();
105     void createVolumeSliderContainer();
106     void createVolumeSlider();
107     void createCurrentTimeDisplay();
108     void createTimeRemainingDisplay();
109     void createFullscreenButton();
110 
111     void timeUpdateTimerFired(Timer<RenderMedia>*);
112 
113     void updateControlVisibility();
114     void changeOpacity(HTMLElement*, float opacity);
115     void opacityAnimationTimerFired(Timer<RenderMedia>*);
116 
117     void updateVolumeSliderContainer(bool visible);
118 
119     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
120 
121     RefPtr<HTMLElement> m_controlsShadowRoot;
122     RefPtr<MediaControlElement> m_panel;
123     RefPtr<MediaControlMuteButtonElement> m_muteButton;
124     RefPtr<MediaControlPlayButtonElement> m_playButton;
125     RefPtr<MediaControlSeekButtonElement> m_seekBackButton;
126     RefPtr<MediaControlSeekButtonElement> m_seekForwardButton;
127     RefPtr<MediaControlRewindButtonElement> m_rewindButton;
128     RefPtr<MediaControlReturnToRealtimeButtonElement> m_returnToRealtimeButton;
129     RefPtr<MediaControlToggleClosedCaptionsButtonElement> m_toggleClosedCaptionsButton;
130     RefPtr<MediaControlTimelineElement> m_timeline;
131     RefPtr<MediaControlVolumeSliderElement> m_volumeSlider;
132     RefPtr<MediaControlFullscreenButtonElement> m_fullscreenButton;
133     RefPtr<MediaControlTimelineContainerElement> m_timelineContainer;
134     RefPtr<MediaControlVolumeSliderContainerElement> m_volumeSliderContainer;
135     RefPtr<MediaControlTimeDisplayElement> m_currentTimeDisplay;
136     RefPtr<MediaControlTimeDisplayElement> m_timeRemainingDisplay;
137     RefPtr<MediaControlStatusDisplayElement> m_statusDisplay;
138     RenderObjectChildList m_children;
139     Node* m_lastUnderNode;
140     Node* m_nodeUnderMouse;
141 
142     Timer<RenderMedia> m_timeUpdateTimer;
143     Timer<RenderMedia> m_opacityAnimationTimer;
144     bool m_mouseOver;
145     double m_opacityAnimationStartTime;
146     double m_opacityAnimationDuration;
147     float m_opacityAnimationFrom;
148     float m_opacityAnimationTo;
149 };
150 
toRenderMedia(RenderObject * object)151 inline RenderMedia* toRenderMedia(RenderObject* object)
152 {
153     ASSERT(!object || object->isMedia());
154     return static_cast<RenderMedia*>(object);
155 }
156 
157 // This will catch anyone doing an unnecessary cast.
158 void toRenderMedia(const RenderMedia*);
159 
160 } // namespace WebCore
161 
162 #endif
163 #endif // RenderMedia_h
164