Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[margin-trim][block layout] Trimmed block-end margins should be refle…
…cted in computed style in a horizontal writing-mode BFC. https://bugs.webkit.org/show_bug.cgi?id=253610 rdar://106454992 Reviewed by Alan Baradlay. We currently perform margin trimming by doing some backtracking after a block container with block-end margin trim has completed layout (261750@main). In order to make sure that these margins are properly shown in their computed style value, we need a way for ComputedStyleExtractor to know that the block-end margin for the renderer has been trimmed. This can be done by setting the margin-trim rare data bit for that renderer. Whenever we trim a margin in RenderBlockFlow::trimBlockEndChildrenMargins, we can replace the calls to setMarginAfterForChild with setTrimmedMarginForChild which will both trim the margin and set the rare data bit for the renderer. Later on when ComputedStyleExtractor tries to determine the value of a bottom margin for a renderer it can first use hasTrimmedMargin on the renderer in order to determine if that specific margin is trimmed. While creating this patch and testing the logic, I found that certain margins are not being trimmed correctly. It seems like particularly that self collapsing children that has other nested self collapsing content do not have the nested content trimmed properly. Whenever we have a self collapsing child, we need to also go inside and trim the margins of any other children (and perhaps perform this logic for any other children that are nested inside that). For example <container> <item style="margin-bottom: 10px"></item> <item style="margin-bottom: 10px; height: 0px;"> <item style="margin-bottom: 10px; height: 0px;"> <item style="margin-bottom: 10px; height: 0px;"> <item style="margin-bottom: 10px; height: 0px;"></item> <item style="margin-bottom: 10px; height: 0px;"></item> </item> </item> </item> </container> In this scenario the content itself looks fine as if margin-trimming occurred correctly, however when looking at the computed margin-bottom values of the nested self collapsing children we can see that their margins were not trimmed. Currently we fail the tests in these scenarios that are introduced in this patch because of this. I plan on addressing this in a separate patch following this one. * LayoutTests/imported/w3c/web-platform-tests/css/css-box/margin-trim/computed-margin-values/block-container-block-end-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-box/margin-trim/computed-margin-values/block-container-block-end-nested-child-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-box/margin-trim/computed-margin-values/block-container-block-end-nested-child.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-box/margin-trim/computed-margin-values/block-container-block-end-with-self-collapsing-children-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-box/margin-trim/computed-margin-values/block-container-block-end-with-self-collapsing-children.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-box/margin-trim/computed-margin-values/block-container-block-end.html: Added. * Source/WebCore/css/ComputedStyleExtractor.cpp: (WebCore::rendererCanHaveTrimmedMargin): * Source/WebCore/rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::trimBlockEndChildrenMargins): * Source/WebCore/rendering/RenderBox.cpp: (WebCore::RenderBox::physicalToFlowRelativeDirectionMapping const): (WebCore::RenderBox::hasTrimmedMargin const): (WebCore::RenderBox::hasTrimmedMargin const): * Source/WebCore/rendering/RenderBox.h: (WebCore::RenderBox::isBlockLevelBox const): Canonical link: https://commits.webkit.org/263398@main
- Loading branch information
Showing
10 changed files
with
304 additions
and
16 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...sts/css/css-box/margin-trim/computed-margin-values/block-container-block-end-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
PASS item 1 | ||
|
46 changes: 46 additions & 0 deletions
46
...ox/margin-trim/computed-margin-values/block-container-block-end-nested-child-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
PASS item 1 | ||
FAIL item 2 assert_equals: | ||
<item data-expected-margin-bottom="0" style="block-size: auto;"> | ||
<div><item data-expected-margin-bottom="10"></item></div> | ||
<div> | ||
<item data-expected-margin-bottom="0" style="block-size: auto;"> | ||
<div><item data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
</div> | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
PASS item 3 | ||
PASS item 4 | ||
PASS item 5 | ||
FAIL item 6 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 7 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 8 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 9 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 10 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 11 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
|
55 changes: 55 additions & 0 deletions
55
...ss/css-box/margin-trim/computed-margin-values/block-container-block-end-nested-child.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="author" href="mailto:sammy.gill@apple.com"> | ||
<link rel="help" href="https://w3c.github.io/csswg-drafts/css-box-4/#margin-trim-block"> | ||
<meta name="assert" content="Items, including self-collapsing ones, at the block-end of the container should have their margins trimmed"> | ||
<style> | ||
container { | ||
display: block; | ||
inline-size: min-content; | ||
margin-trim: block-end; | ||
} | ||
item { | ||
display: block; | ||
background-color: green; | ||
inline-size: 50px; | ||
block-size: 10px; | ||
margin-block-end: 10px; | ||
} | ||
.border { | ||
border: 1px solid black; | ||
} | ||
.collapsed { | ||
block-size: 0px; | ||
} | ||
</style> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/check-layout-th.js"></script> | ||
</head> | ||
<body onload="checkLayout('item')"> | ||
<div id="target"> | ||
<container> | ||
<item data-expected-margin-bottom="10"></item> | ||
<item data-expected-margin-bottom="0" style="block-size: auto;"> | ||
<div><item data-expected-margin-bottom="10"></item></div> | ||
<div> | ||
<item data-expected-margin-bottom="0" style="block-size: auto;"> | ||
<div><item data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
</div> | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
</item> | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
</container> | ||
</div> | ||
</body> | ||
</html> |
93 changes: 93 additions & 0 deletions
93
...mputed-margin-values/block-container-block-end-with-self-collapsing-children-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
PASS item 1 | ||
PASS item 2 | ||
FAIL item 3 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
</item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 4 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 5 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 6 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 7 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 8 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 9 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
</item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 10 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 11 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 12 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 13 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 14 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 15 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 16 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
margin-bottom expected "0" but got "10" | ||
FAIL item 17 assert_equals: | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
margin-bottom expected "0" but got "10" | ||
PASS item 18 | ||
|
60 changes: 60 additions & 0 deletions
60
...-trim/computed-margin-values/block-container-block-end-with-self-collapsing-children.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="author" href="mailto:sammy.gill@apple.com"> | ||
<link rel="help" href="https://w3c.github.io/csswg-drafts/css-box-4/#margin-trim-block"> | ||
<meta name="assert" content="Second item and all self-collapsing children at block-end should have margins trimmed"> | ||
<style> | ||
container { | ||
display: block; | ||
inline-size: min-content; | ||
margin-trim: block-end; | ||
} | ||
item { | ||
display: block; | ||
background-color: green; | ||
inline-size: 50px; | ||
block-size: 50px; | ||
margin-block-end: 10px; | ||
} | ||
.collapsed { | ||
block-size: 0px; | ||
} | ||
</style> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/check-layout-th.js"></script> | ||
</head> | ||
<body onload="checkLayout('item')"> | ||
<div id="target"> | ||
<container> | ||
<item data-expected-margin-bottom="10"></item> | ||
<item data-expected-margin-bottom="0"></item> | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
</item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item> | ||
<item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"> | ||
<div><item class="collapsed" data-expected-margin-bottom="0"></item></div> | ||
</item></div> | ||
</item></div> | ||
</item> | ||
<item class="collapsed" data-expected-margin-bottom="0"></item> | ||
</container> | ||
</div> | ||
</body> | ||
</html> |
32 changes: 32 additions & 0 deletions
32
...tform-tests/css/css-box/margin-trim/computed-margin-values/block-container-block-end.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="author" href="mailto:sammy.gill@apple.com"> | ||
<link rel="help" href="https://w3c.github.io/csswg-drafts/css-box-4/#margin-trim-block"> | ||
<meta name="assert" content="block-end margin of item should be trimmed"> | ||
<style> | ||
container { | ||
display: block; | ||
inline-size: min-content; | ||
margin-trim: block-end; | ||
} | ||
item { | ||
display: block; | ||
background-color: green; | ||
inline-size: 50px; | ||
block-size: 50px; | ||
margin-block-end: 10px; | ||
} | ||
</style> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/check-layout-th.js"></script> | ||
</head> | ||
<body onload="checkLayout('item')"> | ||
<div id="target"> | ||
<container> | ||
<item data-expected-margin-bottom="0"></item> | ||
</container> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters