Unreviewed API Test fix; restored a line inadventantly removed in r233926.
[WebKit-https.git] / Source / WebCore / platform / mac / VideoFullscreenInterfaceMac.mm
index dd0b463..bf676f7 100644 (file)
 #import <pal/spi/cocoa/AVKitSPI.h>
 #import <pal/spi/mac/PIPSPI.h>
 
-#import "CoreMediaSoftLink.h"
+#import <pal/cf/CoreMediaSoftLink.h>
 
-SOFT_LINK_FRAMEWORK_OPTIONAL(AVKit)
+SOFTLINK_AVKIT_FRAMEWORK()
 SOFT_LINK_CLASS_OPTIONAL(AVKit, AVValueTiming)
 
 SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(PIP)
 SOFT_LINK_CLASS_OPTIONAL(PIP, PIPViewController)
 
-using namespace WebCore;
-
 @class WebVideoViewContainer;
 
 @protocol WebVideoViewContainerDelegate <NSObject>
@@ -59,6 +57,12 @@ using namespace WebCore;
 
 @end
 
+using WebCore::VideoFullscreenModel;
+using WebCore::HTMLMediaElementEnums;
+using WebCore::VideoFullscreenInterfaceMac;
+using WebCore::VideoFullscreenChangeObserver;
+using WebCore::PlaybackSessionModel;
+
 @interface WebVideoViewContainer : NSView {
     id <WebVideoViewContainerDelegate> _videoViewContainerDelegate;
 }
@@ -103,7 +107,6 @@ enum class PIPState {
     RetainPtr<NSWindow> _returningWindow;
     NSRect _returningRect;
     BOOL _playing;
-    BOOL _didRequestExitingPIP;
     BOOL _exitingToStandardFullscreen;
 }
 
@@ -117,7 +120,6 @@ enum class PIPState {
 - (void)updateIsPlaying:(BOOL)isPlaying newPlaybackRate:(float)playbackRate;
 
 // Handling PIP transitions
-@property (nonatomic, readonly) BOOL didRequestExitingPIP;
 @property (nonatomic, getter=isExitingToStandardFullscreen) BOOL exitingToStandardFullscreen;
 
 - (void)setUpPIPForVideoView:(NSView *)videoView withFrame:(NSRect)frame inWindow:(NSWindow *)window;
@@ -131,7 +133,6 @@ enum class PIPState {
 
 @synthesize playing=_playing;
 @synthesize videoDimensions=_videoDimensions;
-@synthesize didRequestExitingPIP=_didRequestExitingPIP;
 @synthesize exitingToStandardFullscreen=_exitingToStandardFullscreen;
 
 - (instancetype)initWithVideoFullscreenInterfaceMac:(WebCore::VideoFullscreenInterfaceMac*)videoFullscreenInterfaceMac
@@ -154,7 +155,6 @@ enum class PIPState {
     _videoViewContainer = nil;
     _videoViewContainerController = nil;
     _pipState = PIPState::NotInPIP;
-    _didRequestExitingPIP = NO;
     _exitingToStandardFullscreen = NO;
     _returningWindow = nil;
     _returningRect = NSZeroRect;
@@ -221,7 +221,6 @@ enum class PIPState {
     if (_pipState != PIPState::InPIP || !_pipViewController || !_videoViewContainerController)
         return;
 
-    _didRequestExitingPIP = YES;
     [_videoViewContainerController view].layer.backgroundColor = CGColorGetConstantColor(kCGColorClear);
     [_pipViewController dismissViewController:_videoViewContainerController.get()];
     _pipState = PIPState::ExitingPIP;
@@ -231,7 +230,7 @@ enum class PIPState {
 {
     _returningWindow = window;
     _returningRect = rect;
-    
+
     [_pipViewController setReplacementRect:rect];
     [_pipViewController setReplacementWindow:window];
 
@@ -275,8 +274,7 @@ enum class PIPState {
     if (!_videoFullscreenInterfaceMac || !_videoFullscreenInterfaceMac->videoFullscreenChangeObserver())
         return YES;
 
-    _didRequestExitingPIP = YES;
-    _videoFullscreenInterfaceMac->videoFullscreenChangeObserver()->fullscreenMayReturnToInline();
+    _videoFullscreenInterfaceMac->requestHideAndExitFullscreen();
 
     return NO;
 }
@@ -299,7 +297,7 @@ enum class PIPState {
     if (_videoFullscreenInterfaceMac) {
         if (!self.isExitingToStandardFullscreen) {
             if (VideoFullscreenModel* videoFullscreenModel = _videoFullscreenInterfaceMac->videoFullscreenModel()) {
-                videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
+                videoFullscreenModel->didExitPictureInPicture();
                 videoFullscreenModel->setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspect);
             }
         }
@@ -344,6 +342,7 @@ enum class PIPState {
 @end
 
 namespace WebCore {
+using namespace PAL;
 
 VideoFullscreenInterfaceMac::VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac& playbackSessionInterface)
     : m_playbackSessionInterface(playbackSessionInterface)
@@ -427,8 +426,7 @@ void VideoFullscreenInterfaceMac::setupFullscreen(NSView& layerHostedView, const
 
     [videoFullscreenInterfaceObjC() setUpPIPForVideoView:&layerHostedView withFrame:(NSRect)initialRect inWindow:parentWindow];
 
-    RefPtr<VideoFullscreenInterfaceMac> protectedThis(this);
-    dispatch_async(dispatch_get_main_queue(), [protectedThis, this] {
+    dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
         if (m_fullscreenChangeObserver)
             m_fullscreenChangeObserver->didSetupFullscreen();
     });
@@ -439,12 +437,15 @@ void VideoFullscreenInterfaceMac::enterFullscreen()
     LOG(Fullscreen, "VideoFullscreenInterfaceMac::enterFullscreen(%p)", this);
 
     if (mode() == HTMLMediaElementEnums::VideoFullscreenModePictureInPicture) {
+        m_videoFullscreenModel->willEnterPictureInPicture();
         [m_webVideoFullscreenInterfaceObjC enterPIP];
 
 #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
         [m_playbackSessionInterface->playBackControlsManager() setPictureInPictureActive:YES];
 #endif
 
+        // FIXME(rdar://problem/42250952): Move this call into a completion handler or delegate callback.
+        m_videoFullscreenModel->didEnterPictureInPicture();
         if (m_fullscreenChangeObserver)
             m_fullscreenChangeObserver->didEnterFullscreen();
     }
@@ -458,9 +459,6 @@ void VideoFullscreenInterfaceMac::exitFullscreen(const IntRect& finalRect, NSWin
     [m_playbackSessionInterface->playBackControlsManager() setPictureInPictureActive:NO];
 #endif
 
-    if ([m_webVideoFullscreenInterfaceObjC didRequestExitingPIP])
-        return;
-
     if (finalRect.isEmpty())
         [m_webVideoFullscreenInterfaceObjC exitPIP];
     else
@@ -475,9 +473,6 @@ void VideoFullscreenInterfaceMac::exitFullscreenWithoutAnimationToMode(HTMLMedia
     [m_playbackSessionInterface->playBackControlsManager() setPictureInPictureActive:NO];
 #endif
 
-    if ([m_webVideoFullscreenInterfaceObjC didRequestExitingPIP])
-        return;
-
     bool isExitingToStandardFullscreen = mode == HTMLMediaElementEnums::VideoFullscreenModeStandard;
     // On Mac, standard fullscreen is handled by the Fullscreen API and not by VideoFullscreenManager.
     // Just update m_mode directly to HTMLMediaElementEnums::VideoFullscreenModeStandard in that case to keep
@@ -513,6 +508,15 @@ void VideoFullscreenInterfaceMac::invalidate()
     m_webVideoFullscreenInterfaceObjC = nil;
 }
 
+void VideoFullscreenInterfaceMac::requestHideAndExitFullscreen()
+{
+    if (!m_videoFullscreenModel)
+        return;
+
+    m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
+    m_videoFullscreenModel->willExitPictureInPicture();
+}
+
 #if !LOG_DISABLED
 static const char* boolString(bool val)
 {