Allow override of viewport configuration.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Sep 2018 22:31:18 +0000 (22:31 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Sep 2018 22:31:18 +0000 (22:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188772.
<rdar://problem/43538892>.

Patch by James Savage <james.savage@apple.com> on 2018-09-26
Reviewed by Simon Fraser.

Source/WebCore:

* page/Settings.yaml:
* page/ViewportConfiguration.cpp:
(WebCore::ViewportConfiguration::nativeWebpageParameters): Provide a viewport configuration
similar to width=device-width, with initial scale set to 1.
* page/ViewportConfiguration.h:

Source/WebKit:

* Shared/WebPreferences.yaml:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _setShouldIgnoreMetaViewport:]):
(-[WKPreferences _shouldIgnoreMetaViewport]):
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::viewportPropertiesDidChange): If we are ignoring the
<meta> viewport, short circuit calling setViewportArguments() and do not
do any updates.
(WebKit::WebPage::didCommitLoad): Ditto.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::resetViewportDefaultConfiguration): Select the default
configuration based on UIProcess setting.

Tools:

* WebKitTestRunner/TestController.cpp:
(WTR::updateTestOptionsFromTestHeader): Parse new test option key from comments.
* WebKitTestRunner/TestOptions.h:
* WebKitTestRunner/ios/TestControllerIOS.mm:
(WTR::TestController::platformConfigureViewForTest): Handle new test option by
modifying the web view's preferences accordingly.

LayoutTests:

Add test proving that a document without a meta viewport specifying
width=device-width still gets a layout when this setting is enabled. I also
added a baseline case to prove that without this setting we do not layout
at device width.

* fast/viewport/ios/ipad/empty-viewport-expected.txt: Added.
* fast/viewport/ios/ipad/empty-viewport.html: Added.
* fast/viewport/ios/ipad/meta-viewport-disabled-expected.txt: Added.
* fast/viewport/ios/ipad/meta-viewport-disabled.html: Added.

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

20 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/viewport/ios/ipad/empty-meta-expected.txt [new file with mode: 0644]
LayoutTests/fast/viewport/ios/ipad/empty-meta.html [new file with mode: 0644]
LayoutTests/fast/viewport/ios/ipad/meta-viewport-ignored-expected.txt [new file with mode: 0644]
LayoutTests/fast/viewport/ios/ipad/meta-viewport-ignored.html [new file with mode: 0644]
LayoutTests/fast/viewport/ios/resources/viewport-test-utils.js
Source/WebCore/ChangeLog
Source/WebCore/page/Settings.yaml
Source/WebCore/page/ViewportConfiguration.cpp
Source/WebCore/page/ViewportConfiguration.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Tools/ChangeLog
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestOptions.h
Tools/WebKitTestRunner/ios/TestControllerIOS.mm

index 2070720..d520728 100644 (file)
@@ -1,3 +1,21 @@
+2018-09-26  James Savage  <james.savage@apple.com>
+
+        Allow override of viewport configuration.
+        https://bugs.webkit.org/show_bug.cgi?id=188772.
+        <rdar://problem/43538892>.
+
+        Reviewed by Simon Fraser.
+
+        Add test proving that a document without a meta viewport specifying
+        width=device-width still gets a layout when this setting is enabled. I also
+        added a baseline case to prove that without this setting we do not layout
+        at device width.
+
+        * fast/viewport/ios/ipad/empty-viewport-expected.txt: Added.
+        * fast/viewport/ios/ipad/empty-viewport.html: Added.
+        * fast/viewport/ios/ipad/meta-viewport-disabled-expected.txt: Added.
+        * fast/viewport/ios/ipad/meta-viewport-disabled.html: Added.
+
 2018-09-26  Alex Christensen  <achristensen@webkit.org>
 
         uidna_nameToASCII only needs a buffer capacity of 64
diff --git a/LayoutTests/fast/viewport/ios/ipad/empty-meta-expected.txt b/LayoutTests/fast/viewport/ios/ipad/empty-meta-expected.txt
new file mode 100644 (file)
index 0000000..993204c
--- /dev/null
@@ -0,0 +1,6 @@
+Viewport:
+
+scale  0.78376
+maxScale       5.00000
+minScale       0.78376
+visibleRect    {"left":"0.00000","top":"0.00000","width":"979.88843","height":"1281.00000"}
diff --git a/LayoutTests/fast/viewport/ios/ipad/empty-meta.html b/LayoutTests/fast/viewport/ios/ipad/empty-meta.html
new file mode 100644 (file)
index 0000000..1eb1627
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <script src="../resources/viewport-test-utils.js"></script>
+</head>
+<body onload="runTest()">
+
+<p>Viewport: <span id="viewport"></span></p>
+<div id="result"></div>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/viewport/ios/ipad/meta-viewport-ignored-expected.txt b/LayoutTests/fast/viewport/ios/ipad/meta-viewport-ignored-expected.txt
new file mode 100644 (file)
index 0000000..2c68fd5
--- /dev/null
@@ -0,0 +1,6 @@
+Viewport:
+
+scale  1.00000
+maxScale       5.00000
+minScale       1.00000
+visibleRect    {"left":"0.00000","top":"0.00000","width":"768.00000","height":"1004.00000"}
diff --git a/LayoutTests/fast/viewport/ios/ipad/meta-viewport-ignored.html b/LayoutTests/fast/viewport/ios/ipad/meta-viewport-ignored.html
new file mode 100644 (file)
index 0000000..ca9c697
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ shouldIgnoreMetaViewport=true ] -->
+
+<html>
+<head>
+    <script src="../resources/viewport-test-utils.js"></script>
+</head>
+<body onload="runTest()">
+
+<p>Viewport: <span id="viewport"></span></p>
+<div id="result"></div>
+
+</body>
+</html>
index 343a286..01e8900 100644 (file)
@@ -50,7 +50,11 @@ function tableFromJSON(value)
 
 function getViewport()
 {
-    var metaTag = document.head.querySelectorAll('meta')[0];
+    var metaTags = document.head.querySelectorAll('meta');
+    if (!metaTags.length)
+        return;
+
+    var metaTag = metaTags[0];
     document.getElementById('viewport').textContent = metaTag.getAttribute('content');
 }
 
index 1989b12..df4dfd8 100644 (file)
@@ -1,3 +1,17 @@
+2018-09-26  James Savage  <james.savage@apple.com>
+
+        Allow override of viewport configuration.
+        https://bugs.webkit.org/show_bug.cgi?id=188772.
+        <rdar://problem/43538892>.
+
+        Reviewed by Simon Fraser.
+
+        * page/Settings.yaml:
+        * page/ViewportConfiguration.cpp:
+        (WebCore::ViewportConfiguration::nativeWebpageParameters): Provide a viewport configuration
+        similar to width=device-width, with initial scale set to 1.
+        * page/ViewportConfiguration.h:
+
 2018-09-26  Alex Christensen  <achristensen@webkit.org>
 
         URLs with mismatched surrogate pairs in the host should fail to parse
index 531657b..ce25e89 100644 (file)
@@ -763,3 +763,6 @@ incompleteImageBorderEnabled:
 
 shouldDeferAsynchronousScriptsUntilAfterDocumentLoad:
   initial: false
+
+shouldIgnoreMetaViewport:
+  initial: false
index 1c4502a..c033571 100644 (file)
@@ -289,6 +289,20 @@ bool ViewportConfiguration::allowsUserScalingIgnoringAlwaysScalable() const
     return shouldIgnoreScalingConstraints() || m_configuration.allowsUserScaling;
 }
 
+ViewportConfiguration::Parameters ViewportConfiguration::nativeWebpageParameters()
+{
+    Parameters parameters;
+    parameters.width = ViewportArguments::ValueDeviceWidth;
+    parameters.widthIsSet = true;
+    parameters.allowsUserScaling = true;
+    parameters.allowsShrinkToFit = false;
+    parameters.minimumScale = 1;
+    parameters.maximumScale = 5;
+    parameters.initialScale = 1;
+    parameters.initialScaleIsSet = true;
+    return parameters;
+}
+
 ViewportConfiguration::Parameters ViewportConfiguration::webpageParameters()
 {
     Parameters parameters;
index 266dbd7..3fa6cdb 100644 (file)
@@ -101,6 +101,8 @@ public:
     bool allowsShrinkToFit() const;
     bool avoidsUnsafeArea() const { return m_configuration.avoidsUnsafeArea; }
 
+    // Matches a width=device-width, initial-scale=1 viewport.
+    WEBCORE_EXPORT static Parameters nativeWebpageParameters();
     WEBCORE_EXPORT static Parameters webpageParameters();
     WEBCORE_EXPORT static Parameters textDocumentParameters();
     WEBCORE_EXPORT static Parameters imageDocumentParameters();
index d537806..8367df9 100644 (file)
@@ -1,3 +1,25 @@
+2018-09-26  James Savage  <james.savage@apple.com>
+
+        Allow override of viewport configuration.
+        https://bugs.webkit.org/show_bug.cgi?id=188772.
+        <rdar://problem/43538892>.
+
+        Reviewed by Simon Fraser.
+
+        * Shared/WebPreferences.yaml:
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences _setShouldIgnoreMetaViewport:]):
+        (-[WKPreferences _shouldIgnoreMetaViewport]):
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::viewportPropertiesDidChange): If we are ignoring the
+        <meta> viewport, short circuit calling setViewportArguments() and do not
+        do any updates.
+        (WebKit::WebPage::didCommitLoad): Ditto.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::resetViewportDefaultConfiguration): Select the default
+        configuration based on UIProcess setting.
+
 2018-09-26  Chris Dumez  <cdumez@apple.com>
 
         Regression(r236512): WKWebViewCandidateTests.SoftSpaceReplacementAfterCandidateInsertionWithoutReplacement API test is failing
index 564db44..5bdc2e1 100644 (file)
@@ -954,6 +954,10 @@ PassiveTouchListenersAsDefaultOnDocument:
   defaultValue: defaultPassiveTouchListenersAsDefaultOnDocument()
   webcoreName: passiveTouchListenersAsDefaultOnDocument
 
+ShouldIgnoreMetaViewport:
+  type: bool
+  defaultValue: false
+
 # Debug Preferences
 
 AcceleratedDrawingEnabled:
index c258ce2..2d2fcfa 100644 (file)
@@ -809,6 +809,16 @@ static WebCore::EditableLinkBehavior toEditableLinkBehavior(_WKEditableLinkBehav
     return _preferences->lowPowerVideoAudioBufferSizeEnabled();
 }
 
+- (void)_setShouldIgnoreMetaViewport:(BOOL)ignoreMetaViewport
+{
+    return _preferences->setShouldIgnoreMetaViewport(ignoreMetaViewport);
+}
+
+- (BOOL)_shouldIgnoreMetaViewport
+{
+    return _preferences->shouldIgnoreMetaViewport();
+}
+
 #if PLATFORM(MAC)
 - (void)_setJavaEnabledForLocalFiles:(BOOL)enabled
 {
index e2f0d09..03e7529 100644 (file)
@@ -147,6 +147,7 @@ typedef NS_ENUM(NSInteger, _WKEditableLinkBehavior) {
 @property (nonatomic, setter=_setColorFilterEnabled:) BOOL _colorFilterEnabled WK_API_AVAILABLE(macosx(10.14), ios(12.0));
 @property (nonatomic, setter=_setPunchOutWhiteBackgroundsInDarkMode:) BOOL _punchOutWhiteBackgroundsInDarkMode WK_API_AVAILABLE(macosx(10.14), ios(12.0));
 @property (nonatomic, setter=_setLowPowerVideoAudioBufferSizeEnabled:) BOOL _lowPowerVideoAudioBufferSizeEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setShouldIgnoreMetaViewport:) BOOL _shouldIgnoreMetaViewport WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 #if !TARGET_OS_IPHONE
 @property (nonatomic, setter=_setWebGLEnabled:) BOOL _webGLEnabled WK_API_AVAILABLE(macosx(10.13.4));
index 67c0555..41b312e 100644 (file)
@@ -1805,7 +1805,7 @@ void WebPage::disabledAdaptationsDidChange(const OptionSet<DisabledAdaptations>&
 void WebPage::viewportPropertiesDidChange(const ViewportArguments& viewportArguments)
 {
 #if PLATFORM(IOS)
-    if (m_viewportConfiguration.setViewportArguments(viewportArguments))
+    if (!m_page->settings().shouldIgnoreMetaViewport() && m_viewportConfiguration.setViewportArguments(viewportArguments))
         viewportConfigurationChanged();
 #endif
 
@@ -5320,7 +5320,7 @@ void WebPage::didCommitLoad(WebFrame* frame)
     if (m_viewportConfiguration.setContentsSize(coreFrame->view()->contentsSize()))
         viewportChanged = true;
 
-    if (m_viewportConfiguration.setViewportArguments(coreFrame->document()->viewportArguments()))
+    if (!m_page->settings().shouldIgnoreMetaViewport() && m_viewportConfiguration.setViewportArguments(coreFrame->document()->viewportArguments()))
         viewportChanged = true;
 
     if (viewportChanged)
index d0d3b20..b5761b0 100644 (file)
@@ -2749,8 +2749,15 @@ void WebPage::resetViewportDefaultConfiguration(WebFrame* frame, bool hasMobileD
         return;
     }
 
+    auto parametersForStandardFrame = [&] {
+        if (m_page->settings().shouldIgnoreMetaViewport())
+            return ViewportConfiguration::nativeWebpageParameters();
+
+        return ViewportConfiguration::webpageParameters();
+    };
+
     if (!frame) {
-        m_viewportConfiguration.setDefaultConfiguration(ViewportConfiguration::webpageParameters());
+        m_viewportConfiguration.setDefaultConfiguration(parametersForStandardFrame());
         return;
     }
 
@@ -2765,7 +2772,7 @@ void WebPage::resetViewportDefaultConfiguration(WebFrame* frame, bool hasMobileD
     else if (document->isTextDocument())
         m_viewportConfiguration.setDefaultConfiguration(ViewportConfiguration::textDocumentParameters());
     else
-        m_viewportConfiguration.setDefaultConfiguration(ViewportConfiguration::webpageParameters());
+        m_viewportConfiguration.setDefaultConfiguration(parametersForStandardFrame());
 }
 
 void WebPage::viewportConfigurationChanged()
index d049e19..841bd3f 100644 (file)
@@ -1,3 +1,18 @@
+2018-09-26  James Savage  <james.savage@apple.com>
+
+        Allow override of viewport configuration.
+        https://bugs.webkit.org/show_bug.cgi?id=188772.
+        <rdar://problem/43538892>.
+
+        Reviewed by Simon Fraser.
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::updateTestOptionsFromTestHeader): Parse new test option key from comments.
+        * WebKitTestRunner/TestOptions.h:
+        * WebKitTestRunner/ios/TestControllerIOS.mm:
+        (WTR::TestController::platformConfigureViewForTest): Handle new test option by
+        modifying the web view's preferences accordingly.
+
 2018-09-26  Alex Christensen  <achristensen@webkit.org>
 
         URLs with mismatched surrogate pairs in the host should fail to parse
index ae74da4..eeb959a 100644 (file)
@@ -1247,6 +1247,8 @@ static void updateTestOptionsFromTestHeader(TestOptions& testOptions, const std:
             testOptions.jscOptions = value;
         else if (key == "runSingly")
             testOptions.runSingly = parseBooleanTestHeaderValue(value);
+        else if (key == "shouldIgnoreMetaViewport")
+            testOptions.shouldIgnoreMetaViewport = parseBooleanTestHeaderValue(value);
         pairStart = pairEnd + 1;
     }
 }
index 91fe4e6..5d7ee8b 100644 (file)
@@ -62,6 +62,7 @@ struct TestOptions {
     bool punchOutWhiteBackgroundsInDarkMode { false };
     bool runSingly { false };
     bool checkForWorldLeaks { false };
+    bool shouldIgnoreMetaViewport { false };
 
     float deviceScaleFactor { 1 };
     Vector<String> overrideLanguages;
index f28a942..b9dcfd8 100644 (file)
@@ -35,6 +35,7 @@
 #import "UIKitTestSPI.h"
 #import <Foundation/Foundation.h>
 #import <UIKit/UIKit.h>
+#import <WebKit/WKPreferencesPrivate.h>
 #import <WebKit/WKPreferencesRefPrivate.h>
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKStringCF.h>
@@ -132,8 +133,11 @@ void TestController::platformConfigureViewForTest(const TestInvocation& test)
         return;
         
     TestRunnerWKWebView *webView = mainWebView()->platformView();
+
+    if (test.options().shouldIgnoreMetaViewport)
+        webView.configuration.preferences._shouldIgnoreMetaViewport = YES;
+
     CGRect screenBounds = [UIScreen mainScreen].bounds;
-    
     CGSize oldSize = webView.bounds.size;
     mainWebView()->resizeTo(screenBounds.size.width, screenBounds.size.height, PlatformWebView::WebViewSizingMode::HeightRespectsStatusBar);
     CGSize newSize = webView.bounds.size;