summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp16
-rw-r--r--Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h8
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp19
3 files changed, 42 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp
index 561d500231..001369d3bf 100644
--- a/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp
+++ b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp
@@ -15,6 +15,19 @@ GridTrackPlacement::GridTrackPlacement(int span_count_or_position, bool has_span
{
}
+GridTrackPlacement::GridTrackPlacement(String line_name, int span_count_or_position, bool has_span)
+ : m_type(has_span ? Type::Span : Type::Position)
+ , m_span_count_or_position(span_count_or_position)
+ , m_line_name(line_name)
+{
+}
+
+GridTrackPlacement::GridTrackPlacement(String line_name, bool has_span)
+ : m_type(has_span ? Type::Span : Type::Position)
+ , m_line_name(line_name)
+{
+}
+
GridTrackPlacement::GridTrackPlacement()
: m_type(Type::Auto)
{
@@ -35,6 +48,9 @@ String GridTrackPlacement::to_string() const
builder.append(String::number(m_span_count_or_position));
builder.append(" "sv);
}
+ if (has_line_name()) {
+ builder.append(m_line_name);
+ }
return builder.to_string();
}
diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h
index 8a61ebbb3d..a7757a65e6 100644
--- a/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h
+++ b/Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h
@@ -18,7 +18,9 @@ public:
Auto
};
+ GridTrackPlacement(String line_name, int span_count_or_position, bool has_span = false);
GridTrackPlacement(int span_count_or_position, bool has_span = false);
+ GridTrackPlacement(String line_name, bool has_span = false);
GridTrackPlacement();
static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
@@ -26,10 +28,13 @@ public:
bool is_span() const { return m_type == Type::Span; }
bool is_position() const { return m_type == Type::Position; }
bool is_auto() const { return m_type == Type::Auto; }
- bool is_auto_positioned() const { return m_type == Type::Auto || m_type == Type::Span; }
+ bool is_auto_positioned() const { return m_type == Type::Auto || (m_type == Type::Span && !has_line_name()); }
+
+ bool has_line_name() const { return !m_line_name.is_empty(); }
int raw_value() const { return m_span_count_or_position; }
Type type() const { return m_type; }
+ String line_name() const { return m_line_name; }
String to_string() const;
bool operator==(GridTrackPlacement const& other) const
@@ -40,6 +45,7 @@ public:
private:
Type m_type;
int m_span_count_or_position { 0 };
+ String m_line_name;
};
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index defb039fab..4bb4b47405 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -5655,6 +5655,13 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
return true;
return false;
};
+ auto is_line_name = [](Token token) -> bool {
+ // The <custom-ident> additionally excludes the keywords span and auto.
+ if (token.is(Token::Type::Ident) && !token.ident().equals_ignoring_case("span"sv) && !token.ident().equals_ignoring_case("auto"sv))
+ return true;
+ return false;
+ };
+
auto tokens = TokenStream { component_values };
tokens.skip_whitespace();
auto current_token = tokens.next_token().token();
@@ -5666,11 +5673,14 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(1, true));
if (is_valid_integer(current_token))
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(static_cast<int>(current_token.number_value())));
+ if (is_line_name(current_token))
+ return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(current_token.ident()));
return {};
}
auto span_value = false;
auto span_or_position_value = 0;
+ String line_name_value;
while (true) {
if (is_auto(current_token))
return {};
@@ -5686,6 +5696,12 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
else
return {};
}
+ if (is_line_name(current_token)) {
+ if (line_name_value.is_empty())
+ line_name_value = current_token.ident();
+ else
+ return {};
+ }
tokens.skip_whitespace();
if (tokens.has_next_token())
current_token = tokens.next_token().token();
@@ -5700,6 +5716,9 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
// If the <integer> is omitted, it defaults to 1.
if (span_or_position_value == 0)
span_or_position_value = 1;
+
+ if (!line_name_value.is_empty())
+ return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(line_name_value, span_or_position_value, span_value));
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(span_or_position_value, span_value));
}