Diff
Modified: trunk/Source/WebCore/ChangeLog (239654 => 239655)
--- trunk/Source/WebCore/ChangeLog 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/ChangeLog 2019-01-05 08:38:41 UTC (rev 239655)
@@ -1,3 +1,61 @@
+2019-01-05 Zalan Bujtas <[email protected]>
+
+ [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 <[email protected]>
REGRESSION (r238522): Erratic scrolling on Google flights search result page and vrbo.com
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -116,11 +116,11 @@
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
Modified: trunk/Source/WebCore/layout/FormattingContext.h (239654 => 239655)
--- trunk/Source/WebCore/layout/FormattingContext.h 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/FormattingContext.h 2019-01-05 08:38:41 UTC (rev 239655)
@@ -97,7 +97,7 @@
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);
Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -280,10 +280,8 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
// 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 @@
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 @@
// 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 @@
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) };
}
}
Modified: trunk/Source/WebCore/layout/FormattingContextQuirks.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/FormattingContextQuirks.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/FormattingContextQuirks.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -51,10 +51,10 @@
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();
Modified: trunk/Source/WebCore/layout/LayoutUnits.h (239654 => 239655)
--- trunk/Source/WebCore/layout/LayoutUnits.h 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/LayoutUnits.h 2019-01-05 08:38:41 UTC (rev 239655)
@@ -109,7 +109,7 @@
struct HeightAndMargin {
LayoutUnit height;
- VerticalMargin margin;
+ UsedVerticalMargin usedMargin;
};
struct HorizontalGeometry {
Modified: trunk/Source/WebCore/layout/MarginTypes.h (239654 => 239655)
--- trunk/Source/WebCore/layout/MarginTypes.h 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/MarginTypes.h 2019-01-05 08:38:41 UTC (rev 239655)
@@ -32,28 +32,36 @@
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,20 +83,12 @@
Values after;
};
-inline VerticalMargin::VerticalMargin(VerticalMargin::ComputedValues nonCollapsed, Optional<VerticalMargin::CollapsedValues> collapsed)
- : m_nonCollapsed(nonCollapsed)
- , m_collapsed(collapsed)
+inline UsedVerticalMargin::UsedVerticalMargin(UsedVerticalMargin::NonCollapsedValues nonCollapsedValues, UsedVerticalMargin::CollapsedValues collapsedValues)
+ : m_nonCollapsedValues(nonCollapsedValues)
+ , m_collapsedValues(collapsedValues)
{
}
-inline VerticalMargin::ComputedValues VerticalMargin::usedValues() const
-{
- if (!m_collapsed)
- return m_nonCollapsed;
- return { m_collapsed->before.valueOr(m_nonCollapsed.before),
- m_collapsed->after.valueOr(m_nonCollapsed.after) };
}
-
}
-}
#endif
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -358,7 +358,7 @@
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 @@
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
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -57,13 +57,10 @@
// 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 @@
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 = 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;
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -80,10 +80,10 @@
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 @@
// 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.
Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -107,7 +107,7 @@
{
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)
@@ -114,7 +114,7 @@
{
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)
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (239654 => 239655)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2019-01-05 08:38:41 UTC (rev 239655)
@@ -138,7 +138,7 @@
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 @@
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 @@
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 @@
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 @@
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 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::marginAfter() const
{
ASSERT(m_hasValidVerticalMargin);
- return m_verticalMargin.usedValues().after;
+ return m_verticalMargin.after();
}
inline LayoutUnit Box::marginEnd() const
Modified: trunk/Source/WebCore/layout/floats/FloatingContext.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -193,14 +193,14 @@
// 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);
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (239654 => 239655)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2019-01-05 07:17:24 UTC (rev 239654)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2019-01-05 08:38:41 UTC (rev 239655)
@@ -362,7 +362,7 @@
auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
displayBox.setContentBoxHeight(heightAndMargin.height);
- displayBox.setVerticalMargin(heightAndMargin.margin);
+ displayBox.setVerticalMargin(heightAndMargin.usedMargin);
}
void InlineFormattingContext::layoutFormattingContextRoot(const Box& root) const