1/* 2 * Copyright (C) 2010, 2013 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 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 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#include <wtf/win/GDIObject.h> 39 40namespace WebCore { 41class GraphicsContext; 42class PlatformCALayer; 43} 44 45class HUDWidget { 46public: 47 HUDWidget(const WebCore::IntRect& rect) : m_rect(rect) { } 48 49 virtual ~HUDWidget() { } 50 51 virtual void draw(WebCore::GraphicsContext&) = 0; 52 virtual void drag(const WebCore::IntPoint&, bool start) = 0; 53 bool hitTest(const WebCore::IntPoint& point) const { return m_rect.contains(point); } 54 55protected: 56 WebCore::IntRect m_rect; 57}; 58 59class HUDButton : public HUDWidget { 60public: 61 enum HUDButtonType { 62 NoButton, 63 PlayPauseButton, 64 TimeSliderButton, 65 VolumeUpButton, 66 VolumeSliderButton, 67 VolumeDownButton, 68 ExitFullscreenButton 69 }; 70 71 HUDButton(HUDButtonType, const WebCore::IntPoint&); 72 ~HUDButton() { } 73 74 virtual void draw(WebCore::GraphicsContext&); 75 virtual void drag(const WebCore::IntPoint&, bool start) { } 76 void setShowAltButton(bool b) { m_showAltButton = b; } 77 78private: 79 RefPtr<WebCore::Image> m_buttonImage; 80 RefPtr<WebCore::Image> m_buttonImageAlt; 81 HUDButtonType m_type; 82 bool m_showAltButton; 83}; 84 85class HUDSlider : public HUDWidget { 86public: 87 enum HUDSliderButtonShape { RoundButton, DiamondButton }; 88 89 HUDSlider(HUDSliderButtonShape, int buttonSize, const WebCore::IntRect& rect); 90 ~HUDSlider() { } 91 92 virtual void draw(WebCore::GraphicsContext&); 93 virtual void drag(const WebCore::IntPoint&, bool start); 94 float value() const { return static_cast<float>(m_buttonPosition) / (m_rect.width() - m_buttonSize); } 95 void setValue(float value) { m_buttonPosition = static_cast<int>(value * (m_rect.width() - m_buttonSize)); } 96 97private: 98 HUDSliderButtonShape m_buttonShape; 99 int m_buttonSize; 100 int m_buttonPosition; 101 int m_dragStartOffset; 102}; 103 104class FullscreenVideoController : WebCore::MediaPlayerPrivateFullscreenClient { 105 WTF_MAKE_NONCOPYABLE(FullscreenVideoController); 106public: 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 116private: 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 GDIObject<HBITMAP> m_bitmap; 156 WebCore::IntSize m_fullscreenSize; 157 WebCore::IntPoint m_hudPosition; 158 OwnPtr<WebCore::MediaPlayerPrivateFullscreenWindow> m_fullscreenWindow; 159 160 class LayerClient; 161 friend class LayerClient; 162 OwnPtr<LayerClient> m_layerClient; 163 RefPtr<WebCore::PlatformCALayer> m_rootChild; 164 165 HUDButton m_playPauseButton; 166 HUDButton m_timeSliderButton; 167 HUDButton m_volumeUpButton; 168 HUDButton m_volumeSliderButton; 169 HUDButton m_volumeDownButton; 170 HUDButton m_exitFullscreenButton; 171 HUDSlider m_volumeSlider; 172 HUDSlider m_timeSlider; 173 174 HUDWidget* m_hitWidget; 175 WebCore::IntPoint m_moveOffset; 176 bool m_movingWindow; 177 WebCore::Timer<FullscreenVideoController> m_timer; 178}; 179 180#endif 181 182#endif // FullscreenVideoController_h 183