summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorEnver Balalic <balalic.enver@gmail.com>2022-03-30 19:44:18 +0200
committerAndreas Kling <kling@serenityos.org>2022-03-30 21:16:47 +0200
commit74d8e201eb7d325ca479fec1ca03e6ff93ca4892 (patch)
tree6df958cdedc63e05652ab84ceb09fc4f8e406159 /Userland/Libraries
parentb526a10d767d1257fe44b2ae0e0e08a7da0ca2e5 (diff)
downloadserenity-74d8e201eb7d325ca479fec1ca03e6ff93ca4892.zip
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.cpp13
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.h1
2 files changed, 12 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
index fe2f1a82aa..5dcd1dcfde 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -817,7 +817,7 @@ FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Lay
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_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);
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_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()) {
@@ -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);
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);
+}
}
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
index 45455add5c..da0a787241 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
@@ -81,6 +81,7 @@ protected:
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_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&);