LibWeb: Respect min/max-content available size in auto width calculation
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

...for block level boxes. Otherwise we end up resolving auto width as
zero during intrinsic layout, which leads to incorrectly applied
max-width constraint.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/4123
This commit is contained in:
Aliaksandr Kalenik 2025-03-27 23:31:50 +00:00 committed by Jelle Raaijmakers
commit 732a5cdc12
Notes: github-actions[bot] 2025-03-28 02:14:44 +00:00
3 changed files with 45 additions and 2 deletions

View file

@ -265,6 +265,12 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
} else {
width = zero_value;
}
} else if (available_space.width.is_min_content()) {
width = CSS::Length::make_px(calculate_min_content_width(box));
} else if (available_space.width.is_max_content()) {
width = CSS::Length::make_px(calculate_max_content_width(box));
} else {
VERIFY_NOT_REACHED();
}
} else {
if (!margin_left.is_auto() && !margin_right.is_auto()) {
@ -304,8 +310,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() ? CSSPixels { 0 } : used_width.to_px(box);
if (used_width_px > max_width) {
if (used_width.to_px(box) > max_width) {
used_width = try_compute_width(CSS::Length::make_px(max_width));
}
}