diff --git a/Userland/Libraries/LibWeb/CSS/Size.cpp b/Userland/Libraries/LibWeb/CSS/Size.cpp index fc83076d23..2322c583fb 100644 --- a/Userland/Libraries/LibWeb/CSS/Size.cpp +++ b/Userland/Libraries/LibWeb/CSS/Size.cpp @@ -74,4 +74,24 @@ bool Size::contains_percentage() const } } +String Size::to_string() const +{ + switch (m_type) { + case Type::Auto: + return "auto"; + case Type::Length: + case Type::Percentage: + return m_length_percentage.to_string(); + case Type::MinContent: + return "min-content"; + case Type::MaxContent: + return "max-content"; + case Type::FitContent: + return String::formatted("fit-content({})", m_length_percentage.to_string()); + case Type::None: + return "none"; + } + VERIFY_NOT_REACHED(); +} + } diff --git a/Userland/Libraries/LibWeb/CSS/Size.h b/Userland/Libraries/LibWeb/CSS/Size.h index 31852807fb..6c86f9325d 100644 --- a/Userland/Libraries/LibWeb/CSS/Size.h +++ b/Userland/Libraries/LibWeb/CSS/Size.h @@ -63,6 +63,8 @@ public: return m_length_percentage.length(); } + String to_string() const; + private: Size(Type type, LengthPercentage); @@ -71,3 +73,11 @@ private: }; } + +template<> +struct AK::Formatter : Formatter { + ErrorOr format(FormatBuilder& builder, Web::CSS::Size const& size) + { + return Formatter::format(builder, size.to_string()); + } +};