db18c0da0116dbb57d0997e66a708aa5e71aec47
[WebKit-https.git] / Source / WebCore / platform / mac / WebVideoFullscreenInterfaceMac.h
1 /*
2  * Copyright (C) 2016 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 #ifndef WebVideoFullscreenInterfaceMac_h
27 #define WebVideoFullscreenInterfaceMac_h
28
29 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
30
31 #include "HTMLMediaElementEnums.h"
32 #include "WebPlaybackSessionInterfaceMac.h"
33 #include "WebPlaybackSessionModel.h"
34 #include "WebVideoFullscreenInterface.h"
35 #include "WebVideoFullscreenModel.h"
36 #include <wtf/RefCounted.h>
37 #include <wtf/RetainPtr.h>
38 #include <wtf/text/WTFString.h>
39
40 OBJC_CLASS NSWindow;
41 OBJC_CLASS WebVideoFullscreenInterfaceMacObjC;
42
43 namespace WebCore {
44 class IntRect;
45 class FloatSize;
46 class WebPlaybackSessionInterfaceMac;
47 class WebVideoFullscreenChangeObserver;
48
49 class WEBCORE_EXPORT WebVideoFullscreenInterfaceMac
50     : public WebVideoFullscreenInterface
51     , public WebVideoFullscreenModelClient
52     , private WebPlaybackSessionModelClient
53     , public RefCounted<WebVideoFullscreenInterfaceMac> {
54
55 public:
56     static Ref<WebVideoFullscreenInterfaceMac> create(WebPlaybackSessionInterfaceMac& playbackSessionInterface)
57     {
58         return adoptRef(*new WebVideoFullscreenInterfaceMac(playbackSessionInterface));
59     }
60     virtual ~WebVideoFullscreenInterfaceMac();
61     WebVideoFullscreenModel* webVideoFullscreenModel() const { return m_videoFullscreenModel; }
62     WebPlaybackSessionModel* webPlaybackSessionModel() const { return m_playbackSessionInterface->webPlaybackSessionModel(); }
63     WEBCORE_EXPORT void setWebVideoFullscreenModel(WebVideoFullscreenModel*);
64     WebVideoFullscreenChangeObserver* webVideoFullscreenChangeObserver() const { return m_fullscreenChangeObserver; }
65     WEBCORE_EXPORT void setWebVideoFullscreenChangeObserver(WebVideoFullscreenChangeObserver*);
66
67     // WebPlaybackSessionModelClient
68     WEBCORE_EXPORT void rateChanged(bool isPlaying, float playbackRate) override;
69     WEBCORE_EXPORT void externalPlaybackChanged(bool  enabled, WebPlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) override;
70
71     // WebVideoFullscreenModelClient
72     WEBCORE_EXPORT void hasVideoChanged(bool) final;
73     WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
74
75     WEBCORE_EXPORT void setupFullscreen(NSView& layerHostedView, const IntRect& initialRect, NSWindow *parentWindow, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback);
76     WEBCORE_EXPORT void enterFullscreen();
77     WEBCORE_EXPORT void exitFullscreen(const IntRect& finalRect, NSWindow *parentWindow);
78     WEBCORE_EXPORT void exitFullscreenWithoutAnimationToMode(HTMLMediaElementEnums::VideoFullscreenMode);
79     WEBCORE_EXPORT void cleanupFullscreen();
80     WEBCORE_EXPORT void invalidate();
81     WEBCORE_EXPORT void requestHideAndExitFullscreen() { }
82     WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const IntRect& inlineRect, NSWindow *parentWindow);
83     WEBCORE_EXPORT void ensureControlsManager();
84
85     HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_mode; }
86     bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode & mode; }
87     bool isMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode == mode; }
88     void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
89     void clearMode(HTMLMediaElementEnums::VideoFullscreenMode);
90
91     bool isPlayingVideoInEnhancedFullscreen() const;
92
93     WEBCORE_EXPORT bool mayAutomaticallyShowVideoPictureInPicture() const { return false; }
94     void applicationDidBecomeActive() { }
95
96     WEBCORE_EXPORT WebVideoFullscreenInterfaceMacObjC *videoFullscreenInterfaceObjC();
97
98 private:
99     WebVideoFullscreenInterfaceMac(WebPlaybackSessionInterfaceMac&);
100     Ref<WebPlaybackSessionInterfaceMac> m_playbackSessionInterface;
101     WebVideoFullscreenModel* m_videoFullscreenModel { nullptr };
102     WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
103     HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };
104     RetainPtr<WebVideoFullscreenInterfaceMacObjC> m_webVideoFullscreenInterfaceObjC;
105 };
106
107 }
108
109 #endif
110
111 #endif /* WebVideoFullscreenInterfaceMac_h */