LibWeb: Prevent max-width expanding the width

This commit is contained in:
Emil Militzer 2023-07-11 16:22:25 +02:00 committed by Andreas Kling
parent c006a1ef41
commit bf3144fcff
3 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,5 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (1,1) content-size 798x0 [BFC] children: not-inline
BlockContainer <body> at (10,10) content-size 4x54 positioned [BFC] children: not-inline
BlockContainer <div.outer> at (11,11) content-size 2x52 children: not-inline
BlockContainer <div.inner> at (12,12) content-size 0x50 children: not-inline

View file

@ -0,0 +1,8 @@
<!doctype html><style>
* { border: 1px solid black; }
body { position: absolute; }
.inner {
max-width: 50px;
height: 50px;
}
</style><body><div class="outer"><div class="inner">

View file

@ -255,7 +255,7 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
// but this time using the computed value of 'max-width' as the computed value for 'width'.
if (!should_treat_max_width_as_none(box, available_space.width)) {
auto max_width = calculate_inner_width(box, remaining_available_space.width, computed_values.max_width());
auto used_width_px = used_width.is_auto() ? remaining_available_space.width.to_px() : used_width.to_px(box);
auto used_width_px = used_width.is_auto() ? CSSPixels { 0 } : used_width.to_px(box);
if (used_width_px > max_width.to_px(box)) {
used_width = try_compute_width(max_width);
}