Title: [249903] trunk/Source/WebCore
Revision
249903
Author
[email protected]
Date
2019-09-16 09:56:35 -0700 (Mon, 16 Sep 2019)

Log Message

[LFC] Always provide a containing block width value to compute* functions.
https://bugs.webkit.org/show_bug.cgi?id=201809
<rdar://problem/55383153>

Reviewed by Antti Koivisto.

The caller can always make a more informative decision about the default value when the containing block width is not available.
(Currently the only case is when computing the preferred width.)

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeBorderAndPadding):
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry const):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry const):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry const):
(WebCore::Layout::FormattingContext::Geometry::floatingNonReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin const):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin const):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin const):
(WebCore::Layout::FormattingContext::Geometry::inFlowPositionedPositionOffset const):
(WebCore::Layout::FormattingContext::Geometry::computedPadding const):
(WebCore::Layout::FormattingContext::Geometry::computedHorizontalMargin const):
(WebCore::Layout::FormattingContext::Geometry::computedVerticalMargin const):
* layout/LayoutUnits.h:
(WebCore::Layout::UsedHorizontalValues::UsedHorizontalValues):
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin const):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
(WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthForFormattingRoot):
(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot):
(WebCore::Layout::InlineFormattingContext::computeWidthAndHeightForReplacedInlineBox):
* layout/inlineformatting/InlineFormattingContextGeometry.cpp:
(WebCore::Layout::InlineFormattingContext::Geometry::inlineBlockWidthAndMargin):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (249902 => 249903)


--- trunk/Source/WebCore/ChangeLog	2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/ChangeLog	2019-09-16 16:56:35 UTC (rev 249903)
@@ -1,5 +1,45 @@
 2019-09-16  Zalan Bujtas  <[email protected]>
 
+        [LFC] Always provide a containing block width value to compute* functions.
+        https://bugs.webkit.org/show_bug.cgi?id=201809
+        <rdar://problem/55383153>
+
+        Reviewed by Antti Koivisto.
+
+        The caller can always make a more informative decision about the default value when the containing block width is not available.
+        (Currently the only case is when computing the preferred width.)
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeBorderAndPadding):
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry const):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry const):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry const):
+        (WebCore::Layout::FormattingContext::Geometry::floatingNonReplacedWidthAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::inFlowPositionedPositionOffset const):
+        (WebCore::Layout::FormattingContext::Geometry::computedPadding const):
+        (WebCore::Layout::FormattingContext::Geometry::computedHorizontalMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::computedVerticalMargin const):
+        * layout/LayoutUnits.h:
+        (WebCore::Layout::UsedHorizontalValues::UsedHorizontalValues):
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin const):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
+        (WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthForFormattingRoot):
+        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot):
+        (WebCore::Layout::InlineFormattingContext::computeWidthAndHeightForReplacedInlineBox):
+        * layout/inlineformatting/InlineFormattingContextGeometry.cpp:
+        (WebCore::Layout::InlineFormattingContext::Geometry::inlineBlockWidthAndMargin):
+
+2019-09-16  Zalan Bujtas  <[email protected]>
+
         [LFC][BFC] BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin should not read containing block's width
         https://bugs.webkit.org/show_bug.cgi?id=201807
         <rdar://problem/55381342>

Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (249902 => 249903)


--- trunk/Source/WebCore/layout/FormattingContext.cpp	2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp	2019-09-16 16:56:35 UTC (rev 249903)
@@ -128,13 +128,13 @@
     displayBox.setVerticalMargin({ nonCollapsedVerticalMargin, { } });
 }
 
-void FormattingContext::computeBorderAndPadding(const Box& layoutBox, Optional<UsedHorizontalValues> usedValues)
+void FormattingContext::computeBorderAndPadding(const Box& layoutBox, Optional<UsedHorizontalValues> usedHorizontalValues)
 {
-    if (!usedValues)
-        usedValues = UsedHorizontalValues { geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() };
+    if (!usedHorizontalValues)
+        usedHorizontalValues = UsedHorizontalValues { geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() };
     auto& displayBox = formattingState().displayBox(layoutBox);
     displayBox.setBorder(geometry().computedBorder(layoutBox));
-    displayBox.setPadding(geometry().computedPadding(layoutBox, *usedValues));
+    displayBox.setPadding(geometry().computedPadding(layoutBox, *usedHorizontalValues));
 }
 
 void FormattingContext::layoutOutOfFlowContent()

Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (249902 => 249903)


--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2019-09-16 16:56:35 UTC (rev 249903)
@@ -245,11 +245,10 @@
     return left - paddingBoxLeft;
 }
 
-LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(const Box& formattingRoot, UsedHorizontalValues usedValues)
+LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(const Box& formattingRoot, UsedHorizontalValues usedHorizontalValues)
 {
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width] -> shrink to fit -> unsupported -> width(" << LayoutUnit { } << "px) layoutBox: " << &formattingRoot << ")");
     ASSERT(formattingRoot.establishesFormattingContext());
-    ASSERT(usedValues.containingBlockWidth.hasValue());
 
     // Calculation of the shrink-to-fit width is similar to calculating the width of a table cell using the automatic table layout algorithm.
     // Roughly: calculate the preferred width by formatting the content without breaking lines other than where explicit line breaks occur,
@@ -268,7 +267,7 @@
         else
             intrinsicWidthConstraints = *precomputedIntrinsicWidthConstraints;
     }
-    auto availableWidth = *usedValues.containingBlockWidth;
+    auto availableWidth = usedHorizontalValues.containingBlockWidth;
     return std::min(std::max(intrinsicWidthConstraints.minimum, availableWidth), intrinsicWidthConstraints.maximum);
 }
 
@@ -276,7 +275,6 @@
 {
     ASSERT(layoutBox.isOutOfFlowPositioned() && !layoutBox.replaced());
     ASSERT(usedVerticalValues.containingBlockHeight);
-    ASSERT(usedHorizontalValues.containingBlockWidth);
 
     // 10.6.4 Absolutely positioned, non-replaced elements
     //
@@ -306,7 +304,7 @@
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
     auto containingBlockHeight = *usedVerticalValues.containingBlockHeight;
-    auto containingBlockWidth = *usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
 
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -396,7 +394,7 @@
     return { *top, *bottom, { contentHeight(), usedVerticalMargin } };
 }
 
-HorizontalGeometry FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedValues)
+HorizontalGeometry FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues)
 {
     ASSERT(layoutBox.isOutOfFlowPositioned() && !layoutBox.replaced());
     
@@ -429,15 +427,13 @@
     auto& formattingContext = this->formattingContext();
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
-    auto& containingBlock = *layoutBox.containingBlock();
-    auto& containingBlockGeometry = formattingContext.geometryForBox(containingBlock);
-    auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
-    auto isLeftToRightDirection = containingBlock.style().isLeftToRightDirection();
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
     
     auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
     auto right = computedValueIfNotAuto(style.logicalRight(), containingBlockWidth);
-    auto width = computedValueIfNotAuto(usedValues.width ? Length { usedValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
-    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+    auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
+    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
     UsedHorizontalMargin usedHorizontalMargin;
     auto paddingLeft = boxGeometry.paddingLeft().valueOr(0);
     auto paddingRight = boxGeometry.paddingRight().valueOr(0);
@@ -502,7 +498,7 @@
         // Calculate the available width by solving for 'width' after setting 'left' (in case 1) to 0
         left = LayoutUnit { 0 };
         auto availableWidth = containingBlockWidth - (*left + usedHorizontalMargin.start + borderLeft + paddingLeft + paddingRight + borderRight + usedHorizontalMargin.end + *right);
-        width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedValues.width, usedValues.margin });
+        width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedHorizontalValues.width, usedHorizontalValues.margin });
         left = containingBlockWidth - (usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight  + borderRight + usedHorizontalMargin.end + *right);
     } else if (!left && !right && width) {
         // #2
@@ -519,7 +515,7 @@
         // Calculate the available width by solving for 'width' after setting 'right' (in case 3) to 0
         right = LayoutUnit { 0 };
         auto availableWidth = containingBlockWidth - (*left + usedHorizontalMargin.start + borderLeft + paddingLeft + paddingRight + borderRight + usedHorizontalMargin.end + *right);
-        width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedValues.width, usedValues.margin });
+        width = shrinkToFitWidth(layoutBox, UsedHorizontalValues { availableWidth, usedHorizontalValues.width, usedHorizontalValues.margin });
         right = containingBlockWidth - (*left + usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight + borderRight + usedHorizontalMargin.end);
     } else if (!left && width && right) {
         // #4
@@ -538,7 +534,7 @@
 
     // For out-of-flow elements the containing block is formed by the padding edge of the ancestor.
     // At this point the positioned value is in the coordinate system of the padding box. Let's convert it to border box coordinate system.
-    auto containingBlockPaddingVerticalEdge = containingBlockGeometry.paddingBoxLeft();
+    auto containingBlockPaddingVerticalEdge = formattingContext.geometryForBox(*layoutBox.containingBlock()).paddingBoxLeft();
     *left += containingBlockPaddingVerticalEdge;
     *right += containingBlockPaddingVerticalEdge;
 
@@ -550,7 +546,6 @@
 {
     ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
     ASSERT(usedVerticalValues.containingBlockHeight);
-    ASSERT(usedHorizontalValues.containingBlockWidth);
 
     // 10.6.5 Absolutely positioned, replaced elements
     //
@@ -566,7 +561,7 @@
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
     auto containingBlockHeight = *usedVerticalValues.containingBlockHeight;
-    auto containingBlockWidth = *usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
 
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -629,7 +624,7 @@
     return { *top, *bottom, { height, { *usedMarginBefore, *usedMarginAfter } } };
 }
 
-HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedValues) const
+HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
 
@@ -650,16 +645,15 @@
     auto& formattingContext = this->formattingContext();
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
-    auto& containingBlock = *layoutBox.containingBlock();
-    auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
-    auto isLeftToRightDirection = containingBlock.style().isLeftToRightDirection();
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
 
     auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
     auto right = computedValueIfNotAuto(style.logicalRight(), containingBlockWidth);
-    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
     Optional<LayoutUnit> usedMarginStart = computedHorizontalMargin.start;
     Optional<LayoutUnit> usedMarginEnd = computedHorizontalMargin.end;
-    auto width = inlineReplacedWidthAndMargin(layoutBox, usedValues).width;
+    auto width = inlineReplacedWidthAndMargin(layoutBox, usedHorizontalValues).width;
     auto paddingLeft = boxGeometry.paddingLeft().valueOr(0);
     auto paddingRight = boxGeometry.paddingRight().valueOr(0);
     auto borderLeft = boxGeometry.borderLeft();
@@ -726,7 +720,7 @@
 
     // For out-of-flow elements the containing block is formed by the padding edge of the ancestor.
     // At this point the positioned value is in the coordinate system of the padding box. Let's convert it to border box coordinate system.
-    auto containingBlockPaddingVerticalEdge = formattingContext.geometryForBox(containingBlock).paddingBoxLeft();
+    auto containingBlockPaddingVerticalEdge = formattingContext.geometryForBox(*layoutBox.containingBlock()).paddingBoxLeft();
     *left += containingBlockPaddingVerticalEdge;
     *right += containingBlockPaddingVerticalEdge;
 
@@ -765,7 +759,7 @@
     return HeightAndMargin { *height, usedVerticalMargin };
 }
 
-WidthAndMargin FormattingContext::Geometry::floatingNonReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues)
+WidthAndMargin FormattingContext::Geometry::floatingNonReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues)
 {
     ASSERT(layoutBox.isFloatingPositioned() && !layoutBox.replaced());
 
@@ -774,14 +768,14 @@
     // 1. If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'.
     // 2. If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width.
 
-    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
 
     // #1
     auto usedHorizontallMargin = UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) };
     // #2
-    auto width = computedValueIfNotAuto(usedValues.width ? Length { usedValues.width.value(), Fixed } : layoutBox.style().logicalWidth(), usedValues.containingBlockWidth.valueOr(0));
+    auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : layoutBox.style().logicalWidth(), usedHorizontalValues.containingBlockWidth);
     if (!width)
-        width = shrinkToFitWidth(layoutBox, usedValues);
+        width = shrinkToFitWidth(layoutBox, usedHorizontalValues);
 
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> floating non-replaced -> width(" << *width << "px) margin(" << usedHorizontallMargin.start << "px, " << usedHorizontallMargin.end << "px) -> layoutBox(" << &layoutBox << ")");
     return WidthAndMargin { *width, usedHorizontallMargin, computedHorizontalMargin };
@@ -797,7 +791,7 @@
     return inlineReplacedHeightAndMargin(layoutBox, usedHorizontalValues, usedVerticalValues);
 }
 
-WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     ASSERT(layoutBox.isFloatingPositioned() && layoutBox.replaced());
 
@@ -805,11 +799,11 @@
     //
     // 1. If 'margin-left' or 'margin-right' are computed as 'auto', their used value is '0'.
     // 2. The used value of 'width' is determined as for inline replaced elements.
-    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
 
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> floating replaced -> redirected to inline replaced");
-    return inlineReplacedWidthAndMargin(layoutBox, UsedHorizontalValues { usedValues.containingBlockWidth.valueOr(0),
-        usedValues.width, UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) } });
+    return inlineReplacedWidthAndMargin(layoutBox, UsedHorizontalValues { usedHorizontalValues.containingBlockWidth,
+        usedHorizontalValues.width, UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) } });
 }
 
 VerticalGeometry FormattingContext::Geometry::outOfFlowVerticalGeometry(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues, UsedVerticalValues usedVerticalValues) const
@@ -851,7 +845,6 @@
 HeightAndMargin FormattingContext::Geometry::inlineReplacedHeightAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues, UsedVerticalValues usedVerticalValues) const
 {
     ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
-    ASSERT(usedHorizontalValues.containingBlockWidth);
 
     // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements
     //
@@ -895,7 +888,7 @@
     return { *height, usedVerticalMargin };
 }
 
-WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
 
@@ -919,18 +912,18 @@
     //    If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.
 
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
-    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedValues);
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
 
     auto usedMarginStart = [&] {
-        if (usedValues.margin)
-            return usedValues.margin->start;
+        if (usedHorizontalValues.margin)
+            return usedHorizontalValues.margin->start;
         return computedHorizontalMargin.start.valueOr(0_lu);
     };
 
     auto usedMarginEnd = [&] {
-        if (usedValues.margin)
-            return usedValues.margin->end;
+        if (usedHorizontalValues.margin)
+            return usedHorizontalValues.margin->end;
         return computedHorizontalMargin.end.valueOr(0_lu);
     };
 
@@ -937,7 +930,7 @@
     auto replaced = layoutBox.replaced();
     ASSERT(replaced);
 
-    auto width = computedValueIfNotAuto(usedValues.width ? Length { usedValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
+    auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
     auto heightIsAuto = isHeightAuto(layoutBox);
     auto height = computedHeightValue(layoutBox, HeightType::Normal);
 
@@ -969,7 +962,6 @@
 LayoutSize FormattingContext::Geometry::inFlowPositionedPositionOffset(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     ASSERT(layoutBox.isInFlowPositioned());
-    ASSERT(usedHorizontalValues.containingBlockWidth);
 
     // 9.4.3 Relative positioning
     //
@@ -981,8 +973,7 @@
     // 3. If neither is 'auto', 'bottom' is ignored (i.e., the used value of 'bottom' will be minus the value of 'top').
 
     auto& style = layoutBox.style();
-    auto& containingBlock = *layoutBox.containingBlock();
-    auto containingBlockWidth = *usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
 
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -1026,7 +1017,7 @@
         right = -*left;
     } else {
         // #4
-        auto isLeftToRightDirection = containingBlock.style().isLeftToRightDirection();
+        auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
         if (isLeftToRightDirection)
             right = -*left;
         else
@@ -1053,13 +1044,13 @@
     };
 }
 
-Optional<Edges> FormattingContext::Geometry::computedPadding(const Box& layoutBox, UsedHorizontalValues usedValues) const
+Optional<Edges> FormattingContext::Geometry::computedPadding(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     if (!layoutBox.isPaddingApplicable())
         return WTF::nullopt;
 
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Padding] -> layoutBox: " << &layoutBox);
     return Edges {
         { valueForLength(style.paddingLeft(), containingBlockWidth), valueForLength(style.paddingRight(), containingBlockWidth) },
@@ -1067,17 +1058,17 @@
     };
 }
 
-ComputedHorizontalMargin FormattingContext::Geometry::computedHorizontalMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+ComputedHorizontalMargin FormattingContext::Geometry::computedHorizontalMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
     return { computedValueIfNotAuto(style.marginStart(), containingBlockWidth), computedValueIfNotAuto(style.marginEnd(), containingBlockWidth) };
 }
 
-ComputedVerticalMargin FormattingContext::Geometry::computedVerticalMargin(const Box& layoutBox, UsedHorizontalValues usedValues) const
+ComputedVerticalMargin FormattingContext::Geometry::computedVerticalMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedValues.containingBlockWidth.valueOr(0);
+    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
     return { computedValueIfNotAuto(style.marginBefore(), containingBlockWidth), computedValueIfNotAuto(style.marginAfter(), containingBlockWidth) };
 }
 

Modified: trunk/Source/WebCore/layout/LayoutUnits.h (249902 => 249903)


--- trunk/Source/WebCore/layout/LayoutUnits.h	2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/layout/LayoutUnits.h	2019-09-16 16:56:35 UTC (rev 249903)
@@ -138,16 +138,12 @@
 };
 
 struct UsedHorizontalValues {
-    explicit UsedHorizontalValues()
-        {
-        }
-
     explicit UsedHorizontalValues(LayoutUnit containingBlockWidth)
         : containingBlockWidth(containingBlockWidth)
         {
         }
 
-    explicit UsedHorizontalValues(Optional<LayoutUnit> containingBlockWidth, Optional<LayoutUnit> width, Optional<UsedHorizontalMargin> margin)
+    explicit UsedHorizontalValues(LayoutUnit containingBlockWidth, Optional<LayoutUnit> width, Optional<UsedHorizontalMargin> margin)
         : containingBlockWidth(containingBlockWidth)
         , width(width)
         , margin(margin)
@@ -154,7 +150,7 @@
         {
         }
 
-    Optional<LayoutUnit> containingBlockWidth;
+    LayoutUnit containingBlockWidth;
     Optional<LayoutUnit> width;
     Optional<UsedHorizontalMargin> margin;
 };

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (249902 => 249903)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2019-09-16 16:56:35 UTC (rev 249903)
@@ -41,7 +41,6 @@
 {
     ASSERT(layoutBox.isInFlow() && !layoutBox.replaced());
     ASSERT(layoutBox.isOverflowVisible());
-    ASSERT(usedHorizontalValues.containingBlockWidth);
 
     auto compute = [&]() -> HeightAndMargin {
 
@@ -113,7 +112,6 @@
 WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     ASSERT(layoutBox.isInFlow());
-    ASSERT(usedHorizontalValues.containingBlockWidth);
 
     auto compute = [&]() {
 
@@ -139,7 +137,7 @@
         //    edges of the containing block.
 
         auto& style = layoutBox.style();
-        auto containingBlockWidth = *usedHorizontalValues.containingBlockWidth;
+        auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
         auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
 
         auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (249902 => 249903)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-09-16 16:56:35 UTC (rev 249903)
@@ -107,7 +107,7 @@
     }
 
     Vector<const Box*> formattingContextRootList;
-    auto usedValues = UsedHorizontalValues { };
+    auto usedValues = UsedHorizontalValues { LayoutUnit { } };
     auto* layoutBox = root().firstInFlowOrFloatingChild();
     while (layoutBox) {
         if (layoutBox->establishesFormattingContext()) {
@@ -168,7 +168,7 @@
 {
     ASSERT(formattingRoot.establishesFormattingContext());
 
-    auto usedValues = UsedHorizontalValues { };
+    auto usedValues = UsedHorizontalValues { LayoutUnit { } };
     computeBorderAndPadding(formattingRoot, usedValues);
     computeHorizontalMargin(formattingRoot, usedValues);
 
@@ -226,13 +226,12 @@
     displayBox.setVerticalMargin({ heightAndMargin.nonCollapsedMargin, { } });
 }
 
-void InlineFormattingContext::layoutFormattingContextRoot(const Box& root, UsedHorizontalValues usedValues)
+void InlineFormattingContext::layoutFormattingContextRoot(const Box& root, UsedHorizontalValues usedHorizontalValues)
 {
     ASSERT(root.isFloatingPositioned() || root.isInlineBlockBox());
-    ASSERT(usedValues.containingBlockWidth);
 
-    computeBorderAndPadding(root, usedValues);
-    computeWidthAndMargin(root, usedValues);
+    computeBorderAndPadding(root, usedHorizontalValues);
+    computeWidthAndMargin(root, usedHorizontalValues);
     // This is similar to static positioning in block formatting context. We just need to initialize the top left position.
     formattingState().displayBox(root).setTopLeft({ 0, 0 });
     // Swich over to the new formatting context (the one that the root creates).
@@ -247,15 +246,14 @@
         computeHeightAndMargin(root);
 }
 
-void InlineFormattingContext::computeWidthAndHeightForReplacedInlineBox(const Box& layoutBox, UsedHorizontalValues usedValues)
+void InlineFormattingContext::computeWidthAndHeightForReplacedInlineBox(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues)
 {
     ASSERT(!layoutBox.isContainer());
     ASSERT(!layoutBox.establishesFormattingContext());
     ASSERT(layoutBox.replaced());
-    ASSERT(usedValues.containingBlockWidth);
 
-    computeBorderAndPadding(layoutBox, usedValues);
-    computeWidthAndMargin(layoutBox, usedValues);
+    computeBorderAndPadding(layoutBox, usedHorizontalValues);
+    computeWidthAndMargin(layoutBox, usedHorizontalValues);
     computeHeightAndMargin(layoutBox);
 }
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp (249902 => 249903)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2019-09-16 16:41:46 UTC (rev 249902)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2019-09-16 16:56:35 UTC (rev 249903)
@@ -53,7 +53,7 @@
     // If 'width' is 'auto', the used value is the shrink-to-fit width as for floating elements.
     // A computed value of 'auto' for 'margin-left' or 'margin-right' becomes a used value of '0'.
     // #1
-    auto width = computedValueIfNotAuto(formattingContextRoot.style().logicalWidth(), usedValues.containingBlockWidth.valueOr(0));
+    auto width = computedValueIfNotAuto(formattingContextRoot.style().logicalWidth(), usedValues.containingBlockWidth);
     if (!width)
         width = shrinkToFitWidth(formattingContextRoot, usedValues);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to