1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibWeb: Correct the calculation for right float intrusion

We used to subtract the maximum right margin of any containing box,
but we want to subtract the entire right margin instead. This yielded
incorrect intrusions for right floats not placed in the root.
This commit is contained in:
Ruben 2025-05-24 11:46:01 +02:00 committed by Jelle Raaijmakers
parent 8e5cc74eb1
commit 3263b629c6
Notes: github-actions[bot] 2025-05-27 15:33:02 +00:00
7 changed files with 150 additions and 38 deletions

View file

@ -1267,6 +1267,7 @@ BlockFormattingContext::SpaceUsedAndContainingMarginForFloats BlockFormattingCon
space_and_containing_margin.right_used_space = floating_box.offset_from_edge
+ floating_box.used_values.margin_box_left();
space_and_containing_margin.right_total_containing_margin = offset_from_containing_block_chain_margins_between_here_and_root;
space_and_containing_margin.matching_right_float_box = floating_box.box;
break;
}
}
@ -1290,11 +1291,17 @@ FormattingContext::SpaceUsedByFloats BlockFormattingContext::intrusion_by_floats
auto left_intrusion = max(CSSPixels(0), left_side_floats_limit_to_right - max(CSSPixels(0), box_in_root_rect.x()));
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
for (auto const* containing_block = &box_used_values; containing_block && &containing_block->node() != &root(); containing_block = containing_block->containing_block_used_values()) {
offset_from_containing_block_chain_margins_between_here_and_root = max(offset_from_containing_block_chain_margins_between_here_and_root, containing_block->margin_box_right());
// If we did not match a right float, the right_total_containing_margin will be 0 (as its never set). Since no floats means
// no intrusion we would instead want it to be exactly equal to offset_from_containing_block_chain_margins_between_here_and_root.
// Since this is not the case we have to explicitly handle this case.
CSSPixels right_intrusion = 0;
if (space_and_containing_margin.matching_right_float_box) {
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
for (auto const* containing_block = &box_used_values; containing_block && &containing_block->node() != &root(); containing_block = containing_block->containing_block_used_values()) {
offset_from_containing_block_chain_margins_between_here_and_root += containing_block->margin_box_right();
}
right_intrusion = max(CSSPixels(0), right_side_floats_limit_to_right - offset_from_containing_block_chain_margins_between_here_and_root);
}
auto right_intrusion = max(CSSPixels(0), right_side_floats_limit_to_right - offset_from_containing_block_chain_margins_between_here_and_root);
return { left_intrusion, right_intrusion };
}

View file

@ -123,6 +123,7 @@ protected:
CSSPixels left_total_containing_margin;
CSSPixels right_total_containing_margin;
GC::Ptr<Box const> matching_left_float_box;
GC::Ptr<Box const> matching_right_float_box;
};
struct ShrinkToFitResult {