Skip to content

Commit 45d8f43

Browse files
authored
Merge pull request #27 from wechat-miniprogram/fix-empty-inline-node-prevents-margin-collapse
fix: empty inline nodes should not prevent margin collapse
2 parents 9a036d8 + 6404cc4 commit 45d8f43

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

float-pigment-forest/tests/custom/css_margin.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ fn margin_collapse_1() {
8181
)
8282
}
8383

84+
#[test]
85+
fn margin_collapse_empty_inline_nodes() {
86+
assert_xml!(
87+
r#"
88+
<div style="height: 800px;">
89+
<div style="height: 100px; margin-bottom: 50px;"></div>
90+
<div style="display: inline; height: 0;"></div>
91+
<div style="margin-top: 40px;" expect_top="150"></div>
92+
</div>
93+
"#
94+
)
95+
}
96+
8497
#[test]
8598
fn margin_collapse_negative() {
8699
assert_xml!(

float-pigment-layout/src/algo/flow.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,19 @@ impl<T: LayoutTreeNode> Flow<T> for LayoutUnit<T> {
674674
request.kind == ComputeRequestKind::Position,
675675
);
676676

677-
if let Some((prev_collapsed_margin, prev_collapsed_through)) =
678-
prev_sibling_collapsed_margin
679-
{
680-
if !prev_collapsed_through {
681-
total_main_size += prev_collapsed_margin.solve();
677+
if block_size.main_size(axis_info.dir) > T::Length::zero() {
678+
if let Some((prev_collapsed_margin, prev_collapsed_through)) =
679+
prev_sibling_collapsed_margin
680+
{
681+
if !prev_collapsed_through {
682+
total_main_size += prev_collapsed_margin.solve();
683+
}
682684
}
685+
prev_sibling_collapsed_margin.replace((CollapsedMargin::zero(), false));
683686
}
684687
let main_offset = padding_border
685688
.main_axis_start(axis_info.dir, axis_info.main_dir_rev)
686689
+ total_main_size;
687-
prev_sibling_collapsed_margin.replace((CollapsedMargin::zero(), false));
688690

689691
total_main_size += block_size.main_size(axis_info.dir);
690692
max_cross_size = max_cross_size.max(block_size.cross_size(axis_info.dir));

rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
channel = "1.81.0"
3+
components = [ "rustfmt", "clippy" ]
4+
profile = "minimal"

0 commit comments

Comments
 (0)