[Release] Webkit2-efl-123997_0.11.86
[framework/web/webkit-efl.git] / Source / WebKit / win / FullscreenVideoController.h
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 PlatformCALayer;
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 {
106     WTF_MAKE_NONCOPYABLE(FullscreenVideoController);
107 public:
108     FullscreenVideoController();
109     virtual ~FullscreenVideoController();
110
111     void setMediaElement(WebCore::HTMLMediaElement*);
112     WebCore::HTMLMediaElement* mediaElement() const { return m_mediaElement.get(); }
113
114     void enterFullscreen();
115     void exitFullscreen();
116
117 private:
118     // MediaPlayerPrivateFullscreenWindowClient
119     virtual LRESULT fullscreenClientWndProc(HWND, UINT message, WPARAM, LPARAM);
120     
121     void ensureWindow();
122     
123     bool canPlay() const;
124     void play();
125     void pause();
126     float volume() const;
127     void setVolume(float);
128     float currentTime() const;
129     void setCurrentTime(float);
130     float duration() const;
131     void beginScrubbing();
132     void endScrubbing();
133
134     WebCore::IntPoint fullscreenToHUDCoordinates(const WebCore::IntPoint& point) const
135     {
136         return WebCore::IntPoint(point.x()- m_hudPosition.x(), point.y() - m_hudPosition.y());
137     }
138
139     static void registerHUDWindowClass();
140     static LRESULT CALLBACK hudWndProc(HWND, UINT message, WPARAM, LPARAM);
141     void createHUDWindow();
142     void timerFired(WebCore::Timer<FullscreenVideoController>*);
143
144     void togglePlay();
145     void draw();
146
147     void onChar(int c);
148     void onMouseDown(const WebCore::IntPoint&);
149     void onMouseMove(const WebCore::IntPoint&);
150     void onMouseUp(const WebCore::IntPoint&);
151     void onKeyDown(int virtualKey);
152
153     RefPtr<WebCore::HTMLMediaElement> m_mediaElement;
154
155     HWND m_hudWindow;
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)
161     class LayerClient;
162     friend class LayerClient;
163     OwnPtr<LayerClient> m_layerClient;
164     RefPtr<WebCore::PlatformCALayer> m_rootChild;
165 #endif
166
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;
175
176     HUDWidget* m_hitWidget;
177     WebCore::IntPoint m_moveOffset;
178     bool m_movingWindow;
179     WebCore::Timer<FullscreenVideoController> m_timer;
180 };
181
182 #endif
183
184 #endif // FullscreenVideoController_h