diff options
author | Oriol Brufau <obrufau@igalia.com> | 2023-06-08 09:11:48 +0200 |
---|---|---|
committer | Oriol Brufau <obrufau@igalia.com> | 2023-06-08 11:05:57 +0200 |
commit | 5e1f059de245eaa7399bd6d5207b79c3834ecdf3 (patch) | |
tree | 9e947b2b9c0d974bdf2859f78eaf0b3fc3ab77ca | |
parent | 1bd1441d0bd3f861dac044a617d152add1667471 (diff) | |
download | servo-5e1f059de245eaa7399bd6d5207b79c3834ecdf3.tar.gz servo-5e1f059de245eaa7399bd6d5207b79c3834ecdf3.zip |
Improve margin collapse in layout-2020
According to https://drafts.csswg.org/css2/#collapsing-margins, bottom
margins should only collapse with the last child if `height` is `auto`.
Also, the note mentions `min-height: 0`, but the normative text doesn't
have such requirement, so I'm dropping it, matching WebKit.
The previous logic is moved into the case of collapsing the top and
bottom margins of the same element, since this can happen either with
`height: auto` or `height: 0`, and requires `min-height: 0`.
3 files changed, 6 insertions, 9 deletions
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index fcd2c2b1837..e23c8db33e8 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -483,8 +483,7 @@ fn layout_in_flow_non_replaced_block_level( let end_margin_can_collapse_with_children = block_is_same_formatting_context && pbm.padding.block_end == Length::zero() && pbm.border.block_end == Length::zero() && - block_size.auto_is(|| Length::zero()) == Length::zero() && - min_box_size.block == Length::zero(); + block_size == LengthOrAuto::Auto; let mut clearance = Length::zero(); let parent_containing_block_position_info; @@ -570,9 +569,11 @@ fn layout_in_flow_non_replaced_block_level( content_block_size += collapsible_margins_in_children.end.solve(); } block_margins_collapsed_with_children.collapsed_through = - start_margin_can_collapse_with_children && - end_margin_can_collapse_with_children && - collapsible_margins_in_children.collapsed_through; + collapsible_margins_in_children.collapsed_through && + block_is_same_formatting_context && + pbm.padding_border_sums.block == Length::zero() && + block_size.auto_is(|| Length::zero()) == Length::zero() && + min_box_size.block == Length::zero(); }, NonReplacedContents::EstablishesAnIndependentFormattingContext(non_replaced) => { let independent_layout = non_replaced.layout( diff --git a/tests/wpt/metadata-layout-2020/css/CSS2/margin-padding-clear/margin-collapse-025.xht.ini b/tests/wpt/metadata-layout-2020/css/CSS2/margin-padding-clear/margin-collapse-025.xht.ini deleted file mode 100644 index 41403961633..00000000000 --- a/tests/wpt/metadata-layout-2020/css/CSS2/margin-padding-clear/margin-collapse-025.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[margin-collapse-025.xht] - expected: FAIL diff --git a/tests/wpt/metadata-layout-2020/css/CSS2/margin-padding-clear/margin-collapse-037.xht.ini b/tests/wpt/metadata-layout-2020/css/CSS2/margin-padding-clear/margin-collapse-037.xht.ini deleted file mode 100644 index 049aa133c56..00000000000 --- a/tests/wpt/metadata-layout-2020/css/CSS2/margin-padding-clear/margin-collapse-037.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[margin-collapse-037.xht] - expected: FAIL |