Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: c48c498ba0e6117510137abb70af9202c8dbbeaa
https://github.com/WebKit/WebKit/commit/c48c498ba0e6117510137abb70af9202c8dbbeaa
Author: Aditya Keerthi <[email protected]>
Date: 2025-02-17 (Mon, 17 Feb 2025)
Changed paths:
M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
M Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
M Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
M Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm
M Tools/TestWebKitAPI/Tests/WebKitCocoa/ScreenTime.mm
Log Message:
-----------
[Screen Time Refactoring] WKWebView shrinks when added to a stack view
https://bugs.webkit.org/show_bug.cgi?id=287800
rdar://144728151
Reviewed by Wenson Hsieh.
Currently, `WKWebView` sizes `STWebpageView` using Auto Layout, applying
equal top, leading, width, and height constraints to ensure the Screen Time view
covers the web view.
However, this approach results in the `WKWebView` shrinking down to a width of
480pt when it is added to a stack view. This is due to the presence of an
`NSRemoteView` subview, inside `STWebpageView`, with an intrinsic content size
of (480, 272).
By default, stack views add a greater than or equal trailing constraint to
their arranged subviews. Specifically, the stack view's trailing edge must
be greater than or equal to the web view's trailing edge. Additionally, a lower
priority constraint that enforces equality between the stack view's trailing
edge and the web view's trailing edge is added.
Thus the following constraints are present:
- `NSStackView`'s trailing edge >= `WKWebView`'s trailing edge (high priority)
- `WKWebView`'s edges == `STWebpageView`'s edges (high priority)
- `STWebpageView`'s edges == `NSRemoteView`'s edges (high priority)
- `NSRemoteView`'s width == 480 (high priority)
- `NSStackView`'s trailing edge == `WKWebView`'s trailing edge (low priority)
Consequently, a satisfying layout for all high priority constraints is to size
the `WKWebView` down to 480pt, and have the `STWebpageView` (and `NSRemoteView`)
fill the web view's frame.
To fix, stop using Auto Layout to size the `STWebpageView` and use manual,
frame-based layout. By giving the `STWebpageView` an explicit frame, the
intrinsic content size constraint on the `NSRemoteView` becomes unsatisfiable,
and both the `STWebpageView` and `NSRemoteView` can simply fill the
`WKWebView`'s frame.
Note that on iOS, the same issue does not exist, as the remote view does not
have an intrinsic content size. However, the same change is applied on iOS to
share code.
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _installScreenTimeWebpageController]):
(-[WKWebView _updateScreenTimeViewGeometry]):
Ensure the Screen Time view covers the web view by setting its frame equal to
the web view's bounds.
(-[WKWebView observeValueForKeyPath:ofObject:change:context:]):
Use manual layout for WebKit's own blocking view to keep logic similar.
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView layoutSubviews]):
* Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView renewGState]):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ScreenTime.mm:
(webViewForScreenTimeTests):
(TEST(ScreenTime, WKWebViewFillsStackView)):
Add a test which puts a `WKWebView` with Screen Time enabled, inside a stack
view, and asserts the web view is sized to fill the stack view.
Prior to this fix, the test fails, as the web view's width is shrunk to 480pt.
Canonical link: https://commits.webkit.org/290501@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes