Skip to content
Permalink
Browse files
Use the fullscreen preferred size when reporting screen dimensions
https://bugs.webkit.org/show_bug.cgi?id=249297
<rdar://99403187>

Reviewed by Megan Gardner.

When we have a preferred size for fullscreen windows, use it when
reporting the screen dimensions to the page.

* Source/WebKit/UIProcess/WebPageProxy.h:
Expose `overrideScreenSize`.

* Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::overrideScreenSize):
Read the fullscreen preferred size and override the screen size with it.

* Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:
(-[WKFullScreenWindowController enterFullScreen:]):
Use the (modified) page's screen size as target size for the fullscreen
window.

Canonical link: https://commits.webkit.org/258005@main
  • Loading branch information
Etienne Segonzac authored and hortont424 committed Dec 16, 2022
1 parent ff73fb7 commit da50bb2bfac4cb2530f12086789caf196b3adcb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
@@ -857,6 +857,8 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
void scrollingNodeScrollWillStartScroll(WebCore::ScrollingNodeID);
void scrollingNodeScrollDidEndScroll(WebCore::ScrollingNodeID);

WebCore::FloatSize overrideScreenSize();

void dynamicViewportSizeUpdate(const WebCore::FloatSize& viewLayoutSize, const WebCore::FloatSize& minimumUnobscuredSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation, double minimumEffectiveDeviceWidth, DynamicViewportSizeUpdateID);

void setViewportConfigurationViewLayoutSize(const WebCore::FloatSize&, double scaleFactor, double minimumEffectiveDeviceWidth);
@@ -2529,7 +2531,6 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
#if PLATFORM(IOS_FAMILY)
WebCore::FloatSize screenSize();
WebCore::FloatSize availableScreenSize();
WebCore::FloatSize overrideScreenSize();
float textAutosizingWidth();

void couldNotRestorePageState();
@@ -85,6 +85,10 @@

#define WEBPAGEPROXY_RELEASE_LOG(channel, fmt, ...) RELEASE_LOG(channel, "%p - [pageProxyID=%llu, webPageID=%llu, PID=%i] WebPageProxy::" fmt, this, m_identifier.toUInt64(), m_webPageID.toUInt64(), m_process->processIdentifier(), ##__VA_ARGS__)

#if HAVE(UIKIT_WEBKIT_INTERNALS)
static constexpr CGFloat kTargetFullscreenAspectRatio = 1.7778;
#endif

namespace WebKit {
using namespace WebCore;

@@ -891,6 +895,13 @@ static bool exceedsRenderTreeSizeSizeThreshold(uint64_t thresholdSize, uint64_t

FloatSize WebPageProxy::overrideScreenSize()
{
#if HAVE(UIKIT_WEBKIT_INTERNALS)
// Report screen dimensions based on fullscreen preferences.
CGFloat preferredWidth = m_preferences->mediaPreferredFullscreenWidth();
CGFloat preferredHeight = preferredWidth / kTargetFullscreenAspectRatio;
return FloatSize(CGSizeMake(preferredWidth, preferredHeight));
#endif

return WebCore::overrideScreenSize();
}

@@ -165,7 +165,6 @@ void store(WKWebView* webView)
static constexpr NSTimeInterval kAnimationDuration = 0.2;
#if HAVE(UIKIT_WEBKIT_INTERNALS)
static constexpr CGFloat kFullScreenWindowCornerRadius = 12;
static constexpr CGFloat kTargetWindowAspectRatio = 1.7778;
#endif

#pragma mark -
@@ -564,14 +563,16 @@ - (void)enterFullScreen:(CGSize)videoDimensions
[_window setWindowLevel:UIWindowLevelNormal - 1];
[_window setHidden:NO];
#if HAVE(UIKIT_WEBKIT_INTERNALS)
CGFloat preferredWidth = page->preferences().mediaPreferredFullscreenWidth();
CGFloat preferredHeight = preferredWidth / kTargetWindowAspectRatio;
CGFloat videoAspectRatio = videoDimensions.height ? (videoDimensions.width / videoDimensions.height) : kTargetWindowAspectRatio;
auto screenSize = page->overrideScreenSize();
CGFloat preferredWidth = screenSize.width();
CGFloat preferredHeight = screenSize.height();
CGFloat preferredAspectRatio = preferredWidth / preferredHeight;
CGFloat videoAspectRatio = videoDimensions.height ? (videoDimensions.width / videoDimensions.height) : preferredAspectRatio;

CGFloat targetWidth = preferredWidth;
CGFloat targetHeight = preferredHeight;
if (videoDimensions.height && videoDimensions.width) {
if (videoAspectRatio > kTargetWindowAspectRatio)
if (videoAspectRatio > preferredAspectRatio)
targetHeight = videoDimensions.height * preferredWidth / videoDimensions.width;
else
targetWidth = videoDimensions.width * preferredHeight / videoDimensions.height;

0 comments on commit da50bb2

Please sign in to comment.