3d8241e8ae7641f123804c2a0f1fe213cc91e28a
[WebKit-https.git] / Source / WebCore / platform / ios / WebVideoFullscreenInterfaceAVKit.h
1 /*
2  * Copyright (C) 2014 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
27 #ifndef WebVideoFullscreenInterfaceAVKit_h
28 #define WebVideoFullscreenInterfaceAVKit_h
29
30 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
31
32 #include <WebCore/EventListener.h>
33 #include <WebCore/HTMLMediaElement.h>
34 #include <WebCore/PlatformLayer.h>
35 #include <WebCore/WebVideoFullscreenInterface.h>
36 #include <wtf/RefPtr.h>
37 #include <wtf/RetainPtr.h>
38 #include <wtf/ThreadSafeRefCounted.h>
39
40 OBJC_CLASS WebAVPlayerController;
41 OBJC_CLASS AVPlayerViewController;
42 OBJC_CLASS UIViewController;
43 OBJC_CLASS UIWindow;
44 OBJC_CLASS UIView;
45 OBJC_CLASS CALayer;
46 OBJC_CLASS WebAVVideoLayer;
47
48 namespace WTF {
49 class String;
50 }
51
52 namespace WebCore {
53 class IntRect;
54 class WebVideoFullscreenModel;
55     
56 class WebVideoFullscreenChangeObserver {
57 public:
58     virtual ~WebVideoFullscreenChangeObserver() { };
59     virtual void didSetupFullscreen() = 0;
60     virtual void didEnterFullscreen() = 0;
61     virtual void didExitFullscreen() = 0;
62     virtual void didCleanupFullscreen() = 0;
63     virtual void fullscreenMayReturnToInline() = 0;
64 };
65
66 class WEBCORE_EXPORT WebVideoFullscreenInterfaceAVKit
67     : public WebVideoFullscreenInterface
68     , public ThreadSafeRefCounted<WebVideoFullscreenInterfaceAVKit> {
69
70 public:
71     WEBCORE_EXPORT WebVideoFullscreenInterfaceAVKit();
72     virtual ~WebVideoFullscreenInterfaceAVKit() { }
73     WEBCORE_EXPORT void setWebVideoFullscreenModel(WebVideoFullscreenModel*);
74     WEBCORE_EXPORT void setWebVideoFullscreenChangeObserver(WebVideoFullscreenChangeObserver*);
75     
76     WEBCORE_EXPORT virtual void resetMediaState() override;
77     WEBCORE_EXPORT virtual void setDuration(double) override;
78     WEBCORE_EXPORT virtual void setCurrentTime(double currentTime, double anchorTime) override;
79     WEBCORE_EXPORT virtual void setRate(bool isPlaying, float playbackRate) override;
80     WEBCORE_EXPORT virtual void setVideoDimensions(bool hasVideo, float width, float height) override;
81     WEBCORE_EXPORT virtual void setSeekableRanges(const TimeRanges&) override;
82     WEBCORE_EXPORT virtual void setCanPlayFastReverse(bool) override;
83     WEBCORE_EXPORT virtual void setAudioMediaSelectionOptions(const Vector<WTF::String>& options, uint64_t selectedIndex) override;
84     WEBCORE_EXPORT virtual void setLegibleMediaSelectionOptions(const Vector<WTF::String>& options, uint64_t selectedIndex) override;
85     WEBCORE_EXPORT virtual void setExternalPlayback(bool enabled, ExternalPlaybackTargetType, WTF::String localizedDeviceName) override;
86     
87     WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&, IntRect initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
88     WEBCORE_EXPORT virtual void enterFullscreen();
89     WEBCORE_EXPORT virtual void exitFullscreen(IntRect finalRect);
90     WEBCORE_EXPORT virtual void cleanupFullscreen();
91     WEBCORE_EXPORT virtual void invalidate();
92     WEBCORE_EXPORT virtual void requestHideAndExitFullscreen();
93
94     HTMLMediaElement::VideoFullscreenMode mode() const { return m_mode; }
95     void setIsOptimized(bool);
96     WEBCORE_EXPORT bool mayAutomaticallyShowVideoOptimized();
97     bool fullscreenMayReturnToInline();
98
99 protected:
100     void beginSession();
101     void setupFullscreenInternal(PlatformLayer&, IntRect initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
102     void enterFullscreenOptimized();
103     void enterFullscreenStandard();
104     void exitFullscreenInternal(IntRect finalRect);
105     void cleanupFullscreenInternal();
106
107     RetainPtr<WebAVPlayerController> m_playerController;
108     RetainPtr<AVPlayerViewController> m_playerViewController;
109     RetainPtr<CALayer> m_videoLayer;
110     RetainPtr<WebAVVideoLayer> m_videoLayerContainer;
111     WebVideoFullscreenModel* m_videoFullscreenModel;
112     WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver;
113
114     // These are only used when fullscreen is presented in a separate window.
115     RetainPtr<UIWindow> m_window;
116     RetainPtr<UIViewController> m_viewController;
117     RetainPtr<UIView> m_parentView;
118     RetainPtr<UIWindow> m_parentWindow;
119     HTMLMediaElement::VideoFullscreenMode m_mode;
120     bool m_exitRequested;
121     bool m_exitCompleted;
122     bool m_enterRequested;
123
124     void doEnterFullscreen();
125 };
126
127 }
128
129 #endif
130
131 #endif