Touching HTMLMediaElement.h or MediaPlayer.h causes a world rebuild.
[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/HTMLMediaElementEnums.h>
34 #include <WebCore/PlatformLayer.h>
35 #include <WebCore/WebVideoFullscreenInterface.h>
36 #include <functional>
37 #include <objc/objc.h>
38 #include <wtf/RefPtr.h>
39 #include <wtf/RetainPtr.h>
40 #include <wtf/ThreadSafeRefCounted.h>
41
42 OBJC_CLASS WebAVPlayerController;
43 OBJC_CLASS AVPlayerViewController;
44 OBJC_CLASS UIViewController;
45 OBJC_CLASS UIWindow;
46 OBJC_CLASS UIView;
47 OBJC_CLASS CALayer;
48 OBJC_CLASS WebAVVideoLayer;
49 OBJC_CLASS WebCALayerHostWrapper;
50
51 namespace WTF {
52 class String;
53 }
54
55 namespace WebCore {
56 class IntRect;
57 class WebVideoFullscreenModel;
58     
59 class WebVideoFullscreenChangeObserver {
60 public:
61     virtual ~WebVideoFullscreenChangeObserver() { };
62     virtual void didSetupFullscreen() = 0;
63     virtual void didEnterFullscreen() = 0;
64     virtual void didExitFullscreen() = 0;
65     virtual void didCleanupFullscreen() = 0;
66     virtual void fullscreenMayReturnToInline() = 0;
67 };
68
69 class WEBCORE_EXPORT WebVideoFullscreenInterfaceAVKit
70     : public WebVideoFullscreenInterface
71     , public ThreadSafeRefCounted<WebVideoFullscreenInterfaceAVKit> {
72
73 public:
74     static Ref<WebVideoFullscreenInterfaceAVKit> create()
75     {
76         return adoptRef(*new WebVideoFullscreenInterfaceAVKit());
77     }
78     virtual ~WebVideoFullscreenInterfaceAVKit() { }
79     WEBCORE_EXPORT void setWebVideoFullscreenModel(WebVideoFullscreenModel*);
80     WEBCORE_EXPORT void setWebVideoFullscreenChangeObserver(WebVideoFullscreenChangeObserver*);
81     
82     WEBCORE_EXPORT virtual void resetMediaState() override;
83     WEBCORE_EXPORT virtual void setDuration(double) override;
84     WEBCORE_EXPORT virtual void setCurrentTime(double currentTime, double anchorTime) override;
85     WEBCORE_EXPORT virtual void setBufferedTime(double bufferedTime) override;
86     WEBCORE_EXPORT virtual void setRate(bool isPlaying, float playbackRate) override;
87     WEBCORE_EXPORT virtual void setVideoDimensions(bool hasVideo, float width, float height) override;
88     WEBCORE_EXPORT virtual void setSeekableRanges(const TimeRanges&) override;
89     WEBCORE_EXPORT virtual void setCanPlayFastReverse(bool) override;
90     WEBCORE_EXPORT virtual void setAudioMediaSelectionOptions(const Vector<WTF::String>& options, uint64_t selectedIndex) override;
91     WEBCORE_EXPORT virtual void setLegibleMediaSelectionOptions(const Vector<WTF::String>& options, uint64_t selectedIndex) override;
92     WEBCORE_EXPORT virtual void setExternalPlayback(bool enabled, ExternalPlaybackTargetType, WTF::String localizedDeviceName) override;
93     
94     WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&, const IntRect& initialRect, UIView *, HTMLMediaElementEnums::VideoFullscreenMode, bool allowOptimizedFullscreen);
95     WEBCORE_EXPORT virtual void enterFullscreen();
96     WEBCORE_EXPORT virtual void exitFullscreen(const IntRect& finalRect);
97     WEBCORE_EXPORT virtual void cleanupFullscreen();
98     WEBCORE_EXPORT virtual void invalidate();
99     WEBCORE_EXPORT virtual void requestHideAndExitFullscreen();
100     WEBCORE_EXPORT virtual void preparedToReturnToInline(bool visible, const IntRect& inlineRect);
101
102     HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_mode; }
103     bool allowOptimizedFullscreen() const { return m_allowOptimizedFullscreen; }
104     void setIsOptimized(bool);
105     WEBCORE_EXPORT bool mayAutomaticallyShowVideoOptimized() const;
106     void fullscreenMayReturnToInline(std::function<void(bool)> callback);
107
108     void willStartOptimizedFullscreen();
109     void didStartOptimizedFullscreen();
110     void willStopOptimizedFullscreen();
111     void didStopOptimizedFullscreen();
112     void willCancelOptimizedFullscreen();
113     void didCancelOptimizedFullscreen();
114     void prepareForOptimizedFullscreenStopWithCompletionHandler(void (^)(BOOL));
115
116     void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
117     void clearMode(HTMLMediaElementEnums::VideoFullscreenMode);
118     bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode & mode; }
119     bool isMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode == mode; }
120
121 protected:
122     WEBCORE_EXPORT WebVideoFullscreenInterfaceAVKit();
123     void beginSession();
124     void setupFullscreenInternal(PlatformLayer&, const IntRect& initialRect, UIView *, HTMLMediaElementEnums::VideoFullscreenMode, bool allowOptimizedFullscreen);
125     void enterFullscreenOptimized();
126     void enterFullscreenStandard();
127     void exitFullscreenInternal(const IntRect& finalRect);
128     void cleanupFullscreenInternal();
129
130     RetainPtr<WebAVPlayerController> m_playerController;
131     RetainPtr<AVPlayerViewController> m_playerViewController;
132     RetainPtr<CALayer> m_videoLayer;
133     RetainPtr<WebAVVideoLayer> m_videoLayerContainer;
134     RetainPtr<WebCALayerHostWrapper> m_layerHostWrapper;
135     WebVideoFullscreenModel* m_videoFullscreenModel { nullptr };
136     WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
137
138     // These are only used when fullscreen is presented in a separate window.
139     RetainPtr<UIWindow> m_window;
140     RetainPtr<UIViewController> m_viewController;
141     RetainPtr<UIView> m_parentView;
142     RetainPtr<UIWindow> m_parentWindow;
143     HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };
144     std::function<void(bool)> m_prepareToInlineCallback;
145     bool m_allowOptimizedFullscreen { false };
146     bool m_exitRequested { false };
147     bool m_exitCompleted { false };
148     bool m_enterRequested { false };
149
150     void doEnterFullscreen();
151 };
152
153 }
154
155 #endif
156
157 #endif