LibWeb: Use available size in calculate_inner_height()

Although the parameter is named "available size," it is always supposed
to represent the containing block size whenever it has a definite value.
Therefore, it is possible to simply use this value instead of performing
a containing block lookup.

This change actually improves correctness for grid items whose
containing block is defined by the grid area, as
`Node::containing_block()` does not account for this.
This commit is contained in:
Aliaksandr Kalenik 2024-09-15 16:13:51 +02:00 committed by Andreas Kling
commit 6481ef821d
Notes: github-actions[bot] 2024-09-15 16:01:00 +00:00
3 changed files with 37 additions and 11 deletions

View file

@ -1639,19 +1639,10 @@ CSSPixels FormattingContext::calculate_inner_width(Layout::Box const& box, Avail
return width.resolved(box, width_of_containing_block).to_px(box);
}
CSSPixels FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const&, CSS::Size const& height) const
CSSPixels FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const& available_height, CSS::Size const& height) const
{
VERIFY(!height.is_auto());
auto const* containing_block = box.non_anonymous_containing_block();
auto const& containing_block_state = m_state.get(*containing_block);
auto height_of_containing_block = containing_block_state.content_height();
if (box.computed_values().position() == CSS::Positioning::Absolute) {
// https://www.w3.org/TR/css-position-3/#def-cb
// If the box has position: absolute, then the containing block is formed by the padding edge of the ancestor
height_of_containing_block += containing_block_state.padding_top + containing_block_state.padding_bottom;
}
auto height_of_containing_block = available_height.to_px_or_zero();
auto& computed_values = box.computed_values();
if (computed_values.box_sizing() == CSS::BoxSizing::BorderBox) {
auto width_of_containing_block = containing_block_width_for(box);