1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

LibWeb: Implement the flex order CSS property

Adds support for the flex order property and a test page for it
on the browser welcome page.
This commit is contained in:
Enver Balalic 2022-03-31 22:11:38 +02:00 committed by Andreas Kling
parent 2377344a89
commit 58398b1e12
9 changed files with 142 additions and 1 deletions

View file

@ -7,6 +7,7 @@
#include "InlineFormattingContext.h"
#include <AK/Function.h>
#include <AK/QuickSort.h>
#include <AK/StdLibExtras.h>
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/BlockFormattingContext.h>
@ -170,6 +171,8 @@ void FlexFormattingContext::generate_anonymous_flex_items()
// calculations that could change that.
// This is particularly important since we take references to the items stored in flex_items
// later, whose addresses won't be stable if we added or removed any items.
HashMap<int, Vector<FlexItem>> order_item_bucket;
flex_container().for_each_child_of_type<Box>([&](Box& child_box) {
// Skip anonymous text runs that are only whitespace.
if (child_box.is_anonymous() && !child_box.first_child_of_type<BlockContainer>()) {
@ -192,9 +195,24 @@ void FlexFormattingContext::generate_anonymous_flex_items()
child_box.set_flex_item(true);
FlexItem flex_item = { child_box };
populate_specified_margins(flex_item, m_flex_direction);
m_flex_items.append(move(flex_item));
auto& order_bucket = order_item_bucket.ensure(child_box.computed_values().order());
order_bucket.append(move(flex_item));
return IterationDecision::Continue;
});
auto keys = order_item_bucket.keys();
quick_sort(keys, [](auto& a, auto& b) { return a < b; });
for (auto key : keys) {
auto order_bucket = order_item_bucket.get(key);
if (order_bucket.has_value()) {
for (auto flex_item : order_bucket.value()) {
m_flex_items.append(move(flex_item));
}
}
}
}
bool FlexFormattingContext::has_definite_main_size(Box const& box) const