5e48eaa214fb377f8239bfcff86263fa01b0f4c2
[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 WEBCORE_EXPORT 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     VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
59     PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); }
60     WEBCORE_EXPORT void setVideoFullscreenModel(VideoFullscreenModel*);
61     VideoFullscreenChangeObserver* videoFullscreenChangeObserver() const { return m_fullscreenChangeObserver; }
62     WEBCORE_EXPORT void setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver*);
63
64     // PlaybackSessionModelClient
65     WEBCORE_EXPORT void rateChanged(bool isPlaying, float playbackRate) override;
66     WEBCORE_EXPORT void externalPlaybackChanged(bool  enabled, PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) override;
67     WEBCORE_EXPORT void ensureControlsManager() override;
68
69     // VideoFullscreenModelClient
70     WEBCORE_EXPORT void hasVideoChanged(bool) final;
71     WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
72
73     WEBCORE_EXPORT void setupFullscreen(NSView& layerHostedView, const IntRect& initialRect, NSWindow *parentWindow, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback);
74     WEBCORE_EXPORT void enterFullscreen();
75     WEBCORE_EXPORT void exitFullscreen(const IntRect& finalRect, NSWindow *parentWindow);
76     WEBCORE_EXPORT void exitFullscreenWithoutAnimationToMode(HTMLMediaElementEnums::VideoFullscreenMode);
77     WEBCORE_EXPORT void cleanupFullscreen();
78     WEBCORE_EXPORT void invalidate();
79     void requestHideAndExitFullscreen() { }
80     WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const IntRect& inlineRect, NSWindow *parentWindow);
81     void preparedToExitFullscreen() { }
82
83     HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_mode; }
84     bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode & mode; }
85     bool isMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode == mode; }
86     void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
87     void clearMode(HTMLMediaElementEnums::VideoFullscreenMode);
88
89     bool isPlayingVideoInEnhancedFullscreen() const;
90
91     bool mayAutomaticallyShowVideoPictureInPicture() const { return false; }
92     void applicationDidBecomeActive() { }
93
94     WEBCORE_EXPORT WebVideoFullscreenInterfaceMacObjC *videoFullscreenInterfaceObjC();
95
96 private:
97     VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&);
98     Ref<PlaybackSessionInterfaceMac> m_playbackSessionInterface;
99     VideoFullscreenModel* m_videoFullscreenModel { nullptr };
100     VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
101     HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };
102     RetainPtr<WebVideoFullscreenInterfaceMacObjC> m_webVideoFullscreenInterfaceObjC;
103 };
104
105 }
106
107 #endif
108