Title: [279830] trunk
Revision
279830
Author
[email protected]
Date
2021-07-12 09:15:13 -0700 (Mon, 12 Jul 2021)

Log Message

[watchOS] Make a few additional adjustments to support system minimum layout margins
https://bugs.webkit.org/show_bug.cgi?id=227859
rdar://80113612

Reviewed by Tim Horton.

Source/WebCore:

Reduce the default minimum viewport scale on watchOS to avoid horizontal scrolling when loading wide fixed-
viewport-width web content. See WebKit ChangeLog for more details.

* page/ViewportConfiguration.cpp:
(WebCore::platformDeviceWidthOverride):
(WebCore::platformMinimumScaleForWebpage):
(WebCore::shouldOverrideShrinkToFitArgument):
(WebCore::ViewportConfiguration::nativeWebpageParametersWithShrinkToFit):
(WebCore::ViewportConfiguration::webpageParameters):

Source/WebKit:

Make a couple of minor adjustments to deal with the fact that `-contentInset` includes system content insets
(specifically, `-_contentScrollInset`) on watchOS, due to method swizzling that happens in PepperUICore. See
changes below for more detail.

Test: fast/viewport/watchos/viewport-with-system-minimum-layout-margins.html

* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _computedContentInset]):

Only apply `-safeAreaInsets` on top of `-contentInset` when computing the total scroll view content inset on
watchOS (as opposed to applying both `-safeAreaInsets` and `-_contentScrollInset`); this is because
`-contentInset` on watchOS is actually equivalent to `-_effectiveContentInset` on other iOS-family platforms, so
additionally adding `-_contentScrollInset` here would result in the scroll content inset being double-counted.

* UIProcess/ios/WKScrollView.mm:
(-[WKScrollView setContentInset:]):
(-[WKScrollView _setContentScrollInsetInternal:]):
(-[WKScrollView _updateContentScrollInset]):

In the case where the WebKit client explicitly sets the scroll view's content insets using `-[WKScrollView
setContentInset:]`, set a flag (`_contentInsetWasExternallyOverridden`) and immediately revert any internally
specified `-_contentScrollInset` on WKScrollView. Due to the swizzled implementation of `-[UIScrollView
contentInset]` described above, it's practically impossible for any client to use `-setContentInset:` correctly
when there is a nonzero `-_contentScrollInset` on watchOS, so preferable to simply get out of the way of the
client in this scenario.

In the context of _SFNanoBrowserViewController, this ensures that scroll view content inset adjustment logic in
Safari doesn't inadvertently cause horizontal content insets to increase by `-_contentScrollInset` every time
`-[WKScrollView setContentInset:]` is invoked by the client.

Tools:

Add support for simulating arbitrary horizontal (trailing and leading) values for `-systemMinimumLayoutMargin`
in WebKitTestRunner, via a new "horizontalSystemMinimumLayoutMargin" test option. By default, this is 0.

* WebKitTestRunner/TestOptions.cpp:
(WTR::TestOptions::defaults):
(WTR::TestOptions::keyTypeMapping):
* WebKitTestRunner/TestOptions.h:
(WTR::TestOptions::horizontalSystemMinimumLayoutMargin const):
* WebKitTestRunner/ios/PlatformWebViewIOS.mm:
(-[PlatformWebViewController systemMinimumLayoutMargins]):

Override this UIViewController method and replace the leading and trailing layout margin values with the values
from test options.

(WTR::PlatformWebView::PlatformWebView):
* WebKitTestRunner/ios/TestControllerIOS.mm:
(WTR::TestController::platformResetStateToConsistentValues):

Additionally make a slight adjustment here to avoid calling `-setContentInset` on the scroll view in between
tests if the content insets aren't changing. This is needed in order for the new layout test to work on watchOS.

LayoutTests:

Add a new layout test that uses the new test option to verify that nonzero horizontal system minimum layout
margins shrink the width of the viewport on watchOS (this test also disables watchOS device adaptations and uses
a device-width viewport with `initial-scale=1` such that we can simply check the value of `innerWidth`).

* fast/viewport/watchos/viewport-with-system-minimum-layout-margins-expected.txt: Added.
* fast/viewport/watchos/viewport-with-system-minimum-layout-margins.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (279829 => 279830)


--- trunk/LayoutTests/ChangeLog	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/LayoutTests/ChangeLog	2021-07-12 16:15:13 UTC (rev 279830)
@@ -1,3 +1,18 @@
+2021-07-12  Wenson Hsieh  <[email protected]>
+
+        [watchOS] Make a few additional adjustments to support system minimum layout margins
+        https://bugs.webkit.org/show_bug.cgi?id=227859
+        rdar://80113612
+
+        Reviewed by Tim Horton.
+
+        Add a new layout test that uses the new test option to verify that nonzero horizontal system minimum layout
+        margins shrink the width of the viewport on watchOS (this test also disables watchOS device adaptations and uses
+        a device-width viewport with `initial-scale=1` such that we can simply check the value of `innerWidth`).
+
+        * fast/viewport/watchos/viewport-with-system-minimum-layout-margins-expected.txt: Added.
+        * fast/viewport/watchos/viewport-with-system-minimum-layout-margins.html: Added.
+
 2021-07-12  Tyler Wilcock  <[email protected]>
 
         AX: Add ARIA role "image" as a new role, and leave "img" as a synonym

Added: trunk/LayoutTests/fast/viewport/watchos/viewport-with-system-minimum-layout-margins-expected.txt (0 => 279830)


--- trunk/LayoutTests/fast/viewport/watchos/viewport-with-system-minimum-layout-margins-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/viewport/watchos/viewport-with-system-minimum-layout-margins-expected.txt	2021-07-12 16:15:13 UTC (rev 279830)
@@ -0,0 +1,10 @@
+This test verifies that non-zero horizontal system minimum layout margins affect the width of the viewport.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS innerWidth is 132
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/viewport/watchos/viewport-with-system-minimum-layout-margins.html (0 => 279830)


--- trunk/LayoutTests/fast/viewport/watchos/viewport-with-system-minimum-layout-margins.html	                        (rev 0)
+++ trunk/LayoutTests/fast/viewport/watchos/viewport-with-system-minimum-layout-margins.html	2021-07-12 16:15:13 UTC (rev 279830)
@@ -0,0 +1,31 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true horizontalSystemMinimumLayoutMargin=12 ] -->
+<html>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="disabled-adaptations" content="watch">
+<head>
+<script src=""
+<script src=""
+<style>
+body, html {
+    margin: 0;
+    width: 100%;
+    height: 100%;
+}
+</style>
+<script>
+jsTestIsAsync = true;
+
+async function runTest() {
+    description("This test verifies that non-zero horizontal system minimum layout margins affect the width of the viewport.");
+
+    if (!window.testRunner)
+        return;
+
+    await UIHelper.ensureVisibleContentRectUpdate();
+    shouldBe("innerWidth", "132");
+    finishJSTest();
+}
+</script>
+</head>
+<body _onload_="runTest()"></body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (279829 => 279830)


--- trunk/Source/WebCore/ChangeLog	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Source/WebCore/ChangeLog	2021-07-12 16:15:13 UTC (rev 279830)
@@ -1,3 +1,21 @@
+2021-07-12  Wenson Hsieh  <[email protected]>
+
+        [watchOS] Make a few additional adjustments to support system minimum layout margins
+        https://bugs.webkit.org/show_bug.cgi?id=227859
+        rdar://80113612
+
+        Reviewed by Tim Horton.
+
+        Reduce the default minimum viewport scale on watchOS to avoid horizontal scrolling when loading wide fixed-
+        viewport-width web content. See WebKit ChangeLog for more details.
+
+        * page/ViewportConfiguration.cpp:
+        (WebCore::platformDeviceWidthOverride):
+        (WebCore::platformMinimumScaleForWebpage):
+        (WebCore::shouldOverrideShrinkToFitArgument):
+        (WebCore::ViewportConfiguration::nativeWebpageParametersWithShrinkToFit):
+        (WebCore::ViewportConfiguration::webpageParameters):
+
 2021-07-12  Tyler Wilcock  <[email protected]>
 
         AX: Add ARIA role "image" as a new role, and leave "img" as a synonym

Modified: trunk/Source/WebCore/page/ViewportConfiguration.cpp (279829 => 279830)


--- trunk/Source/WebCore/page/ViewportConfiguration.cpp	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Source/WebCore/page/ViewportConfiguration.cpp	2021-07-12 16:15:13 UTC (rev 279830)
@@ -45,7 +45,7 @@
 }
 #endif // ASSERT_ENABLED
 
-static float platformDeviceWidthOverride()
+static constexpr float platformDeviceWidthOverride()
 {
 #if PLATFORM(WATCHOS)
     return 320;
@@ -54,9 +54,18 @@
 #endif
 }
 
-static bool shouldOverrideShrinkToFitArgument()
+static constexpr double platformMinimumScaleForWebpage()
 {
 #if PLATFORM(WATCHOS)
+    return 0.1;
+#else
+    return 0.25;
+#endif
+}
+
+static constexpr bool shouldOverrideShrinkToFitArgument()
+{
+#if PLATFORM(WATCHOS)
     return true;
 #else
     return false;
@@ -372,7 +381,7 @@
 {
     Parameters parameters = ViewportConfiguration::nativeWebpageParametersWithoutShrinkToFit();
     parameters.allowsShrinkToFit = true;
-    parameters.minimumScale = 0.25;
+    parameters.minimumScale = platformMinimumScaleForWebpage();
     parameters.initialScaleIsSet = false;
     return parameters;
 }
@@ -384,7 +393,7 @@
     parameters.widthIsSet = true;
     parameters.allowsUserScaling = true;
     parameters.allowsShrinkToFit = true;
-    parameters.minimumScale = 0.25;
+    parameters.minimumScale = platformMinimumScaleForWebpage();
     parameters.maximumScale = 5;
     return parameters;
 }

Modified: trunk/Source/WebKit/ChangeLog (279829 => 279830)


--- trunk/Source/WebKit/ChangeLog	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Source/WebKit/ChangeLog	2021-07-12 16:15:13 UTC (rev 279830)
@@ -1,3 +1,41 @@
+2021-07-12  Wenson Hsieh  <[email protected]>
+
+        [watchOS] Make a few additional adjustments to support system minimum layout margins
+        https://bugs.webkit.org/show_bug.cgi?id=227859
+        rdar://80113612
+
+        Reviewed by Tim Horton.
+
+        Make a couple of minor adjustments to deal with the fact that `-contentInset` includes system content insets
+        (specifically, `-_contentScrollInset`) on watchOS, due to method swizzling that happens in PepperUICore. See
+        changes below for more detail.
+
+        Test: fast/viewport/watchos/viewport-with-system-minimum-layout-margins.html
+
+        * UIProcess/API/ios/WKWebViewIOS.mm:
+        (-[WKWebView _computedContentInset]):
+
+        Only apply `-safeAreaInsets` on top of `-contentInset` when computing the total scroll view content inset on
+        watchOS (as opposed to applying both `-safeAreaInsets` and `-_contentScrollInset`); this is because
+        `-contentInset` on watchOS is actually equivalent to `-_effectiveContentInset` on other iOS-family platforms, so
+        additionally adding `-_contentScrollInset` here would result in the scroll content inset being double-counted.
+
+        * UIProcess/ios/WKScrollView.mm:
+        (-[WKScrollView setContentInset:]):
+        (-[WKScrollView _setContentScrollInsetInternal:]):
+        (-[WKScrollView _updateContentScrollInset]):
+
+        In the case where the WebKit client explicitly sets the scroll view's content insets using `-[WKScrollView
+        setContentInset:]`, set a flag (`_contentInsetWasExternallyOverridden`) and immediately revert any internally
+        specified `-_contentScrollInset` on WKScrollView. Due to the swizzled implementation of `-[UIScrollView
+        contentInset]` described above, it's practically impossible for any client to use `-setContentInset:` correctly
+        when there is a nonzero `-_contentScrollInset` on watchOS, so preferable to simply get out of the way of the
+        client in this scenario.
+
+        In the context of _SFNanoBrowserViewController, this ensures that scroll view content inset adjustment logic in
+        Safari doesn't inadvertently cause horizontal content insets to increase by `-_contentScrollInset` every time
+        `-[WKScrollView setContentInset:]` is invoked by the client.
+
 2021-07-12  Alexander Mikhaylenko  <[email protected]>
 
         [GTK] Touch navigation gesture triggers kinetic scrolling when cancelling

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (279829 => 279830)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2021-07-12 16:15:13 UTC (rev 279830)
@@ -633,10 +633,17 @@
         return _obscuredInsets;
 
     UIEdgeInsets insets = [_scrollView contentInset];
+    if (self._safeAreaShouldAffectObscuredInsets) {
+#if PLATFORM(WATCHOS)
+        // On watchOS, PepperUICore swizzles -[UIScrollView contentInset], such that it includes -_contentScrollInset as well.
+        // To avoid double-counting -_contentScrollInset when determining the total content inset, we only apply safe area insets here.
+        auto additionalScrollViewContentInset = self.safeAreaInsets;
+#else
+        auto additionalScrollViewContentInset = self._scrollViewSystemContentInset;
+#endif
+        insets = UIEdgeInsetsAdd(insets, additionalScrollViewContentInset, self._effectiveObscuredInsetEdgesAffectedBySafeArea);
+    }
 
-    if (self._safeAreaShouldAffectObscuredInsets)
-        insets = UIEdgeInsetsAdd(insets, self._scrollViewSystemContentInset, self._effectiveObscuredInsetEdgesAffectedBySafeArea);
-
     return insets;
 }
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKScrollView.mm (279829 => 279830)


--- trunk/Source/WebKit/UIProcess/ios/WKScrollView.mm	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Source/WebKit/UIProcess/ios/WKScrollView.mm	2021-07-12 16:15:13 UTC (rev 279830)
@@ -131,6 +131,7 @@
 #if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
     BOOL _contentInsetAdjustmentBehaviorWasExternallyOverridden;
 #endif
+    BOOL _contentInsetWasExternallyOverridden;
     CGFloat _keyboardBottomInsetAdjustment;
     BOOL _scrollEnabledByClient;
     BOOL _scrollEnabledInternal;
@@ -271,6 +272,14 @@
 {
     [super setContentInset:contentInset];
 
+    _contentInsetWasExternallyOverridden = YES;
+#if PLATFORM(WATCHOS)
+    if (_contentScrollInsetInternal) {
+        _contentScrollInsetInternal = std::nullopt;
+        [self _updateContentScrollInset];
+    }
+#endif // PLATFORM(WATCHOS)
+
     [_internalDelegate _scheduleVisibleContentRectUpdate];
 }
 
@@ -433,6 +442,11 @@
 
 - (BOOL)_setContentScrollInsetInternal:(UIEdgeInsets)insets
 {
+#if PLATFORM(WATCHOS)
+    if (_contentInsetWasExternallyOverridden)
+        return NO;
+#endif // PLATFORM(WATCHOS)
+
     if (_contentScrollInsetFromClient)
         return NO;
 
@@ -450,6 +464,10 @@
         super.contentScrollInset = *insets;
     else if (auto insets = _contentScrollInsetInternal)
         super.contentScrollInset = *insets;
+#if PLATFORM(WATCHOS)
+    else if (_contentInsetWasExternallyOverridden)
+        super.contentScrollInset = UIEdgeInsetsZero;
+#endif // PLATFORM(WATCHOS)
     else
         ASSERT_NOT_REACHED();
 }

Modified: trunk/Tools/ChangeLog (279829 => 279830)


--- trunk/Tools/ChangeLog	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Tools/ChangeLog	2021-07-12 16:15:13 UTC (rev 279830)
@@ -1,3 +1,32 @@
+2021-07-12  Wenson Hsieh  <[email protected]>
+
+        [watchOS] Make a few additional adjustments to support system minimum layout margins
+        https://bugs.webkit.org/show_bug.cgi?id=227859
+        rdar://80113612
+
+        Reviewed by Tim Horton.
+
+        Add support for simulating arbitrary horizontal (trailing and leading) values for `-systemMinimumLayoutMargin`
+        in WebKitTestRunner, via a new "horizontalSystemMinimumLayoutMargin" test option. By default, this is 0.
+
+        * WebKitTestRunner/TestOptions.cpp:
+        (WTR::TestOptions::defaults):
+        (WTR::TestOptions::keyTypeMapping):
+        * WebKitTestRunner/TestOptions.h:
+        (WTR::TestOptions::horizontalSystemMinimumLayoutMargin const):
+        * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
+        (-[PlatformWebViewController systemMinimumLayoutMargins]):
+
+        Override this UIViewController method and replace the leading and trailing layout margin values with the values
+        from test options.
+
+        (WTR::PlatformWebView::PlatformWebView):
+        * WebKitTestRunner/ios/TestControllerIOS.mm:
+        (WTR::TestController::platformResetStateToConsistentValues):
+
+        Additionally make a slight adjustment here to avoid calling `-setContentInset` on the scroll view in between
+        tests if the content insets aren't changing. This is needed in order for the new layout test to work on watchOS.
+
 2021-07-09  Myles C. Maxfield  <[email protected]>
 
         SVGImageForContainer reports true for is<SVGImage>() but it doesn't inherit from SVGImage

Modified: trunk/Tools/WebKitTestRunner/TestOptions.cpp (279829 => 279830)


--- trunk/Tools/WebKitTestRunner/TestOptions.cpp	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Tools/WebKitTestRunner/TestOptions.cpp	2021-07-12 16:15:13 UTC (rev 279830)
@@ -159,6 +159,7 @@
         };
         features.doubleTestRunnerFeatures = {
             { "contentInset.top", 0 },
+            { "horizontalSystemMinimumLayoutMargin", 0 },
             { "deviceScaleFactor", 1 },
             { "viewHeight", 600 },
             { "viewWidth", 800 },
@@ -210,6 +211,7 @@
         { "useThreadedScrolling", TestHeaderKeyType::BoolTestRunner },
     
         { "contentInset.top", TestHeaderKeyType::DoubleTestRunner },
+        { "horizontalSystemMinimumLayoutMargin", TestHeaderKeyType::DoubleTestRunner },
         { "deviceScaleFactor", TestHeaderKeyType::DoubleTestRunner },
         { "viewHeight", TestHeaderKeyType::DoubleTestRunner },
         { "viewWidth", TestHeaderKeyType::DoubleTestRunner },

Modified: trunk/Tools/WebKitTestRunner/TestOptions.h (279829 => 279830)


--- trunk/Tools/WebKitTestRunner/TestOptions.h	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Tools/WebKitTestRunner/TestOptions.h	2021-07-12 16:15:13 UTC (rev 279830)
@@ -73,6 +73,7 @@
     bool useRemoteLayerTree() const { return boolTestRunnerFeatureValue("useRemoteLayerTree"); }
     bool useThreadedScrolling() const { return boolTestRunnerFeatureValue("useThreadedScrolling"); }
     double contentInsetTop() const { return doubleTestRunnerFeatureValue("contentInset.top"); }
+    double horizontalSystemMinimumLayoutMargin() const { return doubleTestRunnerFeatureValue("horizontalSystemMinimumLayoutMargin"); }
     double deviceScaleFactor() const { return doubleTestRunnerFeatureValue("deviceScaleFactor"); }
     double viewHeight() const { return doubleTestRunnerFeatureValue("viewHeight"); }
     double viewWidth() const { return doubleTestRunnerFeatureValue("viewWidth"); }

Modified: trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm (279829 => 279830)


--- trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2021-07-12 16:15:13 UTC (rev 279830)
@@ -135,10 +135,19 @@
 } // namespace WTR
 
 @interface PlatformWebViewController : UIViewController
+@property (nonatomic) CGFloat horizontalSystemMinimumLayoutMargin;
 @end
 
 @implementation PlatformWebViewController
 
+- (NSDirectionalEdgeInsets)systemMinimumLayoutMargins
+{
+    auto layoutMargins = [super systemMinimumLayoutMargins];
+    layoutMargins.leading = self.horizontalSystemMinimumLayoutMargin;
+    layoutMargins.trailing = self.horizontalSystemMinimumLayoutMargin;
+    return layoutMargins;
+}
+
 - (void)viewWillTransitionToSize:(CGSize)toSize withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
 {
     [super viewWillTransitionToSize:toSize withTransitionCoordinator:coordinator];
@@ -204,7 +213,9 @@
     m_window.backgroundColor = [UIColor lightGrayColor];
     m_window.platformWebView = this;
 
-    [m_window setRootViewController:adoptNS([[PlatformWebViewController alloc] init]).get()];
+    auto webViewController = adoptNS([[PlatformWebViewController alloc] init]);
+    [webViewController setHorizontalSystemMinimumLayoutMargin:options.horizontalSystemMinimumLayoutMargin()];
+    [m_window setRootViewController:webViewController.get()];
 
     m_view = [[TestRunnerWKWebView alloc] initWithFrame:viewRectForWindowRect(rect, WebViewSizingMode::Default) configuration:configuration];
 

Modified: trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm (279829 => 279830)


--- trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm	2021-07-12 16:14:28 UTC (rev 279829)
+++ trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm	2021-07-12 16:15:13 UTC (rev 279830)
@@ -218,10 +218,14 @@
         UIScrollView *scrollView = webView.scrollView;
         [scrollView _removeAllAnimations:YES];
         [scrollView setZoomScale:1 animated:NO];
-        
+
+        auto currentContentInset = scrollView.contentInset;
         auto contentInsetTop = options.contentInsetTop();
-        scrollView.contentInset = UIEdgeInsetsMake(contentInsetTop, 0, 0, 0);
-        scrollView.contentOffset = CGPointMake(0, -contentInsetTop);
+        if (currentContentInset.top != contentInsetTop) {
+            currentContentInset.top = contentInsetTop;
+            scrollView.contentInset = currentContentInset;
+            scrollView.contentOffset = CGPointMake(-currentContentInset.left, -currentContentInset.top);
+        }
 
         if (webView.interactingWithFormControl)
             shouldRestoreFirstResponder = [webView resignFirstResponder];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to