Title: [255118] trunk/Source/WebCore
Revision
255118
Author
za...@apple.com
Date
2020-01-25 07:57:09 -0800 (Sat, 25 Jan 2020)

Log Message

[LFC][IFC] Layout logic should be driven by the type of the inline box
https://bugs.webkit.org/show_bug.cgi?id=206792
<rdar://problem/58889080>

Reviewed by Antti Koivisto.

Use the type of the inline box to decide what layout functions to call and not whether the
box has children or it establishes a formatting context.

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::nextInPreOrder):
(WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
(WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthForFormattingRoot):
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::isVisuallyNonEmpty const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (255117 => 255118)


--- trunk/Source/WebCore/ChangeLog	2020-01-25 14:16:30 UTC (rev 255117)
+++ trunk/Source/WebCore/ChangeLog	2020-01-25 15:57:09 UTC (rev 255118)
@@ -1,3 +1,22 @@
+2020-01-25  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Layout logic should be driven by the type of the inline box
+        https://bugs.webkit.org/show_bug.cgi?id=206792
+        <rdar://problem/58889080>
+
+        Reviewed by Antti Koivisto.
+
+        Use the type of the inline box to decide what layout functions to call and not whether the
+        box has children or it establishes a formatting context.
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::nextInPreOrder):
+        (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
+        (WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthForFormattingRoot):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineLineBuilder.cpp:
+        (WebCore::Layout::LineBuilder::isVisuallyNonEmpty const):
+
 2020-01-25  Antti Koivisto  <an...@apple.com>
 
         [LFC][Integration] Re-enable line layout integration

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (255117 => 255118)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-01-25 14:16:30 UTC (rev 255117)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-01-25 15:57:09 UTC (rev 255118)
@@ -53,13 +53,20 @@
 {
 }
 
-static inline const Box* nextInPreOrder(const Box& layoutBox, const Container& stayWithin)
+static inline const Box* nextInlineLevelBoxToLayout(const Box& layoutBox, const Container& stayWithin)
 {
-    const Box* nextInPreOrder = nullptr;
-    if (!layoutBox.establishesFormattingContext() && is<Container>(layoutBox) && downcast<Container>(layoutBox).hasInFlowOrFloatingChild())
-        return downcast<Container>(layoutBox).firstInFlowOrFloatingChild();
+    // Atomic inline-level boxes and floats are opaque boxes meaning that they are
+    // responsible for their own content (do not need to descend into their subtrees).
+    // Only inline boxes may have relevant descendant content.
+    if (layoutBox.isInlineBox()) {
+        if (is<Container>(layoutBox) && downcast<Container>(layoutBox).hasInFlowOrFloatingChild()) {
+            // Anonymous inline boxes/line breaks can't have descendant content by definition.
+            ASSERT(!layoutBox.isAnonymous() && !layoutBox.isLineBreakBox());
+            return downcast<Container>(layoutBox).firstInFlowOrFloatingChild();
+        }
+    }
 
-    for (nextInPreOrder = &layoutBox; nextInPreOrder && nextInPreOrder != &stayWithin; nextInPreOrder = nextInPreOrder->parent()) {
+    for (auto* nextInPreOrder = &layoutBox; nextInPreOrder && nextInPreOrder != &stayWithin; nextInPreOrder = nextInPreOrder->parent()) {
         if (auto* nextSibling = nextInPreOrder->nextInFlowOrFloatingSibling())
             return nextSibling;
     }
@@ -113,7 +120,7 @@
         } else
             ASSERT_NOT_REACHED();
 
-        layoutBox = nextInPreOrder(*layoutBox, root());
+        layoutBox = nextInlineLevelBoxToLayout(*layoutBox, root());
     }
 
     collectInlineContentIfNeeded();
@@ -175,22 +182,28 @@
     Vector<const Box*> formattingContextRootList;
     auto horizontalConstraints = HorizontalConstraints { 0_lu, 0_lu };
     auto* layoutBox = root().firstInFlowOrFloatingChild();
+    // In order to compute the max/min widths, we need to compute margins, borders and paddings for certain inline boxes first.
     while (layoutBox) {
-        if (layoutBox->establishesFormattingContext()) {
+        if (layoutBox->isAnonymous()) {
+            layoutBox = nextInlineLevelBoxToLayout(*layoutBox, root());
+            continue;
+        }
+        if (layoutBox->isReplaced()) {
+            computeBorderAndPadding(*layoutBox, horizontalConstraints);
+            computeWidthAndMargin(*layoutBox, horizontalConstraints);
+        } else if (layoutBox->isFloatingPositioned() || layoutBox->isAtomicInlineLevelBox()) {
+            ASSERT(layoutBox->establishesFormattingContext());
             formattingContextRootList.append(layoutBox);
-            computeIntrinsicWidthForFormattingRoot(*layoutBox, horizontalConstraints);
-        } else if (layoutBox->isReplaced() || (layoutBox->isInlineBox() && !layoutBox->isAnonymous())) {
+
             computeBorderAndPadding(*layoutBox, horizontalConstraints);
-            // inline-block and replaced.
-            auto needsWidthComputation = layoutBox->isReplaced();
-            if (needsWidthComputation)
-                computeWidthAndMargin(*layoutBox, horizontalConstraints);
-            else {
-                // Simple inline container with no intrinsic width <span>.
-                computeHorizontalMargin(*layoutBox, horizontalConstraints);
-            }
-        }
-        layoutBox = nextInPreOrder(*layoutBox, root());
+            computeHorizontalMargin(*layoutBox, horizontalConstraints);
+            computeIntrinsicWidthForFormattingRoot(*layoutBox);
+        } else if (layoutBox->isInlineBox()) {
+            computeBorderAndPadding(*layoutBox, horizontalConstraints);
+            computeHorizontalMargin(*layoutBox, horizontalConstraints);
+        } else
+            ASSERT_NOT_REACHED();
+        layoutBox = nextInlineLevelBoxToLayout(*layoutBox, root());
     }
 
     collectInlineContentIfNeeded();
@@ -232,13 +245,9 @@
     return maximumLineWidth;
 }
 
-void InlineFormattingContext::computeIntrinsicWidthForFormattingRoot(const Box& formattingRoot, const HorizontalConstraints& horizontalConstraints)
+void InlineFormattingContext::computeIntrinsicWidthForFormattingRoot(const Box& formattingRoot)
 {
     ASSERT(formattingRoot.establishesFormattingContext());
-
-    computeBorderAndPadding(formattingRoot, horizontalConstraints);
-    computeHorizontalMargin(formattingRoot, horizontalConstraints);
-
     auto constraints = IntrinsicWidthConstraints { };
     if (auto fixedWidth = geometry().fixedValue(formattingRoot.style().logicalWidth()))
         constraints = { *fixedWidth, *fixedWidth };

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (255117 => 255118)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2020-01-25 14:16:30 UTC (rev 255117)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2020-01-25 15:57:09 UTC (rev 255118)
@@ -79,7 +79,7 @@
 
     void lineLayout(InlineItems&, LineLayoutContext::InlineItemRange, const HorizontalConstraints&, const VerticalConstraints&);
 
-    void computeIntrinsicWidthForFormattingRoot(const Box&, const HorizontalConstraints&);
+    void computeIntrinsicWidthForFormattingRoot(const Box&);
     InlineLayoutUnit computedIntrinsicWidthForConstraint(const HorizontalConstraints&) const;
 
     void computeHorizontalMargin(const Box&, const HorizontalConstraints&);

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp (255117 => 255118)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-01-25 14:16:30 UTC (rev 255117)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-01-25 15:57:09 UTC (rev 255118)
@@ -644,9 +644,9 @@
     }
 
     if (run.isBox()) {
-        if (!run.layoutBox().establishesFormattingContext())
+        if (run.layoutBox().isReplaced())
             return true;
-        ASSERT(run.layoutBox().isInlineBlockBox());
+        ASSERT(run.layoutBox().isInlineBlockBox() || run.layoutBox().isInlineTableBox());
         if (!run.logicalWidth())
             return false;
         if (m_isIntrinsicSizing || formattingContext().geometryForBox(run.layoutBox()).height())
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to