FullscreenVideoController.h 5.9 KB

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