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

LibWeb: Define if identifier represent area or line during layout [GFC]

This fixes regression introduced in
c03e025a32 by assuming that it is
possible to determine whether identifier stands for line or area
during parsing.
This commit is contained in:
Aliaksandr Kalenik 2023-08-27 16:27:35 +02:00 committed by Andreas Kling
parent 5d7e73adfe
commit b66f65dc9e
10 changed files with 104 additions and 145 deletions

View file

@ -17,13 +17,15 @@ String GridTrackPlacement::to_string() const
[&](Auto const&) {
builder.append("auto"sv);
},
[&](Area const& area) {
builder.append(area.name);
},
[&](Line const& line) {
builder.appendff("{}", line.value);
if (line.name.has_value())
builder.appendff(" {}", line.name.value());
[&](AreaOrLine const& area_or_line) {
if (area_or_line.line_number.has_value() && area_or_line.name.has_value()) {
builder.appendff("{} {}", *area_or_line.line_number, *area_or_line.name);
} else if (area_or_line.line_number.has_value()) {
builder.appendff("{}", *area_or_line.line_number);
}
if (area_or_line.name.has_value()) {
builder.appendff("{}", *area_or_line.name);
}
},
[&](Span const& span) {
builder.appendff("span {}", span.value);

View file

@ -18,14 +18,9 @@ public:
return GridTrackPlacement();
}
static GridTrackPlacement make_area(String name)
static GridTrackPlacement make_line(Optional<int> line_number, Optional<String> name)
{
return GridTrackPlacement(Area { .name = name });
}
static GridTrackPlacement make_line(int value, Optional<String> name)
{
return GridTrackPlacement(Line { .value = value, .name = name });
return GridTrackPlacement(AreaOrLine { .line_number = line_number, .name = name });
}
static GridTrackPlacement make_span(int value)
@ -34,21 +29,25 @@ public:
}
bool is_auto() const { return m_value.has<Auto>(); }
bool is_area() const { return m_value.has<Area>(); }
bool is_line() const { return m_value.has<Line>(); }
bool is_span() const { return m_value.has<Span>(); }
bool is_area_or_line() const { return m_value.has<AreaOrLine>(); }
bool is_auto_positioned() const { return is_auto() || is_span(); }
bool is_positioned() const { return !is_auto_positioned(); }
bool has_line_name() const
bool has_identifier() const
{
return is_line() && m_value.get<Line>().name.has_value();
return is_area_or_line() && m_value.get<AreaOrLine>().name.has_value();
}
String area_name() const { return m_value.get<Area>().name; }
String line_name() const { return m_value.get<Line>().name.value(); }
int line_number() const { return m_value.get<Line>().value; }
bool has_line_number() const
{
return is_area_or_line() && m_value.get<AreaOrLine>().line_number.has_value();
}
String identifier() const { return *m_value.get<AreaOrLine>().name; }
int line_number() const { return *m_value.get<AreaOrLine>().line_number; }
int span() const { return m_value.get<Span>().value; }
String to_string() const;
@ -60,15 +59,10 @@ private:
bool operator==(Auto const&) const = default;
};
struct Area {
String name;
bool operator==(Area const& other) const = default;
};
struct Line {
int value;
struct AreaOrLine {
Optional<int> line_number;
Optional<String> name;
bool operator==(Line const& other) const = default;
bool operator==(AreaOrLine const& other) const = default;
};
struct Span {
@ -78,14 +72,12 @@ private:
GridTrackPlacement()
: m_value(Auto {}) {};
GridTrackPlacement(Area value)
: m_value(value) {};
GridTrackPlacement(Line value)
GridTrackPlacement(AreaOrLine value)
: m_value(value) {};
GridTrackPlacement(Span value)
: m_value(value) {};
Variant<Auto, Area, Line, Span> m_value;
Variant<Auto, AreaOrLine, Span> m_value;
};
}

View file

@ -5371,7 +5371,7 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
if (is_identifier(current_token)) {
auto maybe_string = String::from_utf8(current_token.ident());
if (!maybe_string.is_error())
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_area(maybe_string.value()));
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line({}, maybe_string.value()));
}
return nullptr;
}