1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

LibWeb: Return CSSPixels from calculate_inner_height()

Similar to calculate_inner_width(), let's make the caller responsible
for handling "auto" instead of returning the input height as is when
when it cannot be resolved.
This commit is contained in:
Aliaksandr Kalenik 2024-01-07 05:46:36 +01:00 committed by Andreas Kling
parent 05a1dbeb91
commit 39abd9095e
6 changed files with 22 additions and 20 deletions

View file

@ -515,7 +515,7 @@ CSSPixels FormattingContext::tentative_height_for_replaced_element(Box const& bo
return 150;
// FIXME: Handle cases when available_space is not definite.
return calculate_inner_height(box, available_space.height, computed_height).to_px(box);
return calculate_inner_height(box, available_space.height, computed_height);
}
CSSPixels FormattingContext::compute_height_for_replaced_element(Box const& box, AvailableSpace const& available_space) const
@ -837,11 +837,11 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
auto constrained_height = unconstrained_height;
if (!computed_max_height.is_none()) {
auto inner_max_height = calculate_inner_height(box, available_space.height, computed_max_height);
constrained_height = min(constrained_height, inner_max_height.to_px(box));
constrained_height = min(constrained_height, inner_max_height);
}
if (!computed_min_height.is_auto()) {
auto inner_min_height = calculate_inner_height(box, available_space.height, computed_min_height);
constrained_height = max(constrained_height, inner_min_height.to_px(box));
constrained_height = max(constrained_height, inner_min_height);
}
return constrained_height;
};
@ -1022,7 +1022,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
if (should_treat_height_as_auto(box, available_space)) {
used_height = height.to_px(box, height_of_containing_block);
} else {
used_height = calculate_inner_height(box, available_space.height, height).to_px(box);
used_height = calculate_inner_height(box, available_space.height, height);
}
used_height = apply_min_max_height_constraints(used_height);
@ -1494,8 +1494,10 @@ CSSPixels FormattingContext::calculate_inner_width(Layout::Box const& box, Avail
return width.resolved(box, width_of_containing_block).to_px(box);
}
CSS::Length 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&, 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();
@ -1504,9 +1506,6 @@ CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, Av
// 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;
}
if (height.is_auto()) {
return height.resolved(box, height_of_containing_block);
}
auto& computed_values = box.computed_values();
if (computed_values.box_sizing() == CSS::BoxSizing::BorderBox) {
@ -1520,10 +1519,10 @@ CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, Av
- padding_top.to_px(box)
- computed_values.border_bottom().width
- padding_bottom.to_px(box);
return CSS::Length::make_px(max(inner_height, 0));
return max(inner_height, 0);
}
return height.resolved(box, height_of_containing_block);
return height.resolved(box, height_of_containing_block).to_px(box);
}
CSSPixels FormattingContext::containing_block_width_for(NodeWithStyleAndBoxModelMetrics const& node) const