From e4eb6d4f1f36ed5905ee2f5e75e0fb7468fa70eb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Mar 2022 14:11:55 +0100 Subject: [PATCH] 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. --- .../LibWeb/Layout/FlexFormattingContext.cpp | 24 +++++++++++++++++++ .../LibWeb/Layout/FlexFormattingContext.h | 2 ++ 2 files changed, 26 insertions(+) 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;