WebKit Bugzilla
Attachment 349349 Details for
Bug 189478
: Expose a few WebPlaybackControlsManager-driven PIP APIs to clients
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189478-20180910160807.patch (text/plain), 12.22 KB, created by
Matt Rajca
on 2018-09-10 16:08:08 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Matt Rajca
Created:
2018-09-10 16:08:08 PDT
Size:
12.22 KB
patch
obsolete
>Subversion Revision: 235860 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 90577d93183fd5ce2e249bbcb375ee359100b0d2..fd685f4eaf8f4f57e5576072b91607d5c2c37598 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,33 @@ >+2018-09-10 Matt Rajca <mrajca@apple.com> >+ >+ Expose a few WebPlaybackControlsManager-driven PIP APIs to clients >+ https://bugs.webkit.org/show_bug.cgi?id=189478 >+ <rdar://problem/44312650> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch exposes APIs necessary to toggle PIP and query its status from clients of WKWebView. >+ The existing PIP test has been updated to use the new APIs instead of simulating mouse clicks. >+ I also increased the size of the video element in the test page so it gets picked up by the >+ main content heuristics. >+ >+ * UIProcess/API/Cocoa/WKWebView.mm: >+ (-[WKWebView _updateMediaPlaybackControlsManager]): Create a media playback controls manager if necessary. >+ (-[WKWebView _isPictureInPictureActive]): Return true if the "active" media element is in PIP. >+ (-[WKWebView _togglePictureInPicture]): Toggle PIP on the "active" media element. >+ (-[WKWebView _canTogglePictureInPicture]): Renamed from... >+ (-[WKWebView _canTogglePictureInPictureForTesting]): >+ * UIProcess/API/Cocoa/WKWebViewPrivate.h: >+ * UIProcess/Cocoa/WebViewImpl.h: >+ * UIProcess/Cocoa/WebViewImpl.mm: >+ (WebKit::WebViewImpl::isPictureInPictureActive): Return true if the "active" media element is in PIP. >+ (WebKit::WebViewImpl::togglePictureInPicture): Toggle PIP on the "active" media element. >+ (WebKit::WebViewImpl::updateMediaPlaybackControlsManager): Let clients create a playback >+ controls manager even when there is no Touch Bar present. >+ (WebKit::WebViewImpl::updateMediaTouchBar): Extract some code into a helper method. >+ (WebKit::WebViewImpl::canTogglePictureInPicture): Renamed from... >+ (WebKit::WebViewImpl::canTogglePictureInPictureForTesting): >+ > 2018-09-10 Daniel Bates <dabates@apple.com> > > [iOS] Arrow keys do not dispatch DOM events to non-editable elements >diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >index e0c29c5e4b7fd91ed3ca064b9c923e48abac8fb8..69422b88c4d8df3f5e76492fb26bd2b6d3430869 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >@@ -4232,6 +4232,38 @@ - (void)_setHistoryDelegate:(id <WKHistoryDelegatePrivate>)historyDelegate > _navigationState->setHistoryDelegate(historyDelegate); > } > >+- (void)_updateMediaPlaybackControlsManager >+{ >+#if HAVE(TOUCH_BAR) >+ _impl->updateMediaPlaybackControlsManager(); >+#endif >+} >+ >+- (BOOL)_canTogglePictureInPicture >+{ >+#if HAVE(TOUCH_BAR) >+ return _impl->canTogglePictureInPicture(); >+#else >+ return NO; >+#endif >+} >+ >+- (BOOL)_isPictureInPictureActive >+{ >+#if HAVE(TOUCH_BAR) >+ return _impl->isPictureInPictureActive(); >+#else >+ return NO; >+#endif >+} >+ >+- (void)_togglePictureInPicture >+{ >+#if HAVE(TOUCH_BAR) >+ _impl->togglePictureInPicture(); >+#endif >+} >+ > - (NSURL *)_unreachableURL > { > return [NSURL _web_URLWithWTFString:_page->pageLoadState().unreachableURL()]; >@@ -6495,15 +6527,6 @@ - (void)_setDefersLoadingForTesting:(BOOL)defersLoading > _page->setDefersLoadingForTesting(defersLoading); > } > >-- (BOOL)_canTogglePictureInPictureForTesting >-{ >-#if HAVE(TOUCH_BAR) >- return _impl->canTogglePictureInPictureForTesting(); >-#else >- return NO; >-#endif >-} >- > - (_WKInspector *)_inspector > { > if (auto* inspector = _page->inspector()) >diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h b/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h >index f5e99972298e7ce58d6b31a1af2ca720c65ffe56..9b817230817a803bc859ae82fe34948faf941fa8 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h >+++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h >@@ -356,6 +356,11 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) { > > @property (nonatomic, setter=_setMediaCaptureEnabled:) BOOL _mediaCaptureEnabled WK_API_AVAILABLE(macosx(10.13), ios(11.0)); > >+@property (nonatomic, readonly) BOOL _canTogglePictureInPicture; >+@property (nonatomic, readonly) BOOL _isPictureInPictureActive; >+- (void)_updateMediaPlaybackControlsManager; >+- (void)_togglePictureInPicture; >+ > @end > > #if !TARGET_OS_IPHONE >@@ -472,8 +477,6 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) { > - (BOOL)_completeBackSwipeForTesting; > - (void)_setDefersLoadingForTesting:(BOOL)defersLoading; > >-- (BOOL)_canTogglePictureInPictureForTesting; >- > @property (nonatomic, readonly) _WKInspector *_inspector WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > @property (nonatomic, readonly) _WKFrameHandle *_mainFrame WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > >diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >index d964d509d90bd3038ac9e58c39fe272bca17a8f3..b08d9b9c501b47a7362e25aeca26dce9b5ea4f4c 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >@@ -540,8 +540,11 @@ public: > void didFinishProcessingAllPendingMouseEvents(); > > #if HAVE(TOUCH_BAR) >+ bool isPictureInPictureActive(); >+ void togglePictureInPicture(); > NSTouchBar *makeTouchBar(); > void updateTouchBar(); >+ void updateMediaPlaybackControlsManager(); > NSTouchBar *currentTouchBar() const { return m_currentTouchBar.get(); } > NSCandidateListTouchBarItem *candidateListTouchBarItem() const; > #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER) >@@ -560,7 +563,7 @@ public: > void updateTouchBarAndRefreshTextBarIdentifiers(); > void setIsCustomizingTouchBar(bool isCustomizingTouchBar) { m_isCustomizingTouchBar = isCustomizingTouchBar; }; > >- bool canTogglePictureInPictureForTesting(); >+ bool canTogglePictureInPicture(); > #endif // HAVE(TOUCH_BAR) > > bool beginBackSwipeForTesting(); >diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >index 1af4addf1d7c47a7128629aee3618dd981770bb4..5d3e5f15d4795999148637de8bbdd7dc9ca16ced 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >@@ -1210,6 +1210,36 @@ void WebViewImpl::updateTextTouchBar() > } > } > >+bool WebViewImpl::isPictureInPictureActive() >+{ >+ if (!m_playbackControlsManager) >+ return false; >+ >+ return [m_playbackControlsManager isPictureInPictureActive]; >+} >+ >+void WebViewImpl::togglePictureInPicture() >+{ >+ [m_playbackControlsManager togglePictureInPicture]; >+} >+ >+void WebViewImpl::updateMediaPlaybackControlsManager() >+{ >+ if (!m_page->hasActiveVideoForControlsManager()) >+ return; >+ >+ if (!m_playbackControlsManager) { >+ m_playbackControlsManager = adoptNS([[WebPlaybackControlsManager alloc] init]); >+ [m_playbackControlsManager setAllowsPictureInPicturePlayback:m_page->preferences().allowsPictureInPictureMediaPlayback()]; >+ [m_playbackControlsManager setCanTogglePictureInPicture:NO]; >+ } >+ >+ if (PlatformPlaybackSessionInterface* interface = m_page->playbackSessionManager()->controlsManagerInterface()) { >+ [m_playbackControlsManager setPlaybackSessionInterfaceMac:interface]; >+ interface->updatePlaybackControlsManagerCanTogglePictureInPicture(); >+ } >+} >+ > void WebViewImpl::updateMediaTouchBar() > { > #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER) && ENABLE(VIDEO_PRESENTATION_MODE) >@@ -1232,16 +1262,7 @@ void WebViewImpl::updateMediaTouchBar() > #endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 > } > >- if (!m_playbackControlsManager) { >- m_playbackControlsManager = adoptNS([[WebPlaybackControlsManager alloc] init]); >- [m_playbackControlsManager setAllowsPictureInPicturePlayback:m_page->preferences().allowsPictureInPictureMediaPlayback()]; >- [m_playbackControlsManager setCanTogglePictureInPicture:NO]; >- } >- >- if (PlatformPlaybackSessionInterface* interface = m_page->playbackSessionManager()->controlsManagerInterface()) { >- [m_playbackControlsManager setPlaybackSessionInterfaceMac:interface]; >- interface->updatePlaybackControlsManagerCanTogglePictureInPicture(); >- } >+ updateMediaPlaybackControlsManager(); > > [m_mediaTouchBarProvider setPlaybackControlsController:m_playbackControlsManager.get()]; > [m_mediaPlaybackControlsView setPlaybackControlsController:m_playbackControlsManager.get()]; >@@ -1279,7 +1300,7 @@ void WebViewImpl::updateMediaTouchBar() > > #if HAVE(TOUCH_BAR) > >-bool WebViewImpl::canTogglePictureInPictureForTesting() >+bool WebViewImpl::canTogglePictureInPicture() > { > #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER) > return [m_playbackControlsManager canTogglePictureInPicture]; >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.html >index 82cdc81a42daef62c713aa2a77cbbbab7c6dd743..8188e434e72faadab5007a51a9ed3827aa54beb4 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.html >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.html >@@ -19,8 +19,8 @@ > <style> > #video { > background-color: red; >- width: 150px; >- height: 150px; >+ width: 640px; >+ height: 480px; > } > </style> > </head> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm >index acac484eb64d79ef921de7af0c3112d08533b264..1722c43ec89011c912c5add9751e8d870665b43d 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm >@@ -114,7 +114,7 @@ namespace TestWebKitAPI { > TEST(PictureInPicture, WKUIDelegate) > { > RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); >- RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]); >+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 640, 480) configuration:configuration.get()]); > [configuration preferences]._fullScreenEnabled = YES; > [configuration preferences]._allowsPictureInPictureMediaPlayback = YES; > RetainPtr<PictureInPictureUIDelegate> handler = adoptNS([[PictureInPictureUIDelegate alloc] init]); >@@ -139,8 +139,17 @@ TEST(PictureInPicture, WKUIDelegate) > hasVideoInPictureInPictureValue = false; > hasVideoInPictureInPictureCalled = false; > >+#if HAVE(TOUCH_BAR) >+ while (![webView _canTogglePictureInPicture]) >+ [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]]; >+ >+ ASSERT_FALSE([webView _isPictureInPictureActive]); >+ [webView _togglePictureInPicture]; >+#else > NSEvent *event = [NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:NSMakePoint(5, 5) modifierFlags:0 timestamp:0 windowNumber:window.get().windowNumber context:0 eventNumber:0 clickCount:0 pressure:0]; > [webView mouseDown:event]; >+#endif >+ > TestWebKitAPI::Util::run(&hasVideoInPictureInPictureCalled); > ASSERT_TRUE(hasVideoInPictureInPictureValue); > >@@ -148,11 +157,18 @@ TEST(PictureInPicture, WKUIDelegate) > [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; > > #if HAVE(TOUCH_BAR) >- ASSERT_TRUE([webView _canTogglePictureInPictureForTesting]); >+ ASSERT_TRUE([webView _isPictureInPictureActive]); >+ ASSERT_TRUE([webView _canTogglePictureInPicture]); > #endif > > hasVideoInPictureInPictureCalled = false; >+ >+#if HAVE(TOUCH_BAR) >+ [webView _togglePictureInPicture]; >+#else > [webView mouseDown:event]; >+#endif >+ > TestWebKitAPI::Util::run(&hasVideoInPictureInPictureCalled); > ASSERT_FALSE(hasVideoInPictureInPictureValue); > } >@@ -178,7 +194,7 @@ TEST(PictureInPicture, AudioCannotTogglePictureInPicture) > [webView evaluateJavaScript:@"play()" completionHandler:nil]; > > [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; >- ASSERT_FALSE([webView _canTogglePictureInPictureForTesting]); >+ ASSERT_FALSE([webView _canTogglePictureInPicture]); > } > > #endif // HAVE(TOUCH_BAR)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189478
:
349349
|
349361
|
349402