Diff
Modified: trunk/Source/WebCore/ChangeLog (263942 => 263943)
--- trunk/Source/WebCore/ChangeLog 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/ChangeLog 2020-07-04 20:06:27 UTC (rev 263943)
@@ -1,3 +1,76 @@
+2020-07-04 Zalan Bujtas <[email protected]>
+
+ [LFC][BFC] Store used vertical margin values in the formatting state
+ https://bugs.webkit.org/show_bug.cgi?id=213958
+
+ Reviewed by Antti Koivisto.
+
+ Layout related vertical margin values (collapsed vs. non-collapsed) should all go to the FormattingState, while
+ Display::Box should only have the final values.
+
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry):
+ * layout/FormattingContextGeometry.cpp:
+ (WebCore::Layout::FormattingContext::Geometry::staticVerticalPositionForOutOfFlowPositioned const):
+ * layout/MarginTypes.h:
+ (WebCore::Layout::marginBefore):
+ (WebCore::Layout::marginAfter):
+ (WebCore::Layout::UsedVerticalMargin::before const): Deleted.
+ (WebCore::Layout::UsedVerticalMargin::after const): Deleted.
+ (WebCore::Layout::UsedVerticalMargin::isCollapsedThrough const): Deleted.
+ (WebCore::Layout::UsedVerticalMargin::nonCollapsedValues const): Deleted.
+ (WebCore::Layout::UsedVerticalMargin::collapsedValues const): Deleted.
+ (WebCore::Layout::UsedVerticalMargin::hasCollapsedValues const): Deleted.
+ (WebCore::Layout::UsedVerticalMargin::setCollapsedValues): Deleted.
+ (WebCore::Layout::UsedVerticalMargin::UsedVerticalMargin): Deleted.
+ * layout/Verification.cpp:
+ (WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded):
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors):
+ (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
+ (WebCore::Layout::BlockFormattingContext::verticalPositionWithMargin const):
+ * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
+ * layout/blockformatting/BlockFormattingState.h:
+ (WebCore::Layout::BlockFormattingState::setUsedVerticalMargin):
+ (WebCore::Layout::BlockFormattingState::usedVerticalMargin const):
+ * layout/blockformatting/BlockMarginCollapse.cpp:
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling):
+ * layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp:
+ (WebCore::Layout::TableWrapperBlockFormattingContext::computeHeightAndMarginForTableBox):
+ * layout/displaytree/DisplayBox.cpp:
+ (WebCore::Display::Box::Box):
+ (WebCore::Display::Box::nonCollapsedMarginBox const): Deleted.
+ * layout/displaytree/DisplayBox.h:
+ (WebCore::Display::Box::rectWithMargin const):
+ (WebCore::Display::Box::setHasValidVerticalMargin):
+ (WebCore::Display::Box::setVerticalMargin):
+ (WebCore::Display::Box::marginBefore const):
+ (WebCore::Display::Box::marginAfter const):
+ (WebCore::Display::Box::VerticalMargin::before const): Deleted.
+ (WebCore::Display::Box::VerticalMargin::after const): Deleted.
+ (WebCore::Display::Box::VerticalMargin::isCollapsedThrough const): Deleted.
+ (WebCore::Display::Box::VerticalMargin::nonCollapsedValues const): Deleted.
+ (WebCore::Display::Box::VerticalMargin::collapsedValues const): Deleted.
+ (WebCore::Display::Box::VerticalMargin::hasCollapsedValues const): Deleted.
+ (WebCore::Display::Box::VerticalMargin::setCollapsedValues): Deleted.
+ (WebCore::Display::Box::hasCollapsedThroughMargin const): Deleted.
+ (WebCore::Display::Box::setHasValidVerticalNonCollapsedMargin): Deleted.
+ (WebCore::Display::Box::VerticalMargin::VerticalMargin): Deleted.
+ (WebCore::Display::Box::VerticalMargin::NonCollapsedValues::NonCollapsedValues): Deleted.
+ (WebCore::Display::Box::VerticalMargin::CollapsedValues::CollapsedValues): Deleted.
+ (WebCore::Display::Box::nonCollapsedMarginBefore const): Deleted.
+ (WebCore::Display::Box::nonCollapsedMarginAfter const): Deleted.
+ * layout/floats/FloatingContext.cpp:
+ (WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
+ * layout/inlineformatting/InlineFormattingContext.cpp:
+ (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
+ (WebCore::Layout::InlineFormattingContext::computeHeightAndMargin):
+ * layout/tableformatting/TableFormattingContext.cpp:
+ (WebCore::Layout::TableFormattingContext::setUsedGeometryForRows):
+ (WebCore::Layout::TableFormattingContext::setUsedGeometryForSections):
+ (WebCore::Layout::TableFormattingContext::layoutCell):
+
2020-07-04 Darin Adler <[email protected]>
[Cocoa] Remove unconditional features from FeatureDefines.xcconfig, making sure they are covered in PlatformEnableCocoa.h
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -122,8 +122,8 @@
auto nonCollapsedVerticalMargin = verticalGeometry.contentHeightAndMargin.nonCollapsedMargin;
displayBox.setTop(verticalGeometry.top + nonCollapsedVerticalMargin.before);
displayBox.setContentBoxHeight(verticalGeometry.contentHeightAndMargin.contentHeight);
- // Margins of absolutely positioned boxes do not collapse
- displayBox.setVerticalMargin(nonCollapsedVerticalMargin);
+ // Margins of absolutely positioned boxes do not collapse.
+ displayBox.setVerticalMargin({ nonCollapsedVerticalMargin.before, nonCollapsedVerticalMargin.after });
}
void FormattingContext::computeBorderAndPadding(const Box& layoutBox, const HorizontalConstraints& horizontalConstraint)
Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -28,6 +28,7 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+#include "BlockFormattingState.h"
#include "FloatingState.h"
#include "InlineFormattingState.h"
#include "LayoutContext.h"
@@ -281,8 +282,12 @@
LayoutUnit top;
if (layoutBox.previousInFlowSibling() && layoutBox.previousInFlowSibling()->isBlockLevelBox()) {
// Add sibling offset
- auto& previousInFlowBoxGeometry = formattingContext.geometryForBox(*layoutBox.previousInFlowSibling(), EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
- top += previousInFlowBoxGeometry.bottom() + previousInFlowBoxGeometry.nonCollapsedMarginAfter();
+ auto& previousInFlowSibling = *layoutBox.previousInFlowSibling();
+ auto& previousInFlowBoxGeometry = formattingContext.geometryForBox(previousInFlowSibling, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
+ auto& formattingState = downcast<BlockFormattingState>(layoutState().formattingStateForBox(previousInFlowSibling));
+ auto usedVerticalMarginForPreviousBox = formattingState.usedVerticalMargin(previousInFlowSibling);
+
+ top += previousInFlowBoxGeometry.bottom() + usedVerticalMarginForPreviousBox.nonCollapsedValues.after;
} else
top = formattingContext.geometryForBox(layoutBox.parent(), EscapeReason::OutOfFlowBoxNeedsInFlowGeometry).contentBoxTop();
Modified: trunk/Source/WebCore/layout/MarginTypes.h (263942 => 263943)
--- trunk/Source/WebCore/layout/MarginTypes.h 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/MarginTypes.h 2020-07-04 20:06:27 UTC (rev 263943)
@@ -38,15 +38,11 @@
};
struct UsedVerticalMargin {
- LayoutUnit before() const { return m_collapsedValues.before.valueOr(m_nonCollapsedValues.before); }
- LayoutUnit after() const { return m_collapsedValues.after.valueOr(m_nonCollapsedValues.after); }
- bool isCollapsedThrough() const { return m_collapsedValues.isCollapsedThrough; }
-
struct NonCollapsedValues {
LayoutUnit before;
LayoutUnit after;
};
- NonCollapsedValues nonCollapsedValues() const { return m_nonCollapsedValues; }
+ NonCollapsedValues nonCollapsedValues;
struct CollapsedValues {
Optional<LayoutUnit> before;
@@ -53,17 +49,20 @@
Optional<LayoutUnit> after;
bool isCollapsedThrough { false };
};
- CollapsedValues collapsedValues() const { return m_collapsedValues; }
- bool hasCollapsedValues() const { return m_collapsedValues.before || m_collapsedValues.after; }
- void setCollapsedValues(CollapsedValues collapsedValues) { m_collapsedValues = collapsedValues; }
+ CollapsedValues collapsedValues;
+};
- UsedVerticalMargin(NonCollapsedValues, CollapsedValues);
- UsedVerticalMargin() = default;
+static inline LayoutUnit marginBefore(const UsedVerticalMargin& usedVerticalMargin)
+{
+ return usedVerticalMargin.collapsedValues.before.valueOr(usedVerticalMargin.nonCollapsedValues.before);
+}
-private:
- NonCollapsedValues m_nonCollapsedValues;
- CollapsedValues m_collapsedValues;
-};
+static inline LayoutUnit marginAfter(const UsedVerticalMargin& usedVerticalMargin)
+{
+ if (usedVerticalMargin.collapsedValues.isCollapsedThrough)
+ return 0_lu;
+ return usedVerticalMargin.collapsedValues.after.valueOr(usedVerticalMargin.nonCollapsedValues.after);
+}
struct ComputedHorizontalMargin {
Optional<LayoutUnit> start;
@@ -100,12 +99,6 @@
PositiveAndNegativeVerticalMargin::Values positiveAndNegativeMarginBefore;
};
-inline UsedVerticalMargin::UsedVerticalMargin(UsedVerticalMargin::NonCollapsedValues nonCollapsedValues, UsedVerticalMargin::CollapsedValues collapsedValues)
- : m_nonCollapsedValues(nonCollapsedValues)
- , m_collapsedValues(collapsedValues)
-{
}
-
}
-}
#endif
Modified: trunk/Source/WebCore/layout/Verification.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/Verification.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/Verification.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -29,6 +29,7 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#ifndef NDEBUG
+#include "BlockFormattingState.h"
#include "DisplayBox.h"
#include "InlineFormattingState.h"
#include "InlineTextBox.h"
@@ -217,7 +218,7 @@
return mismatched;
}
-static bool outputMismatchingBlockBoxInformationIfNeeded(TextStream& stream, const LayoutState& context, const RenderBox& renderer, const Box& layoutBox)
+static bool outputMismatchingBlockBoxInformationIfNeeded(TextStream& stream, const LayoutState& layoutState, const RenderBox& renderer, const Box& layoutBox)
{
bool firstMismatchingRect = true;
auto outputRect = [&] (const String& prefix, const LayoutRect& rendererRect, const LayoutRect& layoutRect) {
@@ -237,7 +238,7 @@
return displayBox.rect();
// Produce a RenderBox matching margin box.
- auto containingBlockWidth = context.displayBoxForLayoutBox(layoutBox.containingBlock()).contentBoxWidth();
+ auto containingBlockWidth = layoutState.displayBoxForLayoutBox(layoutBox.containingBlock()).contentBoxWidth();
auto marginStart = LayoutUnit { };
auto& marginStartStyle = layoutBox.style().marginStart();
if (marginStartStyle.isFixed() || marginStartStyle.isPercent() || marginStartStyle.isCalculated())
@@ -248,12 +249,20 @@
if (marginEndStyle.isFixed() || marginEndStyle.isPercent() || marginEndStyle.isCalculated())
marginEnd = valueForLength(marginEndStyle, containingBlockWidth);
+ auto marginBefore = displayBox.marginBefore();
+ auto marginAfter = displayBox.marginAfter();
+ if (layoutBox.isBlockLevelBox()) {
+ auto& formattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(layoutBox));
+ auto verticalMargin = formattingState.usedVerticalMargin(layoutBox);
+ marginBefore = verticalMargin.nonCollapsedValues.before;
+ marginAfter = verticalMargin.nonCollapsedValues.after;
+ }
auto borderBox = displayBox.borderBox();
return Display::Rect {
- borderBox.top() - displayBox.nonCollapsedMarginBefore(),
+ borderBox.top() - marginBefore,
borderBox.left() - marginStart,
marginStart + borderBox.width() + marginEnd,
- displayBox.nonCollapsedMarginBefore() + borderBox.height() + displayBox.nonCollapsedMarginAfter()
+ marginBefore + borderBox.height() + marginAfter
};
};
@@ -262,11 +271,11 @@
if (renderer.isInFlowPositioned())
frameRect.move(renderer.offsetForInFlowPosition());
- auto displayBox = Display::Box { context.displayBoxForLayoutBox(layoutBox) };
+ auto displayBox = Display::Box { layoutState.displayBoxForLayoutBox(layoutBox) };
if (layoutBox.isTableBox()) {
// When the <table> is out-of-flow positioned, the wrapper table box has the offset
// while the actual table box is static, inflow.
- auto& tableWrapperDisplayBox = context.displayBoxForLayoutBox(layoutBox.containingBlock());
+ auto& tableWrapperDisplayBox = layoutState.displayBoxForLayoutBox(layoutBox.containingBlock());
displayBox.moveBy(tableWrapperDisplayBox.topLeft());
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -264,7 +264,9 @@
auto nonCollapsedValues = UsedVerticalMargin::NonCollapsedValues { precomputedMarginBefore.nonCollapsedValue, { } };
auto collapsedValues = UsedVerticalMargin::CollapsedValues { precomputedMarginBefore.collapsedValue, { }, false };
auto verticalMargin = UsedVerticalMargin { nonCollapsedValues, collapsedValues };
- displayBox.setVerticalMargin(verticalMargin);
+
+ formattingState().setUsedVerticalMargin(*ancestor, verticalMargin);
+ displayBox.setVerticalMargin({ marginBefore(verticalMargin), marginAfter(verticalMargin) });
displayBox.setTop(verticalPositionWithMargin(*ancestor, verticalMargin, constraintsForAncestor.vertical));
#if ASSERT_ENABLED
setPrecomputedMarginBefore(*ancestor, precomputedMarginBefore);
@@ -369,6 +371,7 @@
// Cache the computed positive and negative margin value pair.
formattingState().setPositiveAndNegativeVerticalMargin(layoutBox, collapsedAndPositiveNegativeValues.positiveAndNegativeVerticalValues);
auto verticalMargin = UsedVerticalMargin { contentHeightAndMargin.nonCollapsedMargin, collapsedAndPositiveNegativeValues.collapsedValues };
+ formattingState().setUsedVerticalMargin(layoutBox, verticalMargin);
// Out of flow boxes don't need vertical adjustment after margin collapsing.
if (layoutBox.isOutOfFlowPositioned()) {
@@ -375,12 +378,12 @@
ASSERT(!hasPrecomputedMarginBefore(layoutBox));
auto& displayBox = formattingState().displayBox(layoutBox);
displayBox.setContentBoxHeight(contentHeightAndMargin.contentHeight);
- displayBox.setVerticalMargin(verticalMargin);
+ displayBox.setVerticalMargin({ contentHeightAndMargin.nonCollapsedMargin.before, contentHeightAndMargin.nonCollapsedMargin.after });
return;
}
#if ASSERT_ENABLED
- if (hasPrecomputedMarginBefore(layoutBox) && precomputedMarginBefore(layoutBox).usedValue() != verticalMargin.before()) {
+ if (hasPrecomputedMarginBefore(layoutBox) && precomputedMarginBefore(layoutBox).usedValue() != marginBefore(verticalMargin)) {
// When the pre-computed margin turns out to be incorrect, we need to re-layout this subtree with the correct margin values.
// <div style="float: left"></div>
// <div>
@@ -398,7 +401,7 @@
displayBox.setTop(verticalPositionWithMargin(layoutBox, verticalMargin, constraints.vertical));
}
displayBox.setContentBoxHeight(contentHeightAndMargin.contentHeight);
- displayBox.setVerticalMargin(verticalMargin);
+ displayBox.setVerticalMargin({ marginBefore(verticalMargin), marginAfter(verticalMargin) });
// Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
MarginCollapse::updateMarginAfterForPreviousSibling(*this, marginCollapse, layoutBox);
}
@@ -467,12 +470,12 @@
auto& previousInFlowSibling = *currentLayoutBox->previousInFlowSibling();
if (!marginCollapse().marginBeforeCollapsesWithPreviousSiblingMarginAfter(*currentLayoutBox)) {
auto& previousBoxGeometry = geometryForBox(previousInFlowSibling);
- return previousBoxGeometry.rectWithMargin().bottom() + verticalMargin.before();
+ return previousBoxGeometry.rectWithMargin().bottom() + marginBefore(verticalMargin);
}
if (!marginCollapse().marginsCollapseThrough(previousInFlowSibling)) {
auto& previousBoxGeometry = geometryForBox(previousInFlowSibling);
- return previousBoxGeometry.bottom() + verticalMargin.before();
+ return previousBoxGeometry.bottom() + marginBefore(verticalMargin);
}
currentLayoutBox = &previousInFlowSibling;
}
@@ -483,13 +486,13 @@
if (directlyAdjoinsParent) {
// If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it.
// In this case, the position of the element depends on its relationship with the other elements whose margins are being collapsed.
- if (verticalMargin.collapsedValues().isCollapsedThrough) {
+ if (verticalMargin.collapsedValues.isCollapsedThrough) {
// If the element's margins are collapsed with its parent's top margin, the top border edge of the box is defined to be the same as the parent's.
if (marginCollapse().marginBeforeCollapsesWithParentMarginBefore(layoutBox))
return containingBlockContentBoxTop;
// Otherwise, either the element's parent is not taking part in the margin collapsing, or only the parent's bottom margin is involved.
// The position of the element's top border edge is the same as it would have been if the element had a non-zero bottom border.
- auto beforeMarginWithBottomBorder = marginCollapse().marginBeforeIgnoringCollapsingThrough(layoutBox, verticalMargin.nonCollapsedValues());
+ auto beforeMarginWithBottomBorder = marginCollapse().marginBeforeIgnoringCollapsingThrough(layoutBox, verticalMargin.nonCollapsedValues);
return containingBlockContentBoxTop + beforeMarginWithBottomBorder;
}
// Non-collapsed through box vertical position depending whether the margin collapses.
@@ -496,7 +499,7 @@
if (marginCollapse().marginBeforeCollapsesWithParentMarginBefore(layoutBox))
return containingBlockContentBoxTop;
- return containingBlockContentBoxTop + verticalMargin.before();
+ return containingBlockContentBoxTop + marginBefore(verticalMargin);
}
// At this point this box indirectly (via collapsed through previous in-flow siblings) adjoins the parent. Let's check if it margin collapses with the parent.
auto& containingBlock = layoutBox.containingBlock();
@@ -505,7 +508,7 @@
if (marginCollapse().marginBeforeCollapsesWithParentMarginBefore(*containingBlock.firstInFlowChild()))
return containingBlockContentBoxTop;
- return containingBlockContentBoxTop + verticalMargin.before();
+ return containingBlockContentBoxTop + marginBefore(verticalMargin);
}
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -84,16 +84,15 @@
}
// 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin...
- auto* lastInFlowChild = layoutContainer.lastInFlowChild();
- ASSERT(lastInFlowChild);
- if (!formattingContext().marginCollapse().marginAfterCollapsesWithParentMarginAfter(*lastInFlowChild)) {
- auto& lastInFlowBoxGeometry = formattingContext().geometryForBox(*lastInFlowChild);
- auto bottomEdgeOfBottomMargin = lastInFlowBoxGeometry.bottom() + (lastInFlowBoxGeometry.hasCollapsedThroughMargin() ? LayoutUnit() : lastInFlowBoxGeometry.marginAfter());
+ auto& lastInFlowChild = *layoutContainer.lastInFlowChild();
+ if (!formattingContext().marginCollapse().marginAfterCollapsesWithParentMarginAfter(lastInFlowChild)) {
+ auto& lastInFlowBoxGeometry = formattingContext().geometryForBox(lastInFlowChild);
+ auto bottomEdgeOfBottomMargin = lastInFlowBoxGeometry.bottom() + lastInFlowBoxGeometry.marginAfter();
return { bottomEdgeOfBottomMargin - borderAndPaddingTop, nonCollapsedMargin };
}
// 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
- auto* inFlowChild = lastInFlowChild;
+ auto* inFlowChild = &lastInFlowChild;
while (inFlowChild && formattingContext().marginCollapse().marginBeforeCollapsesWithParentMarginAfter(*inFlowChild))
inFlowChild = inFlowChild->previousInFlowSibling();
if (inFlowChild) {
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.h (263942 => 263943)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.h 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.h 2020-07-04 20:06:27 UTC (rev 263943)
@@ -44,8 +44,12 @@
bool hasPositiveAndNegativeVerticalMargin(const Box& layoutBox) const { return m_positiveAndNegativeVerticalMargin.contains(&layoutBox); }
PositiveAndNegativeVerticalMargin positiveAndNegativeVerticalMargin(const Box& layoutBox) const { return m_positiveAndNegativeVerticalMargin.get(&layoutBox); }
+ void setUsedVerticalMargin(const Box& layoutBox, const UsedVerticalMargin& usedVerticalMargin) { m_usedVerticalMargins.set(&layoutBox, usedVerticalMargin); }
+ UsedVerticalMargin usedVerticalMargin(const Box& layoutBox) const { return m_usedVerticalMargins.get(&layoutBox); }
+
private:
HashMap<const Box*, PositiveAndNegativeVerticalMargin> m_positiveAndNegativeVerticalMargin;
+ HashMap<const Box*, UsedVerticalMargin> m_usedVerticalMargins;
};
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -483,11 +483,10 @@
auto& blockFormattingState = blockFormattingContext.formattingState();
while (marginCollapse.marginBeforeCollapsesWithPreviousSiblingMarginAfter(*currentBox)) {
auto& previousSibling = *currentBox->previousInFlowSibling();
- auto& previousSiblingDisplayBox = blockFormattingState.displayBox(previousSibling);
- auto previousSiblingVerticalMargin = previousSiblingDisplayBox.verticalMargin();
+ auto previousSiblingVerticalMargin = blockFormattingState.usedVerticalMargin(previousSibling);
- auto collapsedVerticalMarginBefore = previousSiblingVerticalMargin.collapsedValues().before;
- auto collapsedVerticalMarginAfter = blockFormattingContext.geometryForBox(*currentBox).verticalMargin().before();
+ auto collapsedVerticalMarginBefore = previousSiblingVerticalMargin.collapsedValues.before;
+ auto collapsedVerticalMarginAfter = blockFormattingContext.geometryForBox(*currentBox).marginBefore();
auto marginsCollapseThrough = marginCollapse.marginsCollapseThrough(previousSibling);
if (marginsCollapseThrough)
Modified: trunk/Source/WebCore/layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -224,11 +224,12 @@
// Cache the computed positive and negative margin value pair.
formattingState().setPositiveAndNegativeVerticalMargin(tableBox, collapsedAndPositiveNegativeValues.positiveAndNegativeVerticalValues);
auto verticalMargin = UsedVerticalMargin { heightAndMargin.nonCollapsedMargin, collapsedAndPositiveNegativeValues.collapsedValues };
+ formattingState().setUsedVerticalMargin(tableBox, verticalMargin);
auto& displayBox = formattingState().displayBox(tableBox);
displayBox.setTop(verticalPositionWithMargin(tableBox, verticalMargin, constraints.vertical));
displayBox.setContentBoxHeight(heightAndMargin.contentHeight);
- displayBox.setVerticalMargin(verticalMargin);
+ displayBox.setVerticalMargin({ marginBefore(verticalMargin), marginAfter(verticalMargin) });
// Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
MarginCollapse::updateMarginAfterForPreviousSibling(*this, marginCollapse, tableBox);
}
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -49,7 +49,6 @@
, m_hasValidLeft(other.m_hasValidLeft)
, m_hasValidHorizontalMargin(other.m_hasValidHorizontalMargin)
, m_hasValidVerticalMargin(other.m_hasValidVerticalMargin)
- , m_hasValidVerticalNonCollapsedMargin(other.m_hasValidVerticalNonCollapsedMargin)
, m_hasValidBorder(other.m_hasValidBorder)
, m_hasValidPadding(other.m_hasValidPadding)
, m_hasValidContentHeight(other.m_hasValidContentHeight)
@@ -75,18 +74,6 @@
return marginBox;
}
-Rect Box::nonCollapsedMarginBox() const
-{
- auto borderBox = this->borderBox();
-
- Rect marginBox;
- marginBox.setTop(borderBox.top() - nonCollapsedMarginBefore());
- marginBox.setLeft(borderBox.left() - marginStart());
- marginBox.setHeight(borderBox.height() + nonCollapsedMarginBefore() + nonCollapsedMarginAfter());
- marginBox.setWidth(borderBox.width() + marginStart() + marginEnd());
- return marginBox;
-}
-
Rect Box::borderBox() const
{
Rect borderBox;
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (263942 => 263943)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2020-07-04 20:06:27 UTC (rev 263943)
@@ -54,59 +54,25 @@
LayoutUnit height() const { return borderTop() + paddingBoxHeight() + borderBottom(); }
bool isEmpty() const { return size().isEmpty(); }
Rect rect() const { return { top(), left(), width(), height() }; }
- Rect rectWithMargin() const;
+ Rect rectWithMargin() const { return { top() - marginBefore(), left() - marginStart(), marginStart() + width() + marginEnd(), marginBefore() + height() + marginAfter() }; }
+ struct VerticalMargin {
+ LayoutUnit before;
+ LayoutUnit after;
+ };
+ VerticalMargin verticalMargin() const;
+
struct HorizontalMargin {
LayoutUnit start;
LayoutUnit end;
};
- struct VerticalMargin {
- LayoutUnit before() const { return m_collapsedValues.before.valueOr(m_nonCollapsedValues.before); }
- LayoutUnit after() const { return m_collapsedValues.after.valueOr(m_nonCollapsedValues.after); }
- bool isCollapsedThrough() const { return m_collapsedValues.isCollapsedThrough; }
-
- struct NonCollapsedValues {
- NonCollapsedValues(Layout::UsedVerticalMargin::NonCollapsedValues);
- NonCollapsedValues() = default;
-
- LayoutUnit before;
- LayoutUnit after;
- };
- NonCollapsedValues nonCollapsedValues() const { return m_nonCollapsedValues; }
-
- struct CollapsedValues {
- CollapsedValues(Layout::UsedVerticalMargin::CollapsedValues);
- CollapsedValues() = default;
-
- Optional<LayoutUnit> before;
- Optional<LayoutUnit> after;
- bool isCollapsedThrough { false };
- };
- CollapsedValues collapsedValues() const { return m_collapsedValues; }
- bool hasCollapsedValues() const { return m_collapsedValues.before || m_collapsedValues.after; }
- void setCollapsedValues(CollapsedValues collapsedValues) { m_collapsedValues = collapsedValues; }
-
- VerticalMargin(NonCollapsedValues, CollapsedValues);
- VerticalMargin(Layout::UsedVerticalMargin);
- VerticalMargin(Layout::UsedVerticalMargin::NonCollapsedValues);
- VerticalMargin() = default;
-
- private:
- NonCollapsedValues m_nonCollapsedValues;
- CollapsedValues m_collapsedValues;
- };
- VerticalMargin verticalMargin() const;
HorizontalMargin horizontalMargin() const;
LayoutUnit marginBefore() const;
LayoutUnit marginStart() const;
LayoutUnit marginAfter() const;
LayoutUnit marginEnd() const;
- bool hasCollapsedThroughMargin() const { return m_verticalMargin.isCollapsedThrough(); }
bool hasClearance() const { return m_hasClearance; }
- LayoutUnit nonCollapsedMarginBefore() const;
- LayoutUnit nonCollapsedMarginAfter() const;
-
LayoutUnit borderTop() const;
LayoutUnit borderLeft() const;
LayoutUnit borderBottom() const;
@@ -144,8 +110,6 @@
LayoutUnit horizontalMarginBorderAndPadding() const { return marginStart() + horizontalBorder() + horizontalPadding().valueOr(0) + marginEnd(); }
Rect marginBox() const;
- Rect nonCollapsedMarginBox() const;
-
Rect borderBox() const;
Rect paddingBox() const;
Rect contentBox() const;
@@ -184,7 +148,6 @@
void setHasValidTop() { m_hasValidTop = true; }
void setHasValidLeft() { m_hasValidLeft = true; }
void setHasValidVerticalMargin() { m_hasValidVerticalMargin = true; }
- void setHasValidVerticalNonCollapsedMargin() { m_hasValidVerticalNonCollapsedMargin = true; }
void setHasValidHorizontalMargin() { m_hasValidHorizontalMargin = true; }
void setHasValidBorder() { m_hasValidBorder = true; }
@@ -210,7 +173,6 @@
bool m_hasValidLeft { false };
bool m_hasValidHorizontalMargin { false };
bool m_hasValidVerticalMargin { false };
- bool m_hasValidVerticalNonCollapsedMargin { false };
bool m_hasValidBorder { false };
bool m_hasValidPadding { false };
bool m_hasValidContentHeight { false };
@@ -219,36 +181,6 @@
#endif // ASSERT_ENABLED
};
-inline Box::VerticalMargin::VerticalMargin(Layout::UsedVerticalMargin usedVerticalMargin)
- : m_nonCollapsedValues(usedVerticalMargin.nonCollapsedValues())
- , m_collapsedValues(usedVerticalMargin.collapsedValues())
-{
-}
-
-inline Box::VerticalMargin::VerticalMargin(VerticalMargin::NonCollapsedValues nonCollapsedValues, VerticalMargin::CollapsedValues collapsedValues)
- : m_nonCollapsedValues(nonCollapsedValues)
- , m_collapsedValues(collapsedValues)
-{
-}
-
-inline Box::VerticalMargin::VerticalMargin(Layout::UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
- : m_nonCollapsedValues(nonCollapsedValues)
-{
-}
-
-inline Box::VerticalMargin::NonCollapsedValues::NonCollapsedValues(Layout::UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
- : before(nonCollapsedValues.before)
- , after(nonCollapsedValues.after)
-{
-}
-
-inline Box::VerticalMargin::CollapsedValues::CollapsedValues(Layout::UsedVerticalMargin::CollapsedValues collapsedValues)
- : before(collapsedValues.before)
- , after(collapsedValues.after)
- , isCollapsedThrough(collapsedValues.isCollapsedThrough)
-{
-}
-
#if ASSERT_ENABLED
inline void Box::invalidateMargin()
{
@@ -341,7 +273,6 @@
{
#if ASSERT_ENABLED
setHasValidVerticalMargin();
- setHasValidVerticalNonCollapsedMargin();
invalidatePrecomputedMarginBefore();
#endif
m_verticalMargin = margin;
@@ -371,14 +302,6 @@
m_padding = Layout::Edges { m_padding ? m_padding->horizontal : Layout::HorizontalEdges(), verticalPadding };
}
-inline Rect Box::rectWithMargin() const
-{
- auto marginAfter = this->marginAfter();
- if (m_verticalMargin.collapsedValues().isCollapsedThrough)
- marginAfter = 0;
- return { top() - marginBefore(), left() - marginStart(), marginStart() + width() + marginEnd(), marginBefore() + height() + marginAfter };
-}
-
inline Box::VerticalMargin Box::verticalMargin() const
{
ASSERT(m_hasValidVerticalMargin);
@@ -394,7 +317,7 @@
inline LayoutUnit Box::marginBefore() const
{
ASSERT(m_hasValidVerticalMargin);
- return m_verticalMargin.before();
+ return m_verticalMargin.before;
}
inline LayoutUnit Box::marginStart() const
@@ -406,7 +329,7 @@
inline LayoutUnit Box::marginAfter() const
{
ASSERT(m_hasValidVerticalMargin);
- return m_verticalMargin.after();
+ return m_verticalMargin.after;
}
inline LayoutUnit Box::marginEnd() const
@@ -415,18 +338,6 @@
return m_horizontalMargin.end;
}
-inline LayoutUnit Box::nonCollapsedMarginBefore() const
-{
- ASSERT(m_hasValidVerticalNonCollapsedMargin);
- return m_verticalMargin.nonCollapsedValues().before;
-}
-
-inline LayoutUnit Box::nonCollapsedMarginAfter() const
-{
- ASSERT(m_hasValidVerticalNonCollapsedMargin);
- return m_verticalMargin.nonCollapsedValues().after;
-}
-
inline Optional<LayoutUnit> Box::paddingTop() const
{
ASSERT(m_hasValidPadding);
Modified: trunk/Source/WebCore/layout/floats/FloatingContext.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -304,12 +304,13 @@
// Clearance inhibits margin collapsing.
if (auto* previousInFlowSibling = layoutBox.previousInFlowSibling()) {
- // Does this box with clearance actually collapse its margin before with the previous inflow box's margin after?
- auto verticalMargin = formattingContext().geometryForBox(layoutBox).verticalMargin();
- if (verticalMargin.hasCollapsedValues() && verticalMargin.collapsedValues().before) {
- auto previousVerticalMargin = formattingContext().geometryForBox(*previousInFlowSibling).verticalMargin();
- auto collapsedMargin = *verticalMargin.collapsedValues().before;
- auto nonCollapsedMargin = previousVerticalMargin.after() + verticalMargin.before();
+ // Does this box with clearance actually collapse its margin before with the previous inflow box's margin after?
+ auto& formattingState = downcast<BlockFormattingState>(layoutState().formattingStateForBox(layoutBox));
+ auto verticalMargin = formattingState.usedVerticalMargin(layoutBox);
+ if (verticalMargin.collapsedValues.before) {
+ auto previousVerticalMarginAfter = formattingContext().geometryForBox(*previousInFlowSibling).marginAfter();
+ auto collapsedMargin = *verticalMargin.collapsedValues.before;
+ auto nonCollapsedMargin = previousVerticalMarginAfter + marginBefore(verticalMargin);
auto marginDifference = nonCollapsedMargin - collapsedMargin;
// Move the box to the position where it would be with non-collapsed margins.
rootRelativeTop += marginDifference;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -116,7 +116,7 @@
// Inline boxes (<span>) can't get sized/positioned yet. At this point we can only compute their margins, borders and paddings.
computeBorderAndPadding(*layoutBox, constraints.horizontal);
computeHorizontalMargin(*layoutBox, constraints.horizontal);
- formattingState().displayBox(*layoutBox).setVerticalMargin({ { }, { } });
+ formattingState().displayBox(*layoutBox).setVerticalMargin({ });
}
} else
ASSERT_NOT_REACHED();
@@ -343,7 +343,7 @@
}
auto& displayBox = formattingState().displayBox(layoutBox);
displayBox.setContentBoxHeight(contentHeightAndMargin.contentHeight);
- displayBox.setVerticalMargin({ contentHeightAndMargin.nonCollapsedMargin });
+ displayBox.setVerticalMargin({ contentHeightAndMargin.nonCollapsedMargin.before, contentHeightAndMargin.nonCollapsedMargin.after });
}
void InlineFormattingContext::collectInlineContentIfNeeded()
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (263942 => 263943)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2020-07-04 19:21:06 UTC (rev 263942)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2020-07-04 20:06:27 UTC (rev 263943)
@@ -156,7 +156,7 @@
rowDisplayBox.setPadding(geometry().computedPadding(rowBox, availableHorizontalSpace));
// Internal table elements do not have margins.
rowDisplayBox.setHorizontalMargin({ });
- rowDisplayBox.setVerticalMargin({ { }, { } });
+ rowDisplayBox.setVerticalMargin({ });
auto computedRowBorder = [&] {
auto border = geometry().computedBorder(rowBox);
@@ -238,7 +238,7 @@
paddingBefore = WTF::nullopt;
// Internal table elements do not have margins.
sectionDisplayBox.setHorizontalMargin({ });
- sectionDisplayBox.setVerticalMargin({ { }, { } });
+ sectionDisplayBox.setVerticalMargin({ });
sectionDisplayBox.setContentBoxWidth(sectionWidth);
auto sectionContentHeight = LayoutUnit { };
@@ -268,7 +268,7 @@
cellDisplayBox.setPadding(geometry().computedPadding(cellBox, availableHorizontalSpace));
// Internal table elements do not have margins.
cellDisplayBox.setHorizontalMargin({ });
- cellDisplayBox.setVerticalMargin({ { }, { } });
+ cellDisplayBox.setVerticalMargin({ });
auto availableSpaceForContent = [&] {
auto& columnList = grid.columns().list();