<!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>[193374] trunk/Source/WebCore</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/193374">193374</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2015-12-03 13:59:17 -0800 (Thu, 03 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Simple line layout: Print out simple line layout statistics for the current page from command line.
https://bugs.webkit.org/show_bug.cgi?id=151806

Reviewed Simon Fraser.

com.apple.WebKit.showSimpleLineLayoutCoverage prints out a coverage summary of the current page,
while com.apple.WebKit.showSimpleLineLayoutReasons lists the non-simple line layout blocks including the reasons why
they are not covered.

No change in functionality.


* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseForText):
(WebCore::SimpleLineLayout::canUseForFontAndText):
(WebCore::SimpleLineLayout::canUseForStyle):
(WebCore::SimpleLineLayout::canUseForWithReason):
(WebCore::SimpleLineLayout::canUseFor):
(WebCore::SimpleLineLayout::printReason):
(WebCore::SimpleLineLayout::printReasons):
(WebCore::SimpleLineLayout::printTextForSubtree):
(WebCore::SimpleLineLayout::textLengthForSubtree):
(WebCore::SimpleLineLayout::collectNonEmptyLeafRenderBlockFlows):
(WebCore::SimpleLineLayout::collectNonEmptyLeafRenderBlockFlowsForCurrentPage):
(WebCore::SimpleLineLayout::printSimpleLineLayoutBlockList):
(WebCore::SimpleLineLayout::printSimpleLineLayoutCoverage):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutcpp">trunk/Source/WebCore/rendering/SimpleLineLayout.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (193373 => 193374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-12-03 21:44:51 UTC (rev 193373)
+++ trunk/Source/WebCore/ChangeLog        2015-12-03 21:59:17 UTC (rev 193374)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-12-03  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+        Simple line layout: Print out simple line layout statistics for the current page from command line.
+        https://bugs.webkit.org/show_bug.cgi?id=151806
+
+        Reviewed Simon Fraser.
+
+        com.apple.WebKit.showSimpleLineLayoutCoverage prints out a coverage summary of the current page,
+        while com.apple.WebKit.showSimpleLineLayoutReasons lists the non-simple line layout blocks including the reasons why
+        they are not covered.
+
+        No change in functionality.
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseForText):
+        (WebCore::SimpleLineLayout::canUseForFontAndText):
+        (WebCore::SimpleLineLayout::canUseForStyle):
+        (WebCore::SimpleLineLayout::canUseForWithReason):
+        (WebCore::SimpleLineLayout::canUseFor):
+        (WebCore::SimpleLineLayout::printReason):
+        (WebCore::SimpleLineLayout::printReasons):
+        (WebCore::SimpleLineLayout::printTextForSubtree):
+        (WebCore::SimpleLineLayout::textLengthForSubtree):
+        (WebCore::SimpleLineLayout::collectNonEmptyLeafRenderBlockFlows):
+        (WebCore::SimpleLineLayout::collectNonEmptyLeafRenderBlockFlowsForCurrentPage):
+        (WebCore::SimpleLineLayout::printSimpleLineLayoutBlockList):
+        (WebCore::SimpleLineLayout::printSimpleLineLayoutCoverage):
+
</ins><span class="cx"> 2015-12-03  Jonathan Davis  &lt;jond@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add WebCrypto to status page
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (193373 => 193374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2015-12-03 21:44:51 UTC (rev 193373)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2015-12-03 21:59:17 UTC (rev 193374)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include &quot;HitTestResult.h&quot;
</span><span class="cx"> #include &quot;InlineTextBox.h&quot;
</span><span class="cx"> #include &quot;LineWidth.h&quot;
</span><ins>+#include &quot;Logging.h&quot;
</ins><span class="cx"> #include &quot;PaintInfo.h&quot;
</span><span class="cx"> #include &quot;RenderBlockFlow.h&quot;
</span><span class="cx"> #include &quot;RenderChildIterator.h&quot;
</span><span class="lines">@@ -49,16 +50,96 @@
</span><span class="cx"> #include &quot;SimpleLineLayoutTextFragmentIterator.h&quot;
</span><span class="cx"> #include &quot;Text.h&quot;
</span><span class="cx"> #include &quot;TextPaintStyle.h&quot;
</span><ins>+#include &quot;TextStream.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> namespace SimpleLineLayout {
</span><span class="cx"> 
</span><ins>+#ifndef NDEBUG
+void printSimpleLineLayoutCoverage();
+void printSimpleLineLayoutBlockList();
+#endif
+
+enum AvoidanceReason_ : uint64_t {
+    NoReason                            = 1LLU  &lt;&lt; 0,
+    FlowIsInsideRegion                  = 1LLU  &lt;&lt; 1,
+    FlowHasHorizonalWritingMode         = 1LLU  &lt;&lt; 2,
+    FlowHasOutline                      = 1LLU  &lt;&lt; 3,
+    FlowIsRuby                          = 1LLU  &lt;&lt; 4,
+    FlowIsPaginated                     = 1LLU  &lt;&lt; 5,
+    FlowHasTextOverflow                 = 1LLU  &lt;&lt; 6,
+    FlowIsDepricatedFlexBox             = 1LLU  &lt;&lt; 7,
+    FlowParentIsPlaceholderElement      = 1LLU  &lt;&lt; 8,
+    FlowParentIsTextAreaWithWrapping    = 1LLU  &lt;&lt; 9,
+    FlowHasNonSupportedChild            = 1LLU  &lt;&lt; 10,
+    FlowHasUnsupportedFloat             = 1LLU  &lt;&lt; 11,
+    FlowHasTextDecoration               = 1LLU  &lt;&lt; 12,
+    FlowIsJustifyAligned                = 1LLU  &lt;&lt; 13,
+    FlowHasOverflowVisible              = 1LLU  &lt;&lt; 14,
+    FlowIsNotLTR                        = 1LLU  &lt;&lt; 15,
+    FlowHasLineBoxContainProperty       = 1LLU  &lt;&lt; 16,
+    FlowIsNotTopToBottom                = 1LLU  &lt;&lt; 17,
+    FlowHasLineBreak                    = 1LLU  &lt;&lt; 18,
+    FlowHasWordBreak                    = 1LLU  &lt;&lt; 19,
+    FlowHasNonNormalUnicodeBiDi         = 1LLU  &lt;&lt; 20,
+    FlowHasRTLOrdering                  = 1LLU  &lt;&lt; 21,
+    FlowHasLineAlignEdges               = 1LLU  &lt;&lt; 22,
+    FlowHasLineSnap                     = 1LLU  &lt;&lt; 23,
+    FlowHasHypensAuto                   = 1LLU  &lt;&lt; 24,
+    FlowHasTextEmphasisFillOrMark       = 1LLU  &lt;&lt; 25,
+    FlowHasTextShadow                   = 1LLU  &lt;&lt; 26,
+    FlowHasPseudoFirstLine              = 1LLU  &lt;&lt; 27,
+    FlowHasPseudoFirstLetter            = 1LLU  &lt;&lt; 28,
+    FlowHasTextCombine                  = 1LLU  &lt;&lt; 29,
+    FlowHasTextFillBox                  = 1LLU  &lt;&lt; 30,
+    FlowHasBorderFitLines               = 1LLU  &lt;&lt; 31,
+    FlowHasNonAutoLineBreak             = 1LLU  &lt;&lt; 32,
+    FlowHasNonAutoTrailingWord          = 1LLU  &lt;&lt; 33,
+    FlowHasSVGFont                      = 1LLU  &lt;&lt; 34,
+    FlowTextIsEmpty                     = 1LLU  &lt;&lt; 35,
+    FlowTextHasNoBreakSpace             = 1LLU  &lt;&lt; 36,
+    FlowTextHasSoftHyphen               = 1LLU  &lt;&lt; 37,
+    FlowTextHasDirectionCharacter       = 1LLU  &lt;&lt; 38,
+    FlowIsMissingPrimaryFont            = 1LLU  &lt;&lt; 39,
+    FlowFontIsMissingGlyph              = 1LLU  &lt;&lt; 40,
+    FlowTextIsCombineText               = 1LLU  &lt;&lt; 41,
+    FlowTextIsRenderCounter             = 1LLU  &lt;&lt; 42,
+    FlowTextIsRenderQuote               = 1LLU  &lt;&lt; 43,
+    FlowTextIsTextFragment              = 1LLU  &lt;&lt; 44,
+    FlowTextIsSVGInlineText             = 1LLU  &lt;&lt; 45,
+    FlowFontIsNotSimple                 = 1LLU  &lt;&lt; 46,
+    FeatureIsDisabled                   = 1LLU  &lt;&lt; 47,
+    FlowHasNoParent                     = 1LLU  &lt;&lt; 48,
+    FlowHasNoChild                      = 1LLU  &lt;&lt; 49,
+    EndOfReasons                        = 1LLU  &lt;&lt; 50
+};
+typedef uint64_t AvoidanceReason;
+typedef uint64_t AvoidanceReasonFlags;
+
+enum class FallThrough { Yes, No };
+
+#ifndef NDEBUG
+#define SET_REASON_AND_RETURN_IF_NEEDED(reasons, reason, fallthrough) { \
+        reasons |= reason; \
+        if (fallthrough == FallThrough::No) \
+            return reasons; \
+    }
+#else
+#define SET_REASON_AND_RETURN_IF_NEEDED(reasons, reason, fallthrough) { \
+        ASSERT_UNUSED(fallthrough, fallthrough == FallThrough::No); \
+        reasons |= reason; \
+        return reasons; \
+    }
+#endif
+
</ins><span class="cx"> template &lt;typename CharacterType&gt;
</span><del>-static bool canUseForText(const CharacterType* text, unsigned length, const Font&amp; font)
</del><ins>+static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned length, const Font&amp; font, FallThrough fallthrough)
</ins><span class="cx"> {
</span><ins>+    AvoidanceReasonFlags reasons = NoReason;
</ins><span class="cx">     // FIXME: &lt;textarea maxlength=0&gt; generates empty text node.
</span><span class="cx">     if (!length)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextIsEmpty, fallthrough);
+
</ins><span class="cx">     for (unsigned i = 0; i &lt; length; ++i) {
</span><span class="cx">         UChar character = text[i];
</span><span class="cx">         if (character == ' ')
</span><span class="lines">@@ -66,130 +147,156 @@
</span><span class="cx"> 
</span><span class="cx">         // These would be easy to support.
</span><span class="cx">         if (character == noBreakSpace)
</span><del>-            return false;
</del><ins>+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextHasNoBreakSpace, fallthrough);
</ins><span class="cx">         if (character == softHyphen)
</span><del>-            return false;
</del><ins>+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextHasSoftHyphen, fallthrough);
</ins><span class="cx"> 
</span><span class="cx">         UCharDirection direction = u_charDirection(character);
</span><span class="cx">         if (direction == U_RIGHT_TO_LEFT || direction == U_RIGHT_TO_LEFT_ARABIC
</span><span class="cx">             || direction == U_RIGHT_TO_LEFT_EMBEDDING || direction == U_RIGHT_TO_LEFT_OVERRIDE
</span><span class="cx">             || direction == U_LEFT_TO_RIGHT_EMBEDDING || direction == U_LEFT_TO_RIGHT_OVERRIDE
</span><span class="cx">             || direction == U_POP_DIRECTIONAL_FORMAT || direction == U_BOUNDARY_NEUTRAL)
</span><del>-            return false;
</del><ins>+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextHasDirectionCharacter, fallthrough);
</ins><span class="cx"> 
</span><span class="cx">         if (!font.glyphForCharacter(character))
</span><del>-            return false;
</del><ins>+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowFontIsMissingGlyph, fallthrough);
</ins><span class="cx">     }
</span><del>-    return true;
</del><ins>+    return reasons;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool canUseForText(const RenderText&amp; textRenderer, const Font&amp; font)
</del><ins>+static AvoidanceReasonFlags canUseForText(const RenderText&amp; textRenderer, const Font&amp; font, FallThrough fallthrough)
</ins><span class="cx"> {
</span><span class="cx">     if (textRenderer.is8Bit())
</span><del>-        return canUseForText(textRenderer.characters8(), textRenderer.textLength(), font);
-    return canUseForText(textRenderer.characters16(), textRenderer.textLength(), font);
</del><ins>+        return canUseForText(textRenderer.characters8(), textRenderer.textLength(), font, fallthrough);
+    return canUseForText(textRenderer.characters16(), textRenderer.textLength(), font, fallthrough);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool canUseForFontAndText(const RenderBlockFlow&amp; flow)
</del><ins>+static AvoidanceReasonFlags canUseForFontAndText(const RenderBlockFlow&amp; flow, FallThrough fallthrough)
</ins><span class="cx"> {
</span><ins>+    AvoidanceReasonFlags reasons = NoReason;
</ins><span class="cx">     // We assume that all lines have metrics based purely on the primary font.
</span><span class="cx">     const auto&amp; style = flow.style();
</span><span class="cx">     auto&amp; primaryFont = style.fontCascade().primaryFont();
</span><span class="cx">     if (primaryFont.isLoading())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsMissingPrimaryFont, fallthrough);
+    if (primaryFont.isSVGFont())
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasSVGFont, fallthrough);
+
</ins><span class="cx">     for (const auto&amp; textRenderer : childrenOfType&lt;RenderText&gt;(flow)) {
</span><del>-        if (textRenderer.isCombineText() || textRenderer.isCounter() || textRenderer.isQuote() || textRenderer.isTextFragment()
-            || textRenderer.isSVGInlineText())
-            return false;
</del><ins>+        if (textRenderer.isCombineText())
+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextIsCombineText, fallthrough);
+        if (textRenderer.isCounter())
+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextIsRenderCounter, fallthrough);
+        if (textRenderer.isQuote())
+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextIsRenderQuote, fallthrough);
+        if (textRenderer.isTextFragment())
+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextIsTextFragment, fallthrough);
+        if (textRenderer.isSVGInlineText())
+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowTextIsSVGInlineText, fallthrough);
</ins><span class="cx">         if (style.fontCascade().codePath(TextRun(textRenderer.text())) != FontCascade::Simple)
</span><del>-            return false;
-        if (!canUseForText(textRenderer, primaryFont))
-            return false;
</del><ins>+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowFontIsNotSimple, fallthrough);
+
+        auto textReasons = canUseForText(textRenderer, primaryFont, fallthrough);
+        if (textReasons != NoReason)
+            SET_REASON_AND_RETURN_IF_NEEDED(reasons, textReasons, fallthrough);
</ins><span class="cx">     }
</span><del>-    return true;
</del><ins>+    return reasons;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool canUseForStyle(const RenderStyle&amp; style)
</del><ins>+static AvoidanceReasonFlags canUseForStyle(const RenderStyle&amp; style, FallThrough fallthrough)
</ins><span class="cx"> {
</span><ins>+    AvoidanceReasonFlags reasons = NoReason;
</ins><span class="cx">     if (style.textOverflow())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextOverflow, fallthrough);
</ins><span class="cx">     if (style.textDecorationsInEffect() != TextDecorationNone)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextDecoration, fallthrough);
</ins><span class="cx">     if (style.textAlign() == JUSTIFY)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsJustifyAligned, fallthrough);
</ins><span class="cx">     // Non-visible overflow should be pretty easy to support.
</span><span class="cx">     if (style.overflowX() != OVISIBLE || style.overflowY() != OVISIBLE)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasOverflowVisible, fallthrough);
</ins><span class="cx">     if (!style.isLeftToRightDirection())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsNotLTR, fallthrough);
</ins><span class="cx">     if (style.lineBoxContain() != RenderStyle::initialLineBoxContain())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasLineBoxContainProperty, fallthrough);
</ins><span class="cx">     if (style.writingMode() != TopToBottomWritingMode)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsNotTopToBottom, fallthrough);
</ins><span class="cx">     if (style.lineBreak() != LineBreakAuto)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasLineBreak, fallthrough);
</ins><span class="cx">     if (style.wordBreak() != NormalWordBreak)
</span><del>-        return false;
-    if (style.unicodeBidi() != UBNormal || style.rtlOrdering() != LogicalOrder)
-        return false;
-    if (style.lineAlign() != LineAlignNone || style.lineSnap() != LineSnapNone)
-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasWordBreak, fallthrough);
+    if (style.unicodeBidi() != UBNormal)
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasNonNormalUnicodeBiDi, fallthrough);
+    if (style.rtlOrdering() != LogicalOrder)
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasRTLOrdering, fallthrough);
+    if (style.lineAlign() != LineAlignNone)
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasLineAlignEdges, fallthrough);
+    if (style.lineSnap() != LineSnapNone)
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasLineSnap, fallthrough);
</ins><span class="cx">     if (style.hyphens() == HyphensAuto)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasHypensAuto, fallthrough);
</ins><span class="cx">     if (style.textEmphasisFill() != TextEmphasisFillFilled || style.textEmphasisMark() != TextEmphasisMarkNone)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextEmphasisFillOrMark, fallthrough);
</ins><span class="cx">     if (style.textShadow())
</span><del>-        return false;
-    if (style.hasPseudoStyle(FIRST_LINE) || style.hasPseudoStyle(FIRST_LETTER))
-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextShadow, fallthrough);
+    if (style.hasPseudoStyle(FIRST_LINE))
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasPseudoFirstLine, fallthrough);
+    if (style.hasPseudoStyle(FIRST_LETTER))
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasPseudoFirstLetter, fallthrough);
</ins><span class="cx">     if (style.hasTextCombine())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextCombine, fallthrough);
</ins><span class="cx">     if (style.backgroundClip() == TextFillBox)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextFillBox, fallthrough);
</ins><span class="cx">     if (style.borderFit() == BorderFitLines)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasBorderFitLines, fallthrough);
</ins><span class="cx">     if (style.lineBreak() != LineBreakAuto)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasNonAutoLineBreak, fallthrough);
</ins><span class="cx"> #if ENABLE(CSS_TRAILING_WORD)
</span><span class="cx">     if (style.trailingWord() != TrailingWord::Auto)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasNonAutoTrailingWord, fallthrough);
</ins><span class="cx"> #endif
</span><del>-    if (style.fontCascade().primaryFont().isSVGFont())
-        return false;
-    return true;
</del><ins>+    return reasons;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool canUseFor(const RenderBlockFlow&amp; flow)
</del><ins>+static AvoidanceReasonFlags canUseForWithReason(const RenderBlockFlow&amp; flow, FallThrough fallthrough)
</ins><span class="cx"> {
</span><ins>+#ifndef NDEBUG
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        registerNotifyCallback(&quot;com.apple.WebKit.showSimpleLineLayoutCoverage&quot;, printSimpleLineLayoutCoverage);
+        registerNotifyCallback(&quot;com.apple.WebKit.showSimpleLineLayoutReasons&quot;, printSimpleLineLayoutBlockList);
+    });
+#endif
+    AvoidanceReasonFlags reasons = NoReason;
</ins><span class="cx">     if (!flow.frame().settings().simpleLineLayoutEnabled())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FeatureIsDisabled, fallthrough);
</ins><span class="cx">     if (!flow.parent())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasNoParent, fallthrough);
</ins><span class="cx">     if (!flow.firstChild())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasNoChild, fallthrough);
</ins><span class="cx">     if (flow.flowThreadState() != RenderObject::NotInsideFlowThread)
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsInsideRegion, fallthrough);
</ins><span class="cx">     if (!flow.isHorizontalWritingMode())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasHorizonalWritingMode, fallthrough);
</ins><span class="cx">     if (flow.hasOutline())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasOutline, fallthrough);
</ins><span class="cx">     if (flow.isRubyText() || flow.isRubyBase())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsRuby, fallthrough);
</ins><span class="cx">     // Printing does pagination without a flow thread.
</span><span class="cx">     if (flow.document().paginated())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsPaginated, fallthrough);
</ins><span class="cx">     if (flow.isAnonymous() &amp;&amp; flow.firstLineBlock())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasPseudoFirstLine, fallthrough);
</ins><span class="cx">     if (flow.isAnonymousBlock() &amp;&amp; flow.parent()-&gt;style().textOverflow())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextOverflow, fallthrough);
</ins><span class="cx">     if (flow.parent()-&gt;isDeprecatedFlexibleBox())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowIsDepricatedFlexBox, fallthrough);
</ins><span class="cx">     // FIXME: Placeholders do something strange.
</span><span class="cx">     if (is&lt;RenderTextControl&gt;(*flow.parent()) &amp;&amp; downcast&lt;RenderTextControl&gt;(*flow.parent()).textFormControlElement().placeholderElement())
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowParentIsPlaceholderElement, fallthrough);
</ins><span class="cx">     // FIXME: Implementation of wrap=hard looks into lineboxes.
</span><span class="cx">     if (flow.parent()-&gt;isTextArea() &amp;&amp; flow.parent()-&gt;element()-&gt;fastHasAttribute(HTMLNames::wrapAttr))
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowParentIsTextAreaWithWrapping, fallthrough);
</ins><span class="cx">     // This currently covers &lt;blockflow&gt;#text&lt;/blockflow&gt;, &lt;blockflow&gt;#text&lt;br&gt;&lt;/blockflow&gt; and mutiple (sibling) RenderText cases.
</span><span class="cx">     // The &lt;blockflow&gt;&lt;inline&gt;#text&lt;/inline&gt;&lt;/blockflow&gt; case is also popular and should be relatively easy to cover.
</span><span class="cx">     for (const auto* child = flow.firstChild(); child;) {
</span><span class="lines">@@ -201,10 +308,12 @@
</span><span class="cx">             child = child-&gt;nextSibling();
</span><span class="cx">             continue;
</span><span class="cx">         }
</span><del>-        return false;
</del><ins>+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasNonSupportedChild, fallthrough);
+        break;
</ins><span class="cx">     }
</span><del>-    if (!canUseForStyle(flow.style()))
-        return false;
</del><ins>+    auto styleReasons = canUseForStyle(flow.style(), fallthrough);
+    if (styleReasons != NoReason)
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, styleReasons, fallthrough);
</ins><span class="cx">     // We can't use the code path if any lines would need to be shifted below floats. This is because we don't keep per-line y coordinates.
</span><span class="cx">     if (flow.containsFloats()) {
</span><span class="cx">         float minimumWidthNeeded = std::numeric_limits&lt;float&gt;::max();
</span><span class="lines">@@ -217,19 +326,25 @@
</span><span class="cx">                 // if a float has a shape, we cannot tell if content will need to be shifted until after we lay it out,
</span><span class="cx">                 // since the amount of space is not uniform for the height of the float.
</span><span class="cx">                 if (floatingObject-&gt;renderer().shapeOutsideInfo())
</span><del>-                    return false;
</del><ins>+                    SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasUnsupportedFloat, fallthrough);
</ins><span class="cx"> #endif
</span><span class="cx">                 float availableWidth = flow.availableLogicalWidthForLine(floatingObject-&gt;y(), false);
</span><span class="cx">                 if (availableWidth &lt; minimumWidthNeeded)
</span><del>-                    return false;
</del><ins>+                    SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasUnsupportedFloat, fallthrough);
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">     }
</span><del>-    if (!canUseForFontAndText(flow))
-        return false;
-    return true;
</del><ins>+    auto fontAndTextReasons = canUseForFontAndText(flow, fallthrough);
+    if (fontAndTextReasons != NoReason)
+        SET_REASON_AND_RETURN_IF_NEEDED(reasons, fontAndTextReasons, fallthrough);
+    return reasons;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool canUseFor(const RenderBlockFlow&amp; flow)
+{
+    return canUseForWithReason(flow, FallThrough::No) == NoReason;
+}
+
</ins><span class="cx"> static float computeLineLeft(ETextAlign textAlign, float availableWidth, float committedWidth, float logicalLeftOffset)
</span><span class="cx"> {
</span><span class="cx">     float remainingWidth = availableWidth - committedWidth;
</span><span class="lines">@@ -662,5 +777,294 @@
</span><span class="cx">     memcpy(m_runs, runVector.data(), m_runCount * sizeof(Run));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#ifndef NDEBUG
+static void printReason(AvoidanceReason reason, TextStream&amp; stream)
+{
+    switch (reason) {
+    case FlowIsInsideRegion:
+        stream &lt;&lt; &quot;flow is inside region&quot;;
+        break;
+    case FlowHasHorizonalWritingMode:
+        stream &lt;&lt; &quot;horizontal writing mode&quot;;
+        break;
+    case FlowHasOutline:
+        stream &lt;&lt; &quot;outline&quot;;
+        break;
+    case FlowIsRuby:
+        stream &lt;&lt; &quot;ruby&quot;;
+        break;
+    case FlowIsPaginated:
+        stream &lt;&lt; &quot;paginated&quot;;
+        break;
+    case FlowHasTextOverflow:
+        stream &lt;&lt; &quot;text-overflow&quot;;
+        break;
+    case FlowIsDepricatedFlexBox:
+        stream &lt;&lt; &quot;depricatedFlexBox&quot;;
+        break;
+    case FlowParentIsPlaceholderElement:
+        stream &lt;&lt; &quot;placeholder element&quot;;
+        break;
+    case FlowParentIsTextAreaWithWrapping:
+        stream &lt;&lt; &quot;wrapping textarea&quot;;
+        break;
+    case FlowHasNonSupportedChild:
+        stream &lt;&lt; &quot;nested renderers&quot;;
+        break;
+    case FlowHasUnsupportedFloat:
+        stream &lt;&lt; &quot;complicated float&quot;;
+        break;
+    case FlowHasTextDecoration:
+        stream &lt;&lt; &quot;text-decoration&quot;;
+        break;
+    case FlowIsJustifyAligned:
+        stream &lt;&lt; &quot;text-align: justify&quot;;
+        break;
+    case FlowHasOverflowVisible:
+        stream &lt;&lt; &quot;overflow: visible&quot;;
+        break;
+    case FlowIsNotLTR:
+        stream &lt;&lt; &quot;dir is not LTR&quot;;
+        break;
+    case FlowHasLineBoxContainProperty:
+        stream &lt;&lt; &quot;line-box-contain property&quot;;
+        break;
+    case FlowIsNotTopToBottom:
+        stream &lt;&lt; &quot;non top-to-bottom flow&quot;;
+        break;
+    case FlowHasLineBreak:
+        stream &lt;&lt; &quot;line-break property&quot;;
+        break;
+    case FlowHasWordBreak:
+        stream &lt;&lt; &quot;word-break property&quot;;
+        break;
+    case FlowHasNonNormalUnicodeBiDi:
+        stream &lt;&lt; &quot;non-normal Unicode bidi&quot;;
+        break;
+    case FlowHasRTLOrdering:
+        stream &lt;&lt; &quot;-webkit-rtl-ordering&quot;;
+        break;
+    case FlowHasLineAlignEdges:
+        stream &lt;&lt; &quot;-webkit-line-align edges&quot;;
+        break;
+    case FlowHasLineSnap:
+        stream &lt;&lt; &quot;-webkit-line-snap property&quot;;
+        break;
+    case FlowHasHypensAuto:
+        stream &lt;&lt; &quot;hyphen: auto&quot;;
+        break;
+    case FlowHasTextEmphasisFillOrMark:
+        stream &lt;&lt; &quot;text-emphasis (fill/mark)&quot;;
+        break;
+    case FlowHasPseudoFirstLine:
+        stream &lt;&lt; &quot;first-line&quot;;
+        break;
+    case FlowHasPseudoFirstLetter:
+        stream &lt;&lt; &quot;first-letter&quot;;
+        break;
+    case FlowHasTextCombine:
+        stream &lt;&lt; &quot;text combine&quot;;
+        break;
+    case FlowHasTextFillBox:
+        stream &lt;&lt; &quot;background-color (text-fill)&quot;;
+        break;
+    case FlowHasBorderFitLines:
+        stream &lt;&lt; &quot;-webkit-border-fit&quot;;
+        break;
+    case FlowHasNonAutoLineBreak:
+        stream &lt;&lt; &quot;line-break is not auto&quot;;
+        break;
+    case FlowHasNonAutoTrailingWord:
+        stream &lt;&lt; &quot;-apple-trailing-word is not auto&quot;;
+        break;
+    case FlowHasSVGFont:
+        stream &lt;&lt; &quot;SVG font&quot;;
+        break;
+    case FlowTextHasNoBreakSpace:
+        stream &lt;&lt; &quot;No-break-space character&quot;;
+        break;
+    case FlowTextHasSoftHyphen:
+        stream &lt;&lt; &quot;soft hyphen character&quot;;
+        break;
+    case FlowTextHasDirectionCharacter:
+        stream &lt;&lt; &quot;direction character&quot;;
+        break;
+    case FlowIsMissingPrimaryFont:
+        stream &lt;&lt; &quot;missing primary font&quot;;
+        break;
+    case FlowFontIsMissingGlyph:
+        stream &lt;&lt; &quot;missing glyph&quot;;
+        break;
+    case FlowTextIsCombineText:
+        stream &lt;&lt; &quot;text is combine&quot;;
+        break;
+    case FlowTextIsRenderCounter:
+        stream &lt;&lt; &quot;unsupported RenderCounter&quot;;
+        break;
+    case FlowTextIsRenderQuote:
+        stream &lt;&lt; &quot;unsupported RenderQuote&quot;;
+        break;
+    case FlowTextIsTextFragment:
+        stream &lt;&lt; &quot;unsupported TextFragment&quot;;
+        break;
+    case FlowTextIsSVGInlineText:
+        stream &lt;&lt; &quot;unsupported SVGInlineText&quot;;
+        break;
+    case FlowFontIsNotSimple:
+        stream &lt;&lt; &quot;complext font&quot;;
+        break;
+    case FlowHasTextShadow:
+        stream &lt;&lt; &quot;text-shadow&quot;;
+        break;
+    case FlowTextIsEmpty:
+    case FlowHasNoChild:
+    case FlowHasNoParent:
+    case FeatureIsDisabled:
+    default:
+        break;
+    }
</ins><span class="cx"> }
</span><ins>+
+static void printReasons(AvoidanceReasonFlags reasons, TextStream&amp; stream)
+{
+    bool first = true;
+    for (auto reasonItem = EndOfReasons &gt;&gt; 1; reasonItem != NoReason; reasonItem &gt;&gt;= 1) {
+        if (!(reasons &amp; reasonItem))
+            continue;
+        stream &lt;&lt; (first ? &quot; &quot; : &quot;, &quot;);
+        first = false;
+        printReason(reasonItem, stream);
+    }
</ins><span class="cx"> }
</span><ins>+
+static void printTextForSubtree(const RenderObject&amp; renderer, unsigned&amp; charactersLeft, TextStream&amp; stream)
+{
+    if (!charactersLeft)
+        return;
+    if (is&lt;RenderText&gt;(renderer)) {
+        String text = downcast&lt;RenderText&gt;(renderer).text();
+        text = text.stripWhiteSpace();
+        unsigned len = std::min(charactersLeft, text.length());
+        stream &lt;&lt; text.left(len);
+        charactersLeft -= len;
+        return;
+    }
+    if (!is&lt;RenderElement&gt;(renderer))
+        return;
+    for (const auto* child = downcast&lt;RenderElement&gt;(renderer).firstChild(); child; child = child-&gt;nextSibling())
+        printTextForSubtree(*child, charactersLeft, stream);
+}
+
+static unsigned textLengthForSubtree(const RenderObject&amp; renderer)
+{
+    if (is&lt;RenderText&gt;(renderer))
+        return downcast&lt;RenderText&gt;(renderer).textLength();
+    if (!is&lt;RenderElement&gt;(renderer))
+        return 0;
+    unsigned textLength = 0;
+    for (const auto* child = downcast&lt;RenderElement&gt;(renderer).firstChild(); child; child = child-&gt;nextSibling())
+        textLength += textLengthForSubtree(*child);
+    return textLength;
+}
+
+static void collectNonEmptyLeafRenderBlockFlows(const RenderObject&amp; renderer, HashSet&lt;const RenderBlockFlow*&gt;&amp; leafRenderers)
+{
+    if (is&lt;RenderText&gt;(renderer)) {
+        if (!downcast&lt;RenderText&gt;(renderer).textLength())
+            return;
+        // Find RenderBlockFlow ancestor.
+        for (const auto* current = renderer.parent(); current; current = current-&gt;parent()) {
+            if (!is&lt;RenderBlockFlow&gt;(current))
+                continue;
+            leafRenderers.add(downcast&lt;RenderBlockFlow&gt;(current));
+            break;
+        }
+        return;
+    }
+    if (!is&lt;RenderElement&gt;(renderer))
+        return;
+    for (const auto* child = downcast&lt;RenderElement&gt;(renderer).firstChild(); child; child = child-&gt;nextSibling())
+        collectNonEmptyLeafRenderBlockFlows(*child, leafRenderers);
+}
+
+static void collectNonEmptyLeafRenderBlockFlowsForCurrentPage(HashSet&lt;const RenderBlockFlow*&gt;&amp; leafRenderers)
+{
+    for (const auto* document : Document::allDocuments()) {
+        if (!document-&gt;renderView() || document-&gt;inPageCache())
+            continue;
+        if (!document-&gt;isHTMLDocument() &amp;&amp; !document-&gt;isXHTMLDocument())
+            continue;
+        collectNonEmptyLeafRenderBlockFlows(*document-&gt;renderView(), leafRenderers);
+    }
+}
+
+void printSimpleLineLayoutBlockList()
+{
+    HashSet&lt;const RenderBlockFlow*&gt; leafRenderers;
+    collectNonEmptyLeafRenderBlockFlowsForCurrentPage(leafRenderers);
+    if (!leafRenderers.size()) {
+        WTFLogAlways(&quot;No text found in this document\n&quot;);
+        return;
+    }
+    TextStream stream;
+    stream &lt;&lt; &quot;---------------------------------------------------\n&quot;;
+    for (const auto* flow : leafRenderers) {
+        auto reason = canUseForWithReason(*flow, FallThrough::Yes);
+        if (reason == NoReason)
+            continue;
+        unsigned printedLength = 30;
+        stream &lt;&lt; &quot;\&quot;&quot;;
+        printTextForSubtree(*flow, printedLength, stream);
+        for (;printedLength &gt; 0; --printedLength)
+            stream &lt;&lt; &quot; &quot;;
+        stream &lt;&lt; &quot;\&quot;(&quot; &lt;&lt; textLengthForSubtree(*flow) &lt;&lt; &quot;):&quot;;
+        printReasons(reason, stream);
+        stream &lt;&lt; &quot;\n&quot;;
+    }
+    stream &lt;&lt; &quot;---------------------------------------------------\n&quot;;
+    WTFLogAlways(&quot;%s&quot;, stream.release().utf8().data());
+}
+
+void printSimpleLineLayoutCoverage()
+{
+    HashSet&lt;const RenderBlockFlow*&gt; leafRenderers;
+    collectNonEmptyLeafRenderBlockFlowsForCurrentPage(leafRenderers);
+    if (!leafRenderers.size()) {
+        WTFLogAlways(&quot;No text found in this document\n&quot;);
+        return;
+    }
+    TextStream stream;
+    HashMap&lt;AvoidanceReason, unsigned&gt; flowStatistics;
+    unsigned textLength = 0;
+    unsigned unsupportedTextLength = 0;
+    unsigned numberOfUnsupportedLeafBlocks = 0;
+    for (const auto* flow : leafRenderers) {
+        auto flowLength = textLengthForSubtree(*flow);
+        textLength += flowLength;
+        auto reasons = canUseForWithReason(*flow, FallThrough::Yes);
+        if (reasons == NoReason)
+            continue;
+        ++numberOfUnsupportedLeafBlocks;
+        unsupportedTextLength += flowLength;
+        for (auto reasonItem = EndOfReasons &gt;&gt; 1; reasonItem != NoReason; reasonItem &gt;&gt;= 1) {
+            if (!(reasons &amp; reasonItem))
+                continue;
+            auto result = flowStatistics.add(reasonItem, flowLength);
+            if (!result.isNewEntry)
+                result.iterator-&gt;value += flowLength;
+        }
+    }
+    stream &lt;&lt; &quot;---------------------------------------------------\n&quot;;
+    stream &lt;&lt; &quot;Number of text blocks: total(&quot; &lt;&lt;  leafRenderers.size() &lt;&lt; &quot;) non-simple(&quot; &lt;&lt; numberOfUnsupportedLeafBlocks &lt;&lt; &quot;)\nText length: total(&quot; &lt;&lt;
+        textLength &lt;&lt; &quot;) non-simple(&quot; &lt;&lt; unsupportedTextLength &lt;&lt; &quot;)\n&quot;;
+    for (const auto reasonEntry : flowStatistics) {
+        printReason(reasonEntry.key, stream);
+        stream &lt;&lt; &quot;: &quot; &lt;&lt; (float)reasonEntry.value / (float)textLength * 100 &lt;&lt; &quot;%\n&quot;;
+    }
+    stream &lt;&lt; &quot;simple line layout coverage: &quot; &lt;&lt; (float)(textLength - unsupportedTextLength) / (float)textLength * 100 &lt;&lt; &quot;%\n&quot;;
+    stream &lt;&lt; &quot;---------------------------------------------------\n&quot;;
+    WTFLogAlways(&quot;%s&quot;, stream.release().utf8().data());
+}
+#endif
+}
+}
</ins></span></pre>
</div>
</div>

</body>
</html>