Skip to content

Commit cf3e7a3

Browse files
committed
[blocks-in-inline] Add support for block after side of margin handling (part 2)
https://bugs.webkit.org/show_bug.cgi?id=303006 Reviewed by Antti Koivisto. RenderBlockFlows with block level boxes only, handle their after side of margin collapsing by calling handleAfterSideOfBlock. This function looks into the MarginInfo state which, at this point, holds information about the trailing child's margin state. Now with blocks-in-inline, we could end up with such trailing block level elements and this patch ensures that their margins are taken into account. Test: fast/inline/blocks-in-inline-layout-with-margin-after2.html * LayoutTests/fast/inline/blocks-in-inline-layout-with-margin-after2-expected.html: Added. * LayoutTests/fast/inline/blocks-in-inline-layout-with-margin-after2.html: Added. * Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp: (WebCore::Layout::InlineDisplayLineBuilder::adjustLineBlockAfterSideWithCollapsedMargin): * Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp: (WebCore::LayoutIntegration::LineLayout::layout): (WebCore::LayoutIntegration::initialMarginState): Deleted. * Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.h: * Source/WebCore/rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutInlineContent): Canonical link: https://commits.webkit.org/303510@main
1 parent e0c8bea commit cf3e7a3

File tree

6 files changed

+56
-17
lines changed

6 files changed

+56
-17
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<style>
2+
.margin-collapse-boundary {
3+
border: 1px solid green;
4+
}
5+
6+
.container {
7+
background-color: green;
8+
}
9+
10+
.middle-block {
11+
margin-bottom: 100px;
12+
}
13+
</style>
14+
<div class=margin-collapse-boundary>
15+
<div class=container>
16+
<span>
17+
span start
18+
<div class=middle-block>block content with margin bottom</div>
19+
</span>
20+
</div>
21+
</div>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- webkit-test-runner [ BlocksInInlineLayoutEnabled=true ] -->
2+
<style>
3+
.margin-collapse-boundary {
4+
border: 1px solid green;
5+
}
6+
7+
.container {
8+
background-color: green;
9+
}
10+
11+
.middle-block {
12+
margin-bottom: 100px;
13+
}
14+
</style>
15+
<div class=margin-collapse-boundary>
16+
<div class=container>
17+
<span>
18+
span start
19+
<div class=middle-block>block content with margin bottom</div>
20+
</span>
21+
</div>
22+
</div>

Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ void InlineDisplayLineBuilder::adjustLineBlockAfterSideWithCollapsedMargin(const
521521
return;
522522
}
523523

524-
if (!marginState.canCollapseMarginAfterWithChildren || !marginState.margin())
524+
if (!marginState.margin())
525525
return;
526526

527527
auto& lastLineWithBlockContent = displayLines[lineIndexWithBlockLevelBox];

Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "LayoutIntegrationInlineContentBuilder.h"
4545
#include "LayoutIntegrationInlineContentPainter.h"
4646
#include "LayoutIntegrationPagination.h"
47+
#include "LayoutIntegrationUtils.h"
4748
#include "LayoutTreeBuilder.h"
4849
#include "PaintInfo.h"
4950
#include "PlacedFloats.h"
@@ -483,13 +484,7 @@ static inline std::optional<Layout::BlockLayoutState::LineGrid> lineGrid(const R
483484
return { };
484485
}
485486

486-
static inline Layout::BlockLayoutState::MarginState initialMarginState(const RenderBlockFlow& rootRenderer)
487-
{
488-
auto marginInfo = RenderBlockFlow::MarginInfo { rootRenderer, RenderBlockFlow::MarginInfo::IgnoreScrollbarForAfterMargin::No };
489-
return { marginInfo.canCollapseWithChildren(), marginInfo.canCollapseMarginBeforeWithChildren(), marginInfo.canCollapseMarginAfterWithChildren(), marginInfo.quirkContainer(), marginInfo.atBeforeSideOfBlock(), marginInfo.atAfterSideOfBlock(), marginInfo.hasMarginBeforeQuirk(), marginInfo.hasMarginAfterQuirk(), marginInfo.determinedMarginBeforeQuirk(), marginInfo.positiveMargin(), marginInfo.negativeMargin() };
490-
}
491-
492-
std::optional<LayoutRect> LineLayout::layout(ForceFullLayout forcedFullLayout)
487+
std::optional<LayoutRect> LineLayout::layout(RenderBlockFlow::MarginInfo& marginInfo, ForceFullLayout forcedFullLayout)
493488
{
494489
if (forcedFullLayout == ForceFullLayout::Yes && m_lineDamage)
495490
Layout::InlineInvalidation::resetInlineDamage(*m_lineDamage);
@@ -524,7 +519,7 @@ std::optional<LayoutRect> LineLayout::layout(ForceFullLayout forcedFullLayout)
524519

525520
auto parentBlockLayoutState = Layout::BlockLayoutState {
526521
m_blockFormattingState.placedFloats(),
527-
initialMarginState(flow()),
522+
Layout::IntegrationUtils::toMarginState(marginInfo),
528523
lineClamp(flow()),
529524
textBoxTrim(flow()),
530525
flow().style().textBoxEdge(),
@@ -546,11 +541,12 @@ std::optional<LayoutRect> LineLayout::layout(ForceFullLayout forcedFullLayout)
546541

547542
if (m_lineDamage) {
548543
// Pagination may require another layout pass.
549-
layout();
544+
layout(marginInfo);
550545

551546
ASSERT(!m_lineDamage);
552547
}
553548

549+
marginInfo = Layout::IntegrationUtils::toMarginInfo(parentBlockLayoutState.marginState());
554550
return isPartialLayout ? std::make_optional(repaintRect) : std::nullopt;
555551
}
556552

Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LineLayout final : public CanMakeCheckedPtr<LineLayout> {
9393
std::pair<LayoutUnit, LayoutUnit> computeIntrinsicWidthConstraints();
9494

9595
enum class ForceFullLayout : bool { No, Yes };
96-
std::optional<LayoutRect> layout(ForceFullLayout = ForceFullLayout::No);
96+
std::optional<LayoutRect> layout(RenderBlockFlow::MarginInfo&, ForceFullLayout = ForceFullLayout::No);
9797
void paint(PaintInfo&, const LayoutPoint& paintOffset, const RenderInline* layerRenderer = nullptr);
9898
bool hitTest(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint& accumulatedOffset, HitTestAction, const RenderInline* layerRenderer = nullptr);
9999
void adjustForPagination();

Source/WebCore/rendering/RenderBlockFlow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,14 +4106,14 @@ void RenderBlockFlow::layoutInlineContent(RelayoutChildren relayoutChildren, Lay
41064106

41074107
ASSERT(containingBlock() || is<RenderView>(*this));
41084108
inlineLayout.updateFormattingContexGeometries(containingBlock() ? containingBlockLogicalWidthForContent() : LayoutUnit());
4109-
auto partialRepaintRect = inlineLayout.layout(relayoutChildren == RelayoutChildren::Yes ? LayoutIntegration::LineLayout::ForceFullLayout::Yes : LayoutIntegration::LineLayout::ForceFullLayout::No);
4109+
4110+
auto marginInfo = MarginInfo { *this, MarginInfo::IgnoreScrollbarForAfterMargin::No };
4111+
auto partialRepaintRect = inlineLayout.layout(marginInfo, relayoutChildren == RelayoutChildren::Yes ? LayoutIntegration::LineLayout::ForceFullLayout::Yes : LayoutIntegration::LineLayout::ForceFullLayout::No);
41104112

41114113
auto clampedContentHeight = updateLineClampStateAndLogicalHeightAfterLayout();
4112-
auto borderBoxLogicalHeight = [&] {
4113-
auto contentHeight = clampedContentHeight.value_or(!hasLines() && hasLineIfEmpty() ? lineHeight() : inlineLayout.contentLogicalHeight());
4114-
return borderAndPaddingLogicalHeight() + contentHeight + scrollbarLogicalHeight();
4115-
};
4116-
setLogicalHeight(borderBoxLogicalHeight());
4114+
auto contentBoxHeight = clampedContentHeight.value_or(!hasLines() && hasLineIfEmpty() ? lineHeight() : inlineLayout.contentLogicalHeight());
4115+
auto borderBoxLogicalHeight = handleAfterSideOfBlock(marginInfo, contentBoxHeight);
4116+
setLogicalHeight(borderBoxLogicalHeight);
41174117
updateRepaintTopAndBottomAfterLayout(relayoutChildren, partialRepaintRect, oldContentTopAndBottomIncludingInkOverflow, repaintLogicalTop, repaintLogicalBottom);
41184118
}
41194119

0 commit comments

Comments
 (0)