Diff
Modified: trunk/Source/WebCore/ChangeLog (232838 => 232839)
--- trunk/Source/WebCore/ChangeLog 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/ChangeLog 2018-06-14 14:27:28 UTC (rev 232839)
@@ -1,3 +1,42 @@
+2018-06-13 Zalan Bujtas <[email protected]>
+
+ [LFC] Miscellaneous fixes to be able to layout <div> with fixed width/height
+ https://bugs.webkit.org/show_bug.cgi?id=186616
+
+ Reviewed by Antti Koivisto.
+
+ 1. Move box horizontally/vertically when relevant margin is computed.
+ 2. Fix isStretchedToViewport() logic and make sure that the width/height is adjusted with the margin when the box is stretchy.
+ 3. Fix isPaddingApplicable() and add "GenericElement" for elements that don't need special handling.
+
+ With this patch LFC produces the correct geometry for the following content:
+ <html><body><div style="width: 100px; height: 100px;"></div></body></html>
+
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::computeFloatingHeightAndMargin const):
+ (WebCore::Layout::FormattingContext::computeFloatingWidthAndMargin const):
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::layout const):
+ (WebCore::Layout::BlockFormattingContext::computeInFlowHeightAndMargin const):
+ (WebCore::Layout::BlockFormattingContext::computeInFlowWidthAndMargin const):
+ * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+ (WebCore::Layout::isStretchedToViewport):
+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
+ (WebCore::Layout::BlockFormattingContext::Geometry::staticPosition):
+ * layout/displaytree/DisplayBox.h:
+ (WebCore::Display::Box::moveHorizontally):
+ (WebCore::Display::Box::moveVertically):
+ (WebCore::Display::Box::Rect::setWidth):
+ (WebCore::Display::Box::Rect::setHeight):
+ (WebCore::Display::Box::Rect::moveHorizontally):
+ (WebCore::Display::Box::Rect::moveVertically):
+ * layout/layouttree/LayoutBox.cpp:
+ (WebCore::Layout::Box::isPaddingApplicable const):
+ * layout/layouttree/LayoutBox.h:
+ * layout/layouttree/LayoutTreeBuilder.cpp:
+ (WebCore::Layout::TreeBuilder::createSubTree):
+
2018-06-13 Chris Dumez <[email protected]>
Crash under SWServer::unregisterConnection(Connection&)
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (232838 => 232839)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2018-06-14 14:27:28 UTC (rev 232839)
@@ -53,6 +53,7 @@
{
auto heightAndMargin = Geometry::floatingHeightAndMargin(layoutContext, layoutBox);
displayBox.setHeight(heightAndMargin.height);
+ displayBox.moveVertically(heightAndMargin.margin.top);
displayBox.setVerticalMargin(heightAndMargin.margin);
}
@@ -60,6 +61,7 @@
{
auto widthAndMargin = Geometry::floatingWidthAndMargin(layoutContext, layoutBox);
displayBox.setWidth(widthAndMargin.width);
+ displayBox.moveHorizontally(widthAndMargin.margin.left);
displayBox.setHorizontalMargin(widthAndMargin.margin);
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (232838 => 232839)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-06-14 14:27:28 UTC (rev 232839)
@@ -73,9 +73,9 @@
auto& layoutBox = layoutPair.layoutBox;
auto& displayBox = layoutPair.displayBox;
+ computeStaticPosition(layoutContext, layoutBox, displayBox);
computeBorderAndPadding(layoutContext, layoutBox, displayBox);
computeWidthAndMargin(layoutContext, layoutBox, displayBox);
- computeStaticPosition(layoutContext, layoutBox, displayBox);
if (layoutBox.establishesFormattingContext()) {
auto formattingContext = layoutContext.formattingContext(layoutBox);
formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox, *formattingContext));
@@ -164,6 +164,7 @@
{
auto heightAndMargin = Geometry::inFlowHeightAndMargin(layoutContext, layoutBox);
displayBox.setHeight(heightAndMargin.height);
+ displayBox.moveVertically(heightAndMargin.margin.top);
displayBox.setVerticalMargin(heightAndMargin.margin);
}
@@ -171,6 +172,7 @@
{
auto widthAndMargin = Geometry::inFlowWidthAndMargin(layoutContext, layoutBox);
displayBox.setWidth(widthAndMargin.width);
+ displayBox.moveHorizontally(widthAndMargin.margin.left);
displayBox.setHorizontalMargin(widthAndMargin.margin);
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (232838 => 232839)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2018-06-14 14:27:28 UTC (rev 232839)
@@ -40,7 +40,7 @@
if (!layoutContext.inQuirksMode())
return false;
- if (!layoutBox.isDocumentBox() || !layoutBox.isBodyBox())
+ if (!layoutBox.isDocumentBox() && !layoutBox.isBodyBox())
return false;
return layoutBox.style().logicalHeight().isAuto();
@@ -114,8 +114,13 @@
if (!isStretchedToViewport(layoutContext, layoutBox))
return { height, { marginTop, marginBottom } };
+
auto initialContainingBlockHeight = layoutContext.displayBoxForLayoutBox(initialContainingBlock(layoutBox))->contentBox().height();
- return { std::max(height, initialContainingBlockHeight), { marginTop, marginBottom } };
+ // Stretch but never overstretch with the margins.
+ if (height + marginTop + marginBottom < initialContainingBlockHeight)
+ height = initialContainingBlockHeight - marginTop - marginBottom;
+
+ return { height, { marginTop, marginBottom } };
}
FormattingContext::Geometry::WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox,
@@ -220,8 +225,14 @@
auto computedWidthAndMarginValue = compute();
if (!isStretchedToViewport(layoutContext, layoutBox))
return computedWidthAndMarginValue;
+
auto initialContainingBlockWidth = layoutContext.displayBoxForLayoutBox(initialContainingBlock(layoutBox))->contentBox().width();
- return FormattingContext::Geometry::WidthAndMargin { std::max(computedWidthAndMarginValue.width, initialContainingBlockWidth), { computedWidthAndMarginValue.margin } };
+ auto horizontalMargins = computedWidthAndMarginValue.margin.left + computedWidthAndMarginValue.margin.right;
+ // Stretch but never overstretch with the margins.
+ if (computedWidthAndMarginValue.width + horizontalMargins < initialContainingBlockWidth)
+ computedWidthAndMarginValue.width = initialContainingBlockWidth - horizontalMargins;
+
+ return { computedWidthAndMarginValue.width, computedWidthAndMarginValue.margin };
}
FormattingContext::Geometry::WidthAndMargin BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
@@ -256,10 +267,7 @@
auto& previousInFlowDisplayBox = *layoutContext.displayBoxForLayoutBox(*previousInFlowSibling);
top = previousInFlowDisplayBox.bottom() + previousInFlowDisplayBox.marginBottom();
}
- auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox);
- LayoutPoint topLeft = { top, left };
- topLeft.moveBy({ displayBox.marginLeft(), displayBox.marginTop() });
- return topLeft;
+ return { top, left };
}
LayoutPoint BlockFormattingContext::Geometry::inFlowPositionedPosition(LayoutContext& layoutContext, const Box& layoutBox)
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (232838 => 232839)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-06-14 14:27:28 UTC (rev 232839)
@@ -80,6 +80,9 @@
void shiftTopTo(LayoutUnit);
void shiftBottomTo(LayoutUnit);
+ void moveHorizontally(LayoutUnit);
+ void moveVertically(LayoutUnit);
+
void expand(LayoutUnit, LayoutUnit);
Rect clone() const;
@@ -156,6 +159,8 @@
void setTopLeft(const LayoutPoint& topLeft) { m_rect.setTopLeft(topLeft); }
void setTop(LayoutUnit top) { m_rect.setTop(top); }
void setLeft(LayoutUnit left) { m_rect.setLeft(left); }
+ void moveHorizontally(LayoutUnit offset) { m_rect.moveHorizontally(offset); }
+ void moveVertically(LayoutUnit offset) { m_rect.moveVertically(offset); }
void setWidth(LayoutUnit width) { m_rect.setWidth(width); }
void setHeight(LayoutUnit height) { m_rect.setHeight(height); }
void setSize(const LayoutSize& size) { m_rect.setSize(size); }
@@ -317,7 +322,6 @@
#if !ASSERT_DISABLED
m_hasValidWidth = true;
#endif
- ASSERT(m_hasValidLeft);
m_rect.setWidth(width);
}
@@ -326,7 +330,6 @@
#if !ASSERT_DISABLED
m_hasValidHeight = true;
#endif
- ASSERT(m_hasValidTop);
m_rect.setHeight(height);
}
@@ -362,6 +365,18 @@
m_rect.shiftMaxYEdgeTo(bottom);
}
+inline void Box::Rect::moveHorizontally(LayoutUnit offset)
+{
+ ASSERT(m_hasValidLeft);
+ m_rect.move(offset, { });
+}
+
+inline void Box::Rect::moveVertically(LayoutUnit offset)
+{
+ ASSERT(m_hasValidTop);
+ m_rect.move({ }, offset);
+}
+
inline void Box::Rect::expand(LayoutUnit width, LayoutUnit height)
{
ASSERT(hasValidGeometry());
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp (232838 => 232839)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-06-14 14:27:28 UTC (rev 232839)
@@ -230,8 +230,9 @@
{
// 8.4 Padding properties:
// Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
- if (!m_elementAttributes)
+ if (isAnonymous())
return false;
+
auto elementType = m_elementAttributes.value().elementType;
return elementType != ElementType::TableRowGroup
&& elementType != ElementType::TableHeaderGroup
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (232838 => 232839)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-06-14 14:27:28 UTC (rev 232839)
@@ -106,7 +106,8 @@
TableColumnGroup,
TableRowGroup,
TableHeaderGroup,
- TableFooterGroup
+ TableFooterGroup,
+ GenericElement
};
struct ElementAttributes {
Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp (232838 => 232839)
--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2018-06-14 10:27:22 UTC (rev 232838)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2018-06-14 14:27:28 UTC (rev 232839)
@@ -72,7 +72,10 @@
return Box::ElementAttributes { Box::ElementType::TableHeaderGroup };
if (element->hasTagName(HTMLNames::tfootTag))
return Box::ElementAttributes { Box::ElementType::TableFooterGroup };
- }
+ if (element->hasTagName(HTMLNames::tfootTag))
+ return Box::ElementAttributes { Box::ElementType::TableFooterGroup };
+ return Box::ElementAttributes { Box::ElementType::GenericElement };
+ }
return std::nullopt;
};