diff --git a/components/layout/floats.rs b/components/layout/floats.rs index e3ae4716e53..a31d7461db0 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -459,8 +459,8 @@ impl SpeculatedFloatPlacement { } } - /// Given the speculated inline size of the floats in for this flow, computes the speculated - /// inline size of the floats out for this flow. + /// Given the speculated inline size of the floats out for this flow's last child, computes the + /// speculated inline size of the floats out for this flow. pub fn compute_floats_out(&mut self, flow: &mut Flow) { if flow.is_block_like() { let block_flow = flow.as_block(); @@ -470,10 +470,10 @@ impl SpeculatedFloatPlacement { if self.left > Au(0) || self.right > Au(0) { let speculated_inline_content_edge_offsets = block_flow.fragment.guess_inline_content_edge_offsets(); - if self.left > Au(0) { + if self.left > Au(0) && speculated_inline_content_edge_offsets.start > Au(0) { self.left = self.left + speculated_inline_content_edge_offsets.start } - if self.right > Au(0) { + if self.right > Au(0) && speculated_inline_content_edge_offsets.end > Au(0) { self.right = self.right + speculated_inline_content_edge_offsets.end } } @@ -507,16 +507,20 @@ impl SpeculatedFloatPlacement { let speculated_inline_content_edge_offsets = parent_block_flow.fragment.guess_inline_content_edge_offsets(); - if placement.left > speculated_inline_content_edge_offsets.start { - placement.left = placement.left - speculated_inline_content_edge_offsets.start - } else { - placement.left = Au(0) - }; - if placement.right > speculated_inline_content_edge_offsets.end { - placement.right = placement.right - speculated_inline_content_edge_offsets.end - } else { - placement.right = Au(0) - }; + if speculated_inline_content_edge_offsets.start > Au(0) { + placement.left = if placement.left > speculated_inline_content_edge_offsets.start { + placement.left - speculated_inline_content_edge_offsets.start + } else { + Au(0) + } + } + if speculated_inline_content_edge_offsets.end > Au(0) { + placement.right = if placement.right > speculated_inline_content_edge_offsets.end { + placement.right - speculated_inline_content_edge_offsets.end + } else { + Au(0) + } + } placement } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 7adc12efd39..b349b7c5467 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -1484,6 +1484,18 @@ "url": "/_mozilla/css/float_right_intrinsic_width_a.html" } ], + "css/float_speculation_negative_inline_margins_a.html": [ + { + "path": "css/float_speculation_negative_inline_margins_a.html", + "references": [ + [ + "/_mozilla/css/float_speculation_negative_inline_margins_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/float_speculation_negative_inline_margins_a.html" + } + ], "css/float_table_a.html": [ { "path": "css/float_table_a.html", @@ -7846,6 +7858,18 @@ "url": "/_mozilla/css/float_right_intrinsic_width_a.html" } ], + "css/float_speculation_negative_inline_margins_a.html": [ + { + "path": "css/float_speculation_negative_inline_margins_a.html", + "references": [ + [ + "/_mozilla/css/float_speculation_negative_inline_margins_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/float_speculation_negative_inline_margins_a.html" + } + ], "css/float_table_a.html": [ { "path": "css/float_table_a.html", diff --git a/tests/wpt/mozilla/tests/css/float_speculation_negative_inline_margins_a.html b/tests/wpt/mozilla/tests/css/float_speculation_negative_inline_margins_a.html new file mode 100644 index 00000000000..383ec5b5552 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/float_speculation_negative_inline_margins_a.html @@ -0,0 +1,30 @@ + + + + + + +
+ diff --git a/tests/wpt/mozilla/tests/css/float_speculation_negative_inline_margins_ref.html b/tests/wpt/mozilla/tests/css/float_speculation_negative_inline_margins_ref.html new file mode 100644 index 00000000000..db43f561b89 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/float_speculation_negative_inline_margins_ref.html @@ -0,0 +1,29 @@ + + + + + +
+