[iOS] Allow SPI clients to lay out at arbitrarily scaled sizes and scale to fit the...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Oct 2018 23:13:37 +0000 (23:13 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Oct 2018 23:13:37 +0000 (23:13 +0000)
commit14d0163158a076a50f46429d5555b31d84283703
tree7663800251671d0a658534083c384646b0a0bc83
parent6ebf134eb5241267862d30c44c921252de1df732
[iOS] Allow SPI clients to lay out at arbitrarily scaled sizes and scale to fit the view
https://bugs.webkit.org/show_bug.cgi?id=190504
<rdar://problem/45117760>

Reviewed by Tim Horton.

Source/WebCore:

Add support in ViewportConfiguration for applying a layout size scale factor to the viewport. See below for
more details.

Tests: fast/viewport/ios/constant-width-viewport-after-changing-view-scale.html
       fast/viewport/ios/device-width-viewport-after-changing-view-scale.html

* page/ViewportConfiguration.cpp:
(WebCore::ViewportConfiguration::setViewLayoutSize):

The viewport's layout size may now be changed alongside the layout size scale factor. If either of these two
variables change, we recompute our minimum layout size and viewport configuration parameters.

(WebCore::ViewportConfiguration::shouldIgnoreHorizontalScalingConstraints const):
(WebCore::ViewportConfiguration::nativeWebpageParameters):
(WebCore::ViewportConfiguration::testingParameters):
(WebCore::ViewportConfiguration::updateConfiguration):

Multiply the minimum scale, initial scale, and maximum scale by the layout size scale factor. This allows us to
keep the document well-proportioned within the viewport, while still laying out at a different layout size.

(WebCore::ViewportConfiguration::updateMinimumLayoutSize):

Compute the minimum layout size by scaling the default layout size derived from our view's size.

(WebCore::ViewportConfiguration::layoutWidth const):
(WebCore::ViewportConfiguration::layoutHeight const):
* page/ViewportConfiguration.h:

Maintain the original initial scale, unaffected by the layout size scale factor. This is used when computing
layout width and height to prevent scaling by the layout size scale factor twice when computing layout sizes.

(WebCore::ViewportConfiguration::description const):

Include the layout size scale factor in ViewportConfiguration's description string.

(WebCore::ViewportConfiguration::Parameters::operator== const):
(WebCore::operator<<):

Source/WebKit:

Add support for _setViewScale: and _viewScale on iOS. While similar in concept to macOS, changing this property
on iOS uses viewport configurations to change the minimum layout size of the document and apply view scaling.
Setting the view scale on iOS to a value `s` multiplies the minimium layout size by a factor `1 / s`, but also
multiplies the initial, minimum and maximum scales by a factor of `s`. The net effect of applying this scale
causes the page to lay out at a larger width and shrink (or a smaller width and expand) to fit the viewport.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:

Send `viewportConfigurationLayoutSizeScaleFactor` alongside `viewportConfigurationViewLayoutSize`.

(-[WKWebView _dispatchSetViewLayoutSize:]):
(-[WKWebView _viewScale]):
(-[WKWebView _setViewScale:]):

Provide a different implementation of `_setViewScale:` on iOS, by scaling the effective minimum layout size.
(See above for more detail).

* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Add missing API availability annotations for the _viewScale property.

* UIProcess/API/mac/WKView.mm:
(-[WKView _setViewScale:]):
* UIProcess/Cocoa/WebViewImpl.mm:

Both -[WKView _setViewScale:] and -[WKWebView _setViewScale:] throw Objective C exceptions upon receiving a bad
argument (e.g. scale <= 0). However, logic for throwing this exception is specific to iOS in WKWebView, and
handled in WebViewImpl on macOS. To make this less confusing, move the exception throwing code out of
!PLATFORM(MAC) in WKWebView, and move the path for raising this exception in WKView on macOS from WebViewImpl to
WKView.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::layoutSizeScaleFactor const):

Tie the notion of "view scale" on iOS to `layoutSizeScaleFactor`. As its name suggests, this is a scale factor
by which we transform the layout size.

* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::setViewportConfigurationViewLayoutSize):
* WebProcess/WebPage/WebPage.cpp:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Plumb the layout size scale factor over to the web process, along with the layout size.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::setViewportConfigurationViewLayoutSize):

Tools:

Teach UIScriptController to set WKWebView's view scale via a new `setViewScale` method, supported in WebKit2 on
macOS and iOS.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::setViewScale):
* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::setViewScale):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::setViewScale):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/UIScriptControllerCocoa.mm: Added.

Add a new file for UIScriptController methods on Cocoa platforms.

(WTR::UIScriptController::setViewScale):
* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::cocoaResetStateToConsistentValues):

Ensure that _viewScale is reset to 1 after running a layout test.

LayoutTests:

Add two new layout tests on iOS that change WKWebView's view scale, and measure the resulting window sizes and
lengths of viewport units.

* fast/viewport/ios/constant-width-viewport-after-changing-view-scale-expected.txt: Added.
* fast/viewport/ios/constant-width-viewport-after-changing-view-scale.html: Added.

Add a test page with a viewport meta tag that has a constant width and an explicit initial scale of 0.5.

* fast/viewport/ios/device-width-viewport-after-changing-view-scale-expected.txt: Added.
* fast/viewport/ios/device-width-viewport-after-changing-view-scale.html: Added.

Add a test page with a viewport meta tag at device-width, with initial scale 1.

* resources/ui-helper.js:
(window.UIHelper.setViewScale):

Add a convenience function that wraps a UI script invocation of `setViewScale` in a promise.

(window.UIHelper):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
32 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/viewport/ios/constant-width-viewport-after-changing-view-scale-expected.txt [new file with mode: 0644]
LayoutTests/fast/viewport/ios/constant-width-viewport-after-changing-view-scale.html [new file with mode: 0644]
LayoutTests/fast/viewport/ios/device-width-viewport-after-changing-view-scale-expected.txt [new file with mode: 0644]
LayoutTests/fast/viewport/ios/device-width-viewport-after-changing-view-scale.html [new file with mode: 0644]
LayoutTests/resources/ui-helper.js
Source/WebCore/ChangeLog
Source/WebCore/page/ViewportConfiguration.cpp
Source/WebCore/page/ViewportConfiguration.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/API/mac/WKView.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/DumpRenderTree/mac/UIScriptControllerMac.mm
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/UIScriptControllerCocoa.mm [new file with mode: 0644]
Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm