PiP from Element Fullscreen should match AVKit's behavior
[WebKit-https.git] / Source / WebCore / platform / mac / VideoFullscreenInterfaceMac.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 #pragma once
27
28 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
29
30 #include "HTMLMediaElementEnums.h"
31 #include "PlaybackSessionInterfaceMac.h"
32 #include "PlaybackSessionModel.h"
33 #include "VideoFullscreenModel.h"
34 #include <wtf/RefCounted.h>
35 #include <wtf/RetainPtr.h>
36 #include <wtf/text/WTFString.h>
37
38 OBJC_CLASS NSWindow;
39 OBJC_CLASS WebVideoFullscreenInterfaceMacObjC;
40
41 namespace WebCore {
42 class IntRect;
43 class FloatSize;
44 class PlaybackSessionInterfaceMac;
45 class VideoFullscreenChangeObserver;
46
47 class VideoFullscreenInterfaceMac
48     : public VideoFullscreenModelClient
49     , private PlaybackSessionModelClient
50     , public RefCounted<VideoFullscreenInterfaceMac> {
51
52 public:
53     static Ref<VideoFullscreenInterfaceMac> create(PlaybackSessionInterfaceMac& playbackSessionInterface)
54     {
55         return adoptRef(*new VideoFullscreenInterfaceMac(playbackSessionInterface));
56     }
57     virtual ~VideoFullscreenInterfaceMac();
58     PlaybackSessionInterfaceMac& playbackSessionInterface() const { return m_playbackSessionInterface.get(); }
59     VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
60     PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); }
61     WEBCORE_EXPORT void setVideoFullscreenModel(VideoFullscreenModel*);
62     VideoFullscreenChangeObserver* videoFullscreenChangeObserver() const { return m_fullscreenChangeObserver; }
63     WEBCORE_EXPORT void setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver*);
64
65     // PlaybackSessionModelClient
66     WEBCORE_EXPORT void rateChanged(bool isPlaying, float playbackRate) override;
67     WEBCORE_EXPORT void externalPlaybackChanged(bool  enabled, PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) override;
68     WEBCORE_EXPORT void ensureControlsManager() override;
69
70     // VideoFullscreenModelClient
71     WEBCORE_EXPORT void hasVideoChanged(bool) final;
72     WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
73
74     WEBCORE_EXPORT void setupFullscreen(NSView& layerHostedView, const IntRect& initialRect, NSWindow *parentWindow, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback);
75     WEBCORE_EXPORT void enterFullscreen();
76     WEBCORE_EXPORT void exitFullscreen(const IntRect& finalRect, NSWindow *parentWindow);
77     WEBCORE_EXPORT void exitFullscreenWithoutAnimationToMode(HTMLMediaElementEnums::VideoFullscreenMode);
78     WEBCORE_EXPORT void cleanupFullscreen();
79     WEBCORE_EXPORT void invalidate();
80     WEBCORE_EXPORT void requestHideAndExitFullscreen();
81     WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const IntRect& inlineRect, NSWindow *parentWindow);
82     void preparedToExitFullscreen() { }
83
84     HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_mode; }
85     bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode & mode; }
86     bool isMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode == mode; }
87     WEBCORE_EXPORT void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
88     void clearMode(HTMLMediaElementEnums::VideoFullscreenMode);
89
90     WEBCORE_EXPORT bool isPlayingVideoInEnhancedFullscreen() const;
91
92     bool mayAutomaticallyShowVideoPictureInPicture() const { return false; }
93     void applicationDidBecomeActive() { }
94
95     WEBCORE_EXPORT WebVideoFullscreenInterfaceMacObjC *videoFullscreenInterfaceObjC();
96
97 private:
98     WEBCORE_EXPORT VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&);
99     Ref<PlaybackSessionInterfaceMac> m_playbackSessionInterface;
100     VideoFullscreenModel* m_videoFullscreenModel { nullptr };
101     VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
102     HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };
103     RetainPtr<WebVideoFullscreenInterfaceMacObjC> m_webVideoFullscreenInterfaceObjC;
104 };
105
106 }
107
108 #endif
109