Title: [191183] trunk
Revision
191183
Author
timothy_hor...@apple.com
Date
2015-10-16 10:30:27 -0700 (Fri, 16 Oct 2015)

Log Message

Hook up autolayout intrinsic sizing for WKWebView
https://bugs.webkit.org/show_bug.cgi?id=150219
<rdar://problem/20016905>

Reviewed by Simon Fraser.

New API test: WebKit2.AutoLayoutIntegration.

* page/FrameView.cpp:
(WebCore::FrameView::autoSizeIfEnabled):
When autosizing a document in which the body expands to the size of 
the view (a feature of quirks mode), the first (width-determining)
autosizing will resize the view to the document height (which is at 
least the body height), and the second time around, the height will
not decrease (because it was expanded to the size of the view).

Instead, the first time around, we should use the computed width,
but shrink the height back down to the minimum, and then expand
only as much as needed to fit the content.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
(-[WKWebView intrinsicContentSize]):
(-[WKWebView _setIntrinsicContentSize:]):
(-[WKWebView _minimumLayoutWidth]):
(-[WKWebView _setMinimumLayoutWidth:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
Add a simple SPI to specify the minimum width that a WKWebView will attempt
to lay out to, similar to WKView except just a width, not a size, and
with no option to force the height to the view size. Similar behavior can
be achieved by clients by setting custom autolayout constraints on the view.

* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::intrinsicContentSizeDidChange):
Forward intrinsic content size changes to the WKWebView, not its inner WKView,
if we have one.

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::transitionToCommittedForNewPage):
Only set the autosizing fixed minimum height if we're using that behavior;
otherwise, setting it to the view's height will end up accidentally
turning on that behavior (which involves an extra layout per resize!).

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm: Added.
(-[AutoLayoutNavigationDelegate webView:didFinishNavigation:]):
(-[AutoLayoutWKWebView load:expectingContentSize:]):
(-[AutoLayoutWKWebView expectContentSizeChange:]):
(-[AutoLayoutWKWebView invalidateIntrinsicContentSize]):
(TEST):
Add a variety of tests, including one which catches the bug that
the WebCore part of this patch fixes.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (191182 => 191183)


--- trunk/Source/WebCore/ChangeLog	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebCore/ChangeLog	2015-10-16 17:30:27 UTC (rev 191183)
@@ -1,3 +1,25 @@
+2015-10-16  Tim Horton  <timothy_hor...@apple.com>
+
+        Hook up autolayout intrinsic sizing for WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=150219
+        <rdar://problem/20016905>
+
+        Reviewed by Simon Fraser.
+
+        New API test: WebKit2.AutoLayoutIntegration.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::autoSizeIfEnabled):
+        When autosizing a document in which the body expands to the size of 
+        the view (a feature of quirks mode), the first (width-determining)
+        autosizing will resize the view to the document height (which is at 
+        least the body height), and the second time around, the height will
+        not decrease (because it was expanded to the size of the view).
+
+        Instead, the first time around, we should use the computed width,
+        but shrink the height back down to the minimum, and then expand
+        only as much as needed to fit the content.
+
 2015-10-16  Brady Eidson  <beid...@apple.com>
 
         Modern IDB: Support IDBDatabase.close().

Modified: trunk/Source/WebCore/page/FrameView.cpp (191182 => 191183)


--- trunk/Source/WebCore/page/FrameView.cpp	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebCore/page/FrameView.cpp	2015-10-16 17:30:27 UTC (rev 191183)
@@ -3281,7 +3281,10 @@
             && !frame().loader().isComplete() && (newSize.height() < size.height() || newSize.width() < size.width()))
             break;
 
-        resize(newSize.width(), newSize.height());
+        // The first time around, resize to the minimum height again; otherwise,
+        // on pages (e.g. quirks mode) where the body/document resize to the view size,
+        // we'll end up not shrinking back down after resizing to the computed preferred width.
+        resize(newSize.width(), i ? newSize.height() : m_minAutoSize.height());
         // Force the scrollbar state to avoid the scrollbar code adding them and causing them to be needed. For example,
         // a vertical scrollbar may cause text to wrap and thus increase the height (which is the only reason the scollbar is needed).
         setVerticalScrollbarLock(false);

Modified: trunk/Source/WebKit2/ChangeLog (191182 => 191183)


--- trunk/Source/WebKit2/ChangeLog	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-16 17:30:27 UTC (rev 191183)
@@ -1,3 +1,35 @@
+2015-10-16  Tim Horton  <timothy_hor...@apple.com>
+
+        Hook up autolayout intrinsic sizing for WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=150219
+        <rdar://problem/20016905>
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView initWithFrame:configuration:]):
+        (-[WKWebView intrinsicContentSize]):
+        (-[WKWebView _setIntrinsicContentSize:]):
+        (-[WKWebView _minimumLayoutWidth]):
+        (-[WKWebView _setMinimumLayoutWidth:]):
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        Add a simple SPI to specify the minimum width that a WKWebView will attempt
+        to lay out to, similar to WKView except just a width, not a size, and
+        with no option to force the height to the view size. Similar behavior can
+        be achieved by clients by setting custom autolayout constraints on the view.
+
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::intrinsicContentSizeDidChange):
+        Forward intrinsic content size changes to the WKWebView, not its inner WKView,
+        if we have one.
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::transitionToCommittedForNewPage):
+        Only set the autosizing fixed minimum height if we're using that behavior;
+        otherwise, setting it to the view's height will end up accidentally
+        turning on that behavior (which involves an extra layout per resize!).
+
 2015-10-15  Anders Carlsson  <ander...@apple.com>
 
         Use the ShowContextMenu message for service menus as well

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (191182 => 191183)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-10-16 17:30:27 UTC (rev 191183)
@@ -160,6 +160,7 @@
     _WKRenderingProgressEvents _observedRenderingProgressEvents;
 
     WebKit::WeakObjCPtr<id <_WKFormDelegate>> _formDelegate;
+
 #if PLATFORM(IOS)
     RetainPtr<WKScrollView> _scrollView;
     RetainPtr<WKContentView> _contentView;
@@ -216,6 +217,7 @@
 #endif
 #if PLATFORM(MAC)
     RetainPtr<WKView> _wkView;
+    CGSize _intrinsicContentSize;
 #endif
 }
 
@@ -373,6 +375,8 @@
     [self addSubview:_wkView.get()];
     _page = WebKit::toImpl([_wkView pageRef]);
 
+    _intrinsicContentSize = CGSizeMake(NSViewNoInstrinsicMetric, NSViewNoInstrinsicMetric);
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     [_wkView _setAutomaticallyAdjustsContentInsets:YES];
 #endif
@@ -1924,6 +1928,26 @@
 {
     return [_wkView performDragOperation:sender];
 }
+
+- (CGSize)intrinsicContentSize
+{
+    return _intrinsicContentSize;
+}
+
+- (void)_setIntrinsicContentSize:(CGSize)intrinsicContentSize
+{
+    // If the intrinsic content size is less than the minimum layout width, the content flowed to fit,
+    // so we can report that that dimension is flexible. If not, we need to report our intrinsic width
+    // so that autolayout will know to provide space for us.
+
+    CGSize intrinsicContentSizeAcknowledgingFlexibleWidth = intrinsicContentSize;
+    if (intrinsicContentSize.width < _page->minimumLayoutSize().width())
+        intrinsicContentSizeAcknowledgingFlexibleWidth.width = NSViewNoInstrinsicMetric;
+
+    _intrinsicContentSize = intrinsicContentSizeAcknowledgingFlexibleWidth;
+    [self invalidateIntrinsicContentSize];
+}
+
 #endif // PLATFORM(MAC)
 
 @end
@@ -3124,6 +3148,21 @@
 
 #endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
 
+- (CGFloat)_minimumLayoutWidth
+{
+    return _page->minimumLayoutSize().width();
+}
+
+- (void)_setMinimumLayoutWidth:(CGFloat)width
+{
+    BOOL expandsToFit = width > 0;
+
+    _page->setMinimumLayoutSize(WebCore::IntSize(width, 0));
+    _page->setMainFrameIsScrollable(!expandsToFit);
+
+    [_wkView setShouldClipToVisibleRect:expandsToFit];
+}
+
 #endif
 
 @end

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h (191182 => 191183)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h	2015-10-16 17:30:27 UTC (rev 191183)
@@ -112,6 +112,7 @@
 @property (nonatomic, readonly) UIEdgeInsets _computedContentInset;
 #else
 @property (nonatomic, setter=_setIgnoresNonWheelEvents:) BOOL _ignoresNonWheelEvents;
+- (void)_setIntrinsicContentSize:(CGSize)intrinsicContentSize;
 #endif
 
 - (WKPageRef)_pageForTesting;

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (191182 => 191183)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2015-10-16 17:30:27 UTC (rev 191183)
@@ -185,6 +185,9 @@
 // Clients that want to maintain default behavior can return nil. To disable the immediate action entirely, return NSNull. And to
 // do something custom, return an object that conforms to the NSImmediateActionAnimationController protocol.
 - (id)_immediateActionAnimationControllerForHitTestResult:(_WKHitTestResult *)hitTestResult withType:(_WKImmediateActionType)type userData:(id<NSSecureCoding>)userData;
+
+@property (nonatomic, setter=_setMinimumLayoutWidth:) CGFloat _minimumLayoutWidth WK_AVAILABLE(WK_MAC_TBA, NA);
+
 #endif
 
 - (WKNavigation *)_reloadWithoutContentBlockers WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (191182 => 191183)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2015-10-16 17:30:27 UTC (rev 191183)
@@ -643,7 +643,10 @@
 
 void PageClientImpl::intrinsicContentSizeDidChange(const IntSize& intrinsicContentSize)
 {
-    [m_wkView _setIntrinsicContentSize:intrinsicContentSize];
+    if (m_webView)
+        [m_webView _setIntrinsicContentSize:intrinsicContentSize];
+    else
+        [m_wkView _setIntrinsicContentSize:intrinsicContentSize];
 }
 
 bool PageClientImpl::executeSavedCommandBySelector(const String& selectorString)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (191182 => 191183)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2015-10-16 17:30:27 UTC (rev 191183)
@@ -1319,7 +1319,9 @@
         int minimumLayoutHeight = std::max(webPage->minimumLayoutSize().height(), 1);
         int maximumSize = std::numeric_limits<int>::max();
         m_frame->coreFrame()->view()->enableAutoSizeMode(true, IntSize(minimumLayoutWidth, minimumLayoutHeight), IntSize(maximumSize, maximumSize));
-        m_frame->coreFrame()->view()->setAutoSizeFixedMinimumHeight(webPage->size().height());
+
+        if (webPage->autoSizingShouldExpandToViewHeight())
+            m_frame->coreFrame()->view()->setAutoSizeFixedMinimumHeight(webPage->size().height());
     }
 
     m_frame->coreFrame()->view()->setProhibitsScrolling(shouldDisableScrolling);

Modified: trunk/Tools/ChangeLog (191182 => 191183)


--- trunk/Tools/ChangeLog	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Tools/ChangeLog	2015-10-16 17:30:27 UTC (rev 191183)
@@ -1,3 +1,21 @@
+2015-10-16  Tim Horton  <timothy_hor...@apple.com>
+
+        Hook up autolayout intrinsic sizing for WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=150219
+        <rdar://problem/20016905>
+
+        Reviewed by Simon Fraser.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm: Added.
+        (-[AutoLayoutNavigationDelegate webView:didFinishNavigation:]):
+        (-[AutoLayoutWKWebView load:expectingContentSize:]):
+        (-[AutoLayoutWKWebView expectContentSizeChange:]):
+        (-[AutoLayoutWKWebView invalidateIntrinsicContentSize]):
+        (TEST):
+        Add a variety of tests, including one which catches the bug that
+        the WebCore part of this patch fixes.
+
 2015-10-15  Csaba Osztrogonác  <o...@webkit.org>
 
         Update the help message of --system-malloc

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (191182 => 191183)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2015-10-16 17:18:57 UTC (rev 191182)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2015-10-16 17:30:27 UTC (rev 191183)
@@ -35,6 +35,7 @@
 		297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 297234B5173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp */; };
 		2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */; };
 		2D9A53AF1B31FA8D0074D5AA /* ShrinkToFit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */; };
+		2DD355361BD08378005DF4A7 /* AutoLayoutIntegration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DD355351BD08378005DF4A7 /* AutoLayoutIntegration.mm */; settings = {ASSET_TAGS = (); }; };
 		2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
 		2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; };
 		2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; };
@@ -504,6 +505,7 @@
 		2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FixedLayoutSize.mm; sourceTree = "<group>"; };
 		2D640B5417875DFF00BFAF99 /* ScrollPinningBehaviors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollPinningBehaviors.cpp; sourceTree = "<group>"; };
 		2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShrinkToFit.mm; sourceTree = "<group>"; };
+		2DD355351BD08378005DF4A7 /* AutoLayoutIntegration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutoLayoutIntegration.mm; sourceTree = "<group>"; };
 		2DD7D3A9178205D00026E1E3 /* ResizeReversePaginatedWebView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeReversePaginatedWebView.cpp; sourceTree = "<group>"; };
 		2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "lots-of-text-vertical-lr.html"; sourceTree = "<group>"; };
 		2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; };
@@ -900,6 +902,7 @@
 			isa = PBXGroup;
 			children = (
 				7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */,
+				2DD355351BD08378005DF4A7 /* AutoLayoutIntegration.mm */,
 				A13EBBAC1B87436F00097110 /* BundleParameters.mm */,
 				A13EBBAE1B87436F00097110 /* BundleParametersPlugIn.mm */,
 				A14FC5861B8991B600D107EB /* ContentFiltering.mm */,
@@ -1742,6 +1745,7 @@
 				1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */,
 				2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */,
 				41973B5D1AF22875006C7B36 /* SharedBuffer.cpp in Sources */,
+				2DD355361BD08378005DF4A7 /* AutoLayoutIntegration.mm in Sources */,
 				7AA6A1521AAC0B31002B2ED3 /* WorkQueue.cpp in Sources */,
 				2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */,
 				41973B5B1AF2286A006C7B36 /* FileSystem.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm (0 => 191183)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm	2015-10-16 17:30:27 UTC (rev 191183)
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2015 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"
+
+#import "PlatformUtilities.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED && PLATFORM(MAC)
+
+static bool didFinishNavigation;
+static bool didInvalidateIntrinsicContentSize;
+
+@interface AutoLayoutNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation AutoLayoutNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    didFinishNavigation = true;
+}
+
+@end
+
+@interface AutoLayoutWKWebView : WKWebView
+@end
+
+@implementation AutoLayoutWKWebView {
+    BOOL _expectingIntrinsicContentSizeChange;
+    NSSize _expectedIntrinsicContentSize;
+}
+
+- (void)load:(NSString *)HTMLString expectingContentSize:(NSSize)size
+{
+    EXPECT_FALSE(_expectingIntrinsicContentSizeChange);
+
+    NSString *baseHTML = @"<style>"
+    "body, html { margin: 0; padding: 0; }"
+    "div { background-color: green; }"
+    ".small { width: 10px; height: 10px; }"
+    ".large { width: 100px; height: 100px; }"
+    ".veryWide { width: 100px; height: 10px; }"
+    ".inline { display: inline-block; }"
+    "</style>";
+
+    didFinishNavigation = false;
+    [self loadHTMLString:[baseHTML stringByAppendingString:HTMLString] baseURL:nil];
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+
+    [self expectContentSizeChange:size];
+}
+
+- (void)expectContentSizeChange:(NSSize)size
+{
+    // NOTE: Each adjacent expected result must be different, or we'll early return and not call invalidateIntrinsicContentSize!
+    EXPECT_FALSE(NSEqualSizes(size, self.intrinsicContentSize));
+
+    _expectingIntrinsicContentSizeChange = YES;
+    _expectedIntrinsicContentSize = size;
+    didInvalidateIntrinsicContentSize = false;
+    TestWebKitAPI::Util::run(&didInvalidateIntrinsicContentSize);
+}
+
+- (void)invalidateIntrinsicContentSize
+{
+    if (!_expectingIntrinsicContentSizeChange)
+        return;
+
+    _expectingIntrinsicContentSizeChange = NO;
+
+    NSSize intrinsicContentSize = self.intrinsicContentSize;
+    EXPECT_EQ(_expectedIntrinsicContentSize.width, intrinsicContentSize.width);
+    EXPECT_EQ(_expectedIntrinsicContentSize.height, intrinsicContentSize.height);
+
+    didInvalidateIntrinsicContentSize = true;
+}
+
+@end
+
+TEST(WebKit2, AutoLayoutIntegration)
+{
+    RetainPtr<AutoLayoutWKWebView> webView = adoptNS([[AutoLayoutWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1000, 1000)]);
+    [webView _setMinimumLayoutWidth:50];
+
+    AutoLayoutNavigationDelegate *delegate = [[AutoLayoutNavigationDelegate alloc] init];
+    [webView setNavigationDelegate:delegate];
+
+    // 10x10 rect with the constraint (width >= 50) -> 50x10
+    [webView load:@"<div class='small'></div>" expectingContentSize:NSMakeSize(50, 10)];
+
+    // 100x100 rect with the constraint (width >= 50) -> 100x100
+    [webView load:@"<div class='large'></div>" expectingContentSize:NSMakeSize(100, 100)];
+
+    // 100x10 rect with the constraint (width >= 50) -> 100x10
+    [webView load:@"<div class='veryWide'></div>" expectingContentSize:NSMakeSize(100, 10)];
+
+    // Ten 10x10 rects, inline, should result in two rows of five; with the constraint (width >= 50) -> 50x20
+    [webView load:@"<div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div>" expectingContentSize:NSMakeSize(50, 20)];
+
+    // Changing the width to 10 should result in ten rows of one; with the constraint (width >= 10) -> 10x100
+    [webView _setMinimumLayoutWidth:10];
+    [webView expectContentSizeChange:NSMakeSize(10, 100)];
+
+    // Changing the width to 100 should result in one rows of ten; with the constraint (width >= 100) -> 100x10
+    [webView _setMinimumLayoutWidth:100];
+    [webView expectContentSizeChange:NSMakeSize(100, 10)];
+
+    // One 100x100 rect and ten 10x10 rects, inline; with the constraint (width >= 20) -> 100x110
+    [webView _setMinimumLayoutWidth:20];
+    [webView load:@"<div class='large'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div><div class='small inline'></div>" expectingContentSize:NSMakeSize(100, 110)];
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to