Diff
Modified: trunk/Source/WebCore/ChangeLog (235500 => 235501)
--- trunk/Source/WebCore/ChangeLog 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/ChangeLog 2018-08-30 14:25:45 UTC (rev 235501)
@@ -1,3 +1,41 @@
+2018-08-30 Zalan Bujtas <za...@apple.com>
+
+ [LFC][Margins] Add non-computed horizontal margins to DisplayBox
+ https://bugs.webkit.org/show_bug.cgi?id=189141
+
+ Reviewed by Antti Koivisto.
+
+ Inflow block boxes' horizontal margins extend all the way to the left/right edge of their containing block.
+ See https://www.w3.org/TR/CSS22/visudet.html#blockwidth for example
+ "...
+ 10.3.3 Block-level, non-replaced elements in normal flow
+ 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
+ ..."
+
+ In certain cases (float avoiding) we need to know the original (non-extended) horiztonal margin values.
+
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::computeFloatingWidthAndMargin const):
+ (WebCore::Layout::FormattingContext::computeOutOfFlowHorizontalGeometry const):
+ * layout/FormattingContextGeometry.cpp:
+ (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry):
+ (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry):
+ (WebCore::Layout::FormattingContext::Geometry::floatingNonReplacedWidthAndMargin):
+ (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
+ * layout/LayoutContext.cpp:
+ (WebCore::Layout::LayoutContext::initializeRoot):
+ * layout/LayoutUnits.h:
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::computeInFlowWidthAndMargin const):
+ * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin):
+ * layout/displaytree/DisplayBox.h:
+ (WebCore::Display::Box::setHasValidHorizontalNonComputedMargin):
+ (WebCore::Display::Box::setHorizontalNonComputedMargin):
+ (WebCore::Display::Box::nonComputedMarginLeft const):
+ (WebCore::Display::Box::nonComputedMarginRight const):
+
2018-08-30 Yusuke Suzuki <yusukesuz...@slowstart.org>
Unreviewed, add comments about enum names to bitfields
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (235500 => 235501)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2018-08-30 14:25:45 UTC (rev 235501)
@@ -67,6 +67,7 @@
displayBox.setContentBoxWidth(widthAndMargin.width);
displayBox.moveHorizontally(widthAndMargin.margin.left);
displayBox.setHorizontalMargin(widthAndMargin.margin);
+ displayBox.setHorizontalNonComputedMargin(widthAndMargin.nonComputedMargin);
}
void FormattingContext::computeOutOfFlowHorizontalGeometry(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
@@ -75,6 +76,7 @@
displayBox.setLeft(horizontalGeometry.left + horizontalGeometry.widthAndMargin.margin.left);
displayBox.setContentBoxWidth(horizontalGeometry.widthAndMargin.width);
displayBox.setHorizontalMargin(horizontalGeometry.widthAndMargin.margin);
+ displayBox.setHorizontalNonComputedMargin(horizontalGeometry.widthAndMargin.nonComputedMargin);
}
void FormattingContext::computeOutOfFlowVerticalGeometry(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (235500 => 235501)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2018-08-30 14:25:45 UTC (rev 235501)
@@ -315,6 +315,8 @@
auto width = computedValueIfNotAuto(style.logicalWidth(), containingBlockWidth);
auto marginLeft = computedValueIfNotAuto(style.marginLeft(), containingBlockWidth);
auto marginRight = computedValueIfNotAuto(style.marginRight(), containingBlockWidth);
+ auto nonComputedMarginLeft = marginLeft.value_or(0);
+ auto nonComputedMarginRight = marginRight.value_or(0);
auto paddingLeft = displayBox.paddingLeft().value_or(0);
auto paddingRight = displayBox.paddingRight().value_or(0);
auto borderLeft = displayBox.borderLeft();
@@ -415,7 +417,7 @@
ASSERT(marginRight);
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Width][Margin] -> out-of-flow non-replaced -> left(" << *left << "px) right(" << *right << "px) width(" << *width << "px) margin(" << *marginLeft << "px, " << *marginRight << "px) layoutBox(" << &layoutBox << ")");
- return { *left, *right, { *width, { *marginLeft, *marginRight } } };
+ return { *left, *right, { *width, { *marginLeft, *marginRight }, { nonComputedMarginLeft, nonComputedMarginRight } } };
}
VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(LayoutContext& layoutContext, const Box& layoutBox)
@@ -515,6 +517,8 @@
auto right = computedValueIfNotAuto(style.logicalRight(), containingBlockWidth);
auto marginLeft = computedValueIfNotAuto(style.marginLeft(), containingBlockWidth);
auto marginRight = computedValueIfNotAuto(style.marginRight(), containingBlockWidth);
+ auto nonComputedMarginLeft = marginLeft.value_or(0);
+ auto nonComputedMarginRight = marginRight.value_or(0);
auto width = inlineReplacedWidthAndMargin(layoutContext, layoutBox).width;
auto paddingLeft = displayBox.paddingLeft().value_or(0);
auto paddingRight = displayBox.paddingRight().value_or(0);
@@ -580,7 +584,7 @@
ASSERT(marginRight);
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Width][Margin] -> out-of-flow replaced -> left(" << *left << "px) right(" << *right << "px) width(" << width << "px) margin(" << *marginLeft << "px, " << *marginRight << "px) layoutBox(" << &layoutBox << ")");
- return { *left, *right, { width, { *marginLeft, *marginRight } } };
+ return { *left, *right, { width, { *marginLeft, *marginRight }, { nonComputedMarginLeft, nonComputedMarginRight } } };
}
HeightAndMargin FormattingContext::Geometry::complicatedCases(LayoutContext& layoutContext, const Box& layoutBox)
@@ -646,7 +650,7 @@
width = shrinkToFitWidth(layoutContext, formattingContext, layoutBox);
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> floating non-replaced -> width(" << *width << "px) margin(" << margin.left << "px, " << margin.right << "px) -> layoutBox(" << &layoutBox << ")");
- return WidthAndMargin { *width, margin };
+ return WidthAndMargin { *width, margin, margin };
}
HeightAndMargin FormattingContext::Geometry::floatingReplacedHeightAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
@@ -805,6 +809,8 @@
auto marginLeft = computeMarginLeft();
auto marginRight = computeMarginRight();
+ auto nonComputedMarginLeft = computedValueIfNotAuto(style.marginLeft(), containingBlockWidth).value_or(0);
+ auto nonComputedMarginRight = computedValueIfNotAuto(style.marginRight(), containingBlockWidth).value_or(0);
auto width = computedValueIfNotAuto(style.logicalWidth(), containingBlockWidth);
auto heightIsAuto = style.logicalHeight().isAuto();
@@ -834,7 +840,7 @@
ASSERT(width);
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow replaced -> width(" << *width << "px) margin(" << marginLeft << "px, " << marginRight << "px) -> layoutBox(" << &layoutBox << ")");
- return { *width, { marginLeft, marginRight } };
+ return { *width, { marginLeft, marginRight }, { nonComputedMarginLeft, nonComputedMarginRight } };
}
Edges FormattingContext::Geometry::computedBorder(LayoutContext&, const Box& layoutBox)
Modified: trunk/Source/WebCore/layout/LayoutContext.cpp (235500 => 235501)
--- trunk/Source/WebCore/layout/LayoutContext.cpp 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/LayoutContext.cpp 2018-08-30 14:25:45 UTC (rev 235501)
@@ -58,6 +58,7 @@
// FIXME: m_root could very well be a formatting context root with ancestors and resolvable border and padding (as opposed to the topmost root)
displayBox.setHorizontalMargin({ });
+ displayBox.setHorizontalNonComputedMargin({ });
displayBox.setVerticalMargin({ });
displayBox.setVerticalNonCollapsedMargin({ });
displayBox.setBorder({ });
Modified: trunk/Source/WebCore/layout/LayoutUnits.h (235500 => 235501)
--- trunk/Source/WebCore/layout/LayoutUnits.h 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/LayoutUnits.h 2018-08-30 14:25:45 UTC (rev 235501)
@@ -89,6 +89,7 @@
struct WidthAndMargin {
LayoutUnit width;
HorizontalEdges margin;
+ HorizontalEdges nonComputedMargin;
};
struct HeightAndMargin {
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (235500 => 235501)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-08-30 14:25:45 UTC (rev 235501)
@@ -261,6 +261,7 @@
displayBox.setContentBoxWidth(widthAndMargin.width);
displayBox.moveHorizontally(widthAndMargin.margin.left);
displayBox.setHorizontalMargin(widthAndMargin.margin);
+ displayBox.setHorizontalNonComputedMargin(widthAndMargin.nonComputedMargin);
}
FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsicWidthConstraints(LayoutContext& layoutContext, const Box& layoutBox) const
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (235500 => 235501)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2018-08-30 14:25:45 UTC (rev 235501)
@@ -189,6 +189,8 @@
auto width = FormattingContext::Geometry::computedValueIfNotAuto(precomputedWidth ? Length { precomputedWidth.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
auto marginLeft = FormattingContext::Geometry::computedValueIfNotAuto(style.marginLeft(), containingBlockWidth);
auto marginRight = FormattingContext::Geometry::computedValueIfNotAuto(style.marginRight(), containingBlockWidth);
+ auto nonComputedMarginLeft = marginLeft.value_or(0);
+ auto nonComputedMarginRight = marginRight.value_or(0);
auto borderLeft = displayBox.borderLeft();
auto borderRight = displayBox.borderRight();
auto paddingLeft = displayBox.paddingLeft().value_or(0);
@@ -236,7 +238,7 @@
ASSERT(marginLeft);
ASSERT(marginRight);
- return WidthAndMargin { *width, { *marginLeft, *marginRight } };
+ return WidthAndMargin { *width, { *marginLeft, *marginRight }, { nonComputedMarginLeft, nonComputedMarginRight } };
};
auto widthAndMargin = compute();
@@ -264,10 +266,10 @@
// #1
auto width = FormattingContext::Geometry::inlineReplacedWidthAndMargin(layoutContext, layoutBox).width;
// #2
- auto margin = inFlowNonReplacedWidthAndMargin(layoutContext, layoutBox, width).margin;
+ auto nonReplacedWidthAndMargin = inFlowNonReplacedWidthAndMargin(layoutContext, layoutBox, width);
- LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow replaced -> width(" << width << "px) margin(" << margin.left << "px, " << margin.left << "px) -> layoutBox(" << &layoutBox << ")");
- return { width, margin };
+ LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow replaced -> width(" << width << "px) margin(" << nonReplacedWidthAndMargin.margin.left << "px, " << nonReplacedWidthAndMargin.margin.right << "px) -> layoutBox(" << &layoutBox << ")");
+ return { width, nonReplacedWidthAndMargin.margin, nonReplacedWidthAndMargin.nonComputedMargin };
}
Position BlockFormattingContext::Geometry::staticPosition(LayoutContext& layoutContext, const Box& layoutBox)
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp (235500 => 235501)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp 2018-08-30 14:25:45 UTC (rev 235501)
@@ -59,6 +59,7 @@
, m_contentHeight(other.m_contentHeight)
, m_margin(other.m_margin)
, m_verticalNonCollapsedMargin(other.m_verticalNonCollapsedMargin)
+ , m_horizontalNonComputedMargin(other.m_horizontalNonComputedMargin)
, m_estimatedMarginTop(other.m_estimatedMarginTop)
, m_border(other.m_border)
, m_padding(other.m_padding)
@@ -68,6 +69,7 @@
, m_hasValidHorizontalMargin(other.m_hasValidHorizontalMargin)
, m_hasValidVerticalMargin(other.m_hasValidVerticalMargin)
, m_hasValidVerticalNonCollapsedMargin(other.m_hasValidVerticalNonCollapsedMargin)
+ , m_hasValidHorizontalNonComputedMargin(other.m_hasValidHorizontalNonComputedMargin)
, m_hasValidBorder(other.m_hasValidBorder)
, m_hasValidPadding(other.m_hasValidPadding)
, m_hasValidContentHeight(other.m_hasValidContentHeight)
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (235500 => 235501)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-08-30 14:21:42 UTC (rev 235500)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-08-30 14:25:45 UTC (rev 235501)
@@ -142,6 +142,9 @@
LayoutUnit nonCollapsedMarginTop() const;
LayoutUnit nonCollapsedMarginBottom() const;
+ LayoutUnit nonComputedMarginLeft() const;
+ LayoutUnit nonComputedMarginRight() const;
+
std::optional<LayoutUnit> estimatedMarginTop() const { return m_estimatedMarginTop; }
LayoutUnit borderTop() const;
@@ -189,6 +192,7 @@
void setHorizontalMargin(Layout::HorizontalEdges);
void setVerticalMargin(Layout::VerticalEdges);
void setVerticalNonCollapsedMargin(Layout::VerticalEdges);
+ void setHorizontalNonComputedMargin(Layout::HorizontalEdges);
void setEstimatedMarginTop(LayoutUnit marginTop) { m_estimatedMarginTop = marginTop; }
void setBorder(Layout::Edges);
@@ -203,6 +207,7 @@
void setHasValidLeft() { m_hasValidLeft = true; }
void setHasValidVerticalMargin() { m_hasValidVerticalMargin = true; }
void setHasValidVerticalNonCollapsedMargin() { m_hasValidVerticalNonCollapsedMargin = true; }
+ void setHasValidHorizontalNonComputedMargin() { m_hasValidHorizontalNonComputedMargin = true; }
void setHasValidHorizontalMargin() { m_hasValidHorizontalMargin = true; }
void setHasValidBorder() { m_hasValidBorder = true; }
@@ -220,6 +225,7 @@
Layout::Edges m_margin;
Layout::VerticalEdges m_verticalNonCollapsedMargin;
+ Layout::HorizontalEdges m_horizontalNonComputedMargin;
std::optional<LayoutUnit> m_estimatedMarginTop;
Layout::Edges m_border;
@@ -231,6 +237,7 @@
bool m_hasValidHorizontalMargin { false };
bool m_hasValidVerticalMargin { false };
bool m_hasValidVerticalNonCollapsedMargin { false };
+ bool m_hasValidHorizontalNonComputedMargin { false };
bool m_hasValidBorder { false };
bool m_hasValidPadding { false };
bool m_hasValidContentHeight { false };
@@ -524,6 +531,14 @@
m_verticalNonCollapsedMargin = margin;
}
+inline void Box::setHorizontalNonComputedMargin(Layout::HorizontalEdges margin)
+{
+#if !ASSERT_DISABLED
+ setHasValidHorizontalNonComputedMargin();
+#endif
+ m_horizontalNonComputedMargin = margin;
+}
+
inline void Box::setBorder(Layout::Edges border)
{
#if !ASSERT_DISABLED
@@ -576,6 +591,18 @@
return m_verticalNonCollapsedMargin.bottom;
}
+inline LayoutUnit Box::nonComputedMarginLeft() const
+{
+ ASSERT(m_hasValidHorizontalNonComputedMargin);
+ return m_horizontalNonComputedMargin.left;
+}
+
+inline LayoutUnit Box::nonComputedMarginRight() const
+{
+ ASSERT(m_hasValidHorizontalNonComputedMargin);
+ return m_horizontalNonComputedMargin.right;
+}
+
inline std::optional<LayoutUnit> Box::paddingTop() const
{
ASSERT(m_hasValidPadding);