diff --git a/components/layout/block.rs b/components/layout/block.rs index d1a333f2b83..c703542b5f9 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1058,10 +1058,17 @@ impl BlockFlow { }; let float_info: FloatedBlockInfo = (**self.float.as_ref().unwrap()).clone(); + + // Our `position` field accounts for positive margins, but not negative margins. (See + // calculation of `extra_inline_size_from_margin` below.) Negative margins must be taken + // into account for float placement, however. So we add them in here. + let inline_size_for_float_placement = self.base.position.size.inline + + min(Au(0), self.fragment.margin.inline_start_end()); + let info = PlacementInfo { size: LogicalSize::new( self.fragment.style.writing_mode, - self.base.position.size.inline, + inline_size_for_float_placement, block_size + self.fragment.margin.block_start_end()) .convert(self.fragment.style.writing_mode, self.base.floats.writing_mode), ceiling: clearance + float_info.float_ceiling, @@ -2214,9 +2221,9 @@ pub trait ISizeAndMarginsComputer { container_size - inline_size - fragment.margin.inline_end }; - // To calculate the total size of this block, we also need to account for any additional - // size contribution from positive margins. Negative margins means the block isn't made - // larger at all by the margin. + // To calculate the total size of this block, we also need to account for any + // additional size contribution from positive margins. Negative margins means the block + // isn't made larger at all by the margin. extra_inline_size_from_margin = max(Au(0), fragment.margin.inline_start) + max(Au(0), fragment.margin.inline_end); } diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 1318c9d6f4d..f050d04fed0 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -99,6 +99,7 @@ flaky_cpu == append_style_a.html append_style_b.html == float_under_top_margin_a.html float_under_top_margin_ref.html == floated_generated_content_a.html floated_generated_content_b.html == floated_list_item_a.html floated_list_item_ref.html +== floated_negative_margins_a.html floated_negative_margins_ref.html == floated_table_with_margin_a.html floated_table_with_margin_ref.html == focus_selector.html focus_selector_ref.html == font_advance.html font_advance_ref.html diff --git a/tests/ref/floated_negative_margins_a.html b/tests/ref/floated_negative_margins_a.html new file mode 100644 index 00000000000..49e3e9b5d6b --- /dev/null +++ b/tests/ref/floated_negative_margins_a.html @@ -0,0 +1,16 @@ + + +
Hello + diff --git a/tests/ref/floated_negative_margins_ref.html b/tests/ref/floated_negative_margins_ref.html new file mode 100644 index 00000000000..6fc5d275c6b --- /dev/null +++ b/tests/ref/floated_negative_margins_ref.html @@ -0,0 +1,15 @@ + + +
Hello +