From 3ca6d7dd366ec5a06d43610323d1ea9efe650fd2 Mon Sep 17 00:00:00 2001 From: Egor Ananyin Date: Thu, 29 Apr 2021 18:20:56 +0300 Subject: [PATCH] LibWeb: Use min-height in calculating block box height Now we use min-height for calculating the height of block boxes. Besides, now we check if min-height/max-height are percentage values and don't use them if parent's height isn't explicitly set (CSS 2.1 section 10.7). --- .../LibWeb/Layout/BlockFormattingContext.cpp | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 3d782d29b7..a93207c9c0 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -314,26 +314,23 @@ void BlockFormattingContext::compute_height(Box& box) if (is(box)) { height = compute_height_for_replaced_element(downcast(box)); } else { - if (box.computed_values().height().is_undefined_or_auto()) { + if (box.computed_values().height().is_undefined_or_auto() + || (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute())) { height = compute_auto_height_for_block_level_element(box); } else { - CSS::Length specified_height; - if (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute()) { - specified_height = CSS::Length::make_auto(); - } else { - specified_height = computed_values.height().resolved_or_auto(box, containing_block.height()); - } - - auto specified_max_height = computed_values.max_height().resolved_or_auto(box, containing_block.height()); - if (!specified_height.is_auto()) { - float used_height = specified_height.to_px(box); - if (!specified_max_height.is_auto()) - used_height = min(used_height, specified_max_height.to_px(box)); - height = used_height; - } + height = computed_values.height().resolved_or_auto(box, containing_block.height()).to_px(box); } } + auto specified_max_height = computed_values.max_height().resolved_or_auto(box, containing_block.height()); + if (!specified_max_height.is_auto() + && !(computed_values.max_height().is_percentage() && !containing_block.computed_values().height().is_absolute())) + height = min(height, specified_max_height.to_px(box)); + auto specified_min_height = computed_values.min_height().resolved_or_auto(box, containing_block.height()); + if (!specified_min_height.is_auto() + && !(computed_values.min_height().is_percentage() && !containing_block.computed_values().height().is_absolute())) + height = max(height, specified_min_height.to_px(box)); + box.set_height(height); }