LibWeb: Don't allow resolved width of abspos elements to become negative

We have to clamp the resulting width to 0 when solving for it.
This commit is contained in:
Andreas Kling 2023-03-25 16:00:54 +01:00
parent 8f311c61af
commit 3f6f3966b9
Notes: sideshowbarker 2024-07-17 06:00:02 +09:00
3 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x0 children: not-inline
BlockContainer <body.outer> at (8,8) content-size 0x0 positioned children: not-inline
BlockContainer <div.inner> at (9,9) content-size 0x0 positioned children: not-inline

View File

@ -0,0 +1,11 @@
<!DOCTYPE html><html><head><style>
.outer {
position: absolute;
}
.inner {
position: absolute;
left: 0;
right: 0;
border: 1px solid black;
}
</style></head><body class="outer"><div class="inner">

View File

@ -515,7 +515,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele
};
auto solve_for_width = [&] {
return CSS::Length::make_px(width_of_containing_block - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left - padding_right - border_right - margin_right.to_px(box) - right.to_px(box));
return CSS::Length::make_px(max(CSSPixels(0), width_of_containing_block - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left - padding_right - border_right - margin_right.to_px(box) - right.to_px(box)));
};
auto solve_for_right = [&] {