Changeset 233926 in webkit


Ignore:
Timestamp:
Jul 18, 2018 12:50:04 PM (6 years ago)
Author:
jer.noble@apple.com
Message:

PiP from Element Fullscreen should match AVKit's behavior
https://bugs.webkit.org/show_bug.cgi?id=187623
Source/WebCore:

Reviewed by Jon Lee.

PiP behavior should be defined at the WebKit2 level, and not in HTMLMediaElement:

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::enterFullscreen):

Add an accessor for pictureInPictureWasStartedWhenEnteringBackground():

  • platform/cocoa/VideoFullscreenModelVideoElement.mm:

(VideoFullscreenInterfaceAVKit::pictureInPictureWasStartedWhenEnteringBackground const):

Add VideoFullscreenModelClient virutal methods for PiP change notifications:

  • platform/cocoa/VideoFullscreenModel.h:

(WebCore::VideoFullscreenModelClient::hasVideoChanged):
(WebCore::VideoFullscreenModelClient::videoDimensionsChanged):
(WebCore::VideoFullscreenModelClient::willEnterPictureInPicture):
(WebCore::VideoFullscreenModelClient::didEnterPictureInPicture):
(WebCore::VideoFullscreenModelClient::failedToEnterPictureInPicture):
(WebCore::VideoFullscreenModelClient::willExitPictureInPicture):
(WebCore::VideoFullscreenModelClient::didExitPictureInPicture):
(WebCore::VideoFullscreenModelClient::failedToExitPictureInPicture):

  • platform/cocoa/VideoFullscreenModelVideoElement.h:
  • platform/cocoa/VideoFullscreenModelVideoElement.mm:

(VideoFullscreenModelVideoElement::willEnterPictureInPicture):
(VideoFullscreenModelVideoElement::didEnterPictureInPicture):
(VideoFullscreenModelVideoElement::failedToEnterPictureInPicture):
(VideoFullscreenModelVideoElement::willExitPictureInPicture):
(VideoFullscreenModelVideoElement::didExitPictureInPicture):
(VideoFullscreenModelVideoElement::failedToExitPictureInPicture):

  • platform/ios/VideoFullscreenInterfaceAVKit.h:
  • platform/ios/VideoFullscreenInterfaceAVKit.mm:

(-[WebAVPlayerLayer layoutSublayers]):
(-[WebAVPlayerLayer resolveBounds]):
(-[WebAVPlayerLayer setVideoGravity:]):
(VideoFullscreenInterfaceAVKit::setupFullscreen):
(VideoFullscreenInterfaceAVKit::presentingViewController):
(VideoFullscreenInterfaceAVKit::willStartPictureInPicture):
(VideoFullscreenInterfaceAVKit::didStartPictureInPicture):
(VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture):
(VideoFullscreenInterfaceAVKit::willStopPictureInPicture):
(VideoFullscreenInterfaceAVKit::didStopPictureInPicture):
(VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason):
(VideoFullscreenInterfaceAVKit::doSetup):

  • platform/ios/WebVideoFullscreenControllerAVKit.mm:

(VideoFullscreenControllerContext::willEnterPictureInPicture):
(VideoFullscreenControllerContext::didEnterPictureInPicture):
(VideoFullscreenControllerContext::failedToEnterPictureInPicture):
(VideoFullscreenControllerContext::willExitPictureInPicture):
(VideoFullscreenControllerContext::didExitPictureInPicture):
(VideoFullscreenControllerContext::failedToExitPictureInPicture):

  • platform/mac/VideoFullscreenInterfaceMac.h:

(WebCore::VideoFullscreenInterfaceMac::requestHideAndExitFullscreen): Deleted.

  • platform/mac/VideoFullscreenInterfaceMac.mm:

(-[WebVideoFullscreenInterfaceMacObjC invalidateFullscreenState]):
(-[WebVideoFullscreenInterfaceMacObjC exitPIP]):
(-[WebVideoFullscreenInterfaceMacObjC exitPIPAnimatingToRect:inWindow:]):
(-[WebVideoFullscreenInterfaceMacObjC pipShouldClose:]):
(-[WebVideoFullscreenInterfaceMacObjC pipDidClose:]):
(WebCore::VideoFullscreenInterfaceMac::enterFullscreen):
(WebCore::VideoFullscreenInterfaceMac::exitFullscreen):
(WebCore::VideoFullscreenInterfaceMac::exitFullscreenWithoutAnimationToMode):
(WebCore::VideoFullscreenInterfaceMac::requestHideAndExitFullscreen):

Source/WebCore/PAL:

Reviewed by Jon Lee.

  • pal/spi/mac/PIPSPI.h:

Source/WebKit:

Reviewed by Jon Lee.

  • UIProcess/Cocoa/PlaybackSessionManagerProxy.h:

(WebKit::PlaybackSessionManagerProxy::controlsManagerContextId const):

  • UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
  • UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:

(WebKit::VideoFullscreenModelContext::willEnterPictureInPicture):
(WebKit::VideoFullscreenModelContext::didEnterPictureInPicture):
(WebKit::VideoFullscreenModelContext::failedToEnterPictureInPicture):
(WebKit::VideoFullscreenModelContext::willExitPictureInPicture):
(WebKit::VideoFullscreenModelContext::didExitPictureInPicture):
(WebKit::VideoFullscreenModelContext::failedToExitPictureInPicture):
(WebKit::VideoFullscreenManagerProxy::controlsManagerInterface):

  • UIProcess/ios/fullscreen/WKFullScreenViewController.mm:

(WKFullScreenViewControllerVideoFullscreenModelClient::setParent):
(WKFullScreenViewControllerVideoFullscreenModelClient::setInterface):
(WKFullScreenViewControllerVideoFullscreenModelClient::interface const):
(-[WKFullScreenViewController initWithWebView:]):
(-[WKFullScreenViewController dealloc]):
(-[WKFullScreenViewController videoControlsManagerDidChange]):
(-[WKFullScreenViewController ensurePiPAnimator]):
(-[WKFullScreenViewController willEnterPictureInPicture]):
(-[WKFullScreenViewController didEnterPictureInPicture]):
(-[WKFullScreenViewController failedToEnterPictureInPicture]):
(-[WKFullScreenViewController loadView]):
(-[WKFullScreenViewController viewWillAppear:]):

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::videoControlsManagerDidChange):

  • UIProcess/mac/WKFullScreenWindowController.h:
  • UIProcess/mac/WKFullScreenWindowController.mm:

(WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient::setParent):
(WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient::setInterface):
(WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient::interface const):
(-[WKFullScreenWindowController initWithWindow:webView:page:]):
(-[WKFullScreenWindowController dealloc]):
(-[WKFullScreenWindowController videoControlsManagerDidChange]):
(-[WKFullScreenWindowController willEnterPictureInPicture]):

Tools:

<rdar://problem/41212379>

Reviewed by Jon Lee.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/ExitFullscreenOnEnterPiP.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/ExitFullscreenOnEnterPiP.mm: Added.

(-[ExitFullscreenOnEnterPiPUIDelegate _webView:hasVideoInPictureInPictureDidChange:]):
(-[ExitFullscreenOnEnterPiPUIDelegate _webViewDidEnterFullscreen:]):
(-[ExitFullscreenOnEnterPiPUIDelegate _webViewDidExitFullscreen:]):
(TestWebKitAPI::TEST):

LayoutTests:

Reviewed by Jon Lee.

  • TestExpectations:
  • media/fullscreen-video-going-into-pip-expected.txt: Removed.
  • media/fullscreen-video-going-into-pip.html: Removed.
  • media/video-contained-in-fullscreen-element-going-into-pip-expected.txt: Removed.
  • media/video-contained-in-fullscreen-element-going-into-pip.html: Removed.
  • platform/mac-wk2/TestExpectations:
Location:
trunk
Files:
2 added
4 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r233923 r233926  
     12018-07-18  Jer Noble  <jer.noble@apple.com>
     2
     3        PiP from Element Fullscreen should match AVKit's behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=187623
     5
     6        Reviewed by Jon Lee.
     7
     8        * TestExpectations:
     9        * media/fullscreen-video-going-into-pip-expected.txt: Removed.
     10        * media/fullscreen-video-going-into-pip.html: Removed.
     11        * media/video-contained-in-fullscreen-element-going-into-pip-expected.txt: Removed.
     12        * media/video-contained-in-fullscreen-element-going-into-pip.html: Removed.
     13        * platform/mac-wk2/TestExpectations:
     14
    1152018-07-18  Truitt Savell  <tsavell@apple.com>
    216
  • trunk/LayoutTests/TestExpectations

    r233922 r233926  
    14471447media/element-containing-pip-video-going-into-fullscreen.html [ WontFix ]
    14481448media/fullscreen-api-enabled-media-with-presentation-mode.html [ WontFix ]
    1449 media/fullscreen-video-going-into-pip.html [ WontFix ]
    14501449media/navigate-with-pip-should-not-crash.html [ WontFix ]
    14511450media/pip-video-going-into-fullscreen.html [ WontFix ]
    1452 media/video-contained-in-fullscreen-element-going-into-pip.html [ WontFix ]
    14531451
    14541452webkit.org/b/159370 [ Debug ] fast/history/page-cache-destroy-document.html [ Skip ]
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r233880 r233926  
    548548[ Sierra+ ] media/element-containing-pip-video-going-into-fullscreen.html [ Pass Timeout ]
    549549webkit.org/b/172998 [ Sierra+ ] media/fullscreen-api-enabled-media-with-presentation-mode.html [ Failure ]
    550 [ Sierra+ ] media/fullscreen-video-going-into-pip.html [ Pass ]
    551550webkit.org/b/173199 [ Sierra+ ] media/navigate-with-pip-should-not-crash.html [ Pass Failure ]
    552551[ Sierra+ ] media/pip-video-going-into-fullscreen.html [ Pass ]
    553 [ Sierra+ ] media/video-contained-in-fullscreen-element-going-into-pip.html [ Pass ]
    554552
    555553# RTL Scrollbars are enabled on Sierra WebKit2.
  • trunk/Source/WebCore/ChangeLog

    r233919 r233926  
     12018-07-18  Jer Noble  <jer.noble@apple.com>
     2
     3        PiP from Element Fullscreen should match AVKit's behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=187623
     5
     6        Reviewed by Jon Lee.
     7
     8        PiP behavior should be defined at the WebKit2 level, and not in HTMLMediaElement:
     9
     10        * html/HTMLMediaElement.cpp:
     11        (WebCore::HTMLMediaElement::enterFullscreen):
     12
     13        Add an accessor for pictureInPictureWasStartedWhenEnteringBackground():
     14
     15        * platform/cocoa/VideoFullscreenModelVideoElement.mm:
     16        (VideoFullscreenInterfaceAVKit::pictureInPictureWasStartedWhenEnteringBackground const):
     17
     18        Add VideoFullscreenModelClient virutal methods for PiP change notifications:
     19
     20        * platform/cocoa/VideoFullscreenModel.h:
     21        (WebCore::VideoFullscreenModelClient::hasVideoChanged):
     22        (WebCore::VideoFullscreenModelClient::videoDimensionsChanged):
     23        (WebCore::VideoFullscreenModelClient::willEnterPictureInPicture):
     24        (WebCore::VideoFullscreenModelClient::didEnterPictureInPicture):
     25        (WebCore::VideoFullscreenModelClient::failedToEnterPictureInPicture):
     26        (WebCore::VideoFullscreenModelClient::willExitPictureInPicture):
     27        (WebCore::VideoFullscreenModelClient::didExitPictureInPicture):
     28        (WebCore::VideoFullscreenModelClient::failedToExitPictureInPicture):
     29        * platform/cocoa/VideoFullscreenModelVideoElement.h:
     30        * platform/cocoa/VideoFullscreenModelVideoElement.mm:
     31        (VideoFullscreenModelVideoElement::willEnterPictureInPicture):
     32        (VideoFullscreenModelVideoElement::didEnterPictureInPicture):
     33        (VideoFullscreenModelVideoElement::failedToEnterPictureInPicture):
     34        (VideoFullscreenModelVideoElement::willExitPictureInPicture):
     35        (VideoFullscreenModelVideoElement::didExitPictureInPicture):
     36        (VideoFullscreenModelVideoElement::failedToExitPictureInPicture):
     37        * platform/ios/VideoFullscreenInterfaceAVKit.h:
     38        * platform/ios/VideoFullscreenInterfaceAVKit.mm:
     39        (-[WebAVPlayerLayer layoutSublayers]):
     40        (-[WebAVPlayerLayer resolveBounds]):
     41        (-[WebAVPlayerLayer setVideoGravity:]):
     42        (VideoFullscreenInterfaceAVKit::setupFullscreen):
     43        (VideoFullscreenInterfaceAVKit::presentingViewController):
     44        (VideoFullscreenInterfaceAVKit::willStartPictureInPicture):
     45        (VideoFullscreenInterfaceAVKit::didStartPictureInPicture):
     46        (VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture):
     47        (VideoFullscreenInterfaceAVKit::willStopPictureInPicture):
     48        (VideoFullscreenInterfaceAVKit::didStopPictureInPicture):
     49        (VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason):
     50        (VideoFullscreenInterfaceAVKit::doSetup):
     51        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
     52        (VideoFullscreenControllerContext::willEnterPictureInPicture):
     53        (VideoFullscreenControllerContext::didEnterPictureInPicture):
     54        (VideoFullscreenControllerContext::failedToEnterPictureInPicture):
     55        (VideoFullscreenControllerContext::willExitPictureInPicture):
     56        (VideoFullscreenControllerContext::didExitPictureInPicture):
     57        (VideoFullscreenControllerContext::failedToExitPictureInPicture):
     58        * platform/mac/VideoFullscreenInterfaceMac.h:
     59        (WebCore::VideoFullscreenInterfaceMac::requestHideAndExitFullscreen): Deleted.
     60        * platform/mac/VideoFullscreenInterfaceMac.mm:
     61        (-[WebVideoFullscreenInterfaceMacObjC invalidateFullscreenState]):
     62        (-[WebVideoFullscreenInterfaceMacObjC exitPIP]):
     63        (-[WebVideoFullscreenInterfaceMacObjC exitPIPAnimatingToRect:inWindow:]):
     64        (-[WebVideoFullscreenInterfaceMacObjC pipShouldClose:]):
     65        (-[WebVideoFullscreenInterfaceMacObjC pipDidClose:]):
     66        (WebCore::VideoFullscreenInterfaceMac::enterFullscreen):
     67        (WebCore::VideoFullscreenInterfaceMac::exitFullscreen):
     68        (WebCore::VideoFullscreenInterfaceMac::exitFullscreenWithoutAnimationToMode):
     69        (WebCore::VideoFullscreenInterfaceMac::requestHideAndExitFullscreen):
     70
    1712018-07-18  Basuke Suzuki  <Basuke.Suzuki@sony.com>
    272
  • trunk/Source/WebCore/PAL/ChangeLog

    r233837 r233926  
     12018-07-18  Jer Noble  <jer.noble@apple.com>
     2
     3        PiP from Element Fullscreen should match AVKit's behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=187623
     5
     6        Reviewed by Jon Lee.
     7
     8        * pal/spi/mac/PIPSPI.h:
     9
    1102018-07-14  Kocsen Chung  <kocsen_chung@apple.com>
    211
  • trunk/Source/WebCore/PAL/pal/spi/mac/PIPSPI.h

    r227552 r233926  
    5050@optional
    5151- (BOOL)pipShouldClose:(PIPViewController *)pip;
     52- (void)pipWillClose:(PIPViewController *)pip;
    5253- (void)pipDidClose:(PIPViewController *)pip;
    5354- (void)pipActionPlay:(PIPViewController *)pip;
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r233865 r233926  
    59195919    m_waitingToEnterFullscreen = true;
    59205920
    5921 #if ENABLE(FULLSCREEN_API)
    5922     if (document().settings().fullScreenEnabled()) {
    5923 #if ENABLE(VIDEO_USES_ELEMENT_FULLSCREEN)
    5924         if (mode == VideoFullscreenModeStandard) {
    5925             document().requestFullScreenForElement(this, Document::ExemptIFrameAllowFullScreenRequirement);
    5926             return;
    5927         }
    5928 #endif
    5929 
    5930         // If this media element is not going to standard fullscreen mode but there's
    5931         // an element that's currently in full screen in the document, exit full screen
    5932         // if it contains this media element.
    5933         if (RefPtr<Element> fullscreenElement = document().webkitCurrentFullScreenElement()) {
    5934             if (fullscreenElement->contains(this))
    5935                 document().webkitCancelFullScreen();
    5936         }
     5921#if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO_USES_ELEMENT_FULLSCREEN)
     5922    if (document().settings().fullScreenEnabled() && mode == VideoFullscreenModeStandard) {
     5923        document().requestFullScreenForElement(this, Document::ExemptIFrameAllowFullScreenRequirement);
     5924        return;
    59375925    }
    59385926#endif
  • trunk/Source/WebCore/platform/cocoa/VideoFullscreenModel.h

    r229714 r233926  
    5858    virtual bool hasVideo() const = 0;
    5959
     60    virtual void willEnterPictureInPicture() = 0;
     61    virtual void didEnterPictureInPicture() = 0;
     62    virtual void failedToEnterPictureInPicture() = 0;
     63    virtual void willExitPictureInPicture() = 0;
     64    virtual void didExitPictureInPicture() = 0;
     65
    6066#if PLATFORM(IOS)
    6167    virtual UIViewController *presentingViewController() { return nullptr; }
     
    6773public:
    6874    virtual ~VideoFullscreenModelClient() = default;
    69     virtual void hasVideoChanged(bool) = 0;
    70     virtual void videoDimensionsChanged(const FloatSize&) = 0;
     75    virtual void hasVideoChanged(bool) { };
     76    virtual void videoDimensionsChanged(const FloatSize&) { };
     77    virtual void willEnterPictureInPicture() { }
     78    virtual void didEnterPictureInPicture() { }
     79    virtual void failedToEnterPictureInPicture() { }
     80    virtual void willExitPictureInPicture() { }
     81    virtual void didExitPictureInPicture() { }
    7182};
    7283
  • trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h

    r233189 r233926  
    8181    void setVideoDimensions(const FloatSize&);
    8282
     83    void willEnterPictureInPicture() override;
     84    void didEnterPictureInPicture() override;
     85    void failedToEnterPictureInPicture() override;
     86    void willExitPictureInPicture() override;
     87    void didExitPictureInPicture() override;
     88
    8389    static const Vector<WTF::AtomicString>& observedEventNames();
    8490    const WTF::AtomicString& eventNameAll();
  • trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm

    r230194 r233926  
    241241}
    242242
     243void VideoFullscreenModelVideoElement::willEnterPictureInPicture()
     244{
     245    for (auto& client : m_clients)
     246        client->willEnterPictureInPicture();
     247}
     248
     249void VideoFullscreenModelVideoElement::didEnterPictureInPicture()
     250{
     251    for (auto& client : m_clients)
     252        client->didEnterPictureInPicture();
     253}
     254
     255void VideoFullscreenModelVideoElement::failedToEnterPictureInPicture()
     256{
     257    for (auto& client : m_clients)
     258        client->failedToEnterPictureInPicture();
     259}
     260
     261void VideoFullscreenModelVideoElement::willExitPictureInPicture()
     262{
     263    for (auto& client : m_clients)
     264        client->willExitPictureInPicture();
     265}
     266
     267void VideoFullscreenModelVideoElement::didExitPictureInPicture()
     268{
     269    for (auto& client : m_clients)
     270        client->didExitPictureInPicture();
     271}
     272
    243273#endif
  • trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h

    r230194 r233926  
    5959class VideoFullscreenChangeObserver;
    6060   
    61 class WEBCORE_EXPORT VideoFullscreenInterfaceAVKit final
     61class VideoFullscreenInterfaceAVKit final
    6262    : public VideoFullscreenModelClient
    6363    , public PlaybackSessionModelClient
     
    6565
    6666public:
    67     static Ref<VideoFullscreenInterfaceAVKit> create(PlaybackSessionInterfaceAVKit&);
     67    WEBCORE_EXPORT static Ref<VideoFullscreenInterfaceAVKit> create(PlaybackSessionInterfaceAVKit&);
    6868    virtual ~VideoFullscreenInterfaceAVKit();
    6969    WEBCORE_EXPORT void setVideoFullscreenModel(VideoFullscreenModel*);
    7070    WEBCORE_EXPORT void setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver*);
     71    PlaybackSessionInterfaceAVKit& playbackSessionInterface() const { return m_playbackSessionInterface.get(); }
    7172    PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); }
    7273
     
    131132#endif
    132133
    133     VideoFullscreenModel* model() const { return m_videoFullscreenModel; }
     134    VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
    134135    bool shouldExitFullscreenWithReason(ExitFullScreenReason);
    135136    HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_currentMode.mode(); }
     
    138139    void fullscreenMayReturnToInline(WTF::Function<void(bool)>&& callback);
    139140    bool wirelessVideoPlaybackDisabled() const;
    140     void applicationDidBecomeActive();
     141    WEBCORE_EXPORT void applicationDidBecomeActive();
    141142
    142143    void willStartPictureInPicture();
     
    152153    bool isPlayingVideoInEnhancedFullscreen() const;
    153154
    154     void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
     155    WEBCORE_EXPORT void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
    155156    void clearMode(HTMLMediaElementEnums::VideoFullscreenMode);
    156157    bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_currentMode.hasMode(mode); }
     
    160161    UIViewController *fullscreenViewController() const { return m_viewController.get(); }
    161162    WebAVPlayerLayerView* playerLayerView() const { return m_playerLayerView.get(); }
     163    WEBCORE_EXPORT bool pictureInPictureWasStartedWhenEnteringBackground() const;
    162164#endif
    163165
  • trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm

    r233476 r233926  
    290290        sourceVideoFrame = smallestRectWithAspectRatioAroundRect(videoAspectRatio, self.modelVideoLayerFrame);
    291291        self.modelVideoLayerFrame = CGRectMake(0, 0, sourceVideoFrame.width(), sourceVideoFrame.height());
    292         ASSERT(_fullscreenInterface->model());
    293         _fullscreenInterface->model()->setVideoLayerFrame(self.modelVideoLayerFrame);
     292        ASSERT(_fullscreenInterface->videoFullscreenModel());
     293        _fullscreenInterface->videoFullscreenModel()->setVideoLayerFrame(self.modelVideoLayerFrame);
    294294        targetVideoFrame = smallestRectWithAspectRatioAroundRect(videoAspectRatio, self.bounds);
    295295    } else
     
    326326    if (!CGRectEqualToRect(self.modelVideoLayerFrame, [self bounds])) {
    327327        self.modelVideoLayerFrame = [self bounds];
    328         ASSERT(_fullscreenInterface->model());
    329         _fullscreenInterface->model()->setVideoLayerFrame(self.modelVideoLayerFrame);
     328        ASSERT(_fullscreenInterface->videoFullscreenModel());
     329        _fullscreenInterface->videoFullscreenModel()->setVideoLayerFrame(self.modelVideoLayerFrame);
    330330    }
    331331    [(UIView *)[_videoSublayer delegate] setTransform:CGAffineTransformIdentity];
     
    351351        ASSERT_NOT_REACHED();
    352352   
    353     ASSERT(_fullscreenInterface->model());
    354     _fullscreenInterface->model()->setVideoLayerGravity(gravity);
     353    ASSERT(_fullscreenInterface->videoFullscreenModel());
     354    _fullscreenInterface->videoFullscreenModel()->setVideoLayerGravity(gravity);
    355355}
    356356
     
    798798}
    799799
     800BOOL VideoFullscreenInterfaceAVKit::pictureInPictureWasStartedWhenEnteringBackground() const
     801{
     802    return [m_playerViewController pictureInPictureWasStartedWhenEnteringBackground];
     803}
     804
    800805#if !ENABLE(FULLSCREEN_API)
    801806
     
    880885
    881886#if PLATFORM(WATCHOS)
    882     m_viewController = model()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController);
     887    m_viewController = videoFullscreenModel()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController);
    883888#endif
    884889
     
    945950UIViewController *VideoFullscreenInterfaceAVKit::presentingViewController()
    946951{
    947     auto *controller = model()->presentingViewController();
     952    auto *controller = videoFullscreenModel()->presentingViewController();
    948953    if (!controller)
    949954        controller = fallbackViewController(m_parentView.get());
     
    11351140    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::willStartPictureInPicture(%p)", this);
    11361141    setMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
     1142    if (m_videoFullscreenModel)
     1143        m_videoFullscreenModel->willEnterPictureInPicture();
    11371144}
    11381145
     
    11401147{
    11411148    LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::didStartPictureInPicture(%p)", this);
    1142     m_shouldReturnToFullscreenAfterEnteringForeground = [m_playerViewController pictureInPictureWasStartedWhenEnteringBackground];
     1149    m_shouldReturnToFullscreenAfterEnteringForeground = pictureInPictureWasStartedWhenEnteringBackground();
    11431150    [m_playerViewController setShowsPlaybackControls:YES];
    11441151
    11451152    if (m_currentMode.hasFullscreen()) {
    1146         if (![m_playerViewController pictureInPictureWasStartedWhenEnteringBackground]) {
     1153        if (!pictureInPictureWasStartedWhenEnteringBackground()) {
    11471154            [[m_playerViewController view] layoutIfNeeded];
    11481155            [m_playerViewController exitFullScreenAnimated:YES completionHandler:[protectedThis = makeRefPtr(this), this] (BOOL success, NSError* error) {
     
    11601167    if (m_fullscreenChangeObserver)
    11611168        m_fullscreenChangeObserver->didEnterFullscreen();
     1169    if (m_videoFullscreenModel)
     1170        m_videoFullscreenModel->didEnterPictureInPicture();
    11621171}
    11631172
     
    11741183    if (m_fullscreenChangeObserver)
    11751184        m_fullscreenChangeObserver->didEnterFullscreen();
     1185    if (m_videoFullscreenModel)
     1186        m_videoFullscreenModel->failedToEnterPictureInPicture();
    11761187
    11771188    if (m_videoFullscreenModel)
     
    11941205    if (m_videoFullscreenModel)
    11951206        m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
     1207    if (m_videoFullscreenModel)
     1208        m_videoFullscreenModel->willExitPictureInPicture();
    11961209}
    11971210
     
    12161229    if (m_fullscreenChangeObserver)
    12171230        m_fullscreenChangeObserver->didExitFullscreen();
     1231    if (m_videoFullscreenModel)
     1232        m_videoFullscreenModel->didExitPictureInPicture();
    12181233}
    12191234
     
    12561271
    12571272    if (reason == ExitFullScreenReason::PictureInPictureStarted) {
    1258         if ([m_playerViewController pictureInPictureWasStartedWhenEnteringBackground])
     1273        if (pictureInPictureWasStartedWhenEnteringBackground())
    12591274            return false;
    12601275
     
    14311446    if (!m_hasVideoContentLayer)
    14321447        m_fullscreenChangeObserver->requestVideoContentLayer();
     1448    if (m_videoFullscreenModel)
     1449        m_videoFullscreenModel->willEnterPictureInPicture();
    14331450}
    14341451
     
    14501467    }
    14511468
     1469    if (m_videoFullscreenModel)
     1470        m_videoFullscreenModel->didEnterPictureInPicture();
     1471
    14521472    if (m_enterFullscreenNeedsEnterPictureInPicture)
    14531473        doEnterFullscreen();
     
    14671487
    14681488    if (m_videoFullscreenModel)
     1489        m_videoFullscreenModel->failedToEnterPictureInPicture();
     1490
     1491    if (m_videoFullscreenModel)
    14691492        m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
    14701493}
     
    14811504    [m_window setHidden:NO];
    14821505    [[m_playerViewController view] setHidden:NO];
     1506
     1507    if (m_videoFullscreenModel)
     1508        m_videoFullscreenModel->willExitPictureInPicture();
    14831509}
    14841510
     
    15041530
    15051531    clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
     1532
     1533    if (m_videoFullscreenModel)
     1534        m_videoFullscreenModel->didExitPictureInPicture();
    15061535
    15071536    if (m_enterFullscreenNeedsExitPictureInPicture)
     
    16541683
    16551684#if PLATFORM(WATCHOS)
    1656     m_viewController = model()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController);
     1685    m_viewController = videoFullscreenModel()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController);
    16571686#endif
    16581687
  • trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm

    r232479 r233926  
    203203    double volume() const override;
    204204    bool isPictureInPictureActive() const override;
     205    void willEnterPictureInPicture() final;
     206    void didEnterPictureInPicture() final;
     207    void failedToEnterPictureInPicture() final;
     208    void willExitPictureInPicture() final;
     209    void didExitPictureInPicture() final;
    205210
    206211    HashSet<PlaybackSessionModelClient*> m_playbackClients;
     
    628633}
    629634
     635void VideoFullscreenControllerContext::willEnterPictureInPicture()
     636{
     637    ASSERT(isUIThread());
     638    for (auto* client : m_fullscreenClients)
     639        client->willEnterPictureInPicture();
     640}
     641
     642void VideoFullscreenControllerContext::didEnterPictureInPicture()
     643{
     644    ASSERT(isUIThread());
     645    for (auto* client : m_fullscreenClients)
     646        client->didEnterPictureInPicture();
     647}
     648
     649void VideoFullscreenControllerContext::failedToEnterPictureInPicture()
     650{
     651    ASSERT(isUIThread());
     652    for (auto* client : m_fullscreenClients)
     653        client->failedToEnterPictureInPicture();
     654}
     655
     656void VideoFullscreenControllerContext::willExitPictureInPicture()
     657{
     658    ASSERT(isUIThread());
     659    for (auto* client : m_fullscreenClients)
     660        client->willExitPictureInPicture();
     661}
     662
     663void VideoFullscreenControllerContext::didExitPictureInPicture()
     664{
     665    ASSERT(isUIThread());
     666    for (auto* client : m_fullscreenClients)
     667        client->didExitPictureInPicture();
     668}
     669
    630670FloatSize VideoFullscreenControllerContext::videoDimensions() const
    631671{
  • trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h

    r230194 r233926  
    4545class VideoFullscreenChangeObserver;
    4646
    47 class WEBCORE_EXPORT VideoFullscreenInterfaceMac
     47class VideoFullscreenInterfaceMac
    4848    : public VideoFullscreenModelClient
    4949    , private PlaybackSessionModelClient
     
    5656    }
    5757    virtual ~VideoFullscreenInterfaceMac();
     58    PlaybackSessionInterfaceMac& playbackSessionInterface() const { return m_playbackSessionInterface.get(); }
    5859    VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
    5960    PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); }
     
    7778    WEBCORE_EXPORT void cleanupFullscreen();
    7879    WEBCORE_EXPORT void invalidate();
    79     void requestHideAndExitFullscreen() { }
     80    WEBCORE_EXPORT void requestHideAndExitFullscreen();
    8081    WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const IntRect& inlineRect, NSWindow *parentWindow);
    8182    void preparedToExitFullscreen() { }
     
    8485    bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode & mode; }
    8586    bool isMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode == mode; }
    86     void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
     87    WEBCORE_EXPORT void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
    8788    void clearMode(HTMLMediaElementEnums::VideoFullscreenMode);
    8889
    89     bool isPlayingVideoInEnhancedFullscreen() const;
     90    WEBCORE_EXPORT bool isPlayingVideoInEnhancedFullscreen() const;
    9091
    9192    bool mayAutomaticallyShowVideoPictureInPicture() const { return false; }
     
    9596
    9697private:
    97     VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&);
     98    WEBCORE_EXPORT VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&);
    9899    Ref<PlaybackSessionInterfaceMac> m_playbackSessionInterface;
    99100    VideoFullscreenModel* m_videoFullscreenModel { nullptr };
  • trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm

    r230177 r233926  
    108108    NSRect _returningRect;
    109109    BOOL _playing;
    110     BOOL _didRequestExitingPIP;
    111110    BOOL _exitingToStandardFullscreen;
    112111}
     
    122121
    123122// Handling PIP transitions
    124 @property (nonatomic, readonly) BOOL didRequestExitingPIP;
    125123@property (nonatomic, getter=isExitingToStandardFullscreen) BOOL exitingToStandardFullscreen;
    126124
     
    136134@synthesize playing=_playing;
    137135@synthesize videoDimensions=_videoDimensions;
    138 @synthesize didRequestExitingPIP=_didRequestExitingPIP;
    139136@synthesize exitingToStandardFullscreen=_exitingToStandardFullscreen;
    140137
     
    159156    _videoViewContainerController = nil;
    160157    _pipState = PIPState::NotInPIP;
    161     _didRequestExitingPIP = NO;
    162158    _exitingToStandardFullscreen = NO;
    163159    _returningWindow = nil;
     
    226222        return;
    227223
    228     _didRequestExitingPIP = YES;
    229224    [_videoViewContainerController view].layer.backgroundColor = CGColorGetConstantColor(kCGColorClear);
    230225    [_pipViewController dismissViewController:_videoViewContainerController.get()];
     
    236231    _returningWindow = window;
    237232    _returningRect = rect;
    238    
     233
    239234    [_pipViewController setReplacementRect:rect];
    240235    [_pipViewController setReplacementWindow:window];
     
    280275        return YES;
    281276
    282     _didRequestExitingPIP = YES;
    283     _videoFullscreenInterfaceMac->videoFullscreenChangeObserver()->fullscreenMayReturnToInline();
     277    _videoFullscreenInterfaceMac->requestHideAndExitFullscreen();
    284278
    285279    return NO;
     
    304298        if (!self.isExitingToStandardFullscreen) {
    305299            if (VideoFullscreenModel* videoFullscreenModel = _videoFullscreenInterfaceMac->videoFullscreenModel()) {
    306                 videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
     300                videoFullscreenModel->didExitPictureInPicture();
    307301                videoFullscreenModel->setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspect);
    308302            }
    309303        }
    310 
    311         _videoFullscreenInterfaceMac->clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
    312304
    313305        if (VideoFullscreenChangeObserver* fullscreenChangeObserver = _videoFullscreenInterfaceMac->videoFullscreenChangeObserver())
     
    444436
    445437    if (mode() == HTMLMediaElementEnums::VideoFullscreenModePictureInPicture) {
     438        m_videoFullscreenModel->willEnterPictureInPicture();
    446439        [m_webVideoFullscreenInterfaceObjC enterPIP];
    447440
     
    450443#endif
    451444
     445        // FIXME(rdar://problem/42250952): Move this call into a completion handler or delegate callback.
     446        m_videoFullscreenModel->didEnterPictureInPicture();
    452447        if (m_fullscreenChangeObserver)
    453448            m_fullscreenChangeObserver->didEnterFullscreen();
     
    462457    [m_playbackSessionInterface->playBackControlsManager() setPictureInPictureActive:NO];
    463458#endif
    464 
    465     if ([m_webVideoFullscreenInterfaceObjC didRequestExitingPIP])
    466         return;
    467459
    468460    if (finalRect.isEmpty())
     
    479471    [m_playbackSessionInterface->playBackControlsManager() setPictureInPictureActive:NO];
    480472#endif
    481 
    482     if ([m_webVideoFullscreenInterfaceObjC didRequestExitingPIP])
    483         return;
    484473
    485474    bool isExitingToStandardFullscreen = mode == HTMLMediaElementEnums::VideoFullscreenModeStandard;
     
    518507}
    519508
     509void VideoFullscreenInterfaceMac::requestHideAndExitFullscreen()
     510{
     511    if (!m_videoFullscreenModel)
     512        return;
     513
     514    m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone);
     515    m_videoFullscreenModel->willExitPictureInPicture();
     516}
     517
    520518#if !LOG_DISABLED
    521519static const char* boolString(bool val)
  • trunk/Source/WebKit/ChangeLog

    r233925 r233926  
     12018-07-18  Jer Noble  <jer.noble@apple.com>
     2
     3        PiP from Element Fullscreen should match AVKit's behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=187623
     5
     6        Reviewed by Jon Lee.
     7
     8        * UIProcess/Cocoa/PlaybackSessionManagerProxy.h:
     9        (WebKit::PlaybackSessionManagerProxy::controlsManagerContextId const):
     10        * UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
     11        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
     12        (WebKit::VideoFullscreenModelContext::willEnterPictureInPicture):
     13        (WebKit::VideoFullscreenModelContext::didEnterPictureInPicture):
     14        (WebKit::VideoFullscreenModelContext::failedToEnterPictureInPicture):
     15        (WebKit::VideoFullscreenModelContext::willExitPictureInPicture):
     16        (WebKit::VideoFullscreenModelContext::didExitPictureInPicture):
     17        (WebKit::VideoFullscreenModelContext::failedToExitPictureInPicture):
     18        (WebKit::VideoFullscreenManagerProxy::controlsManagerInterface):
     19        * UIProcess/ios/fullscreen/WKFullScreenViewController.mm:
     20        (WKFullScreenViewControllerVideoFullscreenModelClient::setParent):
     21        (WKFullScreenViewControllerVideoFullscreenModelClient::setInterface):
     22        (WKFullScreenViewControllerVideoFullscreenModelClient::interface const):
     23        (-[WKFullScreenViewController initWithWebView:]):
     24        (-[WKFullScreenViewController dealloc]):
     25        (-[WKFullScreenViewController videoControlsManagerDidChange]):
     26        (-[WKFullScreenViewController ensurePiPAnimator]):
     27        (-[WKFullScreenViewController willEnterPictureInPicture]):
     28        (-[WKFullScreenViewController didEnterPictureInPicture]):
     29        (-[WKFullScreenViewController failedToEnterPictureInPicture]):
     30        (-[WKFullScreenViewController loadView]):
     31        (-[WKFullScreenViewController viewWillAppear:]):
     32        * UIProcess/Cocoa/WebViewImpl.mm:
     33        (WebKit::WebViewImpl::videoControlsManagerDidChange):
     34        * UIProcess/mac/WKFullScreenWindowController.h:
     35        * UIProcess/mac/WKFullScreenWindowController.mm:
     36        (WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient::setParent):
     37        (WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient::setInterface):
     38        (WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient::interface const):
     39        (-[WKFullScreenWindowController initWithWindow:webView:page:]):
     40        (-[WKFullScreenWindowController dealloc]):
     41        (-[WKFullScreenWindowController videoControlsManagerDidChange]):
     42        (-[WKFullScreenWindowController willEnterPictureInPicture]):
     43
    1442018-07-18  Jer Noble  <jer.noble@apple.com>
    245
  • trunk/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h

    r231231 r233926  
    191191    void removeClientForContext(uint64_t contextId);
    192192
     193    uint64_t controlsManagerContextId() const { return m_controlsManagerContextId; }
     194
    193195    // Messages from PlaybackSessionManager
    194196    void setUpPlaybackControlsManagerWithID(uint64_t contextId);
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h

    r230194 r233926  
    9090    UIViewController *createVideoFullscreenViewController(AVPlayerViewController*) final;
    9191#endif
     92    void willEnterPictureInPicture() final;
     93    void didEnterPictureInPicture() final;
     94    void failedToEnterPictureInPicture() final;
     95    void willExitPictureInPicture() final;
     96    void didExitPictureInPicture() final;
    9297
    9398    // VideoFullscreenChangeObserver
     
    127132    bool isPlayingVideoInEnhancedFullscreen() const;
    128133#endif
     134
     135    PlatformVideoFullscreenInterface* controlsManagerInterface();
    129136
    130137private:
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm

    r233925 r233926  
    283283}
    284284
     285void VideoFullscreenModelContext::willEnterPictureInPicture()
     286{
     287    for (auto& client : m_clients)
     288        client->willEnterPictureInPicture();
     289}
     290
     291void VideoFullscreenModelContext::didEnterPictureInPicture()
     292{
     293    for (auto& client : m_clients)
     294        client->didEnterPictureInPicture();
     295}
     296
     297void VideoFullscreenModelContext::failedToEnterPictureInPicture()
     298{
     299    for (auto& client : m_clients)
     300        client->failedToEnterPictureInPicture();
     301}
     302
     303void VideoFullscreenModelContext::willExitPictureInPicture()
     304{
     305    for (auto& client : m_clients)
     306        client->willExitPictureInPicture();
     307}
     308
     309void VideoFullscreenModelContext::didExitPictureInPicture()
     310{
     311    for (auto& client : m_clients)
     312        client->didExitPictureInPicture();
     313}
     314
    285315#pragma mark - VideoFullscreenManagerProxy
    286316
     
    358388}
    359389#endif
     390
     391PlatformVideoFullscreenInterface* VideoFullscreenManagerProxy::controlsManagerInterface()
     392{
     393    if (auto contextId = m_playbackSessionManagerProxy->controlsManagerContextId())
     394        return &ensureInterface(contextId);
     395    return nullptr;
     396}
    360397
    361398void VideoFullscreenManagerProxy::applicationDidBecomeActive()
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r233713 r233926  
    32843284    updateTouchBar();
    32853285#endif
     3286
     3287#if ENABLE(FULLSCREEN_API)
     3288    if (hasFullScreenWindowController())
     3289        [fullScreenWindowController() videoControlsManagerDidChange];
     3290#endif
    32863291}
    32873292
  • trunk/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm

    r233756 r233926  
    3232#import "PlaybackSessionManagerProxy.h"
    3333#import "UIKitSPI.h"
     34#import "VideoFullscreenManagerProxy.h"
    3435#import "WKFullscreenStackView.h"
    3536#import "WKWebViewInternal.h"
     
    4445
    4546static const NSTimeInterval showHideAnimationDuration = 0.1;
     47static const NSTimeInterval pipHideAnimationDuration = 0.2;
    4648static const NSTimeInterval autoHideDelay = 4.0;
    4749static const double requiredScore = 0.1;
    4850
    4951@class WKFullscreenStackView;
     52
     53@interface WKFullScreenViewController (VideoFullscreenClientCallbacks)
     54- (void)willEnterPictureInPicture;
     55- (void)didEnterPictureInPicture;
     56- (void)failedToEnterPictureInPicture;
     57@end
    5058
    5159class WKFullScreenViewControllerPlaybackSessionModelClient : PlaybackSessionModelClient {
     
    8088};
    8189
     90class WKFullScreenViewControllerVideoFullscreenModelClient : VideoFullscreenModelClient {
     91public:
     92    void setParent(WKFullScreenViewController *parent) { m_parent = parent; }
     93
     94    void setInterface(VideoFullscreenInterfaceAVKit* interface)
     95    {
     96        if (m_interface == interface)
     97            return;
     98
     99        if (m_interface && m_interface->videoFullscreenModel())
     100            m_interface->videoFullscreenModel()->removeClient(*this);
     101        m_interface = interface;
     102        if (m_interface && m_interface->videoFullscreenModel())
     103            m_interface->videoFullscreenModel()->addClient(*this);
     104    }
     105
     106    VideoFullscreenInterfaceAVKit* interface() const { return m_interface.get(); }
     107
     108    void willEnterPictureInPicture() final
     109    {
     110        [m_parent willEnterPictureInPicture];
     111    }
     112
     113    void didEnterPictureInPicture() final
     114    {
     115        [m_parent didEnterPictureInPicture];
     116    }
     117
     118    void failedToEnterPictureInPicture() final
     119    {
     120        [m_parent failedToEnterPictureInPicture];
     121    }
     122
     123private:
     124    WKFullScreenViewController *m_parent { nullptr };
     125    RefPtr<VideoFullscreenInterfaceAVKit> m_interface;
     126};
     127
    82128#pragma mark - _WKExtrinsicButton
    83129
     
    109155@implementation WKFullScreenViewController {
    110156    RetainPtr<UILongPressGestureRecognizer> _touchGestureRecognizer;
     157    RetainPtr<UIView> _animatingView;
    111158    RetainPtr<WKFullscreenStackView> _stackView;
    112159    RetainPtr<_WKExtrinsicButton> _cancelButton;
     
    117164    WebKit::FullscreenTouchSecheuristic _secheuristic;
    118165    WKFullScreenViewControllerPlaybackSessionModelClient _playbackClient;
     166    WKFullScreenViewControllerVideoFullscreenModelClient _videoFullscreenClient;
    119167    CGFloat _nonZeroStatusBarHeight;
    120168}
     
    142190
    143191    _playbackClient.setParent(self);
     192    _videoFullscreenClient.setParent(self);
    144193
    145194    return self;
     
    152201
    153202    _playbackClient.setInterface(nullptr);
     203    _videoFullscreenClient.setParent(nullptr);
     204    _videoFullscreenClient.setInterface(nullptr);
    154205
    155206    [_target release];
     
    206257{
    207258    WebPageProxy* page = [self._webView _page];
    208     PlaybackSessionManagerProxy* playbackSessionManager = page ? page->playbackSessionManager() : nullptr;
    209     PlatformPlaybackSessionInterface* playbackSessionInterface = playbackSessionManager ? playbackSessionManager->controlsManagerInterface() : nullptr;
     259    auto* videoFullscreenManager = page ? page->videoFullscreenManager() : nullptr;
     260    auto* videoFullscreenInterface = videoFullscreenManager ? videoFullscreenManager->controlsManagerInterface() : nullptr;
     261    auto* playbackSessionInterface = videoFullscreenInterface ? &videoFullscreenInterface->playbackSessionInterface() : nullptr;
     262
    210263    _playbackClient.setInterface(playbackSessionInterface);
     264    _videoFullscreenClient.setInterface(videoFullscreenInterface);
    211265
    212266    PlaybackSessionModel* playbackSessionModel = playbackSessionInterface ? playbackSessionInterface->playbackSessionModel() : nullptr;
     
    265319}
    266320
     321- (void)willEnterPictureInPicture
     322{
     323    auto* interface = _videoFullscreenClient.interface();
     324    if (!interface || !interface->pictureInPictureWasStartedWhenEnteringBackground())
     325        return;
     326
     327    [UIView animateWithDuration:pipHideAnimationDuration animations:^{
     328        _animatingView.get().alpha = 0;
     329    }];
     330}
     331
     332- (void)didEnterPictureInPicture
     333{
     334    [self _cancelAction:self];
     335}
     336
     337- (void)failedToEnterPictureInPicture
     338{
     339    auto* interface = _videoFullscreenClient.interface();
     340    if (!interface || !interface->pictureInPictureWasStartedWhenEnteringBackground())
     341        return;
     342
     343    [UIView animateWithDuration:pipHideAnimationDuration animations:^{
     344        _animatingView.get().alpha = 1;
     345    }];
     346}
     347
    267348#pragma mark - UIViewController Overrides
    268349
     
    271352    [self setView:adoptNS([[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]).get()];
    272353    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     354    self.view.backgroundColor = [UIColor blackColor];
     355
     356    _animatingView = adoptNS([[UIView alloc] initWithFrame:self.view.bounds]);
     357    _animatingView.get().autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     358    [self.view addSubview:_animatingView.get()];
    273359
    274360    _cancelButton = [_WKExtrinsicButton buttonWithType:UIButtonTypeSystem];
     
    299385    [_stackView addArrangedSubview:_cancelButton.get() applyingMaterialStyle:AVBackgroundViewMaterialStyleSecondary tintEffectStyle:AVBackgroundViewTintEffectStyleSecondary];
    300386    [_stackView addArrangedSubview:_pipButton.get() applyingMaterialStyle:AVBackgroundViewMaterialStylePrimary tintEffectStyle:AVBackgroundViewTintEffectStyleSecondary];
    301     [[self view] addSubview:_stackView.get()];
     387    [_animatingView addSubview:_stackView.get()];
    302388
    303389    UILayoutGuide *safeArea = self.view.safeAreaLayoutGuide;
     
    329415    self._webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    330416    self._webView.frame = self.view.bounds;
    331     [self.view insertSubview:self._webView atIndex:0];
     417    [_animatingView insertSubview:self._webView atIndex:0];
    332418
    333419    if (auto* manager = self._manager)
  • trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.h

    r229487 r233926  
    3232class LayerTreeContext;
    3333class WebPageProxy;
     34class WKFullScreenWindowControllerVideoFullscreenModelClient;
    3435}
    3536
     
    6061    double _savedScale;
    6162    RefPtr<WebKit::VoidCallback> _repaintCallback;
     63    std::unique_ptr<WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient> _videoFullscreenClient;
    6264    float _savedTopContentInset;
    6365}
     
    8082- (void)beganExitFullScreenWithInitialFrame:(NSRect)initialFrame finalFrame:(NSRect)finalFrame;
    8183
     84- (void)videoControlsManagerDidChange;
     85- (void)didEnterPictureInPicture;
     86
    8287@end
    8388
  • trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm

    r232520 r233926  
    3131
    3232#import "LayerTreeContext.h"
     33#import "VideoFullscreenManagerProxy.h"
    3334#import "WKAPICast.h"
    3435#import "WKViewInternal.h"
     
    4142#import <WebCore/IntRect.h>
    4243#import <WebCore/LocalizedStrings.h>
     44#import <WebCore/VideoFullscreenInterfaceMac.h>
     45#import <WebCore/VideoFullscreenModel.h>
    4346#import <WebCore/WebCoreFullScreenPlaceholderView.h>
    4447#import <WebCore/WebCoreFullScreenWindow.h>
     
    4649#import <wtf/BlockObjCExceptions.h>
    4750
     51using namespace WebCore;
     52
     53static const NSTimeInterval DefaultWatchdogTimerInterval = 1;
     54
     55namespace WebKit {
     56
     57class WKFullScreenWindowControllerVideoFullscreenModelClient : VideoFullscreenModelClient {
     58public:
     59    void setParent(WKFullScreenWindowController *parent) { m_parent = parent; }
     60
     61    void setInterface(VideoFullscreenInterfaceMac* interface)
     62    {
     63        if (m_interface == interface)
     64            return;
     65
     66        if (m_interface && m_interface->videoFullscreenModel())
     67            m_interface->videoFullscreenModel()->removeClient(*this);
     68        m_interface = interface;
     69        if (m_interface && m_interface->videoFullscreenModel())
     70            m_interface->videoFullscreenModel()->addClient(*this);
     71    }
     72
     73    VideoFullscreenInterfaceMac* interface() const { return m_interface.get(); }
     74
     75    void didEnterPictureInPicture() final
     76    {
     77        [m_parent didEnterPictureInPicture];
     78    }
     79
     80private:
     81    WKFullScreenWindowController *m_parent { nullptr };
     82    RefPtr<VideoFullscreenInterfaceMac> m_interface;
     83};
     84
     85}
     86
    4887using namespace WebKit;
    49 using namespace WebCore;
    50 
    51 static const NSTimeInterval DefaultWatchdogTimerInterval = 1;
    5288
    5389enum FullScreenState : NSInteger {
     
    114150    _webView = webView;
    115151    _page = &page;
    116    
     152
     153    _videoFullscreenClient = std::make_unique<WKFullScreenWindowControllerVideoFullscreenModelClient>();
     154    _videoFullscreenClient->setParent(self);
     155
     156    [self videoControlsManagerDidChange];
     157
    117158    return self;
    118159}
     
    132173        ASSERT(!_repaintCallback);
    133174    }
     175
     176    _videoFullscreenClient->setParent(nil);
     177    _videoFullscreenClient->setInterface(nullptr);
    134178
    135179    [super dealloc];
     
    507551}
    508552
     553- (void)videoControlsManagerDidChange
     554{
     555    auto* videoFullscreenManager = _page ? _page->videoFullscreenManager() : nullptr;
     556    auto* videoFullscreenInterface = videoFullscreenManager ? videoFullscreenManager->controlsManagerInterface() : nullptr;
     557
     558    _videoFullscreenClient->setInterface(videoFullscreenInterface);
     559}
     560
     561- (void)didEnterPictureInPicture
     562{
     563    [self requestExitFullScreen];
     564}
     565
    509566#pragma mark -
    510567#pragma mark Custom NSWindow Full Screen Animation
  • trunk/Tools/ChangeLog

    r233921 r233926  
     12018-07-18  Jer Noble  <jer.noble@apple.com>
     2
     3        PiP from Element Fullscreen should match AVKit's behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=187623
     5        <rdar://problem/41212379>
     6
     7        Reviewed by Jon Lee.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/ExitFullscreenOnEnterPiP.html: Added.
     11        * TestWebKitAPI/Tests/WebKitCocoa/ExitFullscreenOnEnterPiP.mm: Added.
     12        (-[ExitFullscreenOnEnterPiPUIDelegate _webView:hasVideoInPictureInPictureDidChange:]):
     13        (-[ExitFullscreenOnEnterPiPUIDelegate _webViewDidEnterFullscreen:]):
     14        (-[ExitFullscreenOnEnterPiPUIDelegate _webViewDidExitFullscreen:]):
     15        (TestWebKitAPI::TEST):
     16
    1172018-07-18  Aakash Jain  <aakash_jain@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r233915 r233926  
    721721                CD78E11E1DB7EE2A0014A2DE /* FullscreenDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */; };
    722722                CD9E292E1C90C33F000BB800 /* audio-only.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD9E292D1C90C1BA000BB800 /* audio-only.html */; };
     723                CDA29B2920FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA29B2820FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm */; };
     724                CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */; };
    723725                CDA315981ED53651009F60D3 /* MediaPlaybackSleepAssertion.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA315961ED53651009F60D3 /* MediaPlaybackSleepAssertion.mm */; };
    724726                CDA3159A1ED548F1009F60D3 /* MediaPlaybackSleepAssertion.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDA315991ED540A5009F60D3 /* MediaPlaybackSleepAssertion.html */; };
     
    982984                                07492B3C1DF8B86600633DE1 /* enumerateMediaDevices.html in Copy Resources */,
    983985                                C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */,
     986                                CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */,
    984987                                F41AB9A31EF4696B0083FA08 /* file-uploading.html in Copy Resources */,
    985988                                BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */,
     
    19091912                CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RequiresUserActionForPlayback.mm; sourceTree = "<group>"; };
    19101913                CD9E292D1C90C1BA000BB800 /* audio-only.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "audio-only.html"; sourceTree = "<group>"; };
     1914                CDA29B2820FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ExitFullscreenOnEnterPiP.mm; sourceTree = "<group>"; };
     1915                CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = ExitFullscreenOnEnterPiP.html; sourceTree = "<group>"; };
    19111916                CDA315961ED53651009F60D3 /* MediaPlaybackSleepAssertion.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPlaybackSleepAssertion.mm; sourceTree = "<group>"; };
    19121917                CDA315991ED540A5009F60D3 /* MediaPlaybackSleepAssertion.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = MediaPlaybackSleepAssertion.html; sourceTree = "<group>"; };
     
    22542259                                A15502281E05020B00A24C57 /* DuplicateCompletionHandlerCalls.mm */,
    22552260                                F44D06461F395C4D001A0E29 /* EditorStateTests.mm */,
     2261                                CDA29B2820FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm */,
    22562262                                2D8104CB1BEC13E70020DA46 /* FindInPage.mm */,
    22572263                                2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */,
     
    25692575                                F44D06441F395C0D001A0E29 /* editor-state-test-harness.html */,
    25702576                                51C8E1A81F27F47300BF731B /* EmptyGrandfatheredResourceLoadStatistics.plist */,
     2577                                CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
    25712578                                F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */,
    25722579                                F407FE381F1D0DE60017CF25 /* enormous.svg */,
     
    38083815                                7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */,
    38093816                                7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */,
     3817                                CDA29B2920FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm in Sources */,
    38103818                                7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */,
    38113819                                7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.