[LFC] Remove redundant InlineFormattingContext::computeBorderAndPadding
[WebKit-https.git] / Source / WebCore / layout / inlineformatting / InlineFormattingContext.cpp
index 93762c6..fb982b3 100644 (file)
@@ -71,7 +71,7 @@ void InlineFormattingContext::layout() const
 
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
     auto& root = downcast<Container>(this->root());
-    auto usedValues = UsedHorizontalValues { layoutState().displayBoxForLayoutBox(root).contentBoxWidth(), { }, { } };
+    auto usedValues = UsedHorizontalValues { layoutState().displayBoxForLayoutBox(root).contentBoxWidth() };
     auto* layoutBox = root.firstInFlowOrFloatingChild();
     // Compute width/height for non-text content and margin/border/padding for inline containers.
     while (layoutBox) {
@@ -92,24 +92,26 @@ void InlineFormattingContext::layout() const
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root << ")");
 }
 
-FormattingContext::InstrinsicWidthConstraints InlineFormattingContext::instrinsicWidthConstraints() const
+void InlineFormattingContext::computeIntrinsicWidthConstraints() const
 {
     ASSERT(is<Container>(root()));
 
     auto& layoutState = this->layoutState();
     auto& root = downcast<Container>(this->root());
-    if (auto instrinsicWidthConstraints = layoutState.formattingStateForBox(root).instrinsicWidthConstraints(root))
-        return *instrinsicWidthConstraints;
+    ASSERT(!layoutState.formattingStateForBox(root).intrinsicWidthConstraints(root));
 
     Vector<const Box*> formattingContextRootList;
     auto usedValues = UsedHorizontalValues { };
     auto* layoutBox = root.firstInFlowOrFloatingChild();
     while (layoutBox) {
-        if (layoutBox->isFloatingPositioned())
-            ASSERT_NOT_IMPLEMENTED_YET();
-        else if (layoutBox->isInlineBlockBox()) {
-            computeIntrinsicWidthForFormattingContextRoot(*layoutBox);
+        if (layoutBox->establishesFormattingContext()) {
             formattingContextRootList.append(layoutBox);
+            if (layoutBox->isFloatingPositioned())
+                computeIntrinsicWidthForFloatBox(*layoutBox);
+            else if (layoutBox->isInlineBlockBox())
+                computeIntrinsicWidthForInlineBlock(*layoutBox);
+            else
+                ASSERT_NOT_REACHED();
         } else if (layoutBox->isReplaced() || is<Container>(*layoutBox)) {
             computeBorderAndPadding(*layoutBox, usedValues);
             // inline-block and replaced.
@@ -118,7 +120,7 @@ FormattingContext::InstrinsicWidthConstraints InlineFormattingContext::instrinsi
                 computeWidthAndMargin(*layoutBox, usedValues);
             else {
                 // Simple inline container with no intrinsic width <span>.
-                computeMargin(downcast<InlineContainer>(*layoutBox), usedValues);
+                computeMargin(*layoutBox, usedValues);
             }
         }
         layoutBox = nextInPreOrder(*layoutBox, root);
@@ -134,8 +136,8 @@ FormattingContext::InstrinsicWidthConstraints InlineFormattingContext::instrinsi
 
         // Switch to the min/max formatting root width values before formatting the lines.
         for (auto* formattingRoot : formattingContextRootList) {
-            auto instrinsicWidths = layoutState.formattingStateForBox(*formattingRoot).instrinsicWidthConstraints(*formattingRoot);
-            layoutState.displayBoxForLayoutBox(*formattingRoot).setContentBoxWidth(availableWidth ? instrinsicWidths->maximum : instrinsicWidths->minimum);
+            auto intrinsicWidths = layoutState.formattingStateForBox(*formattingRoot).intrinsicWidthConstraints(*formattingRoot);
+            layoutState.displayBoxForLayoutBox(*formattingRoot).setContentBoxWidth(availableWidth ? intrinsicWidths->maximum : intrinsicWidths->minimum);
         }
 
         while (auto run = lineBreaker.nextRun(lineLogicalRight, availableWidth, !lineLogicalRight)) {
@@ -148,37 +150,44 @@ FormattingContext::InstrinsicWidthConstraints InlineFormattingContext::instrinsi
         return maxContentLogicalRight;
     };
 
-    auto instrinsicWidthConstraints = FormattingContext::InstrinsicWidthConstraints { maximumLineWidth(0), maximumLineWidth(LayoutUnit::max()) };
-    layoutState.formattingStateForBox(root).setInstrinsicWidthConstraints(root, instrinsicWidthConstraints);
-    return instrinsicWidthConstraints;
+    auto intrinsicWidthConstraints = FormattingContext::IntrinsicWidthConstraints { maximumLineWidth(0), maximumLineWidth(LayoutUnit::max()) };
+    layoutState.formattingStateForBox(root).setIntrinsicWidthConstraints(root, intrinsicWidthConstraints);
 }
 
-void InlineFormattingContext::computeIntrinsicWidthForFormattingContextRoot(const Box& layoutBox) const
+void InlineFormattingContext::computeIntrinsicWidthForFloatBox(const Box& layoutBox) const
 {
-    ASSERT(layoutBox.establishesFormattingContext());
+    ASSERT(layoutBox.isFloatingPositioned());
+    auto& layoutState = this->layoutState();
 
-    auto usedValues = UsedHorizontalValues { };
-    computeBorderAndPadding(layoutBox, usedValues);
-    computeMargin(downcast<InlineContainer>(layoutBox), usedValues);
-    layoutState().createFormattingContext(layoutBox)->instrinsicWidthConstraints();
+    auto usedHorizontalValues = UsedHorizontalValues { };
+    computeBorderAndPadding(layoutBox, usedHorizontalValues);
+    computeMargin(layoutBox, usedHorizontalValues);
+    layoutState.createFormattingContext(layoutBox)->computeIntrinsicWidthConstraints();
+
+    auto usedVerticalValues = UsedVerticalValues { };
+    auto heightAndMargin = Geometry::floatingHeightAndMargin(layoutState, layoutBox, usedVerticalValues, usedHorizontalValues);
+
+    auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
+    displayBox.setContentBoxHeight(heightAndMargin.height);
+    displayBox.setVerticalMargin({ heightAndMargin.nonCollapsedMargin, { } });
 }
 
-void InlineFormattingContext::computeMargin(const InlineContainer& inlineContainer, UsedHorizontalValues usedValues) const
+void InlineFormattingContext::computeIntrinsicWidthForInlineBlock(const Box& layoutBox) const
 {
-    // Non-replaced and formatting root containers (<span></span>) don't have width property -> non width computation.
-    ASSERT(!inlineContainer.replaced());
+    ASSERT(layoutBox.isInlineBlockBox());
 
-    auto& displayBox = layoutState().displayBoxForLayoutBox(inlineContainer);
-    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(inlineContainer, usedValues);
-    displayBox.setHorizontalComputedMargin(computedHorizontalMargin);
-    displayBox.setHorizontalMargin({ computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) });
+    auto usedValues = UsedHorizontalValues { };
+    computeBorderAndPadding(layoutBox, usedValues);
+    computeMargin(layoutBox, usedValues);
+    layoutState().createFormattingContext(layoutBox)->computeIntrinsicWidthConstraints();
 }
 
-void InlineFormattingContext::computeBorderAndPadding(const Box& layoutBox, UsedHorizontalValues usedValues) const
+void InlineFormattingContext::computeMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
 {
+    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
     auto& displayBox = layoutState().displayBoxForLayoutBox(layoutBox);
-    displayBox.setBorder(Geometry::computedBorder(layoutBox));
-    displayBox.setPadding(Geometry::computedPadding(layoutBox, usedValues));
+    displayBox.setHorizontalComputedMargin(computedHorizontalMargin);
+    displayBox.setHorizontalMargin({ computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) });
 }
 
 void InlineFormattingContext::computeWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
@@ -206,7 +215,7 @@ void InlineFormattingContext::computeHeightAndMargin(const Box& layoutBox) const
 
     HeightAndMargin heightAndMargin;
     if (layoutBox.isFloatingPositioned())
-        heightAndMargin = Geometry::floatingHeightAndMargin(layoutState, layoutBox, { });
+        heightAndMargin = Geometry::floatingHeightAndMargin(layoutState, layoutBox, { }, UsedHorizontalValues { layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).contentBoxWidth() });
     else if (layoutBox.isInlineBlockBox())
         heightAndMargin = Geometry::inlineBlockHeightAndMargin(layoutState, layoutBox);
     else if (layoutBox.replaced())