Expose and test fixedLayoutSize via modern WebKit SPI
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Apr 2015 22:37:11 +0000 (22:37 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Apr 2015 22:37:11 +0000 (22:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143500

Reviewed by Simon Fraser.

* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _isFixedLayoutEnabled]):
(-[WKWebView _setFixedLayoutEnabled:]):
(-[WKWebView _fixedLayoutSize]):
(-[WKWebView _setFixedLayoutSize:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _isFixedLayoutEnabled]):
(-[WKView _setFixedLayoutEnabled:]):
(-[WKView _fixedLayoutSize]):
(-[WKView _setFixedLayoutSize:]):
Add API for adjusting the fixed layout size, and whether or not we use it.

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::transitionToCommittedForNewPage):
Repair a mistake I made in r139822, where I brought odd TILED_BACKING_STORE-only
logic (which disables scrollbars if fixedLayoutSize is enabled) to the rest of the ports.
Put it back as TILED_BACKING_STORE-only.

Persist the fixedLayoutSize through view creation; we already persist the enabled state,
but not the size, which doesn't make any sense.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::fixedLayoutSize):
* WebProcess/WebPage/WebPage.h:
Add a fixedLayoutSize() getter.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm: Added.
(-[FixedLayoutSizeNavigationDelegate webView:didFinishNavigation:]):
(TEST):
Add a test that verifies that fixedLayoutSize works at all, that
it persists through a navigation, and that turning it back off reverts to
laying out at the size of the view.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182499 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm [new file with mode: 0644]

index 9f7fcd1..037430c 100644 (file)
@@ -1,3 +1,38 @@
+2015-04-07  Tim Horton  <timothy_horton@apple.com>
+
+        Expose and test fixedLayoutSize via modern WebKit SPI
+        https://bugs.webkit.org/show_bug.cgi?id=143500
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/API/Cocoa/WKViewPrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _isFixedLayoutEnabled]):
+        (-[WKWebView _setFixedLayoutEnabled:]):
+        (-[WKWebView _fixedLayoutSize]):
+        (-[WKWebView _setFixedLayoutSize:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _isFixedLayoutEnabled]):
+        (-[WKView _setFixedLayoutEnabled:]):
+        (-[WKView _fixedLayoutSize]):
+        (-[WKView _setFixedLayoutSize:]):
+        Add API for adjusting the fixed layout size, and whether or not we use it.
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::transitionToCommittedForNewPage):
+        Repair a mistake I made in r139822, where I brought odd TILED_BACKING_STORE-only
+        logic (which disables scrollbars if fixedLayoutSize is enabled) to the rest of the ports.
+        Put it back as TILED_BACKING_STORE-only.
+
+        Persist the fixedLayoutSize through view creation; we already persist the enabled state,
+        but not the size, which doesn't make any sense.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::fixedLayoutSize):
+        * WebProcess/WebPage/WebPage.h:
+        Add a fixedLayoutSize() getter.
+
 2015-04-07  Brady Eidson  <beidson@apple.com>
 
         ContextMenuItem refactoring
index 409df4c..ba5434e 100644 (file)
@@ -90,6 +90,9 @@
 @property (nonatomic, setter=_setTopContentInset:) CGFloat _topContentInset;
 @property (nonatomic, setter=_setTotalHeightOfBanners:) CGFloat _totalHeightOfBanners;
 
+@property (nonatomic, getter=_isFixedLayoutEnabled, setter=_setFixedLayoutEnabled:) BOOL _fixedLayoutEnabled;
+@property (nonatomic, setter=_setFixedLayoutSize:) CGSize _fixedLayoutSize;
+
 @property (nonatomic, setter=_setOverrideDeviceScaleFactor:) CGFloat _overrideDeviceScaleFactor WK_AVAILABLE(WK_MAC_TBA, NA);
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
index a5de78a..fe890b8 100644 (file)
@@ -2232,6 +2232,26 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
     return _page->isShowingNavigationGestureSnapshot();
 }
 
+- (BOOL)_isFixedLayoutEnabled
+{
+    return _page->useFixedLayout();
+}
+
+- (void)_setFixedLayoutEnabled:(BOOL)fixedLayoutEnabled
+{
+    _page->setUseFixedLayout(fixedLayoutEnabled);
+}
+
+- (CGSize)_fixedLayoutSize
+{
+    return _page->fixedLayoutSize();
+}
+
+- (void)_setFixedLayoutSize:(CGSize)fixedLayoutSize
+{
+    _page->setFixedLayoutSize(WebCore::expandedIntSize(WebCore::FloatSize(fixedLayoutSize)));
+}
+
 #pragma mark scrollperf methods
 
 - (void)_setScrollPerformanceDataCollectionEnabled:(BOOL)enabled
index 300d1ee..f27c8a3 100644 (file)
@@ -91,6 +91,9 @@ typedef NS_ENUM(NSInteger, _WKPaginationMode) {
 
 - (void)_close;
 
+@property (nonatomic, getter=_isFixedLayoutEnabled, setter=_setFixedLayoutEnabled:) BOOL _fixedLayoutEnabled;
+@property (nonatomic, setter=_setFixedLayoutSize:) CGSize _fixedLayoutSize;
+
 #if TARGET_OS_IPHONE
 // DERECATED: The setters of the three following function are deprecated, please use overrideLayoutParameters.
 // Define the smallest size a page take with a regular viewport.
index 1236274..c673bf3 100644 (file)
@@ -4322,6 +4322,26 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
     return _data->_overrideDeviceScaleFactor;
 }
 
+- (BOOL)_isFixedLayoutEnabled
+{
+    return _data->_page->useFixedLayout();
+}
+
+- (void)_setFixedLayoutEnabled:(BOOL)fixedLayoutEnabled
+{
+    _data->_page->setUseFixedLayout(fixedLayoutEnabled);
+}
+
+- (CGSize)_fixedLayoutSize
+{
+    return _data->_page->fixedLayoutSize();
+}
+
+- (void)_setFixedLayoutSize:(NSSize)fixedLayoutSize
+{
+    _data->_page->setFixedLayoutSize(expandedIntSize(FloatSize(fixedLayoutSize)));
+}
+
 - (void)_dispatchSetTopContentInset
 {
     if (!_data->_didScheduleSetTopContentInset)
index 127aafd..95577ec 100644 (file)
@@ -1257,12 +1257,14 @@ void WebFrameLoaderClient::transitionToCommittedForNewPage()
     bool isTransparent = !webPage->drawsBackground();
     bool shouldUseFixedLayout = isMainFrame && webPage->useFixedLayout();
     bool shouldDisableScrolling = isMainFrame && !webPage->mainFrameIsScrollable();
-    bool shouldHideScrollbars = shouldUseFixedLayout || shouldDisableScrolling;
+    bool shouldHideScrollbars = shouldDisableScrolling;
     IntRect fixedVisibleContentRect;
 
 #if USE(TILED_BACKING_STORE)
     if (m_frame->coreFrame()->view())
         fixedVisibleContentRect = m_frame->coreFrame()->view()->fixedVisibleContentRect();
+    if (shouldUseFixedLayout)
+        shouldHideScrollbars = true;
 #endif
 
     const ResourceResponse& response = m_frame->coreFrame()->loader().documentLoader()->response();
@@ -1272,7 +1274,7 @@ void WebFrameLoaderClient::transitionToCommittedForNewPage()
     ScrollbarMode defaultScrollbarMode = shouldHideScrollbars ? ScrollbarAlwaysOff : ScrollbarAuto;
 
     m_frame->coreFrame()->createView(webPage->size(), backgroundColor, isTransparent,
-        IntSize(), fixedVisibleContentRect, shouldUseFixedLayout,
+        webPage->fixedLayoutSize(), fixedVisibleContentRect, shouldUseFixedLayout,
         defaultScrollbarMode, /* lock */ shouldHideScrollbars, defaultScrollbarMode, /* lock */ shouldHideScrollbars);
 
     if (int minimumLayoutWidth = webPage->minimumLayoutSize().width()) {
index bbcc65f..72e429b 100644 (file)
@@ -1494,6 +1494,14 @@ void WebPage::setFixedLayoutSize(const IntSize& size)
     view->setFixedLayoutSize(size);
 }
 
+IntSize WebPage::fixedLayoutSize() const
+{
+    FrameView* view = mainFrameView();
+    if (!view)
+        return IntSize();
+    return view->fixedLayoutSize();
+}
+
 void WebPage::listenForLayoutMilestones(uint32_t milestones)
 {
     if (!m_page)
index d8cdf5d..c3a6385 100644 (file)
@@ -359,6 +359,7 @@ public:
     void setUseFixedLayout(bool);
     bool useFixedLayout() const { return m_useFixedLayout; }
     void setFixedLayoutSize(const WebCore::IntSize&);
+    WebCore::IntSize fixedLayoutSize() const;
 
     void listenForLayoutMilestones(uint32_t /* LayoutMilestones */);
 
index dddb00e..678106f 100644 (file)
@@ -1,3 +1,18 @@
+2015-04-07  Tim Horton  <timothy_horton@apple.com>
+
+        Expose and test fixedLayoutSize via modern WebKit SPI
+        https://bugs.webkit.org/show_bug.cgi?id=143500
+
+        Reviewed by Simon Fraser.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm: Added.
+        (-[FixedLayoutSizeNavigationDelegate webView:didFinishNavigation:]):
+        (TEST):
+        Add a test that verifies that fixedLayoutSize works at all, that
+        it persists through a navigation, and that turning it back off reverts to
+        laying out at the size of the view.
+
 2015-04-07  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed. Add myself as a committer.
index e40ae89..0d67b2c 100644 (file)
@@ -27,6 +27,7 @@
                290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290A9BB81735F42300D71BBC /* OpenNewWindow.html */; };
                290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */; };
                297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 297234B5173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp */; };
+               2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */; };
                2D950FBE1A2217D300012434 /* ActionMenusBundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D950FBB1A2217D000012434 /* ActionMenusBundle.mm */; };
                2D950FC01A230C3A00012434 /* action-menu-targets.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2D950FBF1A230C1E00012434 /* action-menu-targets.html */; };
                2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
                29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CustomProtocolsTest.mm; path = WebKit2ObjC/CustomProtocolsTest.mm; sourceTree = "<group>"; };
                29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestBrowsingContextLoadDelegate.mm; sourceTree = "<group>"; };
                29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBrowsingContextLoadDelegate.h; sourceTree = "<group>"; };
+               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>"; };
                2D950FBA1A2217D000012434 /* ActionMenus.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ActionMenus.mm; path = WebKit2ObjC/ActionMenus.mm; sourceTree = "<group>"; };
                2D950FBB1A2217D000012434 /* ActionMenusBundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ActionMenusBundle.mm; path = WebKit2ObjC/ActionMenusBundle.mm; sourceTree = "<group>"; };
                        children = (
                                7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */,
                                A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
+                               2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */,
                                1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
                                CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */,
                                C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
                        buildActionMask = 2147483647;
                        files = (
                                7AA021BB1AB09EA70052953F /* DateMath.cpp in Sources */,
+                               2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */,
                                1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */,
                                2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */,
                                7AA6A1521AAC0B31002B2ED3 /* WorkQueue.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm b/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm
new file mode 100644 (file)
index 0000000..849cb88
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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/WKPreferences.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+static bool fixedLayoutSizeDone;
+static bool fixedLayoutSizeAfterNavigationDone;
+static bool fixedLayoutSizeDisabledDone;
+
+@interface FixedLayoutSizeNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation FixedLayoutSizeNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    // After navigating, fixed layout size should be persisted.
+    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(200, [result integerValue]);
+        fixedLayoutSizeAfterNavigationDone = true;
+    }];
+}
+
+@end
+
+TEST(WebKit2, FixedLayoutSize)
+{
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+
+    FixedLayoutSizeNavigationDelegate *delegate = [[FixedLayoutSizeNavigationDelegate alloc] init];
+    [webView setNavigationDelegate:delegate];
+
+    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(100, [result integerValue]);
+
+        [webView _setFixedLayoutEnabled:YES];
+        [webView _setFixedLayoutSize:NSMakeSize(200, 200)];
+
+        [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
+            EXPECT_EQ(200, [result integerValue]);
+
+            fixedLayoutSizeDone = true;
+        }];
+    }];
+
+    TestWebKitAPI::Util::run(&fixedLayoutSizeDone);
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&fixedLayoutSizeAfterNavigationDone);
+
+    [webView _setFixedLayoutEnabled:NO];
+    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(100, [result integerValue]);
+        fixedLayoutSizeDisabledDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&fixedLayoutSizeDisabledDone);
+}
+
+#endif