diff options
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp | 22 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/GridTrackSize.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 43 |
3 files changed, 64 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp index 850788387c..1015ccaec2 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp @@ -151,13 +151,15 @@ String ExplicitGridTrack::to_string() const } } -GridTrackSizeList::GridTrackSizeList(Vector<CSS::ExplicitGridTrack> track_list) +GridTrackSizeList::GridTrackSizeList(Vector<CSS::ExplicitGridTrack> track_list, Vector<Vector<String>> line_names) : m_track_list(track_list) + , m_line_names(line_names) { } GridTrackSizeList::GridTrackSizeList() : m_track_list({}) + , m_line_names({}) { } @@ -169,11 +171,29 @@ GridTrackSizeList GridTrackSizeList::make_auto() String GridTrackSizeList::to_string() const { StringBuilder builder; + auto print_line_names = [&](size_t index) -> void { + builder.append("["sv); + for (size_t y = 0; y < m_line_names[index].size(); ++y) { + builder.append(m_line_names[index][y]); + if (y != m_line_names[index].size() - 1) + builder.append(" "sv); + } + builder.append("]"sv); + }; + for (size_t i = 0; i < m_track_list.size(); ++i) { + if (m_line_names[i].size() > 0) { + print_line_names(i); + builder.append(" "sv); + } builder.append(m_track_list[i].to_string()); if (i < m_track_list.size() - 1) builder.append(" "sv); } + if (m_line_names[m_track_list.size()].size() > 0) { + builder.append(" "sv); + print_line_names(m_track_list.size()); + } return builder.to_string(); } diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.h b/Userland/Libraries/LibWeb/CSS/GridTrackSize.h index 6a269ae568..07a450e4f4 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.h +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.h @@ -92,20 +92,23 @@ private: class GridTrackSizeList { public: - GridTrackSizeList(Vector<CSS::ExplicitGridTrack> track_list); + GridTrackSizeList(Vector<CSS::ExplicitGridTrack> track_list, Vector<Vector<String>> line_names); GridTrackSizeList(); static GridTrackSizeList make_auto(); Vector<CSS::ExplicitGridTrack> track_list() const { return m_track_list; } + Vector<Vector<String>> line_names() const { return m_line_names; } + String to_string() const; bool operator==(GridTrackSizeList const& other) const { - return m_track_list == other.track_list(); + return m_line_names == other.line_names() && m_track_list == other.track_list(); } private: Vector<CSS::ExplicitGridTrack> m_track_list; + Vector<Vector<String>> m_line_names; }; class GridRepeat { diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index ef47008ed9..defb039fab 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -5500,11 +5500,26 @@ Optional<CSS::GridRepeat> Parser::parse_repeat(Vector<ComponentValue> const& com return {}; Vector<CSS::ExplicitGridTrack> repeat_params; + Vector<Vector<String>> line_names_list; + auto last_object_was_line_names = false; while (part_two_tokens.has_next_token()) { auto token = part_two_tokens.next_token(); + Vector<String> line_names; if (token.is_block()) { + if (last_object_was_line_names) + return {}; + last_object_was_line_names = true; + if (!token.block().is_square()) + return {}; + TokenStream block_tokens { token.block().values() }; + while (block_tokens.has_next_token()) { + auto current_block_token = block_tokens.next_token(); + line_names.append(current_block_token.token().ident()); + } + line_names_list.append(line_names); part_two_tokens.skip_whitespace(); } else { + last_object_was_line_names = false; auto track_sizing_function = parse_track_sizing_function(token); if (!track_sizing_function.has_value()) return {}; @@ -5519,6 +5534,8 @@ Optional<CSS::GridRepeat> Parser::parse_repeat(Vector<ComponentValue> const& com part_two_tokens.skip_whitespace(); } } + while (line_names_list.size() <= repeat_params.size()) + line_names_list.append({}); // Thus the precise syntax of the repeat() notation has several forms: // <track-repeat> = repeat( [ <integer [1,∞]> ] , [ <line-names>? <track-size> ]+ <line-names>? ) @@ -5540,11 +5557,11 @@ Optional<CSS::GridRepeat> Parser::parse_repeat(Vector<ComponentValue> const& com // 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 CSS::GridRepeat(CSS::GridTrackSizeList(repeat_params), CSS::GridRepeat::Type::AutoFill); + return CSS::GridRepeat(CSS::GridTrackSizeList(repeat_params, line_names_list), CSS::GridRepeat::Type::AutoFill); else if (is_auto_fit) - return CSS::GridRepeat(CSS::GridTrackSizeList(repeat_params), CSS::GridRepeat::Type::AutoFit); + return CSS::GridRepeat(CSS::GridTrackSizeList(repeat_params, line_names_list), CSS::GridRepeat::Type::AutoFit); else - return CSS::GridRepeat(CSS::GridTrackSizeList(repeat_params), repeat_count); + return CSS::GridRepeat(CSS::GridTrackSizeList(repeat_params, line_names_list), repeat_count); } Optional<CSS::ExplicitGridTrack> Parser::parse_track_sizing_function(ComponentValue const& token) @@ -5580,12 +5597,26 @@ Optional<CSS::ExplicitGridTrack> Parser::parse_track_sizing_function(ComponentVa RefPtr<StyleValue> Parser::parse_grid_track_sizes(Vector<ComponentValue> const& component_values) { Vector<CSS::ExplicitGridTrack> track_list; + Vector<Vector<String>> line_names_list; + auto last_object_was_line_names = false; TokenStream tokens { component_values }; while (tokens.has_next_token()) { auto token = tokens.next_token(); if (token.is_block()) { - + if (last_object_was_line_names) + return GridTrackSizeStyleValue::make_auto(); + last_object_was_line_names = true; + Vector<String> line_names; + if (!token.block().is_square()) + return GridTrackSizeStyleValue::make_auto(); + TokenStream block_tokens { token.block().values() }; + while (block_tokens.has_next_token()) { + auto current_block_token = block_tokens.next_token(); + line_names.append(current_block_token.token().ident()); + } + line_names_list.append(line_names); } else { + last_object_was_line_names = false; auto track_sizing_function = parse_track_sizing_function(token); if (!track_sizing_function.has_value()) return GridTrackSizeStyleValue::make_auto(); @@ -5594,7 +5625,9 @@ RefPtr<StyleValue> Parser::parse_grid_track_sizes(Vector<ComponentValue> const& track_list.append(track_sizing_function.value()); } } - return GridTrackSizeStyleValue::create(CSS::GridTrackSizeList(track_list)); + while (line_names_list.size() <= track_list.size()) + line_names_list.append({}); + return GridTrackSizeStyleValue::create(CSS::GridTrackSizeList(track_list, line_names_list)); } RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> const& component_values) |