[iOS] Implement idempotent mode for text autosizing
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Apr 2019 06:33:56 +0000 (06:33 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Apr 2019 06:33:56 +0000 (06:33 +0000)
commitb8e8b6840b7bc2f1b524241e2e27d808e9bc7fd6
tree5f6f79d4c2f064d25689d01df5fb725e2c7e80a3
parent4612f31842451e34415833c2ccc9b8a4c80aad75
[iOS] Implement idempotent mode for text autosizing
https://bugs.webkit.org/show_bug.cgi?id=197250
<rdar://problem/50211034>

Reviewed by Jon Lee.

Source/WebCore:

Our text autosizing code has this interesting behavior where it is sensitive to the width of the text's container
and the number of lines of text inside the element. Not only is it sensitive to those things, but as those things
change, their values are stored inside the RenderObject itself and then never recomputed. This means that the text
autosizing parameters are sensitive to the entire history of an element. So, a newly created element with the same
style as an existing element can have dramatically different results.

This patch adds a new mode for text autosizing, which isn't sensitive to either of those things, and therefore
maintains the invariant that a newly created element will behave the same as an existing element with the same style.
Instead of using container size, it instead uses the viewport's initial scale. As the viewport's initial scale
changes, new layouts will be triggered, which will cause the autosizing code to use the new value.

Tests: fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-identity.html
       fast/text-autosizing/ios/idempotentmode/idempotent-autosizing.html

* page/FrameViewLayoutContext.cpp:
(WebCore::FrameViewLayoutContext::applyTextSizingIfNeeded):
* page/Page.cpp:
(WebCore::Page::setInitialScale): WebKit will push the initial scale down into the page.
* page/Page.h:
(WebCore::Page::initialScale const):
* page/SettingsBase.h:
* page/cocoa/SettingsBaseCocoa.mm:
(WebCore::SettingsBase::textAutosizingUsesIdempotentMode):
(WebCore::SettingsBase::defaultTextAutosizingEnabled):
* rendering/RenderBlockFlow.cpp:
(WebCore::idempotentTextSize): Describe a piecewise-linear curve for the text size to follow. The curve scales
depending on the viewport's initial scale.
(WebCore::RenderBlockFlow::adjustComputedFontSizes):
* rendering/RenderBlockFlow.h:
* rendering/RenderElement.cpp:
(WebCore::includeNonFixedHeight): This new mode should consider max-height as well as height when determining if
content overflows.
(WebCore::RenderElement::adjustComputedFontSizesOnBlocks):
(WebCore::RenderElement::resetTextAutosizing):
* rendering/RenderElement.h:
* rendering/RenderObject.h:

Source/WebKit:

Push the initial scale down into the page.

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

LayoutTests:

Add two simple tests that make sure that fonts get autosized > 1x when the layout viewport is wide,
and that fonts don't get autosized when the layout viewport isn't wide.

We don't want to add tons of tests to test exact values because the curve will likely be tweaked
in the future.

* fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-expected.txt: Added.
* fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-identity-expected.txt: Added.
* fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-identity.html: Added.
* fast/text-autosizing/ios/idempotentmode/idempotent-autosizing.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244682 268f45cc-cd09-0410-ab3c-d52691b4dbfc
23 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-expected.txt [new file with mode: 0644]
LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-identity-expected.txt [new file with mode: 0644]
LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-identity.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing.html [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/FrameViewLayoutContext.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/Settings.yaml
Source/WebCore/page/SettingsBase.cpp
Source/WebCore/page/SettingsBase.h
Source/WebCore/page/cocoa/SettingsBaseCocoa.mm
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderBlockFlow.h
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm