LibWeb: Make separate functions for calculating min/max content sizes

At first, these are just wrappers around calculate_intrinsic_sizes().
Eventually, we'll make them do only the work necessary for their
specific size.
This commit is contained in:
Andreas Kling 2022-07-08 00:40:53 +02:00
parent 1690d88887
commit 496cf39cf5
Notes: sideshowbarker 2024-07-17 23:07:41 +09:00
4 changed files with 35 additions and 30 deletions

View file

@ -689,8 +689,8 @@ float FlexFormattingContext::content_size_suggestion(FlexItem const& item) const
{
// FIXME: Apply clamps
if (is_row_layout())
return calculate_min_and_max_content_width(item.box).min_content_size;
return calculate_min_and_max_content_height(item.box).min_content_size;
return calculate_min_content_width(item.box);
return calculate_min_content_height(item.box);
}
// https://drafts.csswg.org/css-flexbox-1/#transferred-size-suggestion

View file

@ -164,10 +164,9 @@ float FormattingContext::greatest_child_width(Box const& box)
FormattingContext::ShrinkToFitResult FormattingContext::calculate_shrink_to_fit_widths(Box const& box)
{
auto [min_content, max_content] = calculate_intrinsic_sizes(box);
return {
.preferred_width = max_content.width(),
.preferred_minimum_width = min_content.width(),
.preferred_width = calculate_max_content_width(box),
.preferred_minimum_width = calculate_min_content_width(box),
};
}
@ -889,18 +888,6 @@ FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Lay
return cached_box_sizes;
}
FormattingContext::MinAndMaxContentSize FormattingContext::calculate_min_and_max_content_width(Layout::Box const& box) const
{
auto const& sizes = calculate_intrinsic_sizes(box);
return { sizes.min_content_size.width(), sizes.max_content_size.width() };
}
FormattingContext::MinAndMaxContentSize FormattingContext::calculate_min_and_max_content_height(Layout::Box const& box) const
{
auto const& sizes = calculate_intrinsic_sizes(box);
return { sizes.min_content_size.height(), sizes.max_content_size.height() };
}
float FormattingContext::calculate_fit_content_size(float min_content_size, float max_content_size, Optional<float> available_space) const
{
// If the available space in a given axis is definite, equal to clamp(min-content size, stretch-fit size, max-content size)
@ -920,14 +907,12 @@ float FormattingContext::calculate_fit_content_size(float min_content_size, floa
float FormattingContext::calculate_fit_content_width(Layout::Box const& box, Optional<float> available_space) const
{
auto [min_content_size, max_content_size] = calculate_min_and_max_content_width(box);
return calculate_fit_content_size(min_content_size, max_content_size, available_space);
return calculate_fit_content_size(calculate_min_content_width(box), calculate_max_content_width(box), available_space);
}
float FormattingContext::calculate_fit_content_height(Layout::Box const& box, Optional<float> available_space) const
{
auto [min_content_size, max_content_size] = calculate_min_and_max_content_height(box);
return calculate_fit_content_size(min_content_size, max_content_size, available_space);
return calculate_fit_content_size(calculate_min_content_height(box), calculate_max_content_height(box), available_space);
}
float FormattingContext::calculate_auto_height(FormattingState const& state, Box const& box)
@ -938,4 +923,25 @@ float FormattingContext::calculate_auto_height(FormattingState const& state, Box
return compute_auto_height_for_block_level_element(state, box);
}
float FormattingContext::calculate_min_content_width(Layout::Box const& box) const
{
return calculate_intrinsic_sizes(box).min_content_size.width();
}
float FormattingContext::calculate_max_content_width(Layout::Box const& box) const
{
return calculate_intrinsic_sizes(box).max_content_size.width();
}
float FormattingContext::calculate_min_content_height(Layout::Box const& box) const
{
return calculate_intrinsic_sizes(box).min_content_size.height();
}
float FormattingContext::calculate_max_content_height(Layout::Box const& box) const
{
return calculate_intrinsic_sizes(box).max_content_size.height();
}
}

View file

@ -45,13 +45,10 @@ public:
virtual void parent_context_did_dimension_child_root_box() { }
struct MinAndMaxContentSize {
float min_content_size { 0 };
float max_content_size { 0 };
};
MinAndMaxContentSize calculate_min_and_max_content_width(Layout::Box const&) const;
MinAndMaxContentSize calculate_min_and_max_content_height(Layout::Box const&) const;
float calculate_min_content_width(Layout::Box const&) const;
float calculate_max_content_width(Layout::Box const&) const;
float calculate_min_content_height(Layout::Box const&) const;
float calculate_max_content_height(Layout::Box const&) const;
float calculate_fit_content_height(Layout::Box const&, Optional<float> available_height) const;
float calculate_fit_content_width(Layout::Box const&, Optional<float> available_width) const;

View file

@ -123,7 +123,8 @@ void TableFormattingContext::calculate_column_widths(Box const& row, CSS::Length
(void)layout_inside(cell, LayoutMode::Normal);
if (cell.colspan() == 1) {
auto [min_width, max_width] = calculate_min_and_max_content_width(cell);
auto min_width = calculate_min_content_width(cell);
auto max_width = calculate_max_content_width(cell);
min_width = max(min_width, cell_state.border_box_width());
max_width = max(max_width, cell_state.border_box_width());
column_widths[column_index].min = max(column_widths[column_index].min, min_width);
@ -137,7 +138,8 @@ void TableFormattingContext::calculate_column_widths(Box const& row, CSS::Length
size_t colspan = cell.colspan();
if (colspan > 1) {
auto& cell_state = m_state.get_mutable(cell);
auto [min_width, max_width] = calculate_min_and_max_content_width(cell);
auto min_width = calculate_min_content_width(cell);
auto max_width = calculate_max_content_width(cell);
float missing_min = max(min_width, cell_state.border_box_width());
float missing_max = max(max_width, cell_state.border_box_width());
for (size_t i = 0; i < colspan; ++i) {