summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-12 14:11:55 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-13 00:04:51 +0100
commite4eb6d4f1f36ed5905ee2f5e75e0fb7468fa70eb (patch)
tree253f26514800d296435c778d68aa5fb9cbe96d53 /Userland/Libraries/LibWeb/Layout
parent5c8e7217f7aa01a4f677ced2a89b04d37e085abe (diff)
downloadserenity-e4eb6d4f1f36ed5905ee2f5e75e0fb7468fa70eb.zip
LibWeb: Add FFC helpers for resolving definite main/cross sizes
Although something has a definite size, we may still have to "resolve" it, since FFC is quite liberal in what it considers to be definite. Let's put that logic in a set of helper functions.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp24
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h2
2 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
index 5f233fdf23..d2c052eda3 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
@@ -197,6 +197,30 @@ float FlexFormattingContext::specified_cross_size(Box const& box) const
return is_row_layout() ? box_state.content_height : box_state.content_width;
}
+float FlexFormattingContext::resolved_definite_cross_size(Box const& box) const
+{
+ if (is_row_layout())
+ VERIFY(box.has_definite_height());
+ else
+ VERIFY(box.has_definite_width());
+ auto const& cross_value = is_row_layout() ? box.computed_values().height() : box.computed_values().width();
+ if (cross_value->is_length())
+ return cross_value->length().to_px(box);
+ return cross_value->resolved(box, CSS::Length::make_px(specified_cross_size(flex_container()))).to_px(box);
+}
+
+float FlexFormattingContext::resolved_definite_main_size(Box const& box) const
+{
+ if (is_row_layout())
+ VERIFY(box.has_definite_width());
+ else
+ VERIFY(box.has_definite_height());
+ auto const& cross_value = is_row_layout() ? box.computed_values().width() : box.computed_values().height();
+ if (cross_value->is_length())
+ return cross_value->length().to_px(box);
+ return cross_value->resolved(box, CSS::Length::make_px(specified_main_size(flex_container()))).to_px(box);
+}
+
bool FlexFormattingContext::has_main_min_size(Box const& box) const
{
auto value = is_row_layout() ? box.computed_values().min_width() : box.computed_values().min_height();
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
index 59806103cb..db00d0483f 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
@@ -59,6 +59,8 @@ private:
bool has_definite_cross_size(Box const&) const;
float specified_main_size(Box const&) const;
float specified_cross_size(Box const&) const;
+ float resolved_definite_main_size(Box const&) const;
+ float resolved_definite_cross_size(Box const&) const;
bool has_main_min_size(Box const&) const;
bool has_cross_min_size(Box const&) const;
float specified_main_max_size(Box const&) const;