mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 19:27:43 +00:00
LibWeb: Parse line names in grid track position properties
Parse line names when passed to the grid-column/row-start/end CSS properties.
This commit is contained in:
parent
78a573d678
commit
829f56572d
3 changed files with 42 additions and 1 deletions
|
@ -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()
|
GridTrackPlacement::GridTrackPlacement()
|
||||||
: m_type(Type::Auto)
|
: m_type(Type::Auto)
|
||||||
{
|
{
|
||||||
|
@ -35,6 +48,9 @@ String GridTrackPlacement::to_string() const
|
||||||
builder.append(String::number(m_span_count_or_position));
|
builder.append(String::number(m_span_count_or_position));
|
||||||
builder.append(" "sv);
|
builder.append(" "sv);
|
||||||
}
|
}
|
||||||
|
if (has_line_name()) {
|
||||||
|
builder.append(m_line_name);
|
||||||
|
}
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,9 @@ public:
|
||||||
Auto
|
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(int span_count_or_position, bool has_span = false);
|
||||||
|
GridTrackPlacement(String line_name, bool has_span = false);
|
||||||
GridTrackPlacement();
|
GridTrackPlacement();
|
||||||
|
|
||||||
static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
|
static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
|
||||||
|
@ -26,10 +28,13 @@ public:
|
||||||
bool is_span() const { return m_type == Type::Span; }
|
bool is_span() const { return m_type == Type::Span; }
|
||||||
bool is_position() const { return m_type == Type::Position; }
|
bool is_position() const { return m_type == Type::Position; }
|
||||||
bool is_auto() const { return m_type == Type::Auto; }
|
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; }
|
int raw_value() const { return m_span_count_or_position; }
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
String line_name() const { return m_line_name; }
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
bool operator==(GridTrackPlacement const& other) const
|
bool operator==(GridTrackPlacement const& other) const
|
||||||
|
@ -40,6 +45,7 @@ public:
|
||||||
private:
|
private:
|
||||||
Type m_type;
|
Type m_type;
|
||||||
int m_span_count_or_position { 0 };
|
int m_span_count_or_position { 0 };
|
||||||
|
String m_line_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5655,6 +5655,13 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
||||||
return true;
|
return true;
|
||||||
return false;
|
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 };
|
auto tokens = TokenStream { component_values };
|
||||||
tokens.skip_whitespace();
|
tokens.skip_whitespace();
|
||||||
auto current_token = tokens.next_token().token();
|
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));
|
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(1, true));
|
||||||
if (is_valid_integer(current_token))
|
if (is_valid_integer(current_token))
|
||||||
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(static_cast<int>(current_token.number_value())));
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto span_value = false;
|
auto span_value = false;
|
||||||
auto span_or_position_value = 0;
|
auto span_or_position_value = 0;
|
||||||
|
String line_name_value;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (is_auto(current_token))
|
if (is_auto(current_token))
|
||||||
return {};
|
return {};
|
||||||
|
@ -5686,6 +5696,12 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
||||||
else
|
else
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
if (is_line_name(current_token)) {
|
||||||
|
if (line_name_value.is_empty())
|
||||||
|
line_name_value = current_token.ident();
|
||||||
|
else
|
||||||
|
return {};
|
||||||
|
}
|
||||||
tokens.skip_whitespace();
|
tokens.skip_whitespace();
|
||||||
if (tokens.has_next_token())
|
if (tokens.has_next_token())
|
||||||
current_token = tokens.next_token().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 the <integer> is omitted, it defaults to 1.
|
||||||
if (span_or_position_value == 0)
|
if (span_or_position_value == 0)
|
||||||
span_or_position_value = 1;
|
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));
|
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(span_or_position_value, span_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue