mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 03:18:11 +00:00
LibWeb: Add spec comments to FFC layout algorithm step 5
This commit is contained in:
parent
82bb5ef8b7
commit
1d0c4a07ff
2 changed files with 28 additions and 15 deletions
|
@ -555,26 +555,38 @@ void FlexFormattingContext::determine_main_size_of_flex_container(bool const mai
|
|||
void FlexFormattingContext::collect_flex_items_into_flex_lines(float const main_available_size)
|
||||
{
|
||||
// FIXME: Also support wrap-reverse
|
||||
if (flex_container().computed_values().flex_wrap() == CSS::FlexWrap::Nowrap) {
|
||||
|
||||
// If the flex container is single-line, collect all the flex items into a single flex line.
|
||||
if (is_single_line()) {
|
||||
FlexLine line;
|
||||
for (auto& flex_item : m_flex_items) {
|
||||
line.items.append(&flex_item);
|
||||
}
|
||||
m_flex_lines.append(line);
|
||||
} else {
|
||||
FlexLine line;
|
||||
float line_main_size = 0;
|
||||
for (auto& flex_item : m_flex_items) {
|
||||
if ((line_main_size + flex_item.hypothetical_main_size) > main_available_size) {
|
||||
m_flex_lines.append(line);
|
||||
line = {};
|
||||
line_main_size = 0;
|
||||
}
|
||||
line.items.append(&flex_item);
|
||||
line_main_size += flex_item.hypothetical_main_size;
|
||||
}
|
||||
m_flex_lines.append(line);
|
||||
m_flex_lines.append(move(line));
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, starting from the first uncollected item, collect consecutive items one by one
|
||||
// until the first time that the next collected item would not fit into the flex container’s inner main size
|
||||
// (or until a forced break is encountered, see §10 Fragmenting Flex Layout).
|
||||
// If the very first uncollected item wouldn't fit, collect just it into the line.
|
||||
|
||||
// For this step, the size of a flex item is its outer hypothetical main size. (Note: This can be negative.)
|
||||
|
||||
// Repeat until all flex items have been collected into flex lines.
|
||||
|
||||
FlexLine line;
|
||||
float line_main_size = 0;
|
||||
for (auto& flex_item : m_flex_items) {
|
||||
if ((line_main_size + flex_item.hypothetical_main_size) > main_available_size) {
|
||||
m_flex_lines.append(move(line));
|
||||
line = {};
|
||||
line_main_size = 0;
|
||||
}
|
||||
line.items.append(&flex_item);
|
||||
line_main_size += flex_item.hypothetical_main_size;
|
||||
}
|
||||
m_flex_lines.append(move(line));
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-flexbox-1/#resolve-flexible-lengths
|
||||
|
|
|
@ -113,6 +113,7 @@ private:
|
|||
void align_all_flex_lines();
|
||||
|
||||
bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; }
|
||||
bool is_single_line() const { return flex_container().computed_values().flex_wrap() == CSS::FlexWrap::Nowrap; }
|
||||
|
||||
void populate_specified_margins(FlexItem&, CSS::FlexDirection) const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue