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