[LFC] VerticalMargin should only have the used values.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jan 2019 08:38:41 +0000 (08:38 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jan 2019 08:38:41 +0000 (08:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193168

Reviewed by Antti Koivisto.

Split VerticalMargin into ComputedVerticalMargin and UsedVerticalMargin.
ComputedVerticalMargin holds the computed (optional) values while UsedVerticalMargin holds both the
collapsed (optional) and the non-collapsed values.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry const):
* layout/FormattingContext.h:
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):
(WebCore::Layout::FormattingContext::Geometry::complicatedCases):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::computedVerticalMargin):
(WebCore::Layout::FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue): Deleted.
* layout/FormattingContextQuirks.cpp:
(WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
* layout/LayoutUnits.h:
* layout/MarginTypes.h:
(WebCore::Layout::UsedVerticalMargin::before const):
(WebCore::Layout::UsedVerticalMargin::after const):
(WebCore::Layout::UsedVerticalMargin::nonCollapsedValues const):
(WebCore::Layout::UsedVerticalMargin::collapsedValues const):
(WebCore::Layout::UsedVerticalMargin::hasCollapsedValues const):
(WebCore::Layout::UsedVerticalMargin::setCollapsedValues):
(WebCore::Layout::UsedVerticalMargin::UsedVerticalMargin):
(WebCore::Layout::VerticalMargin::nonCollapsedValues const): Deleted.
(WebCore::Layout::VerticalMargin::collapsedValues const): Deleted.
(WebCore::Layout::VerticalMargin::setCollapsedValues): Deleted.
(WebCore::Layout::VerticalMargin::VerticalMargin): Deleted.
(WebCore::Layout::VerticalMargin::usedValues const): Deleted.
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):
* layout/blockformatting/BlockFormattingContextQuirks.cpp:
(WebCore::Layout::BlockFormattingContext::Quirks::stretchedHeight):
* layout/blockformatting/BlockMarginCollapse.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginBefore):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginAfter):
* layout/displaytree/DisplayBox.h:
(WebCore::Display::Box::setVerticalMargin):
(WebCore::Display::Box::verticalMargin const):
(WebCore::Display::Box::marginBefore const):
(WebCore::Display::Box::marginAfter const):
* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computeHeightAndMargin const):

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

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/FormattingContext.h
Source/WebCore/layout/FormattingContextGeometry.cpp
Source/WebCore/layout/FormattingContextQuirks.cpp
Source/WebCore/layout/LayoutUnits.h
Source/WebCore/layout/MarginTypes.h
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp
Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
Source/WebCore/layout/displaytree/DisplayBox.h
Source/WebCore/layout/floats/FloatingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

index bdf198a..d156aa2 100644 (file)
@@ -1,3 +1,61 @@
+2019-01-05  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] VerticalMargin should only have the used values.
+        https://bugs.webkit.org/show_bug.cgi?id=193168
+
+        Reviewed by Antti Koivisto.
+
+        Split VerticalMargin into ComputedVerticalMargin and UsedVerticalMargin.
+        ComputedVerticalMargin holds the computed (optional) values while UsedVerticalMargin holds both the
+        collapsed (optional) and the non-collapsed values.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry const):
+        * layout/FormattingContext.h:
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::complicatedCases):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::computedVerticalMargin):
+        (WebCore::Layout::FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue): Deleted.
+        * layout/FormattingContextQuirks.cpp:
+        (WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
+        * layout/LayoutUnits.h:
+        * layout/MarginTypes.h:
+        (WebCore::Layout::UsedVerticalMargin::before const):
+        (WebCore::Layout::UsedVerticalMargin::after const):
+        (WebCore::Layout::UsedVerticalMargin::nonCollapsedValues const):
+        (WebCore::Layout::UsedVerticalMargin::collapsedValues const):
+        (WebCore::Layout::UsedVerticalMargin::hasCollapsedValues const):
+        (WebCore::Layout::UsedVerticalMargin::setCollapsedValues):
+        (WebCore::Layout::UsedVerticalMargin::UsedVerticalMargin):
+        (WebCore::Layout::VerticalMargin::nonCollapsedValues const): Deleted.
+        (WebCore::Layout::VerticalMargin::collapsedValues const): Deleted.
+        (WebCore::Layout::VerticalMargin::setCollapsedValues): Deleted.
+        (WebCore::Layout::VerticalMargin::VerticalMargin): Deleted.
+        (WebCore::Layout::VerticalMargin::usedValues const): Deleted.
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):
+        * layout/blockformatting/BlockFormattingContextQuirks.cpp:
+        (WebCore::Layout::BlockFormattingContext::Quirks::stretchedHeight):
+        * layout/blockformatting/BlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginBefore):
+        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginAfter):
+        * layout/displaytree/DisplayBox.h:
+        (WebCore::Display::Box::setVerticalMargin):
+        (WebCore::Display::Box::verticalMargin const):
+        (WebCore::Display::Box::marginBefore const):
+        (WebCore::Display::Box::marginAfter const):
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computeHeightAndMargin const):
+
 2019-01-04  Daniel Bates  <dabates@apple.com>
 
         REGRESSION (r238522): Erratic scrolling on Google flights search result page and vrbo.com
index 5e536a8..0ccf2d1 100644 (file)
@@ -116,11 +116,11 @@ void FormattingContext::computeOutOfFlowVerticalGeometry(const Box& layoutBox) c
 
     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
     // Margins of absolutely positioned boxes do not collapse
-    ASSERT(!verticalGeometry.heightAndMargin.margin.collapsedValues());
-    auto nonCollapsedVerticalMargin = verticalGeometry.heightAndMargin.margin.nonCollapsedValues();
+    ASSERT(!verticalGeometry.heightAndMargin.usedMargin.hasCollapsedValues());
+    auto nonCollapsedVerticalMargin = verticalGeometry.heightAndMargin.usedMargin.nonCollapsedValues();
     displayBox.setTop(verticalGeometry.top + nonCollapsedVerticalMargin.before);
     displayBox.setContentBoxHeight(verticalGeometry.heightAndMargin.height);
-    displayBox.setVerticalMargin(verticalGeometry.heightAndMargin.margin);
+    displayBox.setVerticalMargin(verticalGeometry.heightAndMargin.usedMargin);
 }
 
 void FormattingContext::computeBorderAndPadding(const Box& layoutBox) const
index 50bbba5..42d729b 100644 (file)
@@ -97,7 +97,7 @@ protected:
         static Optional<Edges> computedPadding(const LayoutState&, const Box&);
 
         static ComputedHorizontalMargin computedHorizontalMargin(const LayoutState&, const Box&);
-        static VerticalMargin::ComputedValues computedNonCollapsedVerticalMarginValue(const LayoutState&, const Box&);
+        static ComputedVerticalMargin computedVerticalMargin(const LayoutState&, const Box&);
 
         static Optional<LayoutUnit> computedValueIfNotAuto(const Length& geometryProperty, LayoutUnit containingBlockWidth);
         static Optional<LayoutUnit> fixedValue(const Length& geometryProperty);
index 947698f..cca6ef9 100644 (file)
@@ -280,10 +280,8 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeomet
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
     auto height = usedHeight ? usedHeight.value() : computedHeightValue(layoutState, layoutBox, HeightType::Normal);
-    auto computedMarginBefore = computedValueIfNotAuto(style.marginBefore(), containingBlockWidth);
-    auto computedMarginAfter = computedValueIfNotAuto(style.marginAfter(), containingBlockWidth);
-    auto usedMarginBefore = computedMarginBefore;
-    auto usedMarginAfter = computedMarginAfter;
+    auto computedVerticalMargin = Geometry::computedVerticalMargin(layoutState, layoutBox);
+    UsedVerticalMargin::NonCollapsedValues usedVerticalMargin; 
     auto paddingTop = displayBox.paddingTop().valueOr(0);
     auto paddingBottom = displayBox.paddingBottom().valueOr(0);
     auto borderTop = displayBox.borderTop();
@@ -293,72 +291,67 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeomet
         top = staticVerticalPositionForOutOfFlowPositioned(layoutState, layoutBox);
 
     if (top && height && bottom) {
-        if (!usedMarginBefore && !usedMarginAfter) {
+        if (!computedVerticalMargin.before && !computedVerticalMargin.after) {
             auto marginBeforeAndAfter = containingBlockHeight - (*top + borderTop + paddingTop + *height + paddingBottom + borderBottom + *bottom);
-            usedMarginBefore = usedMarginAfter = marginBeforeAndAfter / 2;
-        } else if (!usedMarginBefore)
-            usedMarginBefore = containingBlockHeight - (*top + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter + *bottom);
-        else
-            usedMarginAfter = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *bottom);
+            usedVerticalMargin = { marginBeforeAndAfter / 2, marginBeforeAndAfter / 2 };
+        } else if (!computedVerticalMargin.before) {
+            usedVerticalMargin.after = *computedVerticalMargin.after;
+            usedVerticalMargin.before = containingBlockHeight - (*top + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom);
+        } else {
+            usedVerticalMargin.before = *computedVerticalMargin.before;
+            usedVerticalMargin.after = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + *bottom);
+        }
         // Over-constrained?
-        auto boxHeight = *top + *usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter + *bottom;
+        auto boxHeight = *top + usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom;
         if (boxHeight > containingBlockHeight)
-            bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter); 
+            bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after); 
     }
 
     if (!top && !height && bottom) {
         // #1
         height = contentHeightForFormattingContextRoot(layoutState, layoutBox);
-        usedMarginBefore = usedMarginBefore.valueOr(0);
-        usedMarginAfter = usedMarginAfter.valueOr(0);
-        top = containingBlockHeight - (*usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter + *bottom); 
+        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
+        top = containingBlockHeight - (usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom); 
     }
 
     if (!top && !bottom && height) {
         // #2
         top = staticVerticalPositionForOutOfFlowPositioned(layoutState, layoutBox);
-        usedMarginBefore = usedMarginBefore.valueOr(0);
-        usedMarginAfter = usedMarginAfter.valueOr(0);
-        bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter); 
+        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
+        bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after); 
     }
 
     if (!height && !bottom && top) {
         // #3
         height = contentHeightForFormattingContextRoot(layoutState, layoutBox);
-        usedMarginBefore = usedMarginBefore.valueOr(0);
-        usedMarginAfter = usedMarginAfter.valueOr(0);
-        bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter); 
+        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
+        bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after); 
     }
 
     if (!top && height && bottom) {
         // #4
-        usedMarginBefore = usedMarginBefore.valueOr(0);
-        usedMarginAfter = usedMarginAfter.valueOr(0);
-        top = containingBlockHeight - (*usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter + *bottom); 
+        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
+        top = containingBlockHeight - (usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom); 
     }
 
     if (!height && top && bottom) {
         // #5
-        usedMarginBefore = usedMarginBefore.valueOr(0);
-        usedMarginAfter = usedMarginAfter.valueOr(0);
-        height = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + paddingBottom + borderBottom + *usedMarginAfter + *bottom); 
+        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
+        height = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom); 
     }
 
     if (!bottom && top && height) {
         // #6
-        usedMarginBefore = usedMarginBefore.valueOr(0);
-        usedMarginAfter = usedMarginAfter.valueOr(0);
-        bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + *height + paddingBottom + borderBottom + *usedMarginAfter); 
+        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
+        bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + *height + paddingBottom + borderBottom + usedVerticalMargin.after); 
     }
 
     ASSERT(top);
     ASSERT(bottom);
     ASSERT(height);
-    ASSERT(usedMarginBefore);
-    ASSERT(usedMarginAfter);
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Height][Margin] -> out-of-flow non-replaced -> top(" << *top << "px) bottom("  << *bottom << "px) height(" << *height << "px) margin(" << *usedMarginBefore << "px, "  << *usedMarginAfter << "px) layoutBox(" << &layoutBox << ")");
-    return { *top, *bottom, { *height, { { *usedMarginBefore, *usedMarginAfter }, { } } } };
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Height][Margin] -> out-of-flow non-replaced -> top(" << *top << "px) bottom("  << *bottom << "px) height(" << *height << "px) margin(" << usedVerticalMargin.before << "px, "  << usedVerticalMargin.after << "px) layoutBox(" << &layoutBox << ")");
+    return { *top, *bottom, { *height, { usedVerticalMargin, { } } } };
 }
 
 HorizontalGeometry FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry(LayoutState& layoutState, const Box& layoutBox, Optional<LayoutUnit> usedWidth)
@@ -523,10 +516,8 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
     auto height = inlineReplacedHeightAndMargin(layoutState, layoutBox, usedHeight).height;
-    auto computedMarginBefore = computedValueIfNotAuto(style.marginBefore(), containingBlockWidth);
-    auto computedMarginAfter = computedValueIfNotAuto(style.marginAfter(), containingBlockWidth);
-    auto usedMarginBefore = computedMarginBefore;
-    auto usedMarginAfter = computedMarginAfter;
+    auto computedVerticalMargin = Geometry::computedVerticalMargin(layoutState, layoutBox);
+    UsedVerticalMargin::NonCollapsedValues usedVerticalMargin; 
     auto paddingTop = displayBox.paddingTop().valueOr(0);
     auto paddingBottom = displayBox.paddingBottom().valueOr(0);
     auto borderTop = displayBox.borderTop();
@@ -539,36 +530,35 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(
 
     if (!bottom) {
         // #2
-        usedMarginBefore = usedMarginBefore.valueOr(0);
-        usedMarginAfter = usedMarginAfter.valueOr(0);
+        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
     }
 
-    if (!usedMarginBefore && !usedMarginAfter) {
+    if (!computedVerticalMargin.before && !computedVerticalMargin.after) {
         // #3
         auto marginBeforeAndAfter = containingBlockHeight - (*top + borderTop + paddingTop + height + paddingBottom + borderBottom + *bottom);
-        usedMarginBefore = usedMarginAfter = marginBeforeAndAfter / 2;
+        usedVerticalMargin = { marginBeforeAndAfter / 2, marginBeforeAndAfter / 2 };
     }
 
     // #4
     if (!top)
-        top = containingBlockHeight - (*usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter + *bottom);
+        top = containingBlockHeight - (usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom);
 
     if (!bottom)
-        bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter);
+        bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after);
 
-    if (!usedMarginBefore)
-        usedMarginBefore = containingBlockHeight - (*top + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter + *bottom);
+    if (!computedVerticalMargin.before)
+        usedVerticalMargin.before = containingBlockHeight - (*top + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom);
 
-    if (!usedMarginAfter)
-        usedMarginAfter = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *bottom);
+    if (!computedVerticalMargin.after)
+        usedVerticalMargin.after = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + *bottom);
 
     // #5
-    auto boxHeight = *top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter + *bottom;
+    auto boxHeight = *top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom;
     if (boxHeight > containingBlockHeight)
-        bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter); 
+        bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after); 
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Height][Margin] -> out-of-flow replaced -> top(" << *top << "px) bottom("  << *bottom << "px) height(" << height << "px) margin(" << *usedMarginBefore << "px, "  << *usedMarginAfter << "px) layoutBox(" << &layoutBox << ")");
-    return { *top, *bottom, { height, { { *usedMarginBefore, *usedMarginAfter }, { } } } };
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Height][Margin] -> out-of-flow replaced -> top(" << *top << "px) bottom("  << *bottom << "px) height(" << height << "px) margin(" << usedVerticalMargin.before << "px, "  << usedVerticalMargin.after << "px) layoutBox(" << &layoutBox << ")");
+    return { *top, *bottom, { height, { usedVerticalMargin, { } } } };
 }
 
 HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(const LayoutState& layoutState, const Box& layoutBox, Optional<LayoutUnit> usedWidth)
@@ -679,19 +669,10 @@ HeightAndMargin FormattingContext::Geometry::complicatedCases(const LayoutState&
     // 1. If 'margin-top', or 'margin-bottom' are 'auto', their used value is 0.
     // 2. If 'height' is 'auto', the height depends on the element's descendants per 10.6.7.
 
-    auto& style = layoutBox.style();
-    auto& containingBlock = *layoutBox.containingBlock();
-    auto& containingBlockDisplayBox = layoutState.displayBoxForLayoutBox(containingBlock);
-    auto containingBlockWidth = containingBlockDisplayBox.contentBoxWidth();
-
     auto height = usedHeight ? usedHeight.value() : computedHeightValue(layoutState, layoutBox, HeightType::Normal);
-    auto computedMarginBefore = computedValueIfNotAuto(style.marginBefore(), containingBlockWidth);
-    auto computedMarginAfter = computedValueIfNotAuto(style.marginAfter(), containingBlockWidth);
-
+    auto computedVerticalMargin = Geometry::computedVerticalMargin(layoutState, layoutBox);
     // #1
-    auto usedMarginBefore = computedMarginBefore.valueOr(0);
-    auto usedMarginAfter = computedMarginAfter.valueOr(0);
-
+    auto usedVerticalMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) }; 
     // #2
     if (!height) {
         ASSERT(isHeightAuto(layoutBox));
@@ -700,8 +681,8 @@ HeightAndMargin FormattingContext::Geometry::complicatedCases(const LayoutState&
 
     ASSERT(height);
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> floating non-replaced -> height(" << *height << "px) margin(" << usedMarginBefore << "px, " << usedMarginAfter << "px) -> layoutBox(" << &layoutBox << ")");
-    return HeightAndMargin { *height, { { usedMarginBefore, usedMarginAfter }, { } } };
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> floating non-replaced -> height(" << *height << "px) margin(" << usedVerticalMargin.before << "px, " << usedVerticalMargin.after << "px) -> layoutBox(" << &layoutBox << ")");
+    return HeightAndMargin { *height, { usedVerticalMargin, { } } };
 }
 
 WidthAndMargin FormattingContext::Geometry::floatingNonReplacedWidthAndMargin(LayoutState& layoutState, const Box& layoutBox, Optional<LayoutUnit> usedWidth)
@@ -802,8 +783,8 @@ HeightAndMargin FormattingContext::Geometry::inlineReplacedHeightAndMargin(const
     //    the height of the largest rectangle that has a 2:1 ratio, has a height not greater than 150px, and has a width not greater than the device width.
 
     // #1
-    auto margin = computedNonCollapsedVerticalMarginValue(layoutState, layoutBox);
-
+    auto computedVerticalMargin = Geometry::computedVerticalMargin(layoutState, layoutBox);
+    auto usedVerticalMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
     auto& style = layoutBox.style();
     auto replaced = layoutBox.replaced();
 
@@ -828,8 +809,8 @@ HeightAndMargin FormattingContext::Geometry::inlineReplacedHeightAndMargin(const
 
     ASSERT(height);
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow replaced -> height(" << *height << "px) margin(" << margin.before << "px, " << margin.after << "px) -> layoutBox(" << &layoutBox << ")");
-    return { *height, { margin, { } } };
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow replaced -> height(" << *height << "px) margin(" << usedVerticalMargin.before << "px, " << usedVerticalMargin.after << "px) -> layoutBox(" << &layoutBox << ")");
+    return { *height, { usedVerticalMargin, { } } };
 }
 
 WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const LayoutState& layoutState, const Box& layoutBox,
@@ -857,8 +838,8 @@ WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const L
     //    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& containingBlockDisplayBox = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock());
-    auto containingBlockWidth = containingBlockDisplayBox.width();
+    auto& containingBlock = *layoutBox.containingBlock();
+    auto containingBlockWidth = layoutState.displayBoxForLayoutBox(containingBlock).contentBoxWidth();
     auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutState, layoutBox);
 
     auto usedMarginStart = [&] {
@@ -1008,16 +989,12 @@ ComputedHorizontalMargin FormattingContext::Geometry::computedHorizontalMargin(c
     return { computedValueIfNotAuto(style.marginStart(), containingBlockWidth), computedValueIfNotAuto(style.marginEnd(), containingBlockWidth) };
 }
 
-VerticalMargin::ComputedValues FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue(const LayoutState& layoutState, const Box& layoutBox)
+ComputedVerticalMargin FormattingContext::Geometry::computedVerticalMargin(const LayoutState& layoutState, const Box& layoutBox)
 {
     auto& style = layoutBox.style();
     auto containingBlockWidth = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).contentBoxWidth();
 
-    auto usedMarginBefore = computedValueIfNotAuto(style.marginBefore(), containingBlockWidth).valueOr(0_lu);
-    auto usedMarginAfter = computedValueIfNotAuto(style.marginAfter(), containingBlockWidth).valueOr(0_lu);
-
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Margin] -> non collapsed vertical -> margin(" << usedMarginBefore << "px, " << usedMarginAfter << "px) -> layoutBox: " << &layoutBox);
-    return { usedMarginBefore, usedMarginAfter };
+    return { computedValueIfNotAuto(style.marginBefore(), containingBlockWidth), computedValueIfNotAuto(style.marginAfter(), containingBlockWidth) };
 }
 
 }
index b4f44a8..510b970 100644 (file)
@@ -51,10 +51,10 @@ LayoutUnit FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFix
         if (containingBlock->isBodyBox() || containingBlock->isDocumentBox()) {
             auto& displayBox = layoutState.displayBoxForLayoutBox(*containingBlock);
 
-            auto verticalMargin = FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue(layoutState, *containingBlock);
+            auto verticalMargin = Geometry::computedVerticalMargin(layoutState, *containingBlock);
             auto verticalPadding = displayBox.paddingTop().valueOr(0) + displayBox.paddingBottom().valueOr(0);
             auto verticalBorder = displayBox.borderTop() + displayBox.borderBottom();
-            bodyAndDocumentVerticalMarginPaddingAndBorder += verticalMargin.before + verticalMargin.after + verticalPadding + verticalBorder;
+            bodyAndDocumentVerticalMarginPaddingAndBorder += verticalMargin.before.valueOr(0) + verticalMargin.after.valueOr(0) + verticalPadding + verticalBorder;
         }
 
         containingBlock = containingBlock->containingBlock();
index 3b4829a..a63d723 100644 (file)
@@ -109,7 +109,7 @@ struct WidthAndMargin {
 
 struct HeightAndMargin {
     LayoutUnit height;
-    VerticalMargin margin;
+    UsedVerticalMargin usedMargin;
 };
 
 struct HorizontalGeometry {
index fe1fc18..4e1fc56 100644 (file)
 namespace WebCore {
 namespace Layout {
 
-struct VerticalMargin {
-    struct ComputedValues {
+struct ComputedVerticalMargin {
+    Optional<LayoutUnit> before;
+    Optional<LayoutUnit> after;
+};
+
+struct UsedVerticalMargin {
+    LayoutUnit before() const { return m_collapsedValues.before.valueOr(m_nonCollapsedValues.before); }
+    LayoutUnit after() const { return m_collapsedValues.after.valueOr(m_nonCollapsedValues.after); }
+
+    struct NonCollapsedValues {
         LayoutUnit before;
         LayoutUnit after;
     };
-    ComputedValues usedValues() const;
-    ComputedValues nonCollapsedValues() const { return m_nonCollapsed; }
-    
+    NonCollapsedValues nonCollapsedValues() const { return m_nonCollapsedValues; }
+
     struct CollapsedValues {
         Optional<LayoutUnit> before;
         Optional<LayoutUnit> after;
     };
-    Optional<CollapsedValues> collapsedValues() const { return m_collapsed; }
-    void setCollapsedValues(CollapsedValues collapsedValues) { m_collapsed = collapsedValues; }
+    CollapsedValues collapsedValues() const { return m_collapsedValues; }
+    bool hasCollapsedValues() const { return m_collapsedValues.before || m_collapsedValues.after; }
+    void setCollapsedValues(CollapsedValues collapsedValues) { m_collapsedValues = collapsedValues; }
 
-    VerticalMargin(ComputedValues nonCollapsed, Optional<CollapsedValues>);
+    UsedVerticalMargin(NonCollapsedValues, CollapsedValues);
 
-    VerticalMargin() = default;
-    ~VerticalMargin() = default;
+    UsedVerticalMargin() = default;
+    ~UsedVerticalMargin() = default;
 private:
-    ComputedValues m_nonCollapsed;
-    Optional<CollapsedValues> m_collapsed;
+    NonCollapsedValues m_nonCollapsedValues;
+    CollapsedValues m_collapsedValues;
 };
 
 struct ComputedHorizontalMargin {
@@ -75,18 +83,10 @@ struct PositiveAndNegativeVerticalMargin {
     Values after;
 };
 
-inline VerticalMargin::VerticalMargin(VerticalMargin::ComputedValues nonCollapsed, Optional<VerticalMargin::CollapsedValues> collapsed)
-    : m_nonCollapsed(nonCollapsed)
-    , m_collapsed(collapsed)
-{
-}
-
-inline VerticalMargin::ComputedValues VerticalMargin::usedValues() const
+inline UsedVerticalMargin::UsedVerticalMargin(UsedVerticalMargin::NonCollapsedValues nonCollapsedValues, UsedVerticalMargin::CollapsedValues collapsedValues)
+    : m_nonCollapsedValues(nonCollapsedValues)
+    , m_collapsedValues(collapsedValues)
 {
-    if (!m_collapsed)
-        return m_nonCollapsed;
-    return { m_collapsed->before.valueOr(m_nonCollapsed.before),
-        m_collapsed->after.valueOr(m_nonCollapsed.after) };
 }
 
 }
index b8bfa99..a73a577 100644 (file)
@@ -358,7 +358,7 @@ void BlockFormattingContext::computeHeightAndMargin(const Box& layoutBox) const
             auto maxHeightAndMargin = compute(maxHeight);
             // Used height should remain the same.
             ASSERT((layoutState.inQuirksMode() && (layoutBox.isBodyBox() || layoutBox.isDocumentBox())) || maxHeightAndMargin.height == *maxHeight);
-            heightAndMargin = { *maxHeight, maxHeightAndMargin.margin };
+            heightAndMargin = { *maxHeight, maxHeightAndMargin.usedMargin };
         }
     }
 
@@ -367,17 +367,17 @@ void BlockFormattingContext::computeHeightAndMargin(const Box& layoutBox) const
             auto minHeightAndMargin = compute(minHeight);
             // Used height should remain the same.
             ASSERT((layoutState.inQuirksMode() && (layoutBox.isBodyBox() || layoutBox.isDocumentBox())) || minHeightAndMargin.height == *minHeight);
-            heightAndMargin = { *minHeight, minHeightAndMargin.margin };
+            heightAndMargin = { *minHeight, minHeightAndMargin.usedMargin };
         }
     }
 
     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
     displayBox.setContentBoxHeight(heightAndMargin.height);
-    displayBox.setVerticalMargin(heightAndMargin.margin);
+    displayBox.setVerticalMargin(heightAndMargin.usedMargin);
 
     // If this box has already been moved by the estimated vertical margin, no need to move it again.
     if (layoutBox.isFloatingPositioned() || !displayBox.estimatedMarginBefore())
-        displayBox.moveVertically(heightAndMargin.margin.usedValues().before);
+        displayBox.moveVertically(heightAndMargin.usedMargin.before());
 }
 
 FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsicWidthConstraints() const
index 63e0682..fc75b53 100644 (file)
@@ -57,13 +57,10 @@ HeightAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMarg
         // Only children in the normal flow are taken into account (i.e., floating boxes and absolutely positioned boxes are ignored,
         // and relatively positioned boxes are considered without their offset). Note that the child box may be an anonymous block box.
 
-        auto& style = layoutBox.style();
-        auto containingBlockWidth = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).contentBoxWidth();
         auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
-
-        auto nonCollapsedMargin = VerticalMargin::ComputedValues { computedValueIfNotAuto(style.marginBefore(), containingBlockWidth).valueOr(0),
-            computedValueIfNotAuto(style.marginAfter(), containingBlockWidth).valueOr(0) }; 
-        auto collapsedMargin = VerticalMargin::CollapsedValues { MarginCollapse::marginBefore(layoutState, layoutBox), MarginCollapse::marginAfter(layoutState, layoutBox) };
+        auto computedVerticalMargin = Geometry::computedVerticalMargin(layoutState, layoutBox);
+        auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) }; 
+        auto collapsedMargin = UsedVerticalMargin::CollapsedValues { MarginCollapse::marginBefore(layoutState, layoutBox), MarginCollapse::marginAfter(layoutState, layoutBox) };
         auto borderAndPaddingTop = displayBox.borderTop() + displayBox.paddingTop().valueOr(0);
 
         auto height = usedHeight ? usedHeight.value() : computedHeightValue(layoutState, layoutBox, HeightType::Normal);
@@ -104,7 +101,7 @@ HeightAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMarg
 
     auto heightAndMargin = compute();
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow non-replaced -> height(" << heightAndMargin.height << "px) margin(" << heightAndMargin.margin.usedValues().before << "px, " << heightAndMargin.margin.usedValues().after << "px) -> layoutBox(" << &layoutBox << ")");
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow non-replaced -> height(" << heightAndMargin.height << "px) margin(" << heightAndMargin.usedMargin.before() << "px, " << heightAndMargin.usedMargin.after() << "px) -> layoutBox(" << &layoutBox << ")");
     return heightAndMargin;
 }
 
@@ -263,7 +260,7 @@ HeightAndMargin BlockFormattingContext::Geometry::inFlowHeightAndMargin(const La
 
     heightAndMargin = Quirks::stretchedHeight(layoutState, layoutBox, heightAndMargin);
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow non-replaced -> streched to viewport -> height(" << heightAndMargin.height << "px) margin(" << heightAndMargin.margin.usedValues().before << "px, " << heightAndMargin.margin.usedValues().after << "px) -> layoutBox(" << &layoutBox << ")");
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow non-replaced -> streched to viewport -> height(" << heightAndMargin.height << "px) margin(" << heightAndMargin.usedMargin.before() << "px, " << heightAndMargin.usedMargin.after() << "px) -> layoutBox(" << &layoutBox << ")");
     return heightAndMargin;
 }
 
index 4606f9d..f3ebd2d 100644 (file)
@@ -80,10 +80,10 @@ HeightAndMargin BlockFormattingContext::Quirks::stretchedHeight(const LayoutStat
 
     LayoutUnit totalVerticalMargin;
     if (layoutBox.isDocumentBox()) {
-        auto verticalMargin = heightAndMargin.margin.usedValues();
+        auto verticalMargin = heightAndMargin.usedMargin;
         // Document box's margins do not collapse.
-        ASSERT(!heightAndMargin.margin.collapsedValues());
-        totalVerticalMargin = verticalMargin.before + verticalMargin.after;
+        ASSERT(!verticalMargin.hasCollapsedValues());
+        totalVerticalMargin = verticalMargin.before() + verticalMargin.after();
     } else if (layoutBox.isBodyBox()) {
         // Here is the quirky part for body box:
         // Stretch the body using the initial containing block's height and shrink it with document box's margin/border/padding.
@@ -93,8 +93,12 @@ HeightAndMargin BlockFormattingContext::Quirks::stretchedHeight(const LayoutStat
 
         // This quirk happens when the body height is 0 which means its vertical margins collapse through (top and bottom margins are adjoining).
         // However now that we stretch the body they don't collapse through anymore, so we need to use the non-collapsed values instead.
-        auto bodyBoxVerticalMargin = heightAndMargin.height ? heightAndMargin.margin.usedValues() : heightAndMargin.margin.nonCollapsedValues();
-        totalVerticalMargin = bodyBoxVerticalMargin.before + bodyBoxVerticalMargin.after;
+        if (heightAndMargin.height)
+            totalVerticalMargin = heightAndMargin.usedMargin.before() + heightAndMargin.usedMargin.after();
+        else {
+            auto nonCollapsedValues = heightAndMargin.usedMargin.nonCollapsedValues();
+            totalVerticalMargin = nonCollapsedValues.before + nonCollapsedValues.after;
+        }
     }
 
     // Stretch but never overstretch with the margins.
index 5677087..f798af3 100644 (file)
@@ -107,14 +107,14 @@ LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapse
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
-    return computedNonCollapsedVerticalMarginValue(layoutState, layoutBox).before;
+    return computedVerticalMargin(layoutState, layoutBox).before.valueOr(0);
 }
 
 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginAfter(const LayoutState& layoutState, const Box& layoutBox)
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
-    return computedNonCollapsedVerticalMarginValue(layoutState, layoutBox).after;
+    return computedVerticalMargin(layoutState, layoutBox).after.valueOr(0);
 }
 
 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::nonCollapsedMarginBefore(const LayoutState& layoutState, const Box& layoutBox)
index 9bc1b9f..31d86a6 100644 (file)
@@ -138,7 +138,7 @@ public:
     Rect rect() const { return { top(), left(), width(), height() }; }
     Rect rectWithMargin() const { return { top() - marginBefore(), left() - marginStart(), marginStart() + width() + marginEnd(), marginBefore() + height() + marginAfter() }; }
 
-    Layout::VerticalMargin verticalMargin() const;
+    Layout::UsedVerticalMargin verticalMargin() const;
     LayoutUnit marginBefore() const;
     LayoutUnit marginStart() const;
     LayoutUnit marginAfter() const;
@@ -192,7 +192,7 @@ private:
     void setContentBoxWidth(LayoutUnit);
 
     void setHorizontalMargin(Layout::UsedHorizontalMargin);
-    void setVerticalMargin(Layout::VerticalMargin);
+    void setVerticalMargin(Layout::UsedVerticalMargin);
     void setHorizontalComputedMargin(Layout::ComputedHorizontalMargin);
     void setEstimatedMarginBefore(LayoutUnit marginBefore) { m_estimatedMarginBefore = marginBefore; }
 
@@ -225,7 +225,7 @@ private:
     LayoutUnit m_contentHeight;
 
     Layout::UsedHorizontalMargin m_horizontalMargin;
-    Layout::VerticalMargin m_verticalMargin;
+    Layout::UsedVerticalMargin m_verticalMargin;
     Layout::ComputedHorizontalMargin m_horizontalComputedMargin;
     Optional<LayoutUnit> m_estimatedMarginBefore;
 
@@ -515,13 +515,13 @@ inline void Box::setHorizontalMargin(Layout::UsedHorizontalMargin margin)
     m_horizontalMargin = margin;
 }
 
-inline void Box::setVerticalMargin(Layout::VerticalMargin margin)
+inline void Box::setVerticalMargin(Layout::UsedVerticalMargin margin)
 {
 #if !ASSERT_DISABLED
     setHasValidVerticalMargin();
     setHasValidVerticalNonCollapsedMargin();
 #endif
-    ASSERT(!m_estimatedMarginBefore || *m_estimatedMarginBefore == margin.usedValues().before);
+    ASSERT(!m_estimatedMarginBefore || *m_estimatedMarginBefore == margin.before());
     m_verticalMargin = margin;
 }
 
@@ -549,7 +549,7 @@ inline void Box::setPadding(Optional<Layout::Edges> padding)
     m_padding = padding;
 }
 
-inline Layout::VerticalMargin Box::verticalMargin() const
+inline Layout::UsedVerticalMargin Box::verticalMargin() const
 {
     ASSERT(m_hasValidVerticalMargin);
     return m_verticalMargin;
@@ -558,7 +558,7 @@ inline Layout::VerticalMargin Box::verticalMargin() const
 inline LayoutUnit Box::marginBefore() const
 {
     ASSERT(m_hasValidVerticalMargin);
-    return m_verticalMargin.usedValues().before;
+    return m_verticalMargin.before();
 }
 
 inline LayoutUnit Box::marginStart() const
@@ -570,7 +570,7 @@ inline LayoutUnit Box::marginStart() const
 inline LayoutUnit Box::marginAfter() const
 {
     ASSERT(m_hasValidVerticalMargin);
-    return m_verticalMargin.usedValues().after;
+    return m_verticalMargin.after();
 }
 
 inline LayoutUnit Box::marginEnd() const
index 71fc060..71d0539 100644 (file)
@@ -193,14 +193,14 @@ Optional<Position> FloatingContext::verticalPositionWithClearance(const Box& lay
 
             // Reset previous bottom and current top margins to non-collapsing.
             auto previousVerticalMargin = previousInFlowDisplayBox.verticalMargin();
-            if (previousVerticalMargin.collapsedValues() && previousVerticalMargin.collapsedValues()->after) {
-                previousVerticalMargin.setCollapsedValues({ previousVerticalMargin.collapsedValues()->before, { } });
+            if (previousVerticalMargin.collapsedValues().after) {
+                previousVerticalMargin.setCollapsedValues({ previousVerticalMargin.collapsedValues().before, { } });
                 previousInFlowDisplayBox.setVerticalMargin(previousVerticalMargin);
             }
             // FIXME: check if collapsing through has anything to do with this.
             auto verticalMargin = displayBox.verticalMargin();
-            if (verticalMargin.collapsedValues() && verticalMargin.collapsedValues()->before) {
-                verticalMargin.setCollapsedValues({ { }, verticalMargin.collapsedValues()->after });
+            if (verticalMargin.collapsedValues().before) {
+                verticalMargin.setCollapsedValues({ { }, verticalMargin.collapsedValues().after });
                 displayBox.setVerticalMargin(verticalMargin);
             }
 
index b36e68e..e0aaf59 100644 (file)
@@ -362,7 +362,7 @@ void InlineFormattingContext::computeHeightAndMargin(const Box& layoutBox) const
 
     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
     displayBox.setContentBoxHeight(heightAndMargin.height);
-    displayBox.setVerticalMargin(heightAndMargin.margin);
+    displayBox.setVerticalMargin(heightAndMargin.usedMargin);
 }
 
 void InlineFormattingContext::layoutFormattingContextRoot(const Box& root) const