<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[245838] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/245838">245838</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2019-05-28 19:27:20 -0700 (Tue, 28 May 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move idempotent text autosizing to StyleTreeResolver
https://bugs.webkit.org/show_bug.cgi?id=197808
<rdar://problem/50283983>

Reviewed by Antti Koivisto.

Source/WebCore:

This patch migrates the idempotent text autosizing code to live inside style resolution. This is almost
the same as the algorithm that uses the result of layout to calculate autosizing, but this version only
operates on style (and thus doesn't require double layouts). Because it is being run in an environment
with less information, autosizing is occurring in more places, so the curves have been adjusted to make
autosizing not boost as much as the previous implementation did. The new algorithm is modelled after
text-decorations-in-effect. I've claimed 4 of the unused bits in RenderStyle to contain the state of the
autosizing algorithm. StyleResolver::adjustRenderStyle() is where the algorithm is implemented:
- Look at the inherited bits
- Interogate the element's RenderStyle
- Compute new bits for the element, and set them in its RenderStyle
- Based on the newly computed bits, determine whether we should increase the text size
- If so, determine how much using the specified font size, and apply the result to the computed font size

This works because StyleBuilderCustom::applyInheritFontSize() inherits from the specified font size, not
the computed font size.

This patch also will disable autosizing using the other methods (so there aren't two methods of autosizing
fighting each other) and will honor text-size-adjust:none. However, it won't honor text-size-adjust:100%.
If content says text-size-adjust:100%, we will disregard it and take this code path.

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

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::valueForPropertyinStyle):
* css/CSSProperties.json:
* css/StyleBuilderCustom.h:
(WebCore::computeBaseSpecifiedFontSize):
(WebCore::computeLineHeightMultiplierDueToFontSize):
* css/StyleResolver.cpp:
(WebCore::idempotentTextSize):
(WebCore::hasTextChildren):
(WebCore::StyleResolver::adjustRenderStyle):
(WebCore::StyleResolver::checkForTextSizeAdjust):
* page/FrameViewLayoutContext.cpp:
(WebCore::FrameViewLayoutContext::applyTextSizingIfNeeded):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::adjustComputedFontSizes):
(WebCore::idempotentTextSize): Deleted.
* rendering/RenderBlockFlow.h:
* rendering/RenderElement.cpp:
(WebCore::includeNonFixedHeight):
(WebCore::RenderElement::adjustComputedFontSizesOnBlocks):
(WebCore::RenderElement::resetTextAutosizing):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::RenderStyle):
(WebCore::RenderStyle::autosizeStatus const):
(WebCore::RenderStyle::setAutosizeStatus):
* rendering/style/RenderStyle.h:
* rendering/style/TextSizeAdjustment.cpp: Added.
(WebCore::AutosizeStatus::AutosizeStatus):
(WebCore::AutosizeStatus::contains const):
(WebCore::AutosizeStatus::modifiedStatus const):
(WebCore::AutosizeStatus::shouldSkipSubtree const):
* rendering/style/TextSizeAdjustment.h:

LayoutTests:

* fast/text-autosizing/ios/idempotentmode/css-exposure-expected.txt: Added.
* fast/text-autosizing/ios/idempotentmode/css-exposure.html: Added.
* fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip-expected.html: Added.
* fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html: Added.
* platform/ipad/fast/text-autosizing/text-size-adjust-inline-style-expected.html: Removed.
* platform/ipad/fast/text-autosizing/text-size-adjust-inline-style.html: Removed.
We're intentionally not honoring percentages, because this is the most common way that
text autosizing is disabled (by setting it to 100%) on the Web today. However, Web authors
that have done this did it without knowing the full extent of the behavior change, and
the new idempotent text autosizing code path seems to be a progression in most cases
we've seen.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreSourcestxt">trunk/Source/WebCore/Sources.txt</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorecssCSSComputedStyleDeclarationcpp">trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSPropertiesjson">trunk/Source/WebCore/css/CSSProperties.json</a></li>
<li><a href="#trunkSourceWebCorecssStyleBuilderCustomh">trunk/Source/WebCore/css/StyleBuilderCustom.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolvercpp">trunk/Source/WebCore/css/StyleResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolverh">trunk/Source/WebCore/css/StyleResolver.h</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewLayoutContextcpp">trunk/Source/WebCore/page/FrameViewLayoutContext.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockFlowcpp">trunk/Source/WebCore/rendering/RenderBlockFlow.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockFlowh">trunk/Source/WebCore/rendering/RenderBlockFlow.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderElementcpp">trunk/Source/WebCore/rendering/RenderElement.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingstyleRenderStylecpp">trunk/Source/WebCore/rendering/style/RenderStyle.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingstyleRenderStyleh">trunk/Source/WebCore/rendering/style/RenderStyle.h</a></li>
<li><a href="#trunkSourceWebCorerenderingstyleTextSizeAdjustmenth">trunk/Source/WebCore/rendering/style/TextSizeAdjustment.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextautosizingiosidempotentmodecssexposureexpectedtxt">trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttextautosizingiosidempotentmodecssexposurehtml">trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure.html</a></li>
<li><a href="#trunkLayoutTestsfasttextautosizingiosidempotentmodeidempotentautosizingskipexpectedtxt">trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttextautosizingiosidempotentmodeidempotentautosizingskiphtml">trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html</a></li>
<li><a href="#trunkSourceWebCorerenderingstyleTextSizeAdjustmentcpp">trunk/Source/WebCore/rendering/style/TextSizeAdjustment.cpp</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsplatformipadfasttextautosizingtextsizeadjustinlinestyleexpectedhtml">trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style-expected.html</a></li>
<li><a href="#trunkLayoutTestsplatformipadfasttextautosizingtextsizeadjustinlinestylehtml">trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/LayoutTests/ChangeLog 2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2019-05-28  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Move idempotent text autosizing to StyleTreeResolver
+        https://bugs.webkit.org/show_bug.cgi?id=197808
+        <rdar://problem/50283983>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/text-autosizing/ios/idempotentmode/css-exposure-expected.txt: Added.
+        * fast/text-autosizing/ios/idempotentmode/css-exposure.html: Added.
+        * fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip-expected.html: Added.
+        * fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html: Added.
+        * platform/ipad/fast/text-autosizing/text-size-adjust-inline-style-expected.html: Removed.
+        * platform/ipad/fast/text-autosizing/text-size-adjust-inline-style.html: Removed.
+        We're intentionally not honoring percentages, because this is the most common way that
+        text autosizing is disabled (by setting it to 100%) on the Web today. However, Web authors
+        that have done this did it without knowing the full extent of the behavior change, and 
+        the new idempotent text autosizing code path seems to be a progression in most cases
+        we've seen.
+
</ins><span class="cx"> 2019-05-28  Simon Fraser  <simon.fraser@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Use scroll-velocity-based tile coverage for overflow:scroll
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextautosizingiosidempotentmodecssexposureexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure-expected.txt (0 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure-expected.txt                              (rev 0)
+++ trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure-expected.txt 2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+PASS window.getComputedStyle(target).getPropertyValue('-internal-text-autosizing-status') is ""
+PASS target.style.internalTextAutosizingStatus is undefined
+PASS style.sheet.cssRules[0].style.internalTextAutosizingStatus is undefined
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Hello
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextautosizingiosidempotentmodecssexposurehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure.html (0 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure.html                              (rev 0)
+++ trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/css-exposure.html 2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -0,0 +1,22 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../../resources/js-test-pre.js"></script>
+<style id="style">
+#dummy {
+    -internal-text-autosizing-status: auto;
+}
+</style>
+</head>
+<body>
+<div id="target" style="-internal-text-autosizing-status: auto;">Hello</div>
+<script>
+const target = document.getElementById("target");
+const style = document.getElementById("style");
+shouldBeEqualToString("window.getComputedStyle(target).getPropertyValue('-internal-text-autosizing-status')", "");
+shouldBe("target.style.internalTextAutosizingStatus", "undefined");
+shouldBe("style.sheet.cssRules[0].style.internalTextAutosizingStatus", "undefined");
+</script>
+<script src="../../../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextautosizingiosidempotentmodeidempotentautosizingskipexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip-expected.txt (0 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip-expected.txt   2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+PASS result is >= 13
+PASS result is >= 13
+PASS result is 12
+PASS result is 12
+PASS result is 12
+PASS result is 12
+PASS result is >= result2
+PASS result is >= 13
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Test
+Test
+Test
+Test
+Test
+TestTestTestTest
+Test
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextautosizingiosidempotentmodeidempotentautosizingskiphtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html (0 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html                                (rev 0)
+++ trunk/LayoutTests/fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html   2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -0,0 +1,52 @@
</span><ins>+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="initial-scale=0.6666">
+<script>
+if (window.internals) {
+    window.internals.settings.setTextAutosizingEnabled(true);
+    window.internals.settings.setTextAutosizingUsesIdempotentMode(true);
+}
+</script>
+<script src="../../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<div style="background: green;"><span id="target" style="font-size: 12px;">Test</span></div>
+<div style="background: green; overflow: auto;"><span id="target2" style="float: right; font-size: 12px;">Test</span></div>
+<div style="background: green;"><span id="target3" style="display: inline-block; font-size: 12px;">Test</span></div>
+<div style="background: green;"><span style="display: inline-block; font-size: 12px;"><span id="target4">Test</span></span></div>
+<div style="background: green;"><span id="target5" style="position: absolute; left: 0px; top: 0px; font-size: 12px;">Test</span></div>
+<div style="background: green;"><span id="target6" style="display: none; font-size: 12px;">Test</span></div>
+<div style="background: green;"><span id="comparison" style="font-size: 12px;">Test<span>Test<span>Test<span id="target7">Test</span></span></span></span></div>
+<div style="background: green;"><span id="target8" style="font-size: 12px; -webkit-text-size-adjust: 100%">Test</span></div>
+<script>
+let result;
+function check(name, shouldGetAutosized) {
+    let target = document.getElementById(name);
+    target.offsetWidth;
+    result = Number.parseInt(window.getComputedStyle(target).getPropertyValue("font-size"));
+    if (shouldGetAutosized)
+        shouldBeGreaterThanOrEqual("result", "13");
+    else
+        shouldBe("result", "12");
+}
+check("target", true);
+check("target2", true);
+check("target3", false);
+check("target4", false);
+check("target5", false);
+check("target6", false);
+
+let target = document.getElementById("target7");
+target.offsetWidth;
+let comparison = document.getElementById("comparison");
+comparison.offsetWidth;
+result = Number.parseInt(window.getComputedStyle(target).getPropertyValue("font-size"));
+let result2 = Number.parseInt(window.getComputedStyle(comparison).getPropertyValue("font-size"));
+shouldBeGreaterThanOrEqual("result", "result2");
+
+check("target8", true);
+</script>
+<script src="../../../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformipadfasttextautosizingtextsizeadjustinlinestyleexpectedhtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style-expected.html (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style-expected.html 2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style-expected.html    2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -1,23 +0,0 @@
</span><del>-<!DOCTYPE html>
-<html>
-<head>
-<style>
-@font-face {
-    font-family: Ahem;
-    src: url("../../../../resources/Ahem.ttf");
-}
-p {
-    font-family: Ahem;
-    font-size: 20px;
-}
-</style>
-</head>
-<body>
-<p style="font-size: 20px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="font-size: 20px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="font-size: 10px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="font-size: 20px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="font-size: 30px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="font-size: 40px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-</body>
-</html>
</del></span></pre></div>
<a id="trunkLayoutTestsplatformipadfasttextautosizingtextsizeadjustinlinestylehtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style.html (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style.html  2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/LayoutTests/platform/ipad/fast/text-autosizing/text-size-adjust-inline-style.html     2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -1,24 +0,0 @@
</span><del>-<!DOCTYPE html>
-<html>
-<head>
-<!-- We intentionally do not call window.internal.settings.setTextAutosizingEnabled(true) to test the default port behavior. -->
-<style>
-@font-face {
-    font-family: Ahem;
-    src: url("../../../../resources/Ahem.ttf");
-}
-p {
-    font-family: Ahem;
-    font-size: 20px;
-}
-</style>
-</head>
-<body>
-<p style="-webkit-text-size-adjust: auto">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="-webkit-text-size-adjust: none">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="-webkit-text-size-adjust: 50%">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="-webkit-text-size-adjust: 100%">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="-webkit-text-size-adjust: 150%">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-<p style="-webkit-text-size-adjust: 200%">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
-</body>
-</html>
</del></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/ChangeLog      2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -1,3 +1,71 @@
</span><ins>+2019-05-28  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Move idempotent text autosizing to StyleTreeResolver
+        https://bugs.webkit.org/show_bug.cgi?id=197808
+        <rdar://problem/50283983>
+
+        Reviewed by Antti Koivisto.
+
+        This patch migrates the idempotent text autosizing code to live inside style resolution. This is almost
+        the same as the algorithm that uses the result of layout to calculate autosizing, but this version only
+        operates on style (and thus doesn't require double layouts). Because it is being run in an environment
+        with less information, autosizing is occurring in more places, so the curves have been adjusted to make
+        autosizing not boost as much as the previous implementation did. The new algorithm is modelled after
+        text-decorations-in-effect. I've claimed 4 of the unused bits in RenderStyle to contain the state of the
+        autosizing algorithm. StyleResolver::adjustRenderStyle() is where the algorithm is implemented:
+        - Look at the inherited bits
+        - Interogate the element's RenderStyle
+        - Compute new bits for the element, and set them in its RenderStyle
+        - Based on the newly computed bits, determine whether we should increase the text size
+        - If so, determine how much using the specified font size, and apply the result to the computed font size
+
+        This works because StyleBuilderCustom::applyInheritFontSize() inherits from the specified font size, not
+        the computed font size.
+
+        This patch also will disable autosizing using the other methods (so there aren't two methods of autosizing
+        fighting each other) and will honor text-size-adjust:none. However, it won't honor text-size-adjust:100%.
+        If content says text-size-adjust:100%, we will disregard it and take this code path.
+
+        Tests: fast/text-autosizing/ios/idempotentmode/css-exposure.html
+               fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html
+               fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-identity.html
+               fast/text-autosizing/ios/idempotentmode/idempotent-autosizing.html
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::valueForPropertyinStyle):
+        * css/CSSProperties.json:
+        * css/StyleBuilderCustom.h:
+        (WebCore::computeBaseSpecifiedFontSize):
+        (WebCore::computeLineHeightMultiplierDueToFontSize):
+        * css/StyleResolver.cpp:
+        (WebCore::idempotentTextSize):
+        (WebCore::hasTextChildren):
+        (WebCore::StyleResolver::adjustRenderStyle):
+        (WebCore::StyleResolver::checkForTextSizeAdjust):
+        * page/FrameViewLayoutContext.cpp:
+        (WebCore::FrameViewLayoutContext::applyTextSizingIfNeeded):
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::adjustComputedFontSizes):
+        (WebCore::idempotentTextSize): Deleted.
+        * rendering/RenderBlockFlow.h:
+        * rendering/RenderElement.cpp:
+        (WebCore::includeNonFixedHeight):
+        (WebCore::RenderElement::adjustComputedFontSizesOnBlocks):
+        (WebCore::RenderElement::resetTextAutosizing):
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::RenderStyle):
+        (WebCore::RenderStyle::autosizeStatus const):
+        (WebCore::RenderStyle::setAutosizeStatus):
+        * rendering/style/RenderStyle.h:
+        * rendering/style/TextSizeAdjustment.cpp: Added.
+        (WebCore::AutosizeStatus::AutosizeStatus):
+        (WebCore::AutosizeStatus::contains const):
+        (WebCore::AutosizeStatus::modifiedStatus const):
+        (WebCore::AutosizeStatus::shouldSkipSubtree const):
+        * rendering/style/TextSizeAdjustment.h:
+
</ins><span class="cx"> 2019-05-28  Simon Fraser  <simon.fraser@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Use scroll-velocity-based tile coverage for overflow:scroll
</span></span></pre></div>
<a id="trunkSourceWebCoreSourcestxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Sources.txt (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Sources.txt 2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/Sources.txt    2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -2144,6 +2144,7 @@
</span><span class="cx"> rendering/style/StyleSurroundData.cpp
</span><span class="cx"> rendering/style/StyleTransformData.cpp
</span><span class="cx"> rendering/style/StyleVisualData.cpp
</span><ins>+rendering/style/TextSizeAdjustment.cpp
</ins><span class="cx"> rendering/style/WillChangeData.cpp
</span><span class="cx"> 
</span><span class="cx"> rendering/svg/RenderSVGBlock.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -6437,6 +6437,7 @@
</span><span class="cx">          1CECB3BB21F511AA00F44542 /* WHLSLEntryPointScaffolding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLEntryPointScaffolding.h; sourceTree = "<group>"; };
</span><span class="cx">          1CECB3C621F59C8700F44542 /* WHLSLNativeTypeWriter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLNativeTypeWriter.cpp; sourceTree = "<group>"; };
</span><span class="cx">          1CECB3C721F59C8700F44542 /* WHLSLNativeTypeWriter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLNativeTypeWriter.h; sourceTree = "<group>"; };
</span><ins>+               1CF0BFD42298706800ED2074 /* TextSizeAdjustment.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TextSizeAdjustment.cpp; sourceTree = "<group>"; };
</ins><span class="cx">           1CFAE3220A6D6A3F0032593D /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = "<absolute>"; };
</span><span class="cx">          1DC553FD211BA12A004B780E /* NavigatorShare.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NavigatorShare.idl; sourceTree = "<group>"; };
</span><span class="cx">          1DC553FF211BA841004B780E /* ShareData.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ShareData.idl; sourceTree = "<group>"; };
</span><span class="lines">@@ -24930,6 +24931,7 @@
</span><span class="cx">                          BC2274760E8366E200E7F975 /* SVGRenderStyleDefs.cpp */,
</span><span class="cx">                          BC2274770E8366E200E7F975 /* SVGRenderStyleDefs.h */,
</span><span class="cx">                          1CB6B4F8217B83930093B9CD /* TextDecorationThickness.h */,
</span><ins>+                               1CF0BFD42298706800ED2074 /* TextSizeAdjustment.cpp */,
</ins><span class="cx">                           448B1B780F3A2F9B0047A9E2 /* TextSizeAdjustment.h */,
</span><span class="cx">                          1CB6B4FB217B83940093B9CD /* TextUnderlineOffset.h */,
</span><span class="cx">                          0F15ED591B7EC7C500EDDFEB /* WillChangeData.cpp */,
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSComputedStyleDeclarationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp 2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp    2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -2785,6 +2785,9 @@
</span><span class="cx"> 
</span><span class="cx">     switch (propertyID) {
</span><span class="cx">         case CSSPropertyInvalid:
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+        case CSSPropertyInternalTextAutosizingStatus:
+#endif
</ins><span class="cx">             break;
</span><span class="cx"> 
</span><span class="cx">         case CSSPropertyBackgroundColor:
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSPropertiesjson"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSProperties.json (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSProperties.json      2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/css/CSSProperties.json 2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -6228,6 +6228,14 @@
</span><span class="cx">             },
</span><span class="cx">             "status": "non-standard"
</span><span class="cx">         },
</span><ins>+        "-internal-text-autosizing-status": {
+            "inherited": true,
+            "codegen-properties": {
+                "skip-builder": true,
+                "enable-if": "ENABLE_TEXT_AUTOSIZING"
+            },
+            "status": "non-standard"
+        },
</ins><span class="cx">         "-webkit-text-emphasis": {
</span><span class="cx">             "inherited": true,
</span><span class="cx">             "codegen-properties": {
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleBuilderCustomh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleBuilderCustom.h (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleBuilderCustom.h    2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/css/StyleBuilderCustom.h       2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -669,7 +669,7 @@
</span><span class="cx">     if (frame && style.textZoom() != TextZoom::Reset)
</span><span class="cx">         result *= frame->textZoomFactor();
</span><span class="cx">     result *= style.effectiveZoom();
</span><del>-    if (percentageAutosizingEnabled)
</del><ins>+    if (percentageAutosizingEnabled && !document.settings().textAutosizingUsesIdempotentMode())
</ins><span class="cx">         result *= style.textSizeAdjust().multiplier();
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="lines">@@ -701,7 +701,7 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (percentageAutosizingEnabled)
</del><ins>+    if (percentageAutosizingEnabled && !document.settings().textAutosizingUsesIdempotentMode())
</ins><span class="cx">         return style.textSizeAdjust().multiplier();
</span><span class="cx">     return 1;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp       2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/css/StyleResolver.cpp  2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -874,6 +874,29 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+static bool hasTextChildren(const Element& element)
+{
+    for (auto* child = element.firstChild(); child; child = child->nextSibling()) {
+        if (is<Text>(child))
+            return true;
+    }
+    return false;
+}
+
+void StyleResolver::adjustRenderStyleForTextAutosizing(RenderStyle& style, const Element* element)
+{
+    auto newAutosizeStatus = AutosizeStatus::updateStatus(style);
+    auto pageScale = document().page() ? document().page()->initialScale() : 1.0f;
+    if (settings().textAutosizingEnabled() && settings().textAutosizingUsesIdempotentMode() && element && !newAutosizeStatus.shouldSkipSubtree() && !style.textSizeAdjust().isNone() && hasTextChildren(*element) && pageScale != 1.0f) {
+        auto fontDescription = style.fontDescription();
+        fontDescription.setComputedSize(AutosizeStatus::idempotentTextSize(fontDescription.specifiedSize(), pageScale));
+        style.setFontDescription(WTFMove(fontDescription));
+        style.fontCascade().update(&document().fontSelector());
+    }
+}
+#endif
+
</ins><span class="cx"> void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element* element)
</span><span class="cx"> {
</span><span class="cx">     // If the composed tree parent has display:contents, the parent box style will be different from the parent style.
</span><span class="lines">@@ -1124,6 +1147,10 @@
</span><span class="cx">     style.setEffectiveTouchActions(computeEffectiveTouchActions(style, parentStyle.effectiveTouchActions()));
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+    adjustRenderStyleForTextAutosizing(style, element);
+#endif
+
</ins><span class="cx">     if (element)
</span><span class="cx">         adjustRenderStyleForSiteSpecificQuirks(style, *element);
</span><span class="cx"> }
</span><span class="lines">@@ -1820,7 +1847,8 @@
</span><span class="cx"> #if ENABLE(TEXT_AUTOSIZING)
</span><span class="cx"> void StyleResolver::checkForTextSizeAdjust(RenderStyle* style)
</span><span class="cx"> {
</span><del>-    if (style->textSizeAdjust().isAuto())
</del><ins>+    ASSERT(style);
+    if (style->textSizeAdjust().isAuto() || (settings().textAutosizingUsesIdempotentMode() && !style->textSizeAdjust().isNone()))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     auto newFontDescription = style->fontDescription();
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.h (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.h 2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/css/StyleResolver.h    2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -500,6 +500,8 @@
</span><span class="cx">     // the last reference to a style declaration are garbage collected.
</span><span class="cx">     void sweepMatchedPropertiesCache();
</span><span class="cx"> 
</span><ins>+    void adjustRenderStyleForTextAutosizing(RenderStyle&, const Element*);
+
</ins><span class="cx">     typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;
</span><span class="cx">     MatchedPropertiesCache m_matchedPropertiesCache;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewLayoutContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameViewLayoutContext.cpp (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameViewLayoutContext.cpp     2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/page/FrameViewLayoutContext.cpp        2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -491,9 +491,9 @@
</span><span class="cx"> void FrameViewLayoutContext::applyTextSizingIfNeeded(RenderElement& layoutRoot)
</span><span class="cx"> {
</span><span class="cx">     auto& settings = layoutRoot.settings();
</span><del>-    if (!settings.textAutosizingEnabled() || renderView()->printing())
</del><ins>+    bool idempotentMode = settings.textAutosizingUsesIdempotentMode();
+    if (!settings.textAutosizingEnabled() || idempotentMode || renderView()->printing())
</ins><span class="cx">         return;
</span><del>-    bool idempotentMode = settings.textAutosizingUsesIdempotentMode();
</del><span class="cx">     auto minimumZoomFontSize = settings.minimumZoomFontSize();
</span><span class="cx">     if (!idempotentMode && !minimumZoomFontSize)
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockFlowcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp       2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp  2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -3723,44 +3723,12 @@
</span><span class="cx">     return std::max((1.0f / log10f(specifiedSize) * coefficient), 1.0f);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline float idempotentTextSize(float specifiedSize, float pageScale)
</del><ins>+void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth)
</ins><span class="cx"> {
</span><del>-    // This describes a piecewise curve when the page scale is 2/3.
-    FloatPoint points[] = { {0.0f, 0.0f}, {6.0f, 12.0f}, {12.0f, 18.0f} };
-
-    // When the page scale is 1, the curve should be the identity.
-    // Linearly interpolate between the curve above and identity based on the page scale.
-    // Beware that depending on the specific values picked in the curve, this interpolation might change the shape of the curve for very small pageScales.
-    pageScale = std::min(std::max(pageScale, 0.5f), 1.0f);
-    auto scalePoint = [&](FloatPoint point) {
-        float fraction = 3.0f - 3.0f * pageScale;
-        point.setY(point.x() + (point.y() - point.x()) * fraction);
-        return point;
-    };
-
-    if (specifiedSize <= 0)
-        return 0;
-
-    float result = scalePoint(points[WTF_ARRAY_LENGTH(points) - 1]).y();
-    for (size_t i = 1; i < WTF_ARRAY_LENGTH(points); ++i) {
-        if (points[i].x() < specifiedSize)
-            continue;
-        auto leftPoint = scalePoint(points[i - 1]);
-        auto rightPoint = scalePoint(points[i]);
-        float fraction = (specifiedSize - leftPoint.x()) / (rightPoint.x() - leftPoint.x());
-        result = leftPoint.y() + fraction * (rightPoint.y() - leftPoint.y());
-        break;
-    }
-
-    return std::max(result, specifiedSize);
-}
-
-void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth, float pageScale, bool idempotentMode)
-{
</del><span class="cx">     LOG(TextAutosizing, "RenderBlockFlow %p adjustComputedFontSizes, size=%f visibleWidth=%f, width()=%f. Bailing: %d", this, size, visibleWidth, width().toFloat(), visibleWidth >= width());
</span><span class="cx"> 
</span><span class="cx">     // Don't do any work if the block is smaller than the visible area.
</span><del>-    if (!idempotentMode && visibleWidth >= width())
</del><ins>+    if (visibleWidth >= width())
</ins><span class="cx">         return;
</span><span class="cx">     
</span><span class="cx">     unsigned lineCount;
</span><span class="lines">@@ -3798,7 +3766,7 @@
</span><span class="cx">         auto& fontDescription = oldStyle.fontDescription();
</span><span class="cx">         float specifiedSize = fontDescription.specifiedSize();
</span><span class="cx">         float scaledSize = roundf(specifiedSize * scale);
</span><del>-        if (idempotentMode || (scaledSize > 0 && scaledSize < minFontSize)) {
</del><ins>+        if (scaledSize > 0 && scaledSize < minFontSize) {
</ins><span class="cx">             // Record the width of the block and the line count the first time we resize text and use it from then on for text resizing.
</span><span class="cx">             // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915).
</span><span class="cx">             if (m_lineCountForTextAutosizing == NOT_SET)
</span><span class="lines">@@ -3806,14 +3774,8 @@
</span><span class="cx">             if (m_widthForTextAutosizing == -1)
</span><span class="cx">                 m_widthForTextAutosizing = actualWidth;
</span><span class="cx"> 
</span><del>-            float candidateNewSize;
-            if (idempotentMode) {
-                float lineTextSize = idempotentTextSize(specifiedSize, pageScale);
-                candidateNewSize = roundf(lineTextSize);
-            } else {
-                float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(text, specifiedSize) : textMultiplier(text, specifiedSize);
-                candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
-            }
</del><ins>+            float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(text, specifiedSize) : textMultiplier(text, specifiedSize);
+            float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
</ins><span class="cx"> 
</span><span class="cx">             if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto())
</span><span class="cx">                 document().textAutoSizing().addTextNode(*text.textNode(), candidateNewSize);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockFlowh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.h (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlockFlow.h 2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.h    2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -604,7 +604,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TEXT_AUTOSIZING)
</span><span class="cx">     int lineCountForTextAutosizing();
</span><del>-    void adjustComputedFontSizes(float size, float visibleWidth, float pageScale, bool idempotentMode);
</del><ins>+    void adjustComputedFontSizes(float size, float visibleWidth);
</ins><span class="cx">     void resetComputedFontSize()
</span><span class="cx">     {
</span><span class="cx">         m_widthForTextAutosizing = -1;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderElement.cpp 2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp    2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -2125,8 +2125,6 @@
</span><span class="cx">         }
</span><span class="cx">         return RenderObject::FixedHeight;
</span><span class="cx">     }
</span><del>-    if (renderer.document().settings().textAutosizingUsesIdempotentMode() && style.maxHeight().type() == Fixed && is<RenderBlock>(renderer) && style.maxHeight().value() <= downcast<RenderBlock>(renderer).layoutOverflowRect().maxY())
-        return RenderObject::FixedHeight;
</del><span class="cx">     return RenderObject::FlexibleHeight;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -2136,12 +2134,9 @@
</span><span class="cx">     if (!document)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    auto pageScale = document->page() ? document->page()->initialScale() : 1.0f;
-
</del><span class="cx">     Vector<int> depthStack;
</span><span class="cx">     int currentDepth = 0;
</span><span class="cx">     int newFixedDepth = 0;
</span><del>-    auto idempotentMode = document->settings().textAutosizingUsesIdempotentMode();
</del><span class="cx"> 
</span><span class="cx">     // We don't apply autosizing to nodes with fixed height normally.
</span><span class="cx">     // But we apply it to nodes which are located deep enough
</span><span class="lines">@@ -2154,8 +2149,8 @@
</span><span class="cx">             depthStack.append(newFixedDepth);
</span><span class="cx"> 
</span><span class="cx">         int stackSize = depthStack.size();
</span><del>-        if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (idempotentMode || !stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
-            downcast<RenderBlockFlow>(*descendent).adjustComputedFontSizes(size, visibleWidth, pageScale, idempotentMode);
</del><ins>+        if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
+            downcast<RenderBlockFlow>(*descendent).adjustComputedFontSizes(size, visibleWidth);
</ins><span class="cx">         newFixedDepth = 0;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -2176,7 +2171,6 @@
</span><span class="cx">     Vector<int> depthStack;
</span><span class="cx">     int currentDepth = 0;
</span><span class="cx">     int newFixedDepth = 0;
</span><del>-    auto idempotentMode = document->settings().textAutosizingUsesIdempotentMode();
</del><span class="cx"> 
</span><span class="cx">     for (RenderObject* descendent = traverseNext(this, includeNonFixedHeight, currentDepth, newFixedDepth); descendent; descendent = descendent->traverseNext(this, includeNonFixedHeight, currentDepth, newFixedDepth)) {
</span><span class="cx">         while (depthStack.size() > 0 && currentDepth <= depthStack[depthStack.size() - 1])
</span><span class="lines">@@ -2185,7 +2179,7 @@
</span><span class="cx">             depthStack.append(newFixedDepth);
</span><span class="cx"> 
</span><span class="cx">         int stackSize = depthStack.size();
</span><del>-        if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (idempotentMode || !stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
</del><ins>+        if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
</ins><span class="cx">             downcast<RenderBlockFlow>(*descendent).resetComputedFontSize();
</span><span class="cx">         newFixedDepth = 0;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingstyleRenderStylecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp     2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp        2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -165,6 +165,9 @@
</span><span class="cx">     m_inheritedFlags.insideLink = static_cast<unsigned>(InsideLink::NotInside);
</span><span class="cx">     m_inheritedFlags.insideDefaultButton = false;
</span><span class="cx">     m_inheritedFlags.writingMode = initialWritingMode();
</span><ins>+#if ENABLE(TEXT_AUTOSIZING)
+    m_inheritedFlags.autosizeStatus = 0;
+#endif
</ins><span class="cx"> 
</span><span class="cx">     m_nonInheritedFlags.effectiveDisplay = static_cast<unsigned>(initialDisplay());
</span><span class="cx">     m_nonInheritedFlags.originalDisplay = static_cast<unsigned>(initialDisplay());
</span><span class="lines">@@ -489,6 +492,16 @@
</span><span class="cx">         && m_rareNonInheritedData->textOverflow == other.m_rareNonInheritedData->textOverflow;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+AutosizeStatus RenderStyle::autosizeStatus() const
+{
+    return OptionSet<AutosizeStatus::Fields>::fromRaw(m_inheritedFlags.autosizeStatus);
+}
+
+void RenderStyle::setAutosizeStatus(AutosizeStatus autosizeStatus)
+{
+    m_inheritedFlags.autosizeStatus = autosizeStatus.fields().toRaw();
+}
+
</ins><span class="cx"> #endif // ENABLE(TEXT_AUTOSIZING)
</span><span class="cx"> 
</span><span class="cx"> bool RenderStyle::inheritedDataShared(const RenderStyle* other) const
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingstyleRenderStyleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/style/RenderStyle.h       2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h  2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -744,6 +744,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TEXT_AUTOSIZING)
</span><span class="cx">     TextSizeAdjustment textSizeAdjust() const { return m_rareInheritedData->textSizeAdjust; }
</span><ins>+    AutosizeStatus autosizeStatus() const;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     TextSecurity textSecurity() const { return static_cast<TextSecurity>(m_rareInheritedData->textSecurity); }
</span><span class="lines">@@ -1258,6 +1259,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TEXT_AUTOSIZING)
</span><span class="cx">     void setTextSizeAdjust(TextSizeAdjustment adjustment) { SET_VAR(m_rareInheritedData, textSizeAdjust, adjustment); }
</span><ins>+    void setAutosizeStatus(AutosizeStatus);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void setTextSecurity(TextSecurity security) { SET_VAR(m_rareInheritedData, textSecurity, static_cast<unsigned>(security)); }
</span><span class="lines">@@ -1845,6 +1847,11 @@
</span><span class="cx">         // CSS Text Layout Module Level 3: Vertical writing support
</span><span class="cx">         unsigned writingMode : 2; // WritingMode
</span><span class="cx">         // 48 bits
</span><ins>+
+#if ENABLE(TEXT_AUTOSIZING)
+        unsigned autosizeStatus : 4;
+#endif
+        // 52 bits
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     // This constructor is used to implement the replace operation.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingstyleTextSizeAdjustmentcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/rendering/style/TextSizeAdjustment.cpp (0 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/style/TextSizeAdjustment.cpp                              (rev 0)
+++ trunk/Source/WebCore/rendering/style/TextSizeAdjustment.cpp 2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -0,0 +1,105 @@
</span><ins>+/*
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextSizeAdjustment.h"
+
+#if ENABLE(TEXT_AUTOSIZING)
+
+#include "RenderStyle.h"
+
+namespace WebCore {
+
+AutosizeStatus::AutosizeStatus(OptionSet<Fields> fields)
+    : m_fields(fields)
+{
+}
+
+bool AutosizeStatus::contains(Fields fields) const
+{
+    return m_fields.contains(fields);
+}
+
+AutosizeStatus AutosizeStatus::updateStatus(RenderStyle& style)
+{
+    OptionSet<Fields> result = style.autosizeStatus().fields();
+    if (style.hasOutOfFlowPosition())
+        result.add(Fields::FoundOutOfFlowPosition);
+    switch (style.display()) {
+    case DisplayType::InlineBlock:
+        result.add(Fields::FoundInlineBlock);
+        break;
+    case DisplayType::None:
+        result.add(Fields::FoundDisplayNone);
+        break;
+    default: // FIXME: Add more cases.
+        break;
+    }
+    if (style.height().isFixed())
+        result.add(Fields::FoundFixedHeight);
+    style.setAutosizeStatus(result);
+    return result;
+}
+
+bool AutosizeStatus::shouldSkipSubtree() const
+{
+    return m_fields.containsAny({ Fields::FoundOutOfFlowPosition, Fields::FoundInlineBlock, Fields::FoundFixedHeight, Fields::FoundDisplayNone });
+}
+
+float AutosizeStatus::idempotentTextSize(float specifiedSize, float pageScale)
+{
+    // This describes a piecewise curve when the page scale is 2/3.
+    FloatPoint points[] = { {0.0f, 0.0f}, {6.0f, 9.0f}, {14.0f, 17.0f} };
+
+    // When the page scale is 1, the curve should be the identity.
+    // Linearly interpolate between the curve above and identity based on the page scale.
+    // Beware that depending on the specific values picked in the curve, this interpolation might change the shape of the curve for very small pageScales.
+    pageScale = std::min(std::max(pageScale, 0.5f), 1.0f);
+    auto scalePoint = [&](FloatPoint point) {
+        float fraction = 3.0f - 3.0f * pageScale;
+        point.setY(point.x() + (point.y() - point.x()) * fraction);
+        return point;
+    };
+
+    if (specifiedSize <= 0)
+        return 0;
+
+    float result = scalePoint(points[WTF_ARRAY_LENGTH(points) - 1]).y();
+    for (size_t i = 1; i < WTF_ARRAY_LENGTH(points); ++i) {
+        if (points[i].x() < specifiedSize)
+            continue;
+        auto leftPoint = scalePoint(points[i - 1]);
+        auto rightPoint = scalePoint(points[i]);
+        float fraction = (specifiedSize - leftPoint.x()) / (rightPoint.x() - leftPoint.x());
+        result = leftPoint.y() + fraction * (rightPoint.y() - leftPoint.y());
+        break;
+    }
+
+    return std::max(std::round(result), specifiedSize);
+}
+
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebCorerenderingstyleTextSizeAdjustmenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/style/TextSizeAdjustment.h (245837 => 245838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/style/TextSizeAdjustment.h        2019-05-29 01:07:03 UTC (rev 245837)
+++ trunk/Source/WebCore/rendering/style/TextSizeAdjustment.h   2019-05-29 02:27:20 UTC (rev 245838)
</span><span class="lines">@@ -22,8 +22,12 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TEXT_AUTOSIZING)
</span><span class="cx"> 
</span><ins>+#include <wtf/OptionSet.h>
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class RenderStyle;
+
</ins><span class="cx"> enum TextSizeAdjustmentType { AutoTextSizeAdjustment = -1, NoTextSizeAdjustment = -2 };
</span><span class="cx"> 
</span><span class="cx"> class TextSizeAdjustment {
</span><span class="lines">@@ -45,6 +49,30 @@
</span><span class="cx">     float m_value;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+class AutosizeStatus {
+public:
+    enum class Fields : uint8_t {
+        FoundOutOfFlowPosition = 1 << 0,
+        FoundInlineBlock = 1 << 1,
+        FoundFixedHeight = 1 << 2,
+        FoundDisplayNone = 1 << 3
+        // Adding new values requires giving RenderStyle::InheritedFlags::autosizeStatus additional bits.
+    };
+
+    AutosizeStatus(OptionSet<Fields>);
+    OptionSet<Fields> fields() const { return m_fields; }
+
+    bool contains(Fields) const;
+    bool shouldSkipSubtree() const;
+
+    static float idempotentTextSize(float specifiedSize, float pageScale);
+    static AutosizeStatus updateStatus(RenderStyle&);
+
+private:
+    OptionSet<Fields> m_fields;
+};
+
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(TEXT_AUTOSIZING)
</span></span></pre>
</div>
</div>

</body>
</html>