Title: [290866] trunk/Source/WebCore
Revision
290866
Author
za...@apple.com
Date
2022-03-05 08:26:41 -0800 (Sat, 05 Mar 2022)

Log Message

[LFC][Integration] RenderInline should use ADD_REASONS_AND_RETURN_IF_NEEDED
https://bugs.webkit.org/show_bug.cgi?id=237492

Reviewed by Antti Koivisto.

Content inside RenderInline should be accounted for when collecting coverage information.
(This patch also has a bit of a printModernLineLayoutCoverage&co refactoring.)

* layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::printTextForSubtree):
(WebCore::LayoutIntegration::contentLengthForSubtreeStayWithinBlockFlow):
(WebCore::LayoutIntegration::contentLengthForBlockFlow):
(WebCore::LayoutIntegration::printModernLineLayoutBlockList):
(WebCore::LayoutIntegration::printModernLineLayoutCoverage):
(WebCore::LayoutIntegration::canUseForChild):
(WebCore::LayoutIntegration::textLengthForSubtree): Deleted.
(WebCore::LayoutIntegration::collectNonEmptyLeafRenderBlockFlows): Deleted.
(WebCore::LayoutIntegration::collectNonEmptyLeafRenderBlockFlowsForCurrentPage): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290865 => 290866)


--- trunk/Source/WebCore/ChangeLog	2022-03-05 11:33:24 UTC (rev 290865)
+++ trunk/Source/WebCore/ChangeLog	2022-03-05 16:26:41 UTC (rev 290866)
@@ -1,3 +1,24 @@
+2022-03-05  Alan Bujtas  <za...@apple.com>
+
+        [LFC][Integration] RenderInline should use ADD_REASONS_AND_RETURN_IF_NEEDED
+        https://bugs.webkit.org/show_bug.cgi?id=237492
+
+        Reviewed by Antti Koivisto.
+
+        Content inside RenderInline should be accounted for when collecting coverage information.
+        (This patch also has a bit of a printModernLineLayoutCoverage&co refactoring.)
+
+        * layout/integration/LayoutIntegrationCoverage.cpp:
+        (WebCore::LayoutIntegration::printTextForSubtree):
+        (WebCore::LayoutIntegration::contentLengthForSubtreeStayWithinBlockFlow):
+        (WebCore::LayoutIntegration::contentLengthForBlockFlow):
+        (WebCore::LayoutIntegration::printModernLineLayoutBlockList):
+        (WebCore::LayoutIntegration::printModernLineLayoutCoverage):
+        (WebCore::LayoutIntegration::canUseForChild):
+        (WebCore::LayoutIntegration::textLengthForSubtree): Deleted.
+        (WebCore::LayoutIntegration::collectNonEmptyLeafRenderBlockFlows): Deleted.
+        (WebCore::LayoutIntegration::collectNonEmptyLeafRenderBlockFlowsForCurrentPage): Deleted.
+
 2022-03-05  Youenn Fablet  <you...@apple.com>
 
         Implement remote-inbound-rtp packetsLost

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp (290865 => 290866)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2022-03-05 11:33:24 UTC (rev 290865)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2022-03-05 16:26:41 UTC (rev 290866)
@@ -208,78 +208,69 @@
     }
 }
 
-static void printTextForSubtree(const RenderObject& renderer, unsigned& charactersLeft, TextStream& stream)
+static void printTextForSubtree(const RenderElement& 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;
+    for (auto& child : childrenOfType<RenderObject>(downcast<RenderElement>(renderer))) {
+        if (is<RenderText>(child)) {
+            String text = downcast<RenderText>(child).text();
+            text = text.stripWhiteSpace();
+            auto len = std::min(charactersLeft, text.length());
+            stream << text.left(len);
+            charactersLeft -= len;
+            continue;
+        }
+        printTextForSubtree(downcast<RenderElement>(child), charactersLeft, stream);
     }
-    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)
+static unsigned contentLengthForSubtreeStayWithinBlockFlow(const RenderElement& renderer)
 {
-    if (is<RenderText>(renderer))
-        return downcast<RenderText>(renderer).text().length();
-    if (!is<RenderElement>(renderer))
-        return 0;
     unsigned textLength = 0;
-    for (const auto* child = downcast<RenderElement>(renderer).firstChild(); child; child = child->nextSibling())
-        textLength += textLengthForSubtree(*child);
+    for (auto& child : childrenOfType<RenderObject>(renderer)) {
+        if (is<RenderBlockFlow>(child)) {
+            // Do not descend into nested RenderBlockFlow.
+            continue;
+        }
+        if (is<RenderText>(child)) {
+            textLength += downcast<RenderText>(child).text().length();
+            continue;
+        }
+        textLength += contentLengthForSubtreeStayWithinBlockFlow(downcast<RenderElement>(child));
+    }
     return textLength;
 }
 
-static void collectNonEmptyLeafRenderBlockFlows(const RenderObject& renderer, HashSet<const RenderBlockFlow*>& leafRenderers)
+static unsigned contentLengthForBlockFlow(const RenderBlockFlow& blockFlow)
 {
-    if (is<RenderText>(renderer)) {
-        if (!downcast<RenderText>(renderer).text().length())
-            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);
+    return contentLengthForSubtreeStayWithinBlockFlow(blockFlow);
 }
 
-static void collectNonEmptyLeafRenderBlockFlowsForCurrentPage(HashSet<const RenderBlockFlow*>& leafRenderers)
+static Vector<const RenderBlockFlow*> collectRenderBlockFlowsForCurrentPage()
 {
+    Vector<const RenderBlockFlow*> renderFlows;
     for (const auto* document : Document::allDocuments()) {
         if (!document->renderView() || document->backForwardCacheState() != Document::NotInBackForwardCache)
             continue;
         if (!document->isHTMLDocument() && !document->isXHTMLDocument())
             continue;
-        collectNonEmptyLeafRenderBlockFlows(*document->renderView(), leafRenderers);
+        for (auto& descendant : descendantsOfType<RenderBlockFlow>(*document->renderView())) {
+            if (descendant.childrenInline())
+                renderFlows.append(&descendant);
+        }
     }
+    return renderFlows;
 }
 
 static void printModernLineLayoutBlockList(void)
 {
-    HashSet<const RenderBlockFlow*> leafRenderers;
-    collectNonEmptyLeafRenderBlockFlowsForCurrentPage(leafRenderers);
-    if (!leafRenderers.size()) {
+    auto renderBlockFlows = collectRenderBlockFlowsForCurrentPage();
+    if (!renderBlockFlows.size()) {
         WTFLogAlways("No text found in this document\n");
         return;
     }
     TextStream stream;
     stream << "---------------------------------------------------\n";
-    for (const auto* flow : leafRenderers) {
+    for (auto* flow : renderBlockFlows) {
         auto reasons = canUseForLineLayoutWithReason(*flow, IncludeReasons::All);
         if (reasons.isEmpty())
             continue;
@@ -288,7 +279,7 @@
         printTextForSubtree(*flow, printedLength, stream);
         for (;printedLength > 0; --printedLength)
             stream << " ";
-        stream << "\"(" << textLengthForSubtree(*flow) << "):";
+        stream << "\"(" << contentLengthForBlockFlow(*flow) << "):";
         printReasons(reasons, stream);
         stream << "\n";
     }
@@ -298,9 +289,8 @@
 
 static void printModernLineLayoutCoverage(void)
 {
-    HashSet<const RenderBlockFlow*> leafRenderers;
-    collectNonEmptyLeafRenderBlockFlowsForCurrentPage(leafRenderers);
-    if (!leafRenderers.size()) {
+    auto renderBlockFlows = collectRenderBlockFlowsForCurrentPage();
+    if (!renderBlockFlows.size()) {
         WTFLogAlways("No text found in this document\n");
         return;
     }
@@ -311,8 +301,8 @@
     unsigned numberOfUnsupportedLeafBlocks = 0;
     unsigned supportedButForcedToLineLayoutTextLength = 0;
     unsigned numberOfSupportedButForcedToLineLayoutLeafBlocks = 0;
-    for (const auto* flow : leafRenderers) {
-        auto flowLength = textLengthForSubtree(*flow);
+    for (auto* flow : renderBlockFlows) {
+        auto flowLength = contentLengthForBlockFlow(*flow);
         textLength += flowLength;
         auto reasons = canUseForLineLayoutWithReason(*flow, IncludeReasons::All);
         if (reasons.isEmpty()) {
@@ -322,6 +312,8 @@
             }
             continue;
         }
+        if (reasons.contains(AvoidanceReason::FlowDoesNotEstablishInlineFormattingContext))
+            continue;
         ++numberOfUnsupportedLeafBlocks;
         unsupportedTextLength += flowLength;
         for (auto reason : reasons) {
@@ -337,7 +329,7 @@
     } else
         stream << "Modern line layout coverage: " << (float)(textLength - unsupportedTextLength) / (float)textLength * 100 << "%";
     stream << "\n\n";
-    stream << "Number of blocks: total(" <<  leafRenderers.size() << ") legacy(" << numberOfUnsupportedLeafBlocks << ")\nContent length: total(" <<
+    stream << "Number of blocks: total(" <<  renderBlockFlows.size() << ") legacy(" << numberOfUnsupportedLeafBlocks << ")\nContent length: total(" <<
         textLength << ") legacy(" << unsupportedTextLength << ")\n";
     for (const auto& reasonEntry : flowStatistics) {
         printReason(static_cast<AvoidanceReason>(reasonEntry.key), stream);
@@ -528,8 +520,12 @@
         return reasons;
     }
 
-    if (is<RenderInline>(child))
-        return canUseForRenderInlineChild(downcast<RenderInline>(child), includeReasons);
+    if (is<RenderInline>(child)) {
+        auto renderInlineReasons = canUseForRenderInlineChild(downcast<RenderInline>(child), includeReasons);
+        if (renderInlineReasons)
+            ADD_REASONS_AND_RETURN_IF_NEEDED(renderInlineReasons, reasons, includeReasons);
+        return reasons;
+    }
 
     SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonSupportedChild, reasons, includeReasons);
     return reasons;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to