mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibWeb: Move FFC layout algorithm step 7 to a separate function
This commit is contained in:
parent
0c0df78030
commit
3402584646
2 changed files with 34 additions and 35 deletions
|
@ -70,40 +70,6 @@ void FlexFormattingContext::run(Box& flex_container, LayoutMode)
|
||||||
|
|
||||||
// FIXME: Implement reverse and ordering.
|
// FIXME: Implement reverse and ordering.
|
||||||
|
|
||||||
bool is_row = is_row_layout();
|
|
||||||
|
|
||||||
auto calculate_hypothetical_cross_size = [&is_row, this](Box& box) {
|
|
||||||
bool cross_constrained = false;
|
|
||||||
if (is_row) {
|
|
||||||
if (!box.computed_values().height().is_undefined_or_auto() || !box.computed_values().min_height().is_undefined_or_auto()) {
|
|
||||||
cross_constrained = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!box.computed_values().width().is_undefined_or_auto() || !box.computed_values().min_width().is_undefined_or_auto()) {
|
|
||||||
cross_constrained = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cross_constrained && box.children_are_inline()) {
|
|
||||||
auto& block_container = verify_cast<BlockContainer>(box);
|
|
||||||
BlockFormattingContext bfc(block_container, this);
|
|
||||||
bfc.run(box, LayoutMode::Default);
|
|
||||||
InlineFormattingContext ifc(block_container, &bfc);
|
|
||||||
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
|
|
||||||
|
|
||||||
if (is_row)
|
|
||||||
return box.height();
|
|
||||||
return box.width();
|
|
||||||
}
|
|
||||||
if (is_row) {
|
|
||||||
return BlockFormattingContext::compute_theoretical_height(box);
|
|
||||||
} else {
|
|
||||||
BlockFormattingContext context(verify_cast<BlockContainer>(box), this);
|
|
||||||
context.compute_width(box);
|
|
||||||
return box.width();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector<FlexItem> flex_items;
|
Vector<FlexItem> flex_items;
|
||||||
|
|
||||||
// 1. Generate anonymous flex items
|
// 1. Generate anonymous flex items
|
||||||
|
@ -139,7 +105,7 @@ void FlexFormattingContext::run(Box& flex_container, LayoutMode)
|
||||||
// Cross Size Determination
|
// Cross Size Determination
|
||||||
// 7. Determine the hypothetical cross size of each item
|
// 7. Determine the hypothetical cross size of each item
|
||||||
for (auto& flex_item : flex_items) {
|
for (auto& flex_item : flex_items) {
|
||||||
flex_item.hypothetical_cross_size = calculate_hypothetical_cross_size(flex_item.box);
|
flex_item.hypothetical_cross_size = determine_hypothetical_cross_size_of_item(flex_item.box);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Calculate the cross size of each flex line.
|
// 8. Calculate the cross size of each flex line.
|
||||||
|
@ -935,4 +901,35 @@ void FlexFormattingContext::resolve_flexible_lengths(Vector<FlexLine>& flex_line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/css-flexbox-1/#algo-cross-item
|
||||||
|
float FlexFormattingContext::determine_hypothetical_cross_size_of_item(Box& box)
|
||||||
|
{
|
||||||
|
bool cross_constrained = false;
|
||||||
|
if (is_row_layout()) {
|
||||||
|
if (!box.computed_values().height().is_undefined_or_auto() || !box.computed_values().min_height().is_undefined_or_auto()) {
|
||||||
|
cross_constrained = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!box.computed_values().width().is_undefined_or_auto() || !box.computed_values().min_width().is_undefined_or_auto()) {
|
||||||
|
cross_constrained = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cross_constrained && box.children_are_inline()) {
|
||||||
|
auto& block_container = verify_cast<BlockContainer>(box);
|
||||||
|
BlockFormattingContext bfc(block_container, this);
|
||||||
|
bfc.run(box, LayoutMode::Default);
|
||||||
|
InlineFormattingContext ifc(block_container, &bfc);
|
||||||
|
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
|
||||||
|
|
||||||
|
return is_row_layout() ? box.height() : box.width();
|
||||||
|
}
|
||||||
|
if (is_row_layout())
|
||||||
|
return BlockFormattingContext::compute_theoretical_height(box);
|
||||||
|
|
||||||
|
BlockFormattingContext context(verify_cast<BlockContainer>(box), this);
|
||||||
|
context.compute_width(box);
|
||||||
|
return box.width();
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,8 @@ private:
|
||||||
|
|
||||||
void resolve_flexible_lengths(Vector<FlexLine>&, float main_available_size);
|
void resolve_flexible_lengths(Vector<FlexLine>&, float main_available_size);
|
||||||
|
|
||||||
|
float determine_hypothetical_cross_size_of_item(Box&);
|
||||||
|
|
||||||
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