2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef WebVideoFullscreenInterfaceAVKit_h
28 #define WebVideoFullscreenInterfaceAVKit_h
30 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
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>
40 OBJC_CLASS WebAVPlayerController;
41 OBJC_CLASS AVPlayerViewController;
42 OBJC_CLASS UIViewController;
46 OBJC_CLASS WebAVVideoLayer;
54 class WebVideoFullscreenModel;
56 class WebVideoFullscreenChangeObserver {
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;
66 class WEBCORE_EXPORT WebVideoFullscreenInterfaceAVKit
67 : public WebVideoFullscreenInterface
68 , public ThreadSafeRefCounted<WebVideoFullscreenInterfaceAVKit> {
71 WEBCORE_EXPORT WebVideoFullscreenInterfaceAVKit();
72 virtual ~WebVideoFullscreenInterfaceAVKit() { }
73 WEBCORE_EXPORT void setWebVideoFullscreenModel(WebVideoFullscreenModel*);
74 WEBCORE_EXPORT void setWebVideoFullscreenChangeObserver(WebVideoFullscreenChangeObserver*);
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;
87 WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&, const IntRect& initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
88 WEBCORE_EXPORT virtual void enterFullscreen();
89 WEBCORE_EXPORT virtual void exitFullscreen(const IntRect& finalRect);
90 WEBCORE_EXPORT virtual void cleanupFullscreen();
91 WEBCORE_EXPORT virtual void invalidate();
92 WEBCORE_EXPORT virtual void requestHideAndExitFullscreen();
93 WEBCORE_EXPORT virtual void preparedToReturnToInline(bool visible, const IntRect& inlineRect);
95 HTMLMediaElement::VideoFullscreenMode mode() const { return m_mode; }
96 void setIsOptimized(bool);
97 WEBCORE_EXPORT bool mayAutomaticallyShowVideoOptimized();
98 void fullscreenMayReturnToInline();
102 void setupFullscreenInternal(PlatformLayer&, const IntRect& initialRect, UIView *, HTMLMediaElement::VideoFullscreenMode, bool allowOptimizedFullscreen);
103 void enterFullscreenOptimized();
104 void enterFullscreenStandard();
105 void exitFullscreenInternal(const IntRect& finalRect);
106 void cleanupFullscreenInternal();
108 RetainPtr<WebAVPlayerController> m_playerController;
109 RetainPtr<AVPlayerViewController> m_playerViewController;
110 RetainPtr<CALayer> m_videoLayer;
111 RetainPtr<WebAVVideoLayer> m_videoLayerContainer;
112 WebVideoFullscreenModel* m_videoFullscreenModel;
113 WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver;
115 // These are only used when fullscreen is presented in a separate window.
116 RetainPtr<UIWindow> m_window;
117 RetainPtr<UIViewController> m_viewController;
118 RetainPtr<UIView> m_parentView;
119 RetainPtr<UIWindow> m_parentWindow;
120 HTMLMediaElement::VideoFullscreenMode m_mode;
121 bool m_exitRequested;
122 bool m_exitCompleted;
123 bool m_enterRequested;
125 void doEnterFullscreen();