From 0448547553815c5f4243befb5ee91c08508e720c Mon Sep 17 00:00:00 2001 From: martinfalisse Date: Mon, 16 Jan 2023 17:33:30 +0100 Subject: [PATCH] LibWeb: Parse min and max-content Parse min and max-content as well as use its values in the GridTrackSize class. --- Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp | 11 +++++++++++ Userland/Libraries/LibWeb/CSS/GridTrackSize.h | 12 ++++++++---- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 4 ++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp index 5df3bbb188..d498d2df15 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp @@ -33,6 +33,13 @@ GridSize::GridSize(float flexible_length) { } +GridSize::GridSize(Type type) + : m_length { Length::make_auto() } +{ + VERIFY(type == Type::MinContent || type == Type::MaxContent); + m_type = type; +} + GridSize::GridSize() : m_length { Length::make_auto() } { @@ -54,6 +61,10 @@ ErrorOr GridSize::to_string() const return m_percentage.to_string(); case Type::FlexibleLength: return String::formatted("{}fr", m_flexible_length); + case Type::MaxContent: + return String::from_utf8("max-content"sv); + case Type::MinContent: + return String::from_utf8("min-content"sv); } VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.h b/Userland/Libraries/LibWeb/CSS/GridTrackSize.h index 3f6bb4500c..c7ab424df8 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.h +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.h @@ -18,12 +18,14 @@ public: Length, Percentage, FlexibleLength, - // TODO: Max-Content + MaxContent, + MinContent, }; GridSize(Length); GridSize(Percentage); GridSize(float); + GridSize(Type); GridSize(); ~GridSize(); @@ -34,17 +36,19 @@ public: bool is_length() const { return m_type == Type::Length; } bool is_percentage() const { return m_type == Type::Percentage; } bool is_flexible_length() const { return m_type == Type::FlexibleLength; } + bool is_max_content() const { return m_type == Type::MaxContent; } + bool is_min_content() const { return m_type == Type::MinContent; } Length length() const; Percentage percentage() const { return m_percentage; } float flexible_length() const { return m_flexible_length; } - // https://drafts.csswg.org/css-grid/#layout-algorithm - // Intrinsic sizing function - min-content, max-content, auto, fit-content() + // https://www.w3.org/TR/css-grid-2/#layout-algorithm + // An intrinsic sizing function (min-content, max-content, auto, fit-content()). // FIXME: Add missing properties once implemented. bool is_intrinsic_track_sizing() const { - return (m_type == Type::Length && m_length.is_auto()); + return (m_type == Type::Length && m_length.is_auto()) || m_type == Type::MaxContent || m_type == Type::MinContent; } bool is_definite() const diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index daf3e4e157..a1c08a666c 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -5934,6 +5934,10 @@ Optional Parser::parse_grid_size(ComponentValue const& component_ } if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_case("auto"sv)) return GridSize::make_auto(); + if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_case("max-content"sv)) + return GridSize(GridSize::Type::MaxContent); + if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_case("min-content"sv)) + return GridSize(GridSize::Type::MinContent); auto dimension = parse_dimension(token); if (!dimension.has_value()) return {};