1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

LibWeb: Apply min/max-widths to block container during intrinsic layout

Fixes https://github.com/SerenityOS/serenity/issues/22430
This commit is contained in:
Aliaksandr Kalenik 2023-12-26 05:49:45 +01:00 committed by Andreas Kling
parent 9258d7b98a
commit b172c29d9a
5 changed files with 116 additions and 2 deletions

View file

@ -751,8 +751,28 @@ void BlockFormattingContext::layout_block_level_children(BlockContainer const& b
if (layout_mode == LayoutMode::IntrinsicSizing) {
auto& block_container_state = m_state.get_mutable(block_container);
if (!block_container_state.has_definite_width())
block_container_state.set_content_width(greatest_child_width(block_container));
if (!block_container_state.has_definite_width()) {
auto width = greatest_child_width(block_container);
auto computed_values = block_container.computed_values();
// NOTE: Min and max constraints are not applied to a box that is being sized as intrinsic because
// according to css-sizing-3 spec:
// The min-content size of a box in each axis is the size it would have if it was a float given an
// auto size in that axis (and no minimum or maximum size in that axis) and if its containing block
// was zero-sized in that axis.
if (block_container_state.width_constraint == SizeConstraint::None) {
if (!should_treat_max_width_as_none(block_container, available_space.width)) {
auto max_width = calculate_inner_width(block_container, available_space.width,
computed_values.max_width());
width = min(width, max_width.to_px(block_container));
}
if (!computed_values.min_width().is_auto()) {
auto min_width = calculate_inner_width(block_container, available_space.width,
computed_values.min_width());
width = max(width, min_width.to_px(block_container));
}
}
block_container_state.set_content_width(width);
}
if (!block_container_state.has_definite_height())
block_container_state.set_content_height(bottom_of_lowest_margin_box);
}