[Extra zoom mode] 100vw is roughly half of the viewport width in extra zoom mode
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Apr 2018 19:40:26 +0000 (19:40 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Apr 2018 19:40:26 +0000 (19:40 +0000)
commit68ad136c740a862afcecfd5c9df92c68b7a24c49
treee0599714908ced94a5556a111bc9282801294ccd
parent532cfe398de4ffe1dd459e966c70e90b9a0fda5e
[Extra zoom mode] 100vw is roughly half of the viewport width in extra zoom mode
https://bugs.webkit.org/show_bug.cgi?id=184871
<rdar://problem/39477595>

Reviewed by Andy Estes.

Source/WebCore:

Currently, when computing CSS viewport units, we use ViewportConfiguration::initialScaleIgnoringContentSize().
This method computes an initial scale from the layout width and height without relying on any information
derived from the current content size. This is done to ensure that the content size and viewport dimensions for
CSS viewport units should not be simultaneously dependent on each other.

Since shrink-to-fit heuristics depend on content size, we currently assume that shrink-to-fit is disabled when
computing initialScaleIgnoringContentSize, by always passing in `false` for `shouldIgnoreScalingConstraints`.
However, in extra zoom mode, the opposite is true: since we force both `m_canIgnoreScalingConstraints` and
`m_forceHorizontalShrinkToFit` to be `true` in this mode, we will always try to shrink-to-fit regardless of
content size.

Because of this shrink-to-fit disparity between `initialScale` and `initialScaleIgnoringContentSize`, viewport
units in extra zoom mode are currently computed assuming an initial scale set by the page, whereas the real
viewport is scaled to fit, which causes any lengths computed in terms of vw and vh to be incorrect. To fix this,
we introduce a version of shouldIgnoreScalingConstraints() that returns `true` iff scaling constraints are
always ignored, regardless of content size. We then use this in initialScaleIgnoringContentSize, instead of
always passing in `false` for `shouldIgnoreScalingConstraints`.

Test: fast/css/extrazoom/viewport-units-shrink-to-fit.html

* page/ViewportConfiguration.cpp:
(WebCore::ViewportConfiguration::shouldIgnoreScalingConstraintsRegardlessOfContentSize const):
(WebCore::ViewportConfiguration::initialScaleIgnoringContentSize const):
* page/ViewportConfiguration.h:

LayoutTests:

Add a new layout test to verify that shrink-to-fit works as intended in extra zoom mode:
1.  The large element should cause the entire viewport to shrink down to fit.
2.  Removing the large element should adjust the viewport, such that the smaller element now fits the entire
    viewport.
3.  The smaller element (at 100vw and 100vh) should be the same size as the window.

* TestExpectations:
* fast/css/extrazoom/viewport-units-shrink-to-fit-expected.txt: Added.
* fast/css/extrazoom/viewport-units-shrink-to-fit.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230916 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/css/extrazoom/viewport-units-shrink-to-fit-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/extrazoom/viewport-units-shrink-to-fit.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/ViewportConfiguration.cpp
Source/WebCore/page/ViewportConfiguration.h