Title: [229688] trunk
Revision
229688
Author
[email protected]
Date
2018-03-16 16:56:53 -0700 (Fri, 16 Mar 2018)

Log Message

Add SPI to expose width and height anchors for WKWebView's content view
https://bugs.webkit.org/show_bug.cgi?id=183711
<rdar://problem/38562899>

Reviewed by Tim Horton.

Source/WebKit:

Add _contentWidthAnchor and _contentHeightAnchor SPI to WKWebView for internal clients to be able to reason
about the size of the content view on iOS using autolayout.

Test: WebKit.AutoLayoutPositionHeaderAndFooterViewsInScrollView.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _contentWidthAnchor]):
(-[WKWebView _contentHeightAnchor]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Tools:

Adds an API test exercising the new SPI.

* TestWebKitAPI/Tests/WebKitCocoa/AutoLayoutIntegration.mm:
(checkCGRect):
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (229687 => 229688)


--- trunk/Source/WebKit/ChangeLog	2018-03-16 23:48:37 UTC (rev 229687)
+++ trunk/Source/WebKit/ChangeLog	2018-03-16 23:56:53 UTC (rev 229688)
@@ -1,3 +1,21 @@
+2018-03-16  Wenson Hsieh  <[email protected]>
+
+        Add SPI to expose width and height anchors for WKWebView's content view
+        https://bugs.webkit.org/show_bug.cgi?id=183711
+        <rdar://problem/38562899>
+
+        Reviewed by Tim Horton.
+
+        Add _contentWidthAnchor and _contentHeightAnchor SPI to WKWebView for internal clients to be able to reason
+        about the size of the content view on iOS using autolayout.
+
+        Test: WebKit.AutoLayoutPositionHeaderAndFooterViewsInScrollView.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _contentWidthAnchor]):
+        (-[WKWebView _contentHeightAnchor]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
 2018-03-16  Megan Gardner  <[email protected]>
 
         Add _useSystemAppearance to WKView

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (229687 => 229688)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-03-16 23:48:37 UTC (rev 229687)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-03-16 23:56:53 UTC (rev 229688)
@@ -4948,6 +4948,16 @@
 
 #if PLATFORM(IOS)
 
+- (NSLayoutDimension *)_contentWidthAnchor
+{
+    return [_contentView widthAnchor];
+}
+
+- (NSLayoutDimension *)_contentHeightAnchor
+{
+    return [_contentView heightAnchor];
+}
+
 #if ENABLE(FULLSCREEN_API)
 - (void)removeFromSuperview
 {

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (229687 => 229688)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-03-16 23:48:37 UTC (rev 229687)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-03-16 23:56:53 UTC (rev 229688)
@@ -254,6 +254,9 @@
 - (void)_accessibilityRetrieveSpeakSelectionContent WK_API_AVAILABLE(ios(11.0));
 - (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content WK_API_AVAILABLE(ios(11.0));
 
+@property (nonatomic, readonly) NSLayoutDimension *_contentWidthAnchor WK_API_AVAILABLE(ios(WK_IOS_TBA));
+@property (nonatomic, readonly) NSLayoutDimension *_contentHeightAnchor WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 #else
 
 @property (nonatomic, readonly) _WKRectEdge _pinnedState WK_API_AVAILABLE(macosx(WK_MAC_TBA));

Modified: trunk/Tools/ChangeLog (229687 => 229688)


--- trunk/Tools/ChangeLog	2018-03-16 23:48:37 UTC (rev 229687)
+++ trunk/Tools/ChangeLog	2018-03-16 23:56:53 UTC (rev 229688)
@@ -1,3 +1,17 @@
+2018-03-16  Wenson Hsieh  <[email protected]>
+
+        Add SPI to expose width and height anchors for WKWebView's content view
+        https://bugs.webkit.org/show_bug.cgi?id=183711
+        <rdar://problem/38562899>
+
+        Reviewed by Tim Horton.
+
+        Adds an API test exercising the new SPI.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/AutoLayoutIntegration.mm:
+        (checkCGRect):
+        (TEST):
+
 2018-03-16  Chris Dumez  <[email protected]>
 
         WebKit.RestoreSessionStateContainingScrollRestorationDefault API test is failing with async policy delegates

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AutoLayoutIntegration.mm (229687 => 229688)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AutoLayoutIntegration.mm	2018-03-16 23:48:37 UTC (rev 229687)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AutoLayoutIntegration.mm	2018-03-16 23:56:53 UTC (rev 229688)
@@ -27,11 +27,18 @@
 
 #import "PlatformUtilities.h"
 #import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
-#if WK_API_ENABLED && PLATFORM(MAC)
+#if PLATFORM(IOS)
+#import "UIKitSPI.h"
+#endif
 
+#if WK_API_ENABLED
+
+#if PLATFORM(MAC)
+
 static bool didInvalidateIntrinsicContentSize;
 static bool didEvaluateJavaScript;
 
@@ -204,4 +211,54 @@
     [webView setNavigationDelegate:nil];
 }
 
-#endif
+#endif // PLATFORM(MAC)
+
+#if PLATFORM(IOS)
+
+static void checkCGRect(CGRect expected, CGRect observed)
+{
+    bool success = CGRectEqualToRect(expected, observed);
+    EXPECT_TRUE(success);
+    if (!success)
+        NSLog(@"Expected rect: %@ but got: %@", NSStringFromCGRect(expected), NSStringFromCGRect(observed));
+}
+
+TEST(WebKit, AutoLayoutPositionHeaderAndFooterViewsInScrollView)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    UIScrollView *scrollView = [webView scrollView];
+    scrollView.contentInset = UIEdgeInsetsMake(100, 0, 100, 0);
+
+    [webView synchronouslyLoadHTMLString:@"<meta name='viewport' content='width=device-width, initial-scale=1'><body style='width: 100%; height: 5000px; margin: 0'>"];
+
+    auto headerLabel = adoptNS([[UILabel alloc] init]);
+    [headerLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [scrollView addSubview:headerLabel.get()];
+
+    auto footerLabel = adoptNS([[UILabel alloc] init]);
+    [footerLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [scrollView addSubview:footerLabel.get()];
+
+    [NSLayoutConstraint activateConstraints:@[
+        [[headerLabel widthAnchor] constraintEqualToConstant:320],
+        [[headerLabel heightAnchor] constraintEqualToConstant:100],
+        [[headerLabel leftAnchor] constraintEqualToAnchor:scrollView.contentLayoutGuide.leftAnchor],
+        [[headerLabel bottomAnchor] constraintEqualToAnchor:scrollView.contentLayoutGuide.topAnchor],
+        [[footerLabel widthAnchor] constraintEqualToConstant:320],
+        [[footerLabel heightAnchor] constraintEqualToConstant:100],
+        [[footerLabel leftAnchor] constraintEqualToAnchor:scrollView.contentLayoutGuide.leftAnchor],
+        [[footerLabel topAnchor] constraintEqualToAnchor:scrollView.contentLayoutGuide.bottomAnchor],
+        [[webView _contentWidthAnchor] constraintEqualToAnchor:scrollView.contentLayoutGuide.widthAnchor],
+        [[webView _contentHeightAnchor] constraintEqualToAnchor:scrollView.contentLayoutGuide.heightAnchor]
+    ]];
+
+    [webView layoutSubviews];
+    [webView waitForNextPresentationUpdate];
+
+    checkCGRect(CGRectMake(0, -100, 320, 100), [headerLabel frame]);
+    checkCGRect(CGRectMake(0, 5000, 320, 100), [footerLabel frame]);
+}
+
+#endif // PLATFORM(IOS)
+
+#endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to