<!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 <zalan@apple.com>
+
+ 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 <jond@apple.com>
</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 "HitTestResult.h"
</span><span class="cx"> #include "InlineTextBox.h"
</span><span class="cx"> #include "LineWidth.h"
</span><ins>+#include "Logging.h"
</ins><span class="cx"> #include "PaintInfo.h"
</span><span class="cx"> #include "RenderBlockFlow.h"
</span><span class="cx"> #include "RenderChildIterator.h"
</span><span class="lines">@@ -49,16 +50,96 @@
</span><span class="cx"> #include "SimpleLineLayoutTextFragmentIterator.h"
</span><span class="cx"> #include "Text.h"
</span><span class="cx"> #include "TextPaintStyle.h"
</span><ins>+#include "TextStream.h"
</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 << 0,
+ FlowIsInsideRegion = 1LLU << 1,
+ FlowHasHorizonalWritingMode = 1LLU << 2,
+ FlowHasOutline = 1LLU << 3,
+ FlowIsRuby = 1LLU << 4,
+ FlowIsPaginated = 1LLU << 5,
+ FlowHasTextOverflow = 1LLU << 6,
+ FlowIsDepricatedFlexBox = 1LLU << 7,
+ FlowParentIsPlaceholderElement = 1LLU << 8,
+ FlowParentIsTextAreaWithWrapping = 1LLU << 9,
+ FlowHasNonSupportedChild = 1LLU << 10,
+ FlowHasUnsupportedFloat = 1LLU << 11,
+ FlowHasTextDecoration = 1LLU << 12,
+ FlowIsJustifyAligned = 1LLU << 13,
+ FlowHasOverflowVisible = 1LLU << 14,
+ FlowIsNotLTR = 1LLU << 15,
+ FlowHasLineBoxContainProperty = 1LLU << 16,
+ FlowIsNotTopToBottom = 1LLU << 17,
+ FlowHasLineBreak = 1LLU << 18,
+ FlowHasWordBreak = 1LLU << 19,
+ FlowHasNonNormalUnicodeBiDi = 1LLU << 20,
+ FlowHasRTLOrdering = 1LLU << 21,
+ FlowHasLineAlignEdges = 1LLU << 22,
+ FlowHasLineSnap = 1LLU << 23,
+ FlowHasHypensAuto = 1LLU << 24,
+ FlowHasTextEmphasisFillOrMark = 1LLU << 25,
+ FlowHasTextShadow = 1LLU << 26,
+ FlowHasPseudoFirstLine = 1LLU << 27,
+ FlowHasPseudoFirstLetter = 1LLU << 28,
+ FlowHasTextCombine = 1LLU << 29,
+ FlowHasTextFillBox = 1LLU << 30,
+ FlowHasBorderFitLines = 1LLU << 31,
+ FlowHasNonAutoLineBreak = 1LLU << 32,
+ FlowHasNonAutoTrailingWord = 1LLU << 33,
+ FlowHasSVGFont = 1LLU << 34,
+ FlowTextIsEmpty = 1LLU << 35,
+ FlowTextHasNoBreakSpace = 1LLU << 36,
+ FlowTextHasSoftHyphen = 1LLU << 37,
+ FlowTextHasDirectionCharacter = 1LLU << 38,
+ FlowIsMissingPrimaryFont = 1LLU << 39,
+ FlowFontIsMissingGlyph = 1LLU << 40,
+ FlowTextIsCombineText = 1LLU << 41,
+ FlowTextIsRenderCounter = 1LLU << 42,
+ FlowTextIsRenderQuote = 1LLU << 43,
+ FlowTextIsTextFragment = 1LLU << 44,
+ FlowTextIsSVGInlineText = 1LLU << 45,
+ FlowFontIsNotSimple = 1LLU << 46,
+ FeatureIsDisabled = 1LLU << 47,
+ FlowHasNoParent = 1LLU << 48,
+ FlowHasNoChild = 1LLU << 49,
+ EndOfReasons = 1LLU << 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 <typename CharacterType>
</span><del>-static bool canUseForText(const CharacterType* text, unsigned length, const Font& font)
</del><ins>+static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned length, const Font& font, FallThrough fallthrough)
</ins><span class="cx"> {
</span><ins>+ AvoidanceReasonFlags reasons = NoReason;
</ins><span class="cx"> // FIXME: <textarea maxlength=0> 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 < 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& textRenderer, const Font& font)
</del><ins>+static AvoidanceReasonFlags canUseForText(const RenderText& textRenderer, const Font& 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& flow)
</del><ins>+static AvoidanceReasonFlags canUseForFontAndText(const RenderBlockFlow& 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& style = flow.style();
</span><span class="cx"> auto& 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& textRenderer : childrenOfType<RenderText>(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& style)
</del><ins>+static AvoidanceReasonFlags canUseForStyle(const RenderStyle& 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& flow)
</del><ins>+static AvoidanceReasonFlags canUseForWithReason(const RenderBlockFlow& flow, FallThrough fallthrough)
</ins><span class="cx"> {
</span><ins>+#ifndef NDEBUG
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+ registerNotifyCallback("com.apple.WebKit.showSimpleLineLayoutCoverage", printSimpleLineLayoutCoverage);
+ registerNotifyCallback("com.apple.WebKit.showSimpleLineLayoutReasons", 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() && flow.firstLineBlock())
</span><del>- return false;
</del><ins>+ SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasPseudoFirstLine, fallthrough);
</ins><span class="cx"> if (flow.isAnonymousBlock() && flow.parent()->style().textOverflow())
</span><del>- return false;
</del><ins>+ SET_REASON_AND_RETURN_IF_NEEDED(reasons, FlowHasTextOverflow, fallthrough);
</ins><span class="cx"> if (flow.parent()->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<RenderTextControl>(*flow.parent()) && downcast<RenderTextControl>(*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()->isTextArea() && flow.parent()->element()->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 <blockflow>#text</blockflow>, <blockflow>#text<br></blockflow> and mutiple (sibling) RenderText cases.
</span><span class="cx"> // The <blockflow><inline>#text</inline></blockflow> 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->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<float>::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->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->y(), false);
</span><span class="cx"> if (availableWidth < 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& 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& stream)
+{
+ switch (reason) {
+ case FlowIsInsideRegion:
+ stream << "flow is inside region";
+ break;
+ case FlowHasHorizonalWritingMode:
+ stream << "horizontal writing mode";
+ break;
+ case FlowHasOutline:
+ stream << "outline";
+ break;
+ case FlowIsRuby:
+ stream << "ruby";
+ break;
+ case FlowIsPaginated:
+ stream << "paginated";
+ break;
+ case FlowHasTextOverflow:
+ stream << "text-overflow";
+ break;
+ case FlowIsDepricatedFlexBox:
+ stream << "depricatedFlexBox";
+ break;
+ case FlowParentIsPlaceholderElement:
+ stream << "placeholder element";
+ break;
+ case FlowParentIsTextAreaWithWrapping:
+ stream << "wrapping textarea";
+ break;
+ case FlowHasNonSupportedChild:
+ stream << "nested renderers";
+ break;
+ case FlowHasUnsupportedFloat:
+ stream << "complicated float";
+ break;
+ case FlowHasTextDecoration:
+ stream << "text-decoration";
+ break;
+ case FlowIsJustifyAligned:
+ stream << "text-align: justify";
+ break;
+ case FlowHasOverflowVisible:
+ stream << "overflow: visible";
+ break;
+ case FlowIsNotLTR:
+ stream << "dir is not LTR";
+ break;
+ case FlowHasLineBoxContainProperty:
+ stream << "line-box-contain property";
+ break;
+ case FlowIsNotTopToBottom:
+ stream << "non top-to-bottom flow";
+ break;
+ case FlowHasLineBreak:
+ stream << "line-break property";
+ break;
+ case FlowHasWordBreak:
+ stream << "word-break property";
+ break;
+ case FlowHasNonNormalUnicodeBiDi:
+ stream << "non-normal Unicode bidi";
+ break;
+ case FlowHasRTLOrdering:
+ stream << "-webkit-rtl-ordering";
+ break;
+ case FlowHasLineAlignEdges:
+ stream << "-webkit-line-align edges";
+ break;
+ case FlowHasLineSnap:
+ stream << "-webkit-line-snap property";
+ break;
+ case FlowHasHypensAuto:
+ stream << "hyphen: auto";
+ break;
+ case FlowHasTextEmphasisFillOrMark:
+ stream << "text-emphasis (fill/mark)";
+ break;
+ case FlowHasPseudoFirstLine:
+ stream << "first-line";
+ break;
+ case FlowHasPseudoFirstLetter:
+ stream << "first-letter";
+ break;
+ case FlowHasTextCombine:
+ stream << "text combine";
+ break;
+ case FlowHasTextFillBox:
+ stream << "background-color (text-fill)";
+ break;
+ case FlowHasBorderFitLines:
+ stream << "-webkit-border-fit";
+ break;
+ case FlowHasNonAutoLineBreak:
+ stream << "line-break is not auto";
+ break;
+ case FlowHasNonAutoTrailingWord:
+ stream << "-apple-trailing-word is not auto";
+ break;
+ case FlowHasSVGFont:
+ stream << "SVG font";
+ break;
+ case FlowTextHasNoBreakSpace:
+ stream << "No-break-space character";
+ break;
+ case FlowTextHasSoftHyphen:
+ stream << "soft hyphen character";
+ break;
+ case FlowTextHasDirectionCharacter:
+ stream << "direction character";
+ break;
+ case FlowIsMissingPrimaryFont:
+ stream << "missing primary font";
+ break;
+ case FlowFontIsMissingGlyph:
+ stream << "missing glyph";
+ break;
+ case FlowTextIsCombineText:
+ stream << "text is combine";
+ break;
+ case FlowTextIsRenderCounter:
+ stream << "unsupported RenderCounter";
+ break;
+ case FlowTextIsRenderQuote:
+ stream << "unsupported RenderQuote";
+ break;
+ case FlowTextIsTextFragment:
+ stream << "unsupported TextFragment";
+ break;
+ case FlowTextIsSVGInlineText:
+ stream << "unsupported SVGInlineText";
+ break;
+ case FlowFontIsNotSimple:
+ stream << "complext font";
+ break;
+ case FlowHasTextShadow:
+ stream << "text-shadow";
+ break;
+ case FlowTextIsEmpty:
+ case FlowHasNoChild:
+ case FlowHasNoParent:
+ case FeatureIsDisabled:
+ default:
+ break;
+ }
</ins><span class="cx"> }
</span><ins>+
+static void printReasons(AvoidanceReasonFlags reasons, TextStream& stream)
+{
+ bool first = true;
+ for (auto reasonItem = EndOfReasons >> 1; reasonItem != NoReason; reasonItem >>= 1) {
+ if (!(reasons & reasonItem))
+ continue;
+ stream << (first ? " " : ", ");
+ first = false;
+ printReason(reasonItem, stream);
+ }
</ins><span class="cx"> }
</span><ins>+
+static void printTextForSubtree(const RenderObject& renderer, unsigned& charactersLeft, TextStream& stream)
+{
+ if (!charactersLeft)
+ return;
+ if (is<RenderText>(renderer)) {
+ String text = downcast<RenderText>(renderer).text();
+ text = text.stripWhiteSpace();
+ unsigned len = std::min(charactersLeft, text.length());
+ stream << text.left(len);
+ charactersLeft -= len;
+ return;
+ }
+ if (!is<RenderElement>(renderer))
+ return;
+ for (const auto* child = downcast<RenderElement>(renderer).firstChild(); child; child = child->nextSibling())
+ printTextForSubtree(*child, charactersLeft, stream);
+}
+
+static unsigned textLengthForSubtree(const RenderObject& renderer)
+{
+ if (is<RenderText>(renderer))
+ return downcast<RenderText>(renderer).textLength();
+ if (!is<RenderElement>(renderer))
+ return 0;
+ unsigned textLength = 0;
+ for (const auto* child = downcast<RenderElement>(renderer).firstChild(); child; child = child->nextSibling())
+ textLength += textLengthForSubtree(*child);
+ return textLength;
+}
+
+static void collectNonEmptyLeafRenderBlockFlows(const RenderObject& renderer, HashSet<const RenderBlockFlow*>& leafRenderers)
+{
+ if (is<RenderText>(renderer)) {
+ if (!downcast<RenderText>(renderer).textLength())
+ return;
+ // Find RenderBlockFlow ancestor.
+ for (const auto* current = renderer.parent(); current; current = current->parent()) {
+ if (!is<RenderBlockFlow>(current))
+ continue;
+ leafRenderers.add(downcast<RenderBlockFlow>(current));
+ break;
+ }
+ return;
+ }
+ if (!is<RenderElement>(renderer))
+ return;
+ for (const auto* child = downcast<RenderElement>(renderer).firstChild(); child; child = child->nextSibling())
+ collectNonEmptyLeafRenderBlockFlows(*child, leafRenderers);
+}
+
+static void collectNonEmptyLeafRenderBlockFlowsForCurrentPage(HashSet<const RenderBlockFlow*>& leafRenderers)
+{
+ for (const auto* document : Document::allDocuments()) {
+ if (!document->renderView() || document->inPageCache())
+ continue;
+ if (!document->isHTMLDocument() && !document->isXHTMLDocument())
+ continue;
+ collectNonEmptyLeafRenderBlockFlows(*document->renderView(), leafRenderers);
+ }
+}
+
+void printSimpleLineLayoutBlockList()
+{
+ HashSet<const RenderBlockFlow*> leafRenderers;
+ collectNonEmptyLeafRenderBlockFlowsForCurrentPage(leafRenderers);
+ if (!leafRenderers.size()) {
+ WTFLogAlways("No text found in this document\n");
+ return;
+ }
+ TextStream stream;
+ stream << "---------------------------------------------------\n";
+ for (const auto* flow : leafRenderers) {
+ auto reason = canUseForWithReason(*flow, FallThrough::Yes);
+ if (reason == NoReason)
+ continue;
+ unsigned printedLength = 30;
+ stream << "\"";
+ printTextForSubtree(*flow, printedLength, stream);
+ for (;printedLength > 0; --printedLength)
+ stream << " ";
+ stream << "\"(" << textLengthForSubtree(*flow) << "):";
+ printReasons(reason, stream);
+ stream << "\n";
+ }
+ stream << "---------------------------------------------------\n";
+ WTFLogAlways("%s", stream.release().utf8().data());
+}
+
+void printSimpleLineLayoutCoverage()
+{
+ HashSet<const RenderBlockFlow*> leafRenderers;
+ collectNonEmptyLeafRenderBlockFlowsForCurrentPage(leafRenderers);
+ if (!leafRenderers.size()) {
+ WTFLogAlways("No text found in this document\n");
+ return;
+ }
+ TextStream stream;
+ HashMap<AvoidanceReason, unsigned> 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 >> 1; reasonItem != NoReason; reasonItem >>= 1) {
+ if (!(reasons & reasonItem))
+ continue;
+ auto result = flowStatistics.add(reasonItem, flowLength);
+ if (!result.isNewEntry)
+ result.iterator->value += flowLength;
+ }
+ }
+ stream << "---------------------------------------------------\n";
+ stream << "Number of text blocks: total(" << leafRenderers.size() << ") non-simple(" << numberOfUnsupportedLeafBlocks << ")\nText length: total(" <<
+ textLength << ") non-simple(" << unsupportedTextLength << ")\n";
+ for (const auto reasonEntry : flowStatistics) {
+ printReason(reasonEntry.key, stream);
+ stream << ": " << (float)reasonEntry.value / (float)textLength * 100 << "%\n";
+ }
+ stream << "simple line layout coverage: " << (float)(textLength - unsupportedTextLength) / (float)textLength * 100 << "%\n";
+ stream << "---------------------------------------------------\n";
+ WTFLogAlways("%s", stream.release().utf8().data());
+}
+#endif
+}
+}
</ins></span></pre>
</div>
</div>
</body>
</html>