Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fe53385f31781509f93891e44d0ad3dfbfab420e
      
https://github.com/WebKit/WebKit/commit/fe53385f31781509f93891e44d0ad3dfbfab420e
  Author: Alan Baradlay <[email protected]>
  Date:   2026-08-14 (Fri, 14 Aug 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/clearance-covers-the-margin-of-a-collapsed-through-block-in-inline-expected.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/clearance-covers-the-margin-of-a-collapsed-through-block-in-inline-ref.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/clearance-covers-the-margin-of-a-collapsed-through-block-in-inline.html
    M Source/WebCore/layout/formattingContexts/block/BlockLayoutState.h
    M Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp
    M 
Source/WebCore/layout/integration/LayoutIntegrationFormattingContextLayout.cpp
    M Source/WebCore/layout/integration/LayoutIntegrationUtils.cpp
    M Source/WebCore/rendering/RenderBlockFlow.cpp
    M Source/WebCore/rendering/RenderBlockFlow.h

  Log Message:
  -----------
  [block-in-inline] A box that collapsed through with clearance on a line 
pushes the content after it down by its margin
https://bugs.webkit.org/show_bug.cgi?id=321643

Reviewed by Antti Koivisto.

  <div style="float: left; height: 120px"></div>
  <span>
    <div style="clear: both; height: 0; margin-top: 50px"></div>
  </span>
  foo

Clearance sits above the box's margin (CSS 2.2 9.5.2), so the 50px is already 
inside the space the clearance took
and "foo" belongs at the float's bottom edge. It ends up 50px lower.

A box whose margins collapse through keeps them for the content after it (CSS 
2.2 8.3.1, "If the top and bottom
margins of an element with clearance are adjoining, its margins collapse with 
the adjoining margins of following
siblings"), and block layout applies them from the box's margin box top rather 
than from where its border box
ended up, which is also what the spec asks for: "the positions of elements that 
have been collapsed through have
no effect on the positions of the other elements with whose margins they are 
being collapsed". It does that by
taking the container's height back to that position before the collapsed margin 
goes on.

A line has no such position to take back. It starts where the content before it 
ended, which for this box is its
border box, and the margin then goes on top of that.

The clearance sits between the two margins ("because the margins no longer 
collapse with a clearance between them",
CSS 2.2 9.5.2 example 1), so the box's margin before is behind that border box 
already and only the rest of the
collapsed margin is left for the content after it. Carry that margin in the 
margin state, next to the margin
itself, and take it off what a line places.

* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/clearance-covers-the-margin-of-a-collapsed-through-block-in-inline.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/clearance-covers-the-margin-of-a-collapsed-through-block-in-inline-ref.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/clearance-covers-the-margin-of-a-collapsed-through-block-in-inline-expected.html:
 Added.
* Source/WebCore/layout/formattingContexts/block/BlockLayoutState.h:
(WebCore::Layout::BlockLayoutState::MarginState::resetMarginValues):
(WebCore::Layout::BlockLayoutState::MarginState::margin const):
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::initialize):
(WebCore::Layout::LineBuilder::handleBlockContent):
A box that collapses through can also end up above where the content after it 
goes, which is the same offset the
other way round. That is space after the box, so it goes on the advance the 
forced break case already has rather
than through the branch for a box below its own line, which zeroes the margins 
and leaves the line no extent.

* 
Source/WebCore/layout/integration/LayoutIntegrationFormattingContextLayout.cpp:
(WebCore::LayoutIntegration::layoutWithFormattingContextForBlockInInline):
* Source/WebCore/layout/integration/LayoutIntegrationUtils.cpp:
(WebCore::Layout::IntegrationUtils::toMarginState):
(WebCore::Layout::IntegrationUtils::toMarginInfo):
* Source/WebCore/rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::MarginInfo::MarginInfo):
* Source/WebCore/rendering/RenderBlockFlow.h:
(WebCore::RenderBlockFlow::MarginInfo::clearMargin):
(WebCore::RenderBlockFlow::MarginInfo::setMarginBeforeWithClearance):
(WebCore::RenderBlockFlow::MarginInfo::marginBeforeWithClearance const):

Canonical link: https://commits.webkit.org/319160@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to