Skip to content
Permalink
Browse files
Adjust screensize of fullscreen video based on aspect ratio
https://bugs.webkit.org/show_bug.cgi?id=244733
<rdar://97617380>

Reviewed by Tim Horton.

Pass the video dimensions in the EnterFullScreen message so
the UI process can appropriately size the window to match the
video content.

* Source/WebKit/UIProcess/WebFullScreenManagerProxy.cpp:
(WebKit::WebFullScreenManagerProxy::enterFullScreen):
Pass video dimensions.

* Source/WebKit/UIProcess/WebFullScreenManagerProxy.h:
* Source/WebKit/UIProcess/WebFullScreenManagerProxy.messages.in:
Extend message with the video dimensions.

* Source/WebKit/UIProcess/ios/PageClientImplIOS.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::enterFullScreen):
Pass video dimensions.

* Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:
(-[WKFullScreenWindowController enterFullScreen:]):
Compute the aspect ratio so the window size matches the video which is playing.
(-[WKFullScreenWindowController videoDimensionsDidChange:]):
Move to helper so VideoFullscreenManagerProxy can call it.

* Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp:
(WebKit::WebFullScreenManager::enterFullScreenForElement):
Update the main video element and retrieve the video size to pass to the
EnterFullScreen message.

* Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.cpp:
(WebKit::InjectedBundlePageFullScreenClient::enterFullScreenForElement):
* Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.h:
Pass video dimensions.

Canonical link: https://commits.webkit.org/254528@main
  • Loading branch information
mwyrzykowski committed Sep 15, 2022
1 parent 5c92b97 commit b5f2ee5f0c0d6ec20fc1ebe88e2c5b3eba32df72
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 13 deletions.
@@ -177,15 +177,20 @@ bool WebFullScreenManagerProxy::isVideoElement() const
}
#endif

void WebFullScreenManagerProxy::enterFullScreen(bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement)
void WebFullScreenManagerProxy::enterFullScreen(bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement, FloatSize videoDimensions)
{
m_blocksReturnToFullscreenFromPictureInPicture = blocksReturnToFullscreenFromPictureInPicture;
#if HAVE(UIKIT_WEBKIT_INTERNALS)
m_isVideoElement = isVideoElement;
#else
UNUSED_PARAM(isVideoElement);
#endif
#if PLATFORM(IOS_FAMILY)
m_client.enterFullScreen(videoDimensions);
#else
UNUSED_PARAM(videoDimensions);
m_client.enterFullScreen();
#endif
}

void WebFullScreenManagerProxy::exitFullScreen()
@@ -35,6 +35,7 @@
#include <wtf/Vector.h>

namespace WebCore {
class FloatSize;
class IntRect;

template <typename> class RectEdges;
@@ -51,7 +52,11 @@ class WebFullScreenManagerProxyClient {

virtual void closeFullScreenManager() = 0;
virtual bool isFullScreen() = 0;
#if PLATFORM(IOS_FAMILY)
virtual void enterFullScreen(WebCore::FloatSize videoDimensions) = 0;
#else
virtual void enterFullScreen() = 0;
#endif
virtual void exitFullScreen() = 0;
virtual void beganEnterFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) = 0;
virtual void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) = 0;
@@ -94,7 +99,7 @@ class WebFullScreenManagerProxy : public IPC::MessageReceiver {

private:
void supportsFullScreen(bool withKeyboard, CompletionHandler<void(bool)>&&);
void enterFullScreen(bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement);
void enterFullScreen(bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement, WebCore::FloatSize videoDimensions);
void exitFullScreen();
void beganEnterFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame);
void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame);
@@ -23,7 +23,7 @@
#if ENABLE(FULLSCREEN_API)
messages -> WebFullScreenManagerProxy NotRefCounted {
SupportsFullScreen(bool withKeyboard) -> (bool supportsFullScreen) Synchronous
EnterFullScreen(bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement)
EnterFullScreen(bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement, WebCore::FloatSize videoDimensions)
ExitFullScreen()
BeganEnterFullScreen(WebCore::IntRect initialRect, WebCore::IntRect finalRect)
BeganExitFullScreen(WebCore::IntRect initialRect, WebCore::IntRect finalRect)
@@ -226,7 +226,7 @@ class PageClientImpl final : public PageClientImplCocoa
// WebFullScreenManagerProxyClient
void closeFullScreenManager() override;
bool isFullScreen() override;
void enterFullScreen() override;
void enterFullScreen(WebCore::FloatSize videoDimensions) override;
void exitFullScreen() override;
void beganEnterFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
@@ -731,9 +731,9 @@ - (BOOL)_isHostedInAnotherProcess;
return [m_webView fullScreenWindowController].isFullScreen;
}

void PageClientImpl::enterFullScreen()
void PageClientImpl::enterFullScreen(FloatSize videoDimensions)
{
[[m_webView fullScreenWindowController] enterFullScreen];
[[m_webView fullScreenWindowController] enterFullScreen:videoDimensions];
}

void PageClientImpl::exitFullScreen()
@@ -34,7 +34,7 @@
@property (readonly, assign, nonatomic) BOOL isFullScreen;

- (id)initWithWebView:(WKWebView *)webView;
- (void)enterFullScreen;
- (void)enterFullScreen:(CGSize)videoDimensions;
- (void)beganEnterFullScreenWithInitialFrame:(CGRect)initialFrame finalFrame:(CGRect)finalFrame;
- (void)requestEnterFullScreen;
- (void)requestExitFullScreen;
@@ -523,7 +523,7 @@ - (UIView *)webViewPlaceholder
#pragma mark -
#pragma mark External Interface

- (void)enterFullScreen
- (void)enterFullScreen:(CGSize)videoDimensions
{
if ([self isFullScreen])
return;
@@ -548,7 +548,8 @@ - (void)enterFullScreen
[_window setWindowLevel:UIWindowLevelNormal - 1];
[_window setHidden:NO];
#if HAVE(UIKIT_WEBKIT_INTERNALS)
[_window setFrame:CGRectMake(0, 0, 960, 540)];
CGFloat aspectRatio = videoDimensions.height ? (videoDimensions.width / videoDimensions.height) : (960.0 / 540.0);
[_window setFrame:CGRectMake(0, 0, 540 * aspectRatio, 540)];
[_window setNeedsLayout];
[_window layoutIfNeeded];
#endif
@@ -178,7 +178,13 @@ void WebFullScreenManager::enterFullScreenForElement(WebCore::Element* element)
#endif

m_initialFrame = screenRectOfContents(m_element.get());
m_page->injectedBundleFullScreenClient().enterFullScreenForElement(m_page.get(), element, m_element->document().quirks().blocksReturnToFullscreenFromPictureInPictureQuirk(), isVideoElement);
#if ENABLE(VIDEO)
updateMainVideoElement();
auto videoDimensions = m_mainVideoElement ? FloatSize(m_mainVideoElement->videoWidth(), m_mainVideoElement->videoHeight()) : FloatSize(m_initialFrame.width(), m_initialFrame.height());
#else
FloatSize videoDimensions;
#endif
m_page->injectedBundleFullScreenClient().enterFullScreenForElement(m_page.get(), element, m_element->document().quirks().blocksReturnToFullscreenFromPictureInPictureQuirk(), isVideoElement, videoDimensions);
}

void WebFullScreenManager::exitFullScreenForElement(WebCore::Element* element)
@@ -51,13 +51,13 @@ bool InjectedBundlePageFullScreenClient::supportsFullScreen(WebPage *page, bool
return supports;
}

void InjectedBundlePageFullScreenClient::enterFullScreenForElement(WebPage *page, WebCore::Element *element, bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement)
void InjectedBundlePageFullScreenClient::enterFullScreenForElement(WebPage *page, WebCore::Element *element, bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement, FloatSize videoDimensions)
{
if (m_client.enterFullScreenForElement) {
RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(element);
m_client.enterFullScreenForElement(toAPI(page), toAPI(nodeHandle.get()));
} else
page->send(Messages::WebFullScreenManagerProxy::EnterFullScreen(blocksReturnToFullscreenFromPictureInPicture, isVideoElement));
page->send(Messages::WebFullScreenManagerProxy::EnterFullScreen(blocksReturnToFullscreenFromPictureInPicture, isVideoElement, videoDimensions));
}

void InjectedBundlePageFullScreenClient::exitFullScreenForElement(WebPage *page, WebCore::Element *element)
@@ -50,7 +50,7 @@ class WebPage;
class InjectedBundlePageFullScreenClient : public API::Client<WKBundlePageFullScreenClientBase> {
public:
bool supportsFullScreen(WebPage*, bool withKeyboard);
void enterFullScreenForElement(WebPage*, WebCore::Element*, bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement);
void enterFullScreenForElement(WebPage*, WebCore::Element*, bool blocksReturnToFullscreenFromPictureInPicture, bool isVideoElement, WebCore::FloatSize videoDimensions);
void exitFullScreenForElement(WebPage*, WebCore::Element*);
void beganEnterFullScreen(WebPage*, WebCore::IntRect& initialFrame, WebCore::IntRect& finalFrame);
void beganExitFullScreen(WebPage*, WebCore::IntRect& initialFrame, WebCore::IntRect& finalFrame);

0 comments on commit b5f2ee5

Please sign in to comment.