LibWeb: Make height:auto for non-BFC-root blocks more correct

Unlike BFC root blocks with height:auto, when the block *isn't* a BFC
root, we don't have to look for the "bottommost" block-level child and
determine the width from that.

Instead, we should just look at the last in-flow block-level child.
This was already indicated in the spec comment next to the code, but
the code itself was wrong.

This makes the body element on Acid3 have the correct height. It also
introduces a small regression on Acid2 that we'll have to track down.
This commit is contained in:
Andreas Kling 2022-03-29 18:46:14 +02:00
parent 18048efce0
commit 5da7ebb806
Notes: sideshowbarker 2024-07-17 16:33:22 +09:00

View File

@ -216,19 +216,14 @@ float FormattingContext::compute_auto_height_for_block_level_element(FormattingS
// 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin does not collapse with the element's bottom margin
// FIXME: 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
if (!box.children_are_inline()) {
Optional<float> bottom;
box.for_each_child_of_type<Box>([&](Layout::Box& child_box) {
if (child_box.is_absolutely_positioned() || child_box.is_floating())
return;
for (auto* child_box = box.last_child_of_type<Box>(); child_box; child_box = child_box->previous_sibling_of_type<Box>()) {
if (child_box->is_absolutely_positioned() || child_box->is_floating())
continue;
// FIXME: Handle margin collapsing.
auto const& child_box_state = state.get(child_box);
float child_box_bottom = child_box_state.offset.y() + child_box_state.content_height + child_box_state.margin_box_bottom();
if (!bottom.has_value() || child_box_bottom > bottom.value())
bottom = child_box_bottom;
});
return bottom.value_or(0);
auto const& child_box_state = state.get(*child_box);
return max(0, child_box_state.offset.y() + child_box_state.content_height + child_box_state.margin_box_bottom());
}
}
// 4. zero, otherwise