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

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-after-relayout-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-after-relayout.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-before-relayout-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-before-relayout.html
    M Source/WebCore/rendering/RenderBlockFlow.cpp

  Log Message:
  -----------
  [block-in-inline] A block level box's margin after is counted twice when only 
that box needs layout
https://bugs.webkit.org/show_bug.cgi?id=321236

Reviewed by Antti Koivisto.

layoutSimpleBlockContentInInline() is the fast-path taken when a container with 
inline children needs
layout only because one of its block level boxes does. It walks the block level 
boxes, lays each one out,
and takes the MarginInfo the last one leaves behind. The lines are not laid out 
at all.

That is fine while the block level box is the only in-flow content, since its 
margins are then the
container's own. A line next to the box changes that: the line consumes the 
adjacent margin as its own
spacing, so nothing is left to collapse with the container. Normal line layout 
accounts for this in
LineBuilder::layoutInlineContent (see updateMarginStateIfNeeded), which does 
two things once a line places
contentful inline content - it resets the margin values, and it leaves the 
before side of the block. The
shortcut lays out no lines, so it has to do both itself as the walk passes 
contentful inline content.

    <div><span><div style="margin-bottom: 16px">block</div></span>line 
after</div>

reports a 16px margin after on the container once something inside the block 
changes and this path runs:
the margin is still in MarginInfo when the caller hands it to 
handleAfterSideOfBlock(), so it is counted a
second time.

    <div>line before<span><div style="margin-top: 16px">block</div></span></div>

reports a 16px margin before for the same reason. Resetting the margin values 
is not enough here, because
canCollapseWithMarginBefore() reads m_atBeforeSideOfBlock rather than the 
values, so collapseMargins()
still promotes the block's own margin before into the container's collapsed 
margin before and the container
is then repositioned by its parent.

* Source/WebCore/rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::layoutSimpleBlockContentInInline):
* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-after-relayout.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-after-relayout-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-before-relayout.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/normal-flow/block-in-inline-margin-before-relayout-expected.txt:
 Added.

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



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

Reply via email to