Diff
Modified: trunk/Source/WebCore/ChangeLog (271011 => 271012)
--- trunk/Source/WebCore/ChangeLog 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/ChangeLog 2020-12-20 15:11:09 UTC (rev 271012)
@@ -1,3 +1,32 @@
+2020-12-20 Zalan Bujtas <[email protected]>
+
+ [LFC] Move content height logic to the formatting contexts.
+ https://bugs.webkit.org/show_bug.cgi?id=220040
+
+ Reviewed by Simon Fraser.
+
+ Formatting contexts know about their content height.
+
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::geometryForBox const):
+ * layout/FormattingContext.h:
+ * layout/FormattingContextGeometry.cpp:
+ (WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::usedContentHeight const):
+ * layout/blockformatting/BlockFormattingContext.h:
+ * layout/flexformatting/FlexFormattingContext.cpp:
+ (WebCore::Layout::FlexFormattingContext::usedContentHeight const):
+ * layout/flexformatting/FlexFormattingContext.h:
+ * layout/inlineformatting/InlineFormattingContext.cpp:
+ (WebCore::Layout::InlineFormattingContext::usedContentHeight const):
+ * layout/inlineformatting/InlineFormattingContext.h:
+ * layout/tableformatting/TableFormattingContext.cpp:
+ (WebCore::Layout::TableFormattingContext::usedContentHeight const):
+ * layout/tableformatting/TableFormattingContext.h:
+ * layout/tableformatting/TableFormattingContextGeometry.cpp:
+ (WebCore::Layout::TableFormattingContext::Geometry::cellHeigh const):
+
2020-12-19 Rob Buis <[email protected]>
Move FrameLoader::arePluginsEnabled to Frame
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (271011 => 271012)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2020-12-20 15:11:09 UTC (rev 271012)
@@ -194,11 +194,10 @@
}
- if (*escapeReason == EscapeReason::NeedsGeometryFromEstablishedFormattingContext) {
- // This is the case when a formatting root collects geometry information from the established
- // formatting context to be able to determine width/height.
- // e.g <div>text content</div>. The <div> is a formatting root of the IFC.
- // In order to compute the height of the <div>, we need to look inside the IFC and gather geometry information.
+ if (*escapeReason == EscapeReason::TableQuirkNeedsGeometryFromEstablishedFormattingContext) {
+ // This is the case when the table formatting root collects geometry information from the cell's
+ // formatting context to be able to determine width/height. see shouldIgnoreChildContentVerticalMargin
+ ASSERT(root().establishesTableFormattingContext());
return &layoutBox.formattingContextRoot().formattingContextRoot() == &root();
}
Modified: trunk/Source/WebCore/layout/FormattingContext.h (271011 => 271012)
--- trunk/Source/WebCore/layout/FormattingContext.h 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/FormattingContext.h 2020-12-20 15:11:09 UTC (rev 271012)
@@ -87,6 +87,7 @@
LayoutUnit maximum;
};
virtual IntrinsicWidthConstraints computedIntrinsicWidthConstraints() = 0;
+ virtual LayoutUnit usedContentHeight() const = 0;
bool isBlockFormattingContext() const { return root().establishesBlockFormattingContext(); }
bool isInlineFormattingContext() const { return root().establishesInlineFormattingContext(); }
@@ -95,7 +96,7 @@
bool isFlexFormattingContext() const { return root().establishesFlexFormattingContext(); }
enum class EscapeReason {
- NeedsGeometryFromEstablishedFormattingContext,
+ TableQuirkNeedsGeometryFromEstablishedFormattingContext,
OutOfFlowBoxNeedsInFlowGeometry,
FloatBoxIsAlwaysRelativeToFloatStateRoot,
FindFixedHeightAncestorQuirk,
Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (271011 => 271012)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2020-12-20 15:11:09 UTC (rev 271012)
@@ -175,60 +175,9 @@
{
ASSERT(formattingContextRoot.establishesFormattingContext());
ASSERT(isHeightAuto(formattingContextRoot) || formattingContextRoot.establishesTableFormattingContext() || formattingContextRoot.isTableCell());
-
- // 10.6.7 'Auto' heights for block formatting context roots
-
- // If it only has inline-level children, the height is the distance between the top of the topmost line box and the bottom of the bottommost line box.
- // If it has block-level children, the height is the distance between the top margin-edge of the topmost block-level
- // child box and the bottom margin-edge of the bottommost block-level child box.
-
- // In addition, if the element has any floating descendants whose bottom margin edge is below the element's bottom content edge,
- // then the height is increased to include those edges. Only floats that participate in this block formatting context are taken
- // into account, e.g., floats inside absolutely positioned descendants or other floats are not.
if (!formattingContextRoot.hasInFlowOrFloatingChild())
return { };
-
- auto& layoutState = this->layoutState();
- auto& formattingContext = this->formattingContext();
- auto& boxGeometry = formattingContext.geometryForBox(formattingContextRoot);
- auto borderAndPaddingTop = boxGeometry.borderTop() + boxGeometry.paddingTop().valueOr(0);
- auto top = borderAndPaddingTop;
- auto bottom = borderAndPaddingTop;
- if (formattingContextRoot.establishesInlineFormattingContext()) {
- auto& inlineFormattingState = layoutState.establishedInlineFormattingState(formattingContextRoot);
- auto& lines = inlineFormattingState.lines();
- // Even empty containers generate one line.
- ASSERT(!lines.isEmpty());
- top = lines.first().lineBoxLogicalRect().top();
- bottom = lines.last().lineBoxLogicalRect().bottom() + inlineFormattingState.clearGapAfterLastLine();
- } else if (formattingContextRoot.establishesFlexFormattingContext()) {
- auto& lines = layoutState.establishedFlexFormattingState(formattingContextRoot).lines();
- ASSERT(!lines.isEmpty());
- // FIXME: Move flex over to layout geometry.
- top = lines.first().top();
- bottom = lines.last().bottom();
- } else if (formattingContextRoot.establishesBlockFormattingContext() || formattingContextRoot.establishesTableFormattingContext()) {
- if (formattingContextRoot.hasInFlowChild()) {
- auto& firstBoxGeometry = formattingContext.geometryForBox(*formattingContextRoot.firstInFlowChild(), EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
- auto& lastBoxGeometry = formattingContext.geometryForBox(*formattingContextRoot.lastInFlowChild(), EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
- top = BoxGeometry::marginBoxRect(firstBoxGeometry).top();
- bottom = BoxGeometry::marginBoxRect(lastBoxGeometry).bottom();
- }
- } else
- ASSERT_NOT_REACHED();
-
- auto floatingContext = FloatingContext { formattingContext, layoutState.establishedFormattingState(formattingContextRoot).floatingState() };
- auto floatBottom = floatingContext.bottom();
- if (floatBottom) {
- bottom = std::max(*floatBottom, bottom);
- auto floatTop = floatingContext.top();
- ASSERT(floatTop);
- top = std::min(*floatTop, top);
- }
- auto computedHeight = bottom - top;
-
- LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height] -> content height for formatting context root -> height(" << computedHeight << "px) layoutBox("<< &formattingContextRoot << ")");
- return computedHeight;
+ return LayoutContext::createFormattingContext(formattingContextRoot, const_cast<LayoutState&>(layoutState()))->usedContentHeight();
}
Optional<LayoutUnit> FormattingContext::Geometry::computedValue(const Length& geometryProperty, LayoutUnit containingBlockWidth) const
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (271011 => 271012)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2020-12-20 15:11:09 UTC (rev 271012)
@@ -174,6 +174,32 @@
LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> block formatting context -> formatting root(" << &root() << ")");
}
+LayoutUnit BlockFormattingContext::usedContentHeight() const
+{
+ // 10.6.7 'Auto' heights for block formatting context roots
+
+ // If it has block-level children, the height is the distance between the top margin-edge of the topmost block-level
+ // child box and the bottom margin-edge of the bottommost block-level child box.
+
+ // In addition, if the element has any floating descendants whose bottom margin edge is below the element's bottom content edge,
+ // then the height is increased to include those edges. Only floats that participate in this block formatting context are taken
+ // into account, e.g., floats inside absolutely positioned descendants or other floats are not.
+ auto top = Optional<LayoutUnit> { };
+ auto bottom = Optional<LayoutUnit> { };
+ if (root().hasInFlowChild()) {
+ top = BoxGeometry::marginBoxRect(geometryForBox(*root().firstInFlowChild())).top();
+ bottom = BoxGeometry::marginBoxRect(geometryForBox(*root().lastInFlowChild())).bottom();
+ }
+
+ auto floatingContext = FloatingContext { *this, formattingState().floatingState() };
+ if (auto floatTop = floatingContext.top()) {
+ top = std::min(*floatTop, top.valueOr(*floatTop));
+ auto floatBottom = *floatingContext.bottom();
+ bottom = std::max(floatBottom, bottom.valueOr(floatBottom));
+ }
+ return *bottom - *top;
+}
+
Optional<LayoutUnit> BlockFormattingContext::usedAvailableWidthForFloatAvoider(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair& constraintsPair)
{
// Normally the available width for an in-flow block level box is the width of the containing block's content box.
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (271011 => 271012)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2020-12-20 15:11:09 UTC (rev 271012)
@@ -49,6 +49,7 @@
BlockFormattingContext(const ContainerBox& formattingContextRoot, BlockFormattingState&);
void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
+ LayoutUnit usedContentHeight() const override;
protected:
struct ConstraintsPair {
Modified: trunk/Source/WebCore/layout/flexformatting/FlexFormattingContext.cpp (271011 => 271012)
--- trunk/Source/WebCore/layout/flexformatting/FlexFormattingContext.cpp 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/flexformatting/FlexFormattingContext.cpp 2020-12-20 15:11:09 UTC (rev 271012)
@@ -52,6 +52,12 @@
sizeAndPlaceFlexItems(constraints);
}
+LayoutUnit FlexFormattingContext::usedContentHeight() const
+{
+ auto& lines = formattingState().lines();
+ return LayoutUnit { lines.last().bottom() - lines.first().top() };
+}
+
FormattingContext::IntrinsicWidthConstraints FlexFormattingContext::computedIntrinsicWidthConstraints()
{
return { };
Modified: trunk/Source/WebCore/layout/flexformatting/FlexFormattingContext.h (271011 => 271012)
--- trunk/Source/WebCore/layout/flexformatting/FlexFormattingContext.h 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/flexformatting/FlexFormattingContext.h 2020-12-20 15:11:09 UTC (rev 271012)
@@ -42,6 +42,7 @@
public:
FlexFormattingContext(const ContainerBox& formattingContextRoot, FlexFormattingState&);
void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
+ LayoutUnit usedContentHeight() const override;
IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (271011 => 271012)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2020-12-20 15:11:09 UTC (rev 271012)
@@ -141,6 +141,29 @@
LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root() << ")");
}
+LayoutUnit InlineFormattingContext::usedContentHeight() const
+{
+ // 10.6.7 'Auto' heights for block formatting context roots
+
+ // If it only has inline-level children, the height is the distance between the top of the topmost line box and the bottom of the bottommost line box.
+
+ // In addition, if the element has any floating descendants whose bottom margin edge is below the element's bottom content edge,
+ // then the height is increased to include those edges. Only floats that participate in this block formatting context are taken
+ // into account, e.g., floats inside absolutely positioned descendants or other floats are not.
+ auto& lines = formattingState().lines();
+ // Even empty containers generate one line.
+ ASSERT(!lines.isEmpty());
+ auto top = LayoutUnit { lines.first().lineBoxLogicalRect().top() };
+ auto bottom = LayoutUnit { lines.last().lineBoxLogicalRect().bottom() + formattingState().clearGapAfterLastLine() };
+
+ auto floatingContext = FloatingContext { *this, formattingState().floatingState() };
+ if (auto floatBottom = floatingContext.bottom()) {
+ bottom = std::max(*floatBottom, bottom);
+ top = std::min(*floatingContext.top(), top);
+ }
+ return bottom - top;
+}
+
void InlineFormattingContext::lineLayout(InlineItems& inlineItems, LineBuilder::InlineItemRange needsLayoutRange, const ConstraintsForInFlowContent& constraints)
{
InlineLayoutUnit lineLogicalTop = constraints.vertical.logicalTop;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (271011 => 271012)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h 2020-12-20 15:11:09 UTC (rev 271012)
@@ -45,6 +45,7 @@
public:
InlineFormattingContext(const ContainerBox& formattingContextRoot, InlineFormattingState&);
void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
+ LayoutUnit usedContentHeight() const override;
class Quirks : public FormattingContext::Quirks {
public:
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (271011 => 271012)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2020-12-20 15:11:09 UTC (rev 271012)
@@ -65,6 +65,14 @@
setUsedGeometryForSections(constraints);
}
+LayoutUnit TableFormattingContext::usedContentHeight() const
+{
+ // Table has to have some section content, at least one <tbody>.
+ auto top = BoxGeometry::marginBoxRect(geometryForBox(*root().firstInFlowChild())).top();
+ auto bottom = BoxGeometry::marginBoxRect(geometryForBox(*root().lastInFlowChild())).bottom();
+ return bottom - top;
+}
+
void TableFormattingContext::setUsedGeometryForCells(LayoutUnit availableHorizontalSpace)
{
auto& grid = formattingState().tableGrid();
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h (271011 => 271012)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h 2020-12-20 15:11:09 UTC (rev 271012)
@@ -44,6 +44,7 @@
public:
TableFormattingContext(const ContainerBox& formattingContextRoot, TableFormattingState&);
void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
+ LayoutUnit usedContentHeight() const override;
static UniqueRef<TableGrid> ensureTableGrid(const ContainerBox& tableBox);
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp (271011 => 271012)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp 2020-12-20 07:15:48 UTC (rev 271011)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp 2020-12-20 15:11:09 UTC (rev 271012)
@@ -47,8 +47,8 @@
auto formattingContext = this->formattingContext();
auto& firstInFlowChild = *cellBox.firstInFlowChild();
auto& lastInFlowChild = *cellBox.lastInFlowChild();
- auto& firstInFlowChildGeometry = formattingContext.geometryForBox(firstInFlowChild, EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
- auto& lastInFlowChildGeometry = formattingContext.geometryForBox(lastInFlowChild, EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
+ auto& firstInFlowChildGeometry = formattingContext.geometryForBox(firstInFlowChild, EscapeReason::TableQuirkNeedsGeometryFromEstablishedFormattingContext);
+ auto& lastInFlowChildGeometry = formattingContext.geometryForBox(lastInFlowChild, EscapeReason::TableQuirkNeedsGeometryFromEstablishedFormattingContext);
auto top = firstInFlowChild.style().hasMarginBeforeQuirk() ? BoxGeometry::borderBoxRect(firstInFlowChildGeometry).top() : BoxGeometry::marginBoxRect(firstInFlowChildGeometry).top();
auto bottom = lastInFlowChild.style().hasMarginAfterQuirk() ? BoxGeometry::borderBoxRect(lastInFlowChildGeometry).bottom() : BoxGeometry::marginBoxRect(lastInFlowChildGeometry).bottom();