From ad5f7c56c112e4e0901a4452f6655ae2135170be Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 27 Aug 2025 11:43:44 +0100 Subject: [PATCH] LibWeb/CSS: Prepare Size for use in GridSize Make it constructible from a LengthPercentage, report whether it contains a length-percentage, and add an equality operator. --- Libraries/LibWeb/CSS/Size.cpp | 12 ++++++++++++ Libraries/LibWeb/CSS/Size.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/Libraries/LibWeb/CSS/Size.cpp b/Libraries/LibWeb/CSS/Size.cpp index 81d88089c9a..67848ad82ad 100644 --- a/Libraries/LibWeb/CSS/Size.cpp +++ b/Libraries/LibWeb/CSS/Size.cpp @@ -44,6 +44,18 @@ Size Size::make_calculated(NonnullRefPtr calculated) return Size { Type::Calculated, move(calculated) }; } +Size Size::make_length_percentage(LengthPercentage const& length_percentage) +{ + if (length_percentage.is_auto()) + return make_auto(); + if (length_percentage.is_length()) + return make_length(length_percentage.length()); + if (length_percentage.is_percentage()) + return make_percentage(length_percentage.percentage()); + VERIFY(length_percentage.is_calculated()); + return make_calculated(length_percentage.calculated()); +} + Size Size::make_min_content() { return Size { Type::MinContent, Length::make_auto() }; diff --git a/Libraries/LibWeb/CSS/Size.h b/Libraries/LibWeb/CSS/Size.h index 6ff774ba6f0..1cc5a8c6dcc 100644 --- a/Libraries/LibWeb/CSS/Size.h +++ b/Libraries/LibWeb/CSS/Size.h @@ -30,6 +30,7 @@ public: static Size make_length(Length); static Size make_percentage(Percentage); static Size make_calculated(NonnullRefPtr); + static Size make_length_percentage(LengthPercentage const&); static Size make_min_content(); static Size make_max_content(); static Size make_fit_content(LengthPercentage available_space); @@ -45,6 +46,8 @@ public: bool is_fit_content() const { return m_type == Type::FitContent; } bool is_none() const { return m_type == Type::None; } + bool is_length_percentage() const { return is_length() || is_percentage() || is_calculated(); } + [[nodiscard]] CSSPixels to_px(Layout::Node const&, CSSPixels reference_value) const; bool contains_percentage() const; @@ -74,6 +77,7 @@ public: } String to_string(SerializationMode) const; + bool operator==(Size const&) const = default; private: Size(Type type, LengthPercentage);