mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:07:34 +00:00
LibWeb: Move FFC layout algorithm step 8 to a separate function
This commit is contained in:
parent
3402584646
commit
8f027b4792
2 changed files with 36 additions and 28 deletions
|
@ -109,33 +109,7 @@ void FlexFormattingContext::run(Box& flex_container, LayoutMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Calculate the cross size of each flex line.
|
// 8. Calculate the cross size of each flex line.
|
||||||
if (flex_lines.size() == 1 && has_definite_cross_size(flex_container)) {
|
calculate_cross_size_of_each_flex_line(flex_container, flex_lines, cross_min_size, cross_max_size);
|
||||||
flex_lines[0].cross_size = specified_cross_size(flex_container);
|
|
||||||
} else {
|
|
||||||
for (auto& flex_line : flex_lines) {
|
|
||||||
// FIXME: Implement 8.1
|
|
||||||
|
|
||||||
// FIXME: This isn't spec but makes sense here
|
|
||||||
if (has_definite_cross_size(flex_container) && flex_container.computed_values().align_items() == CSS::AlignItems::Stretch) {
|
|
||||||
flex_line.cross_size = specified_cross_size(flex_container) / flex_lines.size();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8.2
|
|
||||||
float largest_hypothetical_cross_size = 0;
|
|
||||||
for (auto& flex_item : flex_line.items) {
|
|
||||||
if (largest_hypothetical_cross_size < flex_item->hypothetical_cross_size_with_margins())
|
|
||||||
largest_hypothetical_cross_size = flex_item->hypothetical_cross_size_with_margins();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8.3
|
|
||||||
flex_line.cross_size = max(0.0f, largest_hypothetical_cross_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flex_lines.size() == 1) {
|
|
||||||
clamp(flex_lines[0].cross_size, cross_min_size, cross_max_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 9. Handle 'align-content: stretch'.
|
// 9. Handle 'align-content: stretch'.
|
||||||
// FIXME: This
|
// FIXME: This
|
||||||
|
@ -930,6 +904,38 @@ float FlexFormattingContext::determine_hypothetical_cross_size_of_item(Box& box)
|
||||||
BlockFormattingContext context(verify_cast<BlockContainer>(box), this);
|
BlockFormattingContext context(verify_cast<BlockContainer>(box), this);
|
||||||
context.compute_width(box);
|
context.compute_width(box);
|
||||||
return box.width();
|
return box.width();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/css-flexbox-1/#algo-cross-line
|
||||||
|
void FlexFormattingContext::calculate_cross_size_of_each_flex_line(const Box& flex_container, Vector<FlexLine>& flex_lines, float cross_min_size, float cross_max_size)
|
||||||
|
{
|
||||||
|
if (flex_lines.size() == 1 && has_definite_cross_size(flex_container)) {
|
||||||
|
flex_lines[0].cross_size = specified_cross_size(flex_container);
|
||||||
|
} else {
|
||||||
|
for (auto& flex_line : flex_lines) {
|
||||||
|
// FIXME: Implement 8.1
|
||||||
|
|
||||||
|
// FIXME: This isn't spec but makes sense here
|
||||||
|
if (has_definite_cross_size(flex_container) && flex_container.computed_values().align_items() == CSS::AlignItems::Stretch) {
|
||||||
|
flex_line.cross_size = specified_cross_size(flex_container) / flex_lines.size();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8.2
|
||||||
|
float largest_hypothetical_cross_size = 0;
|
||||||
|
for (auto& flex_item : flex_line.items) {
|
||||||
|
if (largest_hypothetical_cross_size < flex_item->hypothetical_cross_size_with_margins())
|
||||||
|
largest_hypothetical_cross_size = flex_item->hypothetical_cross_size_with_margins();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8.3
|
||||||
|
flex_line.cross_size = max(0.0f, largest_hypothetical_cross_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flex_lines.size() == 1) {
|
||||||
|
clamp(flex_lines[0].cross_size, cross_min_size, cross_max_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,8 @@ private:
|
||||||
|
|
||||||
float determine_hypothetical_cross_size_of_item(Box&);
|
float determine_hypothetical_cross_size_of_item(Box&);
|
||||||
|
|
||||||
|
void calculate_cross_size_of_each_flex_line(Box const& flex_container, Vector<FlexLine>&, float cross_min_size, float cross_max_size);
|
||||||
|
|
||||||
bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; }
|
bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; }
|
||||||
|
|
||||||
CSS::FlexDirection m_flex_direction {};
|
CSS::FlexDirection m_flex_direction {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue