2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef FullscreenVideoController_h
27 #define FullscreenVideoController_h
31 #include "MediaPlayerPrivateFullscreenWindow.h"
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>
40 class GraphicsContext;
41 #if USE(ACCELERATED_COMPOSITING)
42 class PlatformCALayer;
48 HUDWidget(const WebCore::IntRect& rect) : m_rect(rect) { }
50 virtual ~HUDWidget() { }
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); }
57 WebCore::IntRect m_rect;
60 class HUDButton : public HUDWidget {
72 HUDButton(HUDButtonType, const WebCore::IntPoint&);
75 virtual void draw(WebCore::GraphicsContext&);
76 virtual void drag(const WebCore::IntPoint&, bool start) { }
77 void setShowAltButton(bool b) { m_showAltButton = b; }
80 RefPtr<WebCore::Image> m_buttonImage;
81 RefPtr<WebCore::Image> m_buttonImageAlt;
86 class HUDSlider : public HUDWidget {
88 enum HUDSliderButtonShape { RoundButton, DiamondButton };
90 HUDSlider(HUDSliderButtonShape, int buttonSize, const WebCore::IntRect& rect);
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)); }
99 HUDSliderButtonShape m_buttonShape;
101 int m_buttonPosition;
102 int m_dragStartOffset;
105 class FullscreenVideoController : WebCore::MediaPlayerPrivateFullscreenClient {
106 WTF_MAKE_NONCOPYABLE(FullscreenVideoController);
108 FullscreenVideoController();
109 virtual ~FullscreenVideoController();
111 void setMediaElement(WebCore::HTMLMediaElement*);
112 WebCore::HTMLMediaElement* mediaElement() const { return m_mediaElement.get(); }
114 void enterFullscreen();
115 void exitFullscreen();
118 // MediaPlayerPrivateFullscreenWindowClient
119 virtual LRESULT fullscreenClientWndProc(HWND, UINT message, WPARAM, LPARAM);
123 bool canPlay() const;
126 float volume() const;
127 void setVolume(float);
128 float currentTime() const;
129 void setCurrentTime(float);
130 float duration() const;
131 void beginScrubbing();
134 WebCore::IntPoint fullscreenToHUDCoordinates(const WebCore::IntPoint& point) const
136 return WebCore::IntPoint(point.x()- m_hudPosition.x(), point.y() - m_hudPosition.y());
139 static void registerHUDWindowClass();
140 static LRESULT CALLBACK hudWndProc(HWND, UINT message, WPARAM, LPARAM);
141 void createHUDWindow();
142 void timerFired(WebCore::Timer<FullscreenVideoController>*);
148 void onMouseDown(const WebCore::IntPoint&);
149 void onMouseMove(const WebCore::IntPoint&);
150 void onMouseUp(const WebCore::IntPoint&);
151 void onKeyDown(int virtualKey);
153 RefPtr<WebCore::HTMLMediaElement> m_mediaElement;
156 OwnPtr<HBITMAP> m_bitmap;
157 WebCore::IntSize m_fullscreenSize;
158 WebCore::IntPoint m_hudPosition;
159 OwnPtr<WebCore::MediaPlayerPrivateFullscreenWindow> m_fullscreenWindow;
160 #if USE(ACCELERATED_COMPOSITING)
162 friend class LayerClient;
163 OwnPtr<LayerClient> m_layerClient;
164 RefPtr<WebCore::PlatformCALayer> m_rootChild;
167 HUDButton m_playPauseButton;
168 HUDButton m_timeSliderButton;
169 HUDButton m_volumeUpButton;
170 HUDButton m_volumeSliderButton;
171 HUDButton m_volumeDownButton;
172 HUDButton m_exitFullscreenButton;
173 HUDSlider m_volumeSlider;
174 HUDSlider m_timeSlider;
176 HUDWidget* m_hitWidget;
177 WebCore::IntPoint m_moveOffset;
179 WebCore::Timer<FullscreenVideoController> m_timer;
184 #endif // FullscreenVideoController_h