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

LibWeb: Fix calculating the intrinsic height of a box

For computing height in FormattingContext::calculate_intrinsic_sizes
we were calling into BlockFormattingContext::compute_theoretical_height
which will check if the CSS height property was defined and calculate
the height based on that instead of calculating the intrinsic height

This patch adds a new function calculate_intrinsic_height, which will
call into compute_auto_height_for_block_level_element for a block
element, or into compute_height_for_replaced_element for a replaced
element.
This commit is contained in:
Enver Balalic 2022-03-30 19:44:18 +02:00 committed by Andreas Kling
parent b526a10d76
commit 74d8e201eb
2 changed files with 12 additions and 2 deletions

View file

@ -817,7 +817,7 @@ FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Lay
independent_formatting_context->run(box, LayoutMode::MaxContent); independent_formatting_context->run(box, LayoutMode::MaxContent);
cached_box_sizes.max_content_size.set_width(independent_formatting_context->greatest_child_width(box)); cached_box_sizes.max_content_size.set_width(independent_formatting_context->greatest_child_width(box));
cached_box_sizes.max_content_size.set_height(BlockFormattingContext::compute_theoretical_height(throwaway_state, box)); cached_box_sizes.max_content_size.set_height(compute_intrinsic_height(throwaway_state, box));
} }
{ {
@ -829,7 +829,7 @@ FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Lay
VERIFY(independent_formatting_context); VERIFY(independent_formatting_context);
independent_formatting_context->run(box, LayoutMode::MinContent); independent_formatting_context->run(box, LayoutMode::MinContent);
cached_box_sizes.min_content_size.set_width(independent_formatting_context->greatest_child_width(box)); cached_box_sizes.min_content_size.set_width(independent_formatting_context->greatest_child_width(box));
cached_box_sizes.min_content_size.set_height(BlockFormattingContext::compute_theoretical_height(throwaway_state, box)); cached_box_sizes.min_content_size.set_height(compute_intrinsic_height(throwaway_state, box));
} }
if (cached_box_sizes.min_content_size.width() > cached_box_sizes.max_content_size.width()) { if (cached_box_sizes.min_content_size.width() > cached_box_sizes.max_content_size.width()) {
@ -888,4 +888,13 @@ float FormattingContext::calculate_fit_content_height(Layout::Box const& box, Op
auto [min_content_size, max_content_size] = calculate_min_and_max_content_height(box); auto [min_content_size, max_content_size] = calculate_min_and_max_content_height(box);
return calculate_fit_content_size(min_content_size, max_content_size, available_space); return calculate_fit_content_size(min_content_size, max_content_size, available_space);
} }
float FormattingContext::compute_intrinsic_height(FormattingState const& state, Box const& box)
{
if (is<ReplacedBox>(box)) {
return compute_height_for_replaced_element(state, verify_cast<ReplacedBox>(box));
}
return compute_auto_height_for_block_level_element(state, box);
}
} }

View file

@ -81,6 +81,7 @@ protected:
static float tentative_height_for_replaced_element(FormattingState const&, ReplacedBox const&, CSS::Length const& height); static float tentative_height_for_replaced_element(FormattingState const&, ReplacedBox const&, CSS::Length const& height);
static float compute_auto_height_for_block_formatting_context_root(FormattingState const&, BlockContainer const&); static float compute_auto_height_for_block_formatting_context_root(FormattingState const&, BlockContainer const&);
static float compute_auto_height_for_block_level_element(FormattingState const&, Box const&); static float compute_auto_height_for_block_level_element(FormattingState const&, Box const&);
static float compute_intrinsic_height(FormattingState const& state, Box const& box);
ShrinkToFitResult calculate_shrink_to_fit_widths(Box const&); ShrinkToFitResult calculate_shrink_to_fit_widths(Box const&);