1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

LibWeb: Fix height calculation for absolutely positioned boxes

This commit fixes algorithm for computing auto height (CSS 2.2 10.6.7)
by including floating boxes into computation and implements one of the cases
for computing the height of absolutely positioned, non-replaced elements (10.6.4 rule 3)
This commit is contained in:
Egor Ananyin 2021-04-17 09:09:57 +03:00 committed by Andreas Kling
parent 602f98fe67
commit 1d343116a9
4 changed files with 68 additions and 46 deletions

View file

@ -267,49 +267,6 @@ void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_n
box.set_width(compute_width_for_replaced_element(box));
}
float BlockFormattingContext::compute_auto_height_for_block_level_element(const Box& box)
{
Optional<float> top;
Optional<float> bottom;
if (box.children_are_inline()) {
// If it only has inline-level children, the height is the distance between
// the top of the topmost line box and the bottom of the bottommost line box.
if (!box.line_boxes().is_empty()) {
for (auto& fragment : box.line_boxes().first().fragments()) {
if (!top.has_value() || fragment.offset().y() < top.value())
top = fragment.offset().y();
}
for (auto& fragment : box.line_boxes().last().fragments()) {
if (!bottom.has_value() || (fragment.offset().y() + fragment.height()) > bottom.value())
bottom = fragment.offset().y() + fragment.height();
}
}
} else {
// If it has block-level children, the height is the distance between
// the top margin-edge of the topmost block-level child box
// and the bottom margin-edge of the bottommost block-level child box.
box.for_each_child_of_type<Box>([&](Layout::Box& child_box) {
if (child_box.is_absolutely_positioned())
return IterationDecision::Continue;
if ((box.computed_values().overflow_y() == CSS::Overflow::Visible) && child_box.is_floating())
return IterationDecision::Continue;
float child_box_top = child_box.effective_offset().y() - child_box.box_model().margin_box().top;
float child_box_bottom = child_box.effective_offset().y() + child_box.height() + child_box.box_model().margin_box().bottom;
if (!top.has_value() || child_box_top < top.value())
top = child_box_top;
if (!bottom.has_value() || child_box_bottom > bottom.value())
bottom = child_box_bottom;
return IterationDecision::Continue;
});
}
return bottom.value_or(0) - top.value_or(0);
}
void BlockFormattingContext::compute_height(Box& box)
{
auto& computed_values = box.computed_values();