OSDN Git Service

Improving HTML5 video controls
[android-x86/external-webkit.git] / WebCore / rendering / RenderMedia.h
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
60     const RenderObjectChildList* children() const { return &m_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:
79     virtual RenderObjectChildList* virtualChildren() { return children(); }
80     virtual const RenderObjectChildList* virtualChildren() const { return children(); }
81
82     virtual void destroy();
83     
84     virtual const char* renderName() const { return "RenderMedia"; }
85     virtual bool isMedia() const { return true; }
86     virtual bool isImage() const { return false; }
87
88     virtual int topmostPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
89     virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
90     virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
91     virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true, ApplyTransform = IncludeTransform) const;
92
93     void createControlsShadowRoot();
94     void destroyControlsShadowRoot();
95     void createPanel();
96     void createMuteButton();
97     void createPlayButton();
98     void createSeekBackButton();
99     void createSeekForwardButton();
100     void createRewindButton();
101     void createReturnToRealtimeButton();
102     void createToggleClosedCaptionsButton();
103     void createStatusDisplay();
104     void createTimelineContainer();
105     void createTimeline();
106     void createVolumeSliderContainer();
107     void createVolumeSlider();
108     void createVolumeSliderMuteButton();
109     void createCurrentTimeDisplay();
110     void createTimeRemainingDisplay();
111     void createFullscreenButton();
112     
113     void timeUpdateTimerFired(Timer<RenderMedia>*);
114     
115     void updateControlVisibility();
116     void changeOpacity(HTMLElement*, float opacity);
117     void opacityAnimationTimerFired(Timer<RenderMedia>*);
118
119     void updateVolumeSliderContainer(bool visible);
120
121     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
122
123     virtual bool requiresForcedStyleRecalcPropagation() const { return true; }
124
125     RefPtr<HTMLElement> m_controlsShadowRoot;
126     RefPtr<MediaControlElement> m_panel;
127     RefPtr<MediaControlMuteButtonElement> m_muteButton;
128     RefPtr<MediaControlPlayButtonElement> m_playButton;
129     RefPtr<MediaControlSeekButtonElement> m_seekBackButton;
130     RefPtr<MediaControlSeekButtonElement> m_seekForwardButton;
131     RefPtr<MediaControlRewindButtonElement> m_rewindButton;
132     RefPtr<MediaControlReturnToRealtimeButtonElement> m_returnToRealtimeButton;
133     RefPtr<MediaControlToggleClosedCaptionsButtonElement> m_toggleClosedCaptionsButton;
134     RefPtr<MediaControlTimelineElement> m_timeline;
135     RefPtr<MediaControlVolumeSliderElement> m_volumeSlider;
136     RefPtr<MediaControlMuteButtonElement> m_volumeSliderMuteButton;
137     RefPtr<MediaControlFullscreenButtonElement> m_fullscreenButton;
138     RefPtr<MediaControlTimelineContainerElement> m_timelineContainer;
139     RefPtr<MediaControlVolumeSliderContainerElement> m_volumeSliderContainer;
140     RefPtr<MediaControlTimeDisplayElement> m_currentTimeDisplay;
141     RefPtr<MediaControlTimeDisplayElement> m_timeRemainingDisplay;
142     RefPtr<MediaControlStatusDisplayElement> m_statusDisplay;
143     RenderObjectChildList m_children;
144     Node* m_lastUnderNode;
145     Node* m_nodeUnderMouse;
146     
147     Timer<RenderMedia> m_timeUpdateTimer;
148     Timer<RenderMedia> m_opacityAnimationTimer;
149     bool m_mouseOver;
150     double m_opacityAnimationStartTime;
151     double m_opacityAnimationDuration;
152     float m_opacityAnimationFrom;
153     float m_opacityAnimationTo;
154 #if PLATFORM(ANDROID)
155     double m_lastTouch;
156 #endif
157 };
158
159 inline RenderMedia* toRenderMedia(RenderObject* object)
160 {
161     ASSERT(!object || object->isMedia());
162     return static_cast<RenderMedia*>(object);
163 }
164
165 // This will catch anyone doing an unnecessary cast.
166 void toRenderMedia(const RenderMedia*);
167
168 } // namespace WebCore
169
170 #endif
171 #endif // RenderMedia_h