1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:17:45 +00:00

LibWeb+Base: Re-implement grid track span

Implement span correctly when indicated in the grid-column-start,
grid-row-start, etc. CSS properties. Previously it had been implemented
as if span was something that went alongside the position property, but
actually it seems like if you do 'span 3' in the grid-column-start
property, for example, this means it literally spans 3 blocks, and the
3 has nothing to do with position.
This commit is contained in:
martinfalisse 2022-09-17 18:09:35 +02:00 committed by Andreas Kling
parent 86ce1b64f0
commit 236795e931
5 changed files with 224 additions and 117 deletions

View file

@ -9,28 +9,23 @@
namespace Web::CSS {
GridTrackPlacement::GridTrackPlacement(int position, bool has_span)
: m_position(position)
, m_has_span(has_span)
{
}
GridTrackPlacement::GridTrackPlacement(int position)
: m_position(position)
GridTrackPlacement::GridTrackPlacement(int span_or_position, bool has_span)
: m_type(has_span ? Type::Span : Type::Position)
, m_value(span_or_position)
{
}
GridTrackPlacement::GridTrackPlacement()
: m_is_auto(true)
: m_type(Type::Auto)
{
}
String GridTrackPlacement::to_string() const
{
StringBuilder builder;
if (m_has_span)
if (is_span())
builder.append("span "sv);
builder.append(String::number(m_position));
builder.append(String::number(m_value));
return builder.to_string();
}

View file

@ -12,38 +12,34 @@ namespace Web::CSS {
class GridTrackPlacement {
public:
GridTrackPlacement(int, bool);
GridTrackPlacement(int);
enum class Type {
Span,
Position,
Auto
};
GridTrackPlacement(int, bool = false);
GridTrackPlacement();
static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
void set_position(int position)
{
m_is_auto = false;
m_position = position;
}
int position() const { return m_position; }
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; }
void set_has_span(bool has_span)
{
VERIFY(!m_is_auto);
m_has_span = has_span;
}
bool has_span() const { return m_has_span; }
bool is_auto() const { return m_is_auto; }
int raw_value() const { return m_value; }
Type type() const { return m_type; }
String to_string() const;
bool operator==(GridTrackPlacement const& other) const
{
return m_position == other.position() && m_has_span == other.has_span();
return m_type == other.type() && m_value == other.raw_value();
}
private:
bool m_is_auto { false };
int m_position { 0 };
bool m_has_span { false };
Type m_type;
int m_value { 0 };
};
}

View file

@ -5457,20 +5457,14 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
return {};
}
auto first_grid_track_placement = CSS::GridTrackPlacement();
auto has_span = false;
if (current_token.to_string() == "span"sv) {
has_span = true;
tokens.skip_whitespace();
current_token = tokens.next_token().token();
}
if (current_token.is(Token::Type::Number) && current_token.number().is_integer()) {
first_grid_track_placement.set_position(static_cast<int>(current_token.number_value()));
first_grid_track_placement.set_has_span(has_span);
}
if (!tokens.has_next_token())
return GridTrackPlacementStyleValue::create(first_grid_track_placement);
if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && !tokens.has_next_token())
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(static_cast<int>(current_token.number_value()), has_span));
return {};
}
@ -5488,18 +5482,15 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<Com
}
auto calculate_grid_track_placement = [](auto& current_token, auto& tokens) -> CSS::GridTrackPlacement {
auto grid_track_placement = CSS::GridTrackPlacement();
auto has_span = false;
if (current_token.to_string() == "span"sv) {
has_span = true;
tokens.skip_whitespace();
current_token = tokens.next_token().token();
}
if (current_token.is(Token::Type::Number) && current_token.number().is_integer()) {
grid_track_placement.set_position(static_cast<int>(current_token.number_value()));
grid_track_placement.set_has_span(has_span);
}
return grid_track_placement;
if (current_token.is(Token::Type::Number) && current_token.number().is_integer())
return CSS::GridTrackPlacement(static_cast<int>(current_token.number_value()), has_span);
return CSS::GridTrackPlacement();
};
auto first_grid_track_placement = calculate_grid_track_placement(current_token, tokens);