diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp index 1b389305fc..5d9669a8bc 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp @@ -84,6 +84,13 @@ ExplicitTrackSizing::ExplicitTrackSizing(Vector meta_gri { } +ExplicitTrackSizing::ExplicitTrackSizing(Vector meta_grid_track_sizes, Type type) + : m_meta_grid_track_sizes(meta_grid_track_sizes) + , m_is_auto_fill(type == Type::AutoFill) + , m_is_auto_fit(type == Type::AutoFit) +{ +} + String ExplicitTrackSizing::to_string() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.h b/Userland/Libraries/LibWeb/CSS/GridTrackSize.h index 4202837469..c813571353 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.h +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.h @@ -87,12 +87,21 @@ private: class ExplicitTrackSizing { public: + enum class Type { + AutoFit, + AutoFill, + }; + ExplicitTrackSizing(); ExplicitTrackSizing(Vector); ExplicitTrackSizing(Vector, int repeat_count); + ExplicitTrackSizing(Vector, Type); + static ExplicitTrackSizing make_auto() { return ExplicitTrackSizing(); }; bool is_repeat() const { return m_is_repeat; } + bool is_auto_fill() const { return m_is_auto_fill; } + bool is_auto_fit() const { return m_is_auto_fit; } int repeat_count() const { return m_repeat_count; } Vector meta_grid_track_sizes() const& { return m_meta_grid_track_sizes; } @@ -106,6 +115,8 @@ public: private: Vector m_meta_grid_track_sizes; bool m_is_repeat { false }; + bool m_is_auto_fill { false }; + bool m_is_auto_fit { false }; int m_repeat_count { 0 }; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index e5cc384cba..67f7266e67 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -5440,6 +5440,8 @@ RefPtr Parser::parse_grid_track_sizes(Vector const& // The generic form of the repeat() syntax is, approximately, // repeat( [ | auto-fill | auto-fit ] , ) if (function_token.name().equals_ignoring_case("repeat"sv)) { + auto is_auto_fill = false; + auto is_auto_fit = false; auto function_tokens = TokenStream(function_token.values()); auto comma_separated_list = parse_a_comma_separated_list_of_component_values(function_tokens); if (comma_separated_list.size() != 2) @@ -5454,6 +5456,10 @@ RefPtr Parser::parse_grid_track_sizes(Vector const& auto repeat_count = 0; if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() > 0) repeat_count = current_token.number_value(); + else if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("auto-fill"sv)) + is_auto_fill = true; + else if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("auto-fit"sv)) + is_auto_fit = true; // The second argument is a track list, which is repeated that number of times. TokenStream part_two_tokens { comma_separated_list[1] }; @@ -5478,6 +5484,9 @@ RefPtr Parser::parse_grid_track_sizes(Vector const& auto grid_track_size = parse_grid_track_size(current_component_value); if (!grid_track_size.has_value()) return GridTrackSizeStyleValue::create({}); + // Automatic repetitions (auto-fill or auto-fit) cannot be combined with intrinsic or flexible sizes. + if (grid_track_size.value().is_flexible_length() && (is_auto_fill || is_auto_fit)) + return GridTrackSizeStyleValue::create({}); repeat_params.append(grid_track_size.value()); } part_two_tokens.skip_whitespace(); @@ -5485,8 +5494,6 @@ RefPtr Parser::parse_grid_track_sizes(Vector const& break; } - // Automatic repetitions (auto-fill or auto-fit) cannot be combined with intrinsic or flexible sizes. - // Thus the precise syntax of the repeat() notation has several forms: // = repeat( [ ] , [ ? ]+ ? ) // = repeat( [ auto-fill | auto-fit ] , [ ? ]+ ? ) @@ -5506,6 +5513,10 @@ RefPtr Parser::parse_grid_track_sizes(Vector const& // If a repeat() function that is not a ends up placing two adjacent to // each other, the name lists are merged. For example, repeat(2, [a] 1fr [b]) is equivalent to [a] // 1fr [b a] 1fr [b]. + if (is_auto_fill) + return GridTrackSizeStyleValue::create(CSS::ExplicitTrackSizing(repeat_params, CSS::ExplicitTrackSizing::Type::AutoFill)); + if (is_auto_fit) + return GridTrackSizeStyleValue::create(CSS::ExplicitTrackSizing(repeat_params, CSS::ExplicitTrackSizing::Type::AutoFit)); return GridTrackSizeStyleValue::create(CSS::ExplicitTrackSizing(repeat_params, repeat_count)); } else { // FIXME: Implement MinMax, etc.