[LFC][IFC] Anonymous inline boxes/line break boxes do not generate Display::Boxes
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Feb 2020 14:15:00 +0000 (14:15 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Feb 2020 14:15:00 +0000 (14:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207802
<rdar://problem/59480138>

Reviewed by Antti Koivisto.

1. Painting should not expect a Display::Box per Layout::Box.
2. Do not generate empty Display::Boxes for anonymous inline text boxes/line breaks.

* layout/FormattingState.cpp:
(WebCore::Layout::FormattingState::displayBox):
* layout/displaytree/DisplayPainter.cpp:
(WebCore::Display::paintSubtree):
(WebCore::Display::collectPaintRootsAndContentRect):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutInFlowContent):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@256701 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingState.cpp
Source/WebCore/layout/displaytree/DisplayPainter.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

index 63ec97d..a4d8b3c 100644 (file)
@@ -1,3 +1,22 @@
+2020-02-15  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][IFC] Anonymous inline boxes/line break boxes do not generate Display::Boxes
+        https://bugs.webkit.org/show_bug.cgi?id=207802
+        <rdar://problem/59480138>
+
+        Reviewed by Antti Koivisto.
+
+        1. Painting should not expect a Display::Box per Layout::Box.
+        2. Do not generate empty Display::Boxes for anonymous inline text boxes/line breaks. 
+
+        * layout/FormattingState.cpp:
+        (WebCore::Layout::FormattingState::displayBox):
+        * layout/displaytree/DisplayPainter.cpp:
+        (WebCore::Display::paintSubtree):
+        (WebCore::Display::collectPaintRootsAndContentRect):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
+
 2020-02-14  Jon Lee  <jonlee@apple.com>
 
         Mask WebGL strings
index 97bcdd2..9517b6b 100644 (file)
@@ -52,6 +52,8 @@ Display::Box& FormattingState::displayBox(const Box& layoutBox)
 {
     // Should never need to mutate a display box outside of the formatting context.
     ASSERT(&layoutState().establishedFormattingState(layoutBox.formattingContextRoot()) == this);
+    // Anonymous text wrappers/line break boxes should not need display boxes.
+    ASSERT(!layoutBox.isInlineTextBox() && !layoutBox.isLineBreakBox());
     return layoutState().ensureDisplayBoxForLayoutBox(layoutBox);
 }
 
index 328e518..661777c 100644 (file)
@@ -168,6 +168,8 @@ static void paintSubtree(GraphicsContext& context, const Layout::LayoutState& la
     auto paint = [&] (auto& layoutBox) {
         if (layoutBox.style().visibility() != Visibility::Visible)
             return;
+        if (!layoutState.hasDisplayBox(layoutBox))
+            return;
         auto absoluteDisplayBox = Display::absoluteDisplayBox(layoutState, layoutBox);
         if (!dirtyRect.intersects(snappedIntRect(absoluteDisplayBox.rect())))
             return;
@@ -237,7 +239,8 @@ static LayoutRect collectPaintRootsAndContentRect(const Layout::LayoutState& lay
                 break;
             if (isPaintRootCandidate(layoutBox))
                 appendPaintRoot(layoutBox);
-            contentRect.uniteIfNonZero(Display::absoluteDisplayBox(layoutState, layoutBox).rect());
+            if (layoutState.hasDisplayBox(layoutBox))
+                contentRect.uniteIfNonZero(Display::absoluteDisplayBox(layoutState, layoutBox).rect());
             if (!is<Layout::ContainerBox>(layoutBox) || !downcast<Layout::ContainerBox>(layoutBox).hasChild())
                 break;
             layoutBoxList.append(downcast<Layout::ContainerBox>(layoutBox).firstChild());
index 9bdd846..fcd3b3b 100644 (file)
@@ -106,14 +106,8 @@ void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidatio
                 formattingContext->layoutOutOfFlowContent(invalidationState, horizontalConstraintsForOutOfFlow, verticalConstraintsForOutOfFlow);
             }
         } else if (layoutBox->isInlineBox()) {
-            if (layoutBox->isAnonymous() || layoutBox->isLineBreakBox()) {
-                // Text wrapper boxes are anonymous inline level boxes. Their computed border/padding/margins are 0.
-                auto& displayBox = formattingState().displayBox(*layoutBox);
-                displayBox.setVerticalMargin({ { }, { } });
-                displayBox.setHorizontalMargin({ });
-                displayBox.setBorder({ { }, { } });
-                displayBox.setPadding({ });
-            } else {
+            // Text wrapper boxes (anonymous inline level boxes) and <br>s don't generate display boxes (only display runs).
+            if (!layoutBox->isAnonymous() && !layoutBox->isLineBreakBox()) {
                 // Inline boxes (<span>) can't get sized/positioned yet. At this point we can only compute their margins, borders and paddings.
                 computeBorderAndPadding(*layoutBox, horizontalConstraints);
                 computeHorizontalMargin(*layoutBox, horizontalConstraints);