Title: [257066] trunk
Revision
257066
Author
timothy_hor...@apple.com
Date
2020-02-20 09:34:27 -0800 (Thu, 20 Feb 2020)

Log Message

WKWebView with non-zero origin has the wrong top content inset with NSWindowStyleMaskFullSizeContentView
https://bugs.webkit.org/show_bug.cgi?id=207998
<rdar://problem/40942425>

Reviewed by Sam Weinig.

Source/WebKit:

New API tests: TopContentInset.{AutomaticAdjustment, AutomaticAdjustmentDisabled, AutomaticAdjustmentDoesNotAffectInsetViews}

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::updateContentInsetsIfAutomatic):
Previously, a WKWebView with frame.origin anywhere other than {0, 0}
would end up with the same top content inset as if it overlapped the
titlebar.

It's not clear what the original code was going for; we can determine
the overlapping portion of the contentLayoutRect by simply converting
it from window coordinates to WKWebView coordinates and looking at the
origin (ensuring we don't let it go negative).

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/TopContentInset.mm: Renamed from Tools/TestWebKitAPI/Tests/WebKitCocoa/FullscreenTopContentInset.mm.
(-[FullscreenChangeMessageHandler userContentController:didReceiveScriptMessage:]):
(TestWebKitAPI::TEST):
Add some tests for top content insets.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (257065 => 257066)


--- trunk/Source/WebKit/ChangeLog	2020-02-20 17:20:53 UTC (rev 257065)
+++ trunk/Source/WebKit/ChangeLog	2020-02-20 17:34:27 UTC (rev 257066)
@@ -1,3 +1,24 @@
+2020-02-20  Tim Horton  <timothy_hor...@apple.com>
+
+        WKWebView with non-zero origin has the wrong top content inset with NSWindowStyleMaskFullSizeContentView
+        https://bugs.webkit.org/show_bug.cgi?id=207998
+        <rdar://problem/40942425>
+
+        Reviewed by Sam Weinig.
+
+        New API tests: TopContentInset.{AutomaticAdjustment, AutomaticAdjustmentDisabled, AutomaticAdjustmentDoesNotAffectInsetViews}
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::updateContentInsetsIfAutomatic):
+        Previously, a WKWebView with frame.origin anywhere other than {0, 0}
+        would end up with the same top content inset as if it overlapped the
+        titlebar.
+
+        It's not clear what the original code was going for; we can determine
+        the overlapping portion of the contentLayoutRect by simply converting
+        it from window coordinates to WKWebView coordinates and looking at the
+        origin (ensuring we don't let it go negative).
+
 2020-02-20  Jason Lawrence  <lawrenc...@apple.com>
 
         Unreviewed, rolling out r257025.

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (257065 => 257066)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2020-02-20 17:20:53 UTC (rev 257065)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2020-02-20 17:34:27 UTC (rev 257066)
@@ -1840,8 +1840,8 @@
 
     NSWindow *window = [m_view window];
     if ((window.styleMask & NSWindowStyleMaskFullSizeContentView) && !window.titlebarAppearsTransparent && ![m_view enclosingScrollView]) {
-        NSRect contentLayoutRect = [m_view convertRect:window.contentLayoutRect fromView:nil];
-        CGFloat newTopContentInset = NSMaxY(contentLayoutRect) - NSHeight(contentLayoutRect);
+        NSRect contentLayoutRectInWebViewCoordinates = [m_view convertRect:window.contentLayoutRect fromView:nil];
+        CGFloat newTopContentInset = std::max<CGFloat>(contentLayoutRectInWebViewCoordinates.origin.y, 0);
         if (m_page->topContentInset() != newTopContentInset)
             setTopContentInset(newTopContentInset);
     } else

Modified: trunk/Tools/ChangeLog (257065 => 257066)


--- trunk/Tools/ChangeLog	2020-02-20 17:20:53 UTC (rev 257065)
+++ trunk/Tools/ChangeLog	2020-02-20 17:34:27 UTC (rev 257066)
@@ -1,3 +1,17 @@
+2020-02-20  Tim Horton  <timothy_hor...@apple.com>
+
+        WKWebView with non-zero origin has the wrong top content inset with NSWindowStyleMaskFullSizeContentView
+        https://bugs.webkit.org/show_bug.cgi?id=207998
+        <rdar://problem/40942425>
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/TopContentInset.mm: Renamed from Tools/TestWebKitAPI/Tests/WebKitCocoa/FullscreenTopContentInset.mm.
+        (-[FullscreenChangeMessageHandler userContentController:didReceiveScriptMessage:]):
+        (TestWebKitAPI::TEST):
+        Add some tests for top content insets.
+
 2020-02-20  Jonathan Bedard  <jbed...@apple.com>
 
         results.webkit.org: Correctly report JSC tests for windows (Follow-up fix)

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (257065 => 257066)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-02-20 17:20:53 UTC (rev 257065)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-02-20 17:34:27 UTC (rev 257066)
@@ -571,7 +571,7 @@
 		7C83E0BA1D0A64FB00FEBCF3 /* Coding.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AAD19F51C7CE20300831E47 /* Coding.mm */; };
 		7C83E0BB1D0A650000FEBCF3 /* FindInPage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D8104CB1BEC13E70020DA46 /* FindInPage.mm */; };
 		7C83E0BC1D0A650700FEBCF3 /* FixedLayoutSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */; };
-		7C83E0BD1D0A650C00FEBCF3 /* FullscreenTopContentInset.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */; };
+		7C83E0BD1D0A650C00FEBCF3 /* TopContentInset.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE195B31CFE0ADE0053D256 /* TopContentInset.mm */; };
 		7C83E0BE1D0A651300FEBCF3 /* IndexedDBMultiProcess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51BCEE491C84F4AF0042C82E /* IndexedDBMultiProcess.mm */; };
 		7C83E0BF1D0A652200FEBCF3 /* IndexedDBPersistence.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B1EE8D1C80F5880064FB98 /* IndexedDBPersistence.mm */; };
 		7C83E0C01D0A652700FEBCF3 /* LoadInvalidURLRequest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 57901FAC1CAF12C200ED64F9 /* LoadInvalidURLRequest.mm */; };
@@ -2533,7 +2533,7 @@
 		CDCFFEC022E268D500DF4223 /* NoPauseWhenSwitchingTabs.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NoPauseWhenSwitchingTabs.mm; sourceTree = "<group>"; };
 		CDD68F0C22C18317000CF0AE /* WKWebViewCloseAllMediaPresentations.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCloseAllMediaPresentations.mm; sourceTree = "<group>"; };
 		CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenTopContentInset.html; sourceTree = "<group>"; };
-		CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FullscreenTopContentInset.mm; sourceTree = "<group>"; };
+		CDE195B31CFE0ADE0053D256 /* TopContentInset.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TopContentInset.mm; sourceTree = "<group>"; };
 		CDF0B789216D484300421ECC /* CloseWebViewDuringEnterFullscreen.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CloseWebViewDuringEnterFullscreen.mm; sourceTree = "<group>"; };
 		CDF92236216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CloseWebViewAfterEnterFullscreen.mm; sourceTree = "<group>"; };
 		CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityOrigin.cpp; sourceTree = "<group>"; };
@@ -2980,7 +2980,6 @@
 				5CB5B3BD1FFC517E00C27BB0 /* FrameHandleSerialization.mm */,
 				CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */,
 				3F1B52681D3D7129008D60C4 /* FullscreenLayoutConstraints.mm */,
-				CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */,
 				631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */,
 				07E1F6A01FFC3A080096C7EC /* GetDisplayMedia.mm */,
 				2DADF26221CB8F32003D3E3A /* GetResourceData.mm */,
@@ -3097,6 +3096,7 @@
 				5C16F8FB230C942B0074C4A8 /* TextSize.mm */,
 				C22FA32A228F8708009D7988 /* TextWidth.mm */,
 				5C73A81A2323059800DEA85A /* TLSDeprecation.mm */,
+				CDE195B31CFE0ADE0053D256 /* TopContentInset.mm */,
 				5CB40B4D1F4B98BE007DC7B9 /* UIDelegate.mm */,
 				5C3A77A922F20B8A003827FF /* UploadDirectory.mm */,
 				7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
@@ -4788,7 +4788,6 @@
 				7CCE7EF61A411AE600447C4C /* FrameMIMETypeHTML.cpp in Sources */,
 				7CCE7EF71A411AE600447C4C /* FrameMIMETypePNG.cpp in Sources */,
 				CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */,
-				7C83E0BD1D0A650C00FEBCF3 /* FullscreenTopContentInset.mm in Sources */,
 				CDBFCC451A9FF45300A7B691 /* FullscreenZoomInitialFrame.mm in Sources */,
 				83DB79691EF63B3C00BFA5E5 /* Function.cpp in Sources */,
 				7CCE7EF81A411AE600447C4C /* Geolocation.cpp in Sources */,
@@ -5041,6 +5040,7 @@
 				5C16F8FC230C94370074C4A8 /* TextSize.mm in Sources */,
 				C22FA32B228F8708009D7988 /* TextWidth.mm in Sources */,
 				7CCE7EDD1A411A9200447C4C /* TimeRanges.cpp in Sources */,
+				7C83E0BD1D0A650C00FEBCF3 /* TopContentInset.mm in Sources */,
 				7CCE7ED31A411A7E00447C4C /* TypingStyleCrash.mm in Sources */,
 				57152B7821DD4E8D000C37CA /* U2fCommandConstructorTest.cpp in Sources */,
 				5CB40B4E1F4B98D3007DC7B9 /* UIDelegate.mm in Sources */,

Deleted: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FullscreenTopContentInset.mm (257065 => 257066)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FullscreenTopContentInset.mm	2020-02-20 17:20:53 UTC (rev 257065)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FullscreenTopContentInset.mm	2020-02-20 17:34:27 UTC (rev 257066)
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if PLATFORM(MAC)
-
-#import "PlatformUtilities.h"
-#import <WebKit/WKPreferencesPrivate.h>
-#import <WebKit/WKWebViewConfigurationPrivate.h>
-#import <WebKit/WKWebViewPrivate.h>
-#import <wtf/RetainPtr.h>
-
-static bool receivedLoadedMessage;
-static bool receivedFullscreenChangeMessage;
-
-@interface FullscreenChangeMessageHandler : NSObject <WKScriptMessageHandler>
-@end
-
-@implementation FullscreenChangeMessageHandler
-- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
-{
-    NSString *bodyString = (NSString *)[message body];
-    if ([bodyString isEqualToString:@"fullscreenchange"])
-        receivedFullscreenChangeMessage = true;
-    else if ([bodyString isEqualToString:@"load"])
-        receivedLoadedMessage = true;
-}
-@end
-
-namespace TestWebKitAPI {
-
-TEST(Fullscreen, TopContentInset)
-{
-    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
-    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
-    [webView _setTopContentInset:10];
-    [webView _setAutomaticallyAdjustsContentInsets:NO];
-    [configuration preferences]._fullScreenEnabled = YES;
-    RetainPtr<FullscreenChangeMessageHandler> handler = adoptNS([[FullscreenChangeMessageHandler alloc] init]);
-    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"fullscreenChangeHandler"];
-
-    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]);
-    [[window contentView] addSubview:webView.get()];
-    [window makeKeyAndOrderFront:nil];
-
-    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"FullscreenTopContentInset" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
-    [webView loadRequest:request];
-    TestWebKitAPI::Util::run(&receivedLoadedMessage);
-
-    NSEvent *event = [NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:NSMakePoint(5, 5) modifierFlags:0 timestamp:0 windowNumber:window.get().windowNumber context:0 eventNumber:0 clickCount:0 pressure:0];
-    [webView mouseDown:event];
-
-    TestWebKitAPI::Util::run(&receivedFullscreenChangeMessage);
-    ASSERT_EQ(window.get().screen.frame.size.width, webView.get().frame.size.width);
-    ASSERT_EQ(window.get().screen.frame.size.height + webView.get()._topContentInset, webView.get().frame.size.height);
-
-    receivedFullscreenChangeMessage = false;
-    [webView mouseDown:event];
-    TestWebKitAPI::Util::run(&receivedFullscreenChangeMessage);
-    ASSERT_EQ(10, webView.get()._topContentInset);
-}
-
-} // namespace TestWebKitAPI
-
-#endif

Copied: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TopContentInset.mm (from rev 257065, trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FullscreenTopContentInset.mm) (0 => 257066)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TopContentInset.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TopContentInset.mm	2020-02-20 17:34:27 UTC (rev 257066)
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if PLATFORM(MAC)
+
+#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
+#import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+static bool receivedLoadedMessage;
+static bool receivedFullscreenChangeMessage;
+
+@interface FullscreenChangeMessageHandler : NSObject <WKScriptMessageHandler>
+@end
+
+@implementation FullscreenChangeMessageHandler
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+    NSString *bodyString = (NSString *)[message body];
+    if ([bodyString isEqualToString:@"fullscreenchange"])
+        receivedFullscreenChangeMessage = true;
+    else if ([bodyString isEqualToString:@"load"])
+        receivedLoadedMessage = true;
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(TopContentInset, Fullscreen)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
+    [webView _setTopContentInset:10];
+    [webView _setAutomaticallyAdjustsContentInsets:NO];
+    [configuration preferences]._fullScreenEnabled = YES;
+    RetainPtr<FullscreenChangeMessageHandler> handler = adoptNS([[FullscreenChangeMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"fullscreenChangeHandler"];
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+    [window makeKeyAndOrderFront:nil];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"FullscreenTopContentInset" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&receivedLoadedMessage);
+
+    NSEvent *event = [NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:NSMakePoint(5, 5) modifierFlags:0 timestamp:0 windowNumber:window.get().windowNumber context:0 eventNumber:0 clickCount:0 pressure:0];
+    [webView mouseDown:event];
+
+    TestWebKitAPI::Util::run(&receivedFullscreenChangeMessage);
+    ASSERT_EQ(window.get().screen.frame.size.width, webView.get().frame.size.width);
+    ASSERT_EQ(window.get().screen.frame.size.height + webView.get()._topContentInset, webView.get().frame.size.height);
+
+    receivedFullscreenChangeMessage = false;
+    [webView mouseDown:event];
+    TestWebKitAPI::Util::run(&receivedFullscreenChangeMessage);
+    ASSERT_EQ(10, webView.get()._topContentInset);
+}
+
+TEST(TopContentInset, AutomaticAdjustment)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) configuration:configuration.get()]);
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 400) styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView) backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+    [window makeKeyAndOrderFront:nil];
+
+    [webView loadHTMLString:@"" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    ASSERT_GT(webView.get()._topContentInset, 10);
+}
+
+TEST(TopContentInset, AutomaticAdjustmentDisabled)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) configuration:configuration.get()]);
+    [webView _setAutomaticallyAdjustsContentInsets:NO];
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 400) styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView) backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+    [window makeKeyAndOrderFront:nil];
+
+    [webView loadHTMLString:@"" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    ASSERT_EQ(webView.get()._topContentInset, 0);
+}
+
+TEST(TopContentInset, AutomaticAdjustmentDoesNotAffectInsetViews)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(100, 100, 200, 200) configuration:configuration.get()]);
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 400) styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView) backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+    [window makeKeyAndOrderFront:nil];
+
+    [webView loadHTMLString:@"" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    ASSERT_EQ(webView.get()._topContentInset, 0);
+}
+
+} // namespace TestWebKitAPI
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to