LibWeb: Some flex items have definite size after flexing

This patch implements two of the special "definite size" rules from
the CSS-FLEXBOX-1 spec.

https://drafts.csswg.org/css-flexbox-1/#definite-sizes
This commit is contained in:
Andreas Kling 2022-07-18 18:36:52 +02:00
parent 02c59fe8c9
commit 69243947d5
Notes: sideshowbarker 2024-07-17 08:34:29 +09:00
2 changed files with 28 additions and 0 deletions

View file

@ -414,6 +414,24 @@ void FlexFormattingContext::set_cross_size(Box const& box, float size)
m_state.get_mutable(box).set_content_width(size);
}
void FlexFormattingContext::set_has_definite_main_size(Box const& box, bool definite)
{
auto& used_values = m_state.get_mutable(box);
if (is_row_layout())
used_values.set_has_definite_width(definite);
else
used_values.set_has_definite_height(definite);
}
void FlexFormattingContext::set_has_definite_cross_size(Box const& box, bool definite)
{
auto& used_values = m_state.get_mutable(box);
if (!is_row_layout())
used_values.set_has_definite_width(definite);
else
used_values.set_has_definite_height(definite);
}
void FlexFormattingContext::set_offset(Box const& box, float main_offset, float cross_offset)
{
if (is_row_layout())
@ -964,6 +982,14 @@ void FlexFormattingContext::resolve_flexible_lengths()
// 6.5.
for (auto& flex_item : flex_line.items) {
flex_item->main_size = flex_item->target_main_size;
set_main_size(flex_item->box, flex_item->main_size);
// https://drafts.csswg.org/css-flexbox-1/#definite-sizes
// 1. If the flex container has a definite main size, then the post-flexing main sizes of its flex items are treated as definite.
// 2. If a flex-items flex basis is definite, then its post-flexing main size is also definite.
if (has_definite_main_size(flex_container()) || flex_item->used_flex_basis.is_definite()) {
set_has_definite_main_size(flex_item->box, true);
}
}
flex_line.remaining_free_space = calculate_free_space();

View file

@ -107,6 +107,8 @@ private:
void set_main_size(Box const&, float size);
void set_cross_size(Box const&, float size);
void set_has_definite_main_size(Box const&, bool);
void set_has_definite_cross_size(Box const&, bool);
void set_offset(Box const&, float main_offset, float cross_offset);
void set_main_axis_first_margin(FlexItem&, float margin);
void set_main_axis_second_margin(FlexItem&, float margin);