[iOS] Changing view scale sometimes does not zoom the page to the new initial scale...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Nov 2018 18:10:23 +0000 (18:10 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Nov 2018 18:10:23 +0000 (18:10 +0000)
commit7deecd1d78eeead8df81d9beb0b6f1ca4ae2cc5b
treebe030cb7f76801a1459d310aebdd30d9adc88800
parent11866654dd467fb3d9f2d6bd552cb3fbec1e3aad
[iOS] Changing view scale sometimes does not zoom the page to the new initial scale, when the page is at initial scale
https://bugs.webkit.org/show_bug.cgi?id=191180
<rdar://problem/45744786>

Reviewed by Simon Fraser.

Source/WebCore:

When computing the minimum scale in ViewportConfiguration::minimumScale, if our content width or height is
shorter than the view width or height, then we recompute the minimum scale such that the content dimensions will
fill the bounds of the view by setting the minimum scale to the view width or height divided by the content
width or height.

Suppose the minimum scale is equal to some value `s`; additionally, let `w_c` denote the content width and `w_v`
denote the view width (as integers). If `w_v / s` is not an integral value, the computed content width `w_c` may
be rounded, such that `w_v / w_c` is not precisely equal to `s`. In the case that `w_v / w_c` is ever so
slightly larger than `s`, we will end up overriding the minimum scale `s` with `w_v / w_c`.

As a result, specifying a viewport with a decimal `minimum-scale` will sometimes cause the computed minimum
scale of the viewport (and platform view) to be very slightly different from the minimum scale. The new layout
test below exercises this scenario, specifying a viewport with minimum and initial scales of 0.94 that results
in `ViewportConfiguration::minimumScale` returning 0.94158.

With the `WebPage::setViewportConfigurationViewLayoutSize` check added in r237127, this means setting
`_viewScale:` when the page is at initial scale sometimes doesn't zoom the page to the new initial scale when it
should, since the page scale factor and the initial scale are different enough such that
`areEssentiallyEqualAsFloat` returns false.

This patch addresses these issues by snapping to the minimum scale if the computed scale that fits content
dimensions to view dimensions results in a minimum scale that is close enough to the configuration's minimum
scale, such that the difference can be attributed to rounding error when computing content or view dimensions.

Test: fast/viewport/ios/viewport-minimum-and-initial-scale.html

* page/ViewportConfiguration.cpp:
(WebCore::ViewportConfiguration::minimumScale const):

LayoutTests:

Add a layout test, and make some adjustments to UIHelper.

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

Add a new layout test that contains a viewport meta tag with minimum and initial scales set to 0.94, and checks
that the resulting minimum and initial scales are 0.94 instead of 0.94158.

* fast/viewport/watchos/viewport-disable-extra-zoom-adaptations.html:
* resources/ui-helper.js:

Make UIHelper.zoomScale return a number rather than a string, and adjust a few call sites.

(window.UIHelper.zoomScale):
(window.UIHelper.minimumZoomScale):
(window.UIHelper):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237743 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/viewport/ios/constant-width-viewport-after-changing-view-scale.html
LayoutTests/fast/viewport/ios/device-width-viewport-after-changing-view-scale.html
LayoutTests/fast/viewport/ios/viewport-minimum-and-initial-scale-expected.txt [new file with mode: 0644]
LayoutTests/fast/viewport/ios/viewport-minimum-and-initial-scale.html [new file with mode: 0644]
LayoutTests/fast/viewport/watchos/viewport-disable-extra-zoom-adaptations.html
LayoutTests/resources/ui-helper.js
Source/WebCore/ChangeLog
Source/WebCore/page/ViewportConfiguration.cpp