|
1 /* |
|
2 * Copyright (C) 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 FullscreenVideoController_h |
|
27 #define FullscreenVideoController_h |
|
28 |
|
29 #if ENABLE(VIDEO) |
|
30 |
|
31 #include "MediaPlayerPrivateFullscreenWindow.h" |
|
32 |
|
33 #include <WebCore/HTMLMediaElement.h> |
|
34 #include <WebCore/Image.h> |
|
35 #include <WebCore/IntPoint.h> |
|
36 #include <WebCore/IntSize.h> |
|
37 #include <wtf/RefPtr.h> |
|
38 |
|
39 namespace WebCore { |
|
40 class GraphicsContext; |
|
41 #if USE(ACCELERATED_COMPOSITING) |
|
42 class WKCACFLayer; |
|
43 #endif |
|
44 } |
|
45 |
|
46 class HUDWidget { |
|
47 public: |
|
48 HUDWidget(const WebCore::IntRect& rect) : m_rect(rect) { } |
|
49 |
|
50 virtual ~HUDWidget() { } |
|
51 |
|
52 virtual void draw(WebCore::GraphicsContext&) = 0; |
|
53 virtual void drag(const WebCore::IntPoint&, bool start) = 0; |
|
54 bool hitTest(const WebCore::IntPoint& point) const { return m_rect.contains(point); } |
|
55 |
|
56 protected: |
|
57 WebCore::IntRect m_rect; |
|
58 }; |
|
59 |
|
60 class HUDButton : public HUDWidget { |
|
61 public: |
|
62 enum HUDButtonType { |
|
63 NoButton, |
|
64 PlayPauseButton, |
|
65 TimeSliderButton, |
|
66 VolumeUpButton, |
|
67 VolumeSliderButton, |
|
68 VolumeDownButton, |
|
69 ExitFullscreenButton |
|
70 }; |
|
71 |
|
72 HUDButton(HUDButtonType, const WebCore::IntPoint&); |
|
73 ~HUDButton() { } |
|
74 |
|
75 virtual void draw(WebCore::GraphicsContext&); |
|
76 virtual void drag(const WebCore::IntPoint&, bool start) { } |
|
77 void setShowAltButton(bool b) { m_showAltButton = b; } |
|
78 |
|
79 private: |
|
80 RefPtr<WebCore::Image> m_buttonImage; |
|
81 RefPtr<WebCore::Image> m_buttonImageAlt; |
|
82 HUDButtonType m_type; |
|
83 bool m_showAltButton; |
|
84 }; |
|
85 |
|
86 class HUDSlider : public HUDWidget { |
|
87 public: |
|
88 enum HUDSliderButtonShape { RoundButton, DiamondButton }; |
|
89 |
|
90 HUDSlider(HUDSliderButtonShape, int buttonSize, const WebCore::IntRect& rect); |
|
91 ~HUDSlider() { } |
|
92 |
|
93 virtual void draw(WebCore::GraphicsContext&); |
|
94 virtual void drag(const WebCore::IntPoint&, bool start); |
|
95 float value() const { return static_cast<float>(m_buttonPosition) / (m_rect.width() - m_buttonSize); } |
|
96 void setValue(float value) { m_buttonPosition = static_cast<int>(value * (m_rect.width() - m_buttonSize)); } |
|
97 |
|
98 private: |
|
99 HUDSliderButtonShape m_buttonShape; |
|
100 int m_buttonSize; |
|
101 int m_buttonPosition; |
|
102 int m_dragStartOffset; |
|
103 }; |
|
104 |
|
105 class FullscreenVideoController : WebCore::MediaPlayerPrivateFullscreenClient, public Noncopyable { |
|
106 public: |
|
107 FullscreenVideoController(); |
|
108 virtual ~FullscreenVideoController(); |
|
109 |
|
110 void setMediaElement(WebCore::HTMLMediaElement*); |
|
111 WebCore::HTMLMediaElement* mediaElement() const { return m_mediaElement.get(); } |
|
112 |
|
113 void enterFullscreen(); |
|
114 void exitFullscreen(); |
|
115 |
|
116 private: |
|
117 // MediaPlayerPrivateFullscreenWindowClient |
|
118 virtual LRESULT fullscreenClientWndProc(HWND, UINT message, WPARAM, LPARAM); |
|
119 |
|
120 void ensureWindow(); |
|
121 |
|
122 bool canPlay() const; |
|
123 void play(); |
|
124 void pause(); |
|
125 float volume() const; |
|
126 void setVolume(float); |
|
127 float currentTime() const; |
|
128 void setCurrentTime(float); |
|
129 float duration() const; |
|
130 void beginScrubbing(); |
|
131 void endScrubbing(); |
|
132 |
|
133 WebCore::IntPoint fullscreenToHUDCoordinates(const WebCore::IntPoint& point) const |
|
134 { |
|
135 return WebCore::IntPoint(point.x()- m_hudPosition.x(), point.y() - m_hudPosition.y()); |
|
136 } |
|
137 |
|
138 static void registerHUDWindowClass(); |
|
139 static LRESULT CALLBACK hudWndProc(HWND, UINT message, WPARAM, LPARAM); |
|
140 void createHUDWindow(); |
|
141 void timerFired(WebCore::Timer<FullscreenVideoController>*); |
|
142 |
|
143 void togglePlay(); |
|
144 void draw(); |
|
145 |
|
146 void onChar(int c); |
|
147 void onMouseDown(const WebCore::IntPoint&); |
|
148 void onMouseMove(const WebCore::IntPoint&); |
|
149 void onMouseUp(const WebCore::IntPoint&); |
|
150 void onKeyDown(int virtualKey); |
|
151 |
|
152 RefPtr<WebCore::HTMLMediaElement> m_mediaElement; |
|
153 |
|
154 HWND m_hudWindow; |
|
155 OwnPtr<HBITMAP> m_bitmap; |
|
156 WebCore::IntSize m_fullscreenSize; |
|
157 WebCore::IntPoint m_hudPosition; |
|
158 OwnPtr<WebCore::MediaPlayerPrivateFullscreenWindow> m_fullscreenWindow; |
|
159 #if USE(ACCELERATED_COMPOSITING) |
|
160 RefPtr<WebCore::WKCACFLayer> m_rootChild; |
|
161 class LayoutClient; |
|
162 friend class LayoutClient; |
|
163 OwnPtr<LayoutClient> m_layoutClient; |
|
164 #endif |
|
165 |
|
166 HUDButton m_playPauseButton; |
|
167 HUDButton m_timeSliderButton; |
|
168 HUDButton m_volumeUpButton; |
|
169 HUDButton m_volumeSliderButton; |
|
170 HUDButton m_volumeDownButton; |
|
171 HUDButton m_exitFullscreenButton; |
|
172 HUDSlider m_volumeSlider; |
|
173 HUDSlider m_timeSlider; |
|
174 |
|
175 HUDWidget* m_hitWidget; |
|
176 WebCore::IntPoint m_moveOffset; |
|
177 bool m_movingWindow; |
|
178 WebCore::Timer<FullscreenVideoController> m_timer; |
|
179 }; |
|
180 |
|
181 #endif |
|
182 |
|
183 #endif // FullscreenVideoController_h |