diff --git a/components/layout/block.rs b/components/layout/block.rs index fa5790306b5..090672c00fb 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1650,10 +1650,18 @@ impl BlockFlow { // page set `max-width` in order to avoid hitting floats. The search box on Google // SERPs falls into this category.) if self.fragment.style.max_inline_size() == LengthOrPercentageOrNone::None { + let speculated_left_float_size = + max(Au(0), + self.base.speculated_float_placement_in.left - + self.fragment.margin.inline_start); + let speculated_right_float_size = + max(Au(0), + self.base.speculated_float_placement_in.right - + self.fragment.margin.inline_end); self.fragment.border_box.size.inline = self.fragment.border_box.size.inline - - self.base.speculated_float_placement_in.left - - self.base.speculated_float_placement_in.right; + speculated_left_float_size - + speculated_right_float_size; } } FormattingContextType::None | FormattingContextType::Other => {} diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 9a5d1521d58..9fee4db43ca 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -475,20 +475,18 @@ impl SpeculatedFloatPlacement { let block_flow = flow.as_block(); if block_flow.formatting_context_type() != FormattingContextType::None { *self = block_flow.base.speculated_float_placement_in; - } - - 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) && speculated_inline_content_edge_offsets.start > Au(0) { - self.left = self.left + speculated_inline_content_edge_offsets.start + } else { + 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) && speculated_inline_content_edge_offsets.start > Au(0) { + self.left = self.left + speculated_inline_content_edge_offsets.start + } + if self.right > Au(0) && speculated_inline_content_edge_offsets.end > Au(0) { + self.right = self.right + speculated_inline_content_edge_offsets.end + } } - if self.right > Au(0) && speculated_inline_content_edge_offsets.end > Au(0) { - self.right = self.right + speculated_inline_content_edge_offsets.end - } - } - if block_flow.formatting_context_type() == FormattingContextType::None { self.left = max(self.left, block_flow.base.speculated_float_placement_in.left); self.right = max(self.right, block_flow.base.speculated_float_placement_in.right); } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index aacefe74da3..d81335ad928 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -616,6 +616,18 @@ "url": "/_mozilla/css/block_formatting_context_margin_collapse_a.html" } ], + "css/block_formatting_context_margin_inout_a.html": [ + { + "path": "css/block_formatting_context_margin_inout_a.html", + "references": [ + [ + "/_mozilla/css/block_formatting_context_margin_inout_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/block_formatting_context_margin_inout_a.html" + } + ], "css/block_formatting_context_max_width_a.html": [ { "path": "css/block_formatting_context_max_width_a.html", @@ -7410,6 +7422,18 @@ "url": "/_mozilla/css/block_formatting_context_margin_collapse_a.html" } ], + "css/block_formatting_context_margin_inout_a.html": [ + { + "path": "css/block_formatting_context_margin_inout_a.html", + "references": [ + [ + "/_mozilla/css/block_formatting_context_margin_inout_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/block_formatting_context_margin_inout_a.html" + } + ], "css/block_formatting_context_max_width_a.html": [ { "path": "css/block_formatting_context_max_width_a.html", diff --git a/tests/wpt/mozilla/tests/css/block_formatting_context_margin_inout_a.html b/tests/wpt/mozilla/tests/css/block_formatting_context_margin_inout_a.html new file mode 100644 index 00000000000..a7e6f0cd69e --- /dev/null +++ b/tests/wpt/mozilla/tests/css/block_formatting_context_margin_inout_a.html @@ -0,0 +1,24 @@ + + + + +
+
+
+ diff --git a/tests/wpt/mozilla/tests/css/block_formatting_context_margin_inout_ref.html b/tests/wpt/mozilla/tests/css/block_formatting_context_margin_inout_ref.html new file mode 100644 index 00000000000..c333a800cc4 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/block_formatting_context_margin_inout_ref.html @@ -0,0 +1,32 @@ + + + +
+
+
+