summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartinfalisse <martinmotteditfalisse@gmail.com>2022-10-01 13:49:01 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-06 21:16:01 +0200
commit56f50c9cde86325fe98de2969c44c8edfe7d60a3 (patch)
tree01d091baf11119a7fd1e9a38e6d91c7a6258e307
parent9051a565547642207d88fce11bedf73f63ca2dc2 (diff)
downloadserenity-56f50c9cde86325fe98de2969c44c8edfe7d60a3.zip
Base+LibWeb: Deal with zero-positioned grid items
If a grid item has as its position value a 0 then it should be invalidated.
-rw-r--r--Base/res/html/misc/display-grid.html9
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp32
2 files changed, 32 insertions, 9 deletions
diff --git a/Base/res/html/misc/display-grid.html b/Base/res/html/misc/display-grid.html
index 4b50444c51..eb7a33af17 100644
--- a/Base/res/html/misc/display-grid.html
+++ b/Base/res/html/misc/display-grid.html
@@ -48,6 +48,15 @@
<div class="grid-item" style="grid-column: span 2 / 1;">3</div>
</div>
+<!-- 0 positioned grid items -->
+<p>If you can see this message then the test passed.</p>
+<div class="grid-container">
+ <div class="grid-item" style="grid-row-end: 0;">1</div>
+ <div class="grid-item" style="grid-row: 0 / 0;">2</div>
+ <div class="grid-item" style="grid-column: 0 / 1;">3</div>
+ <div class="grid-item" style="grid-row: 1 / 0;">4</div>
+</div>
+
<!-- Different column sizes -->
<p>Should render a 2x2 grid with columns 50px and 50%</p>
<div
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 6885994c70..9ec03bdc88 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -5456,7 +5456,10 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
// If the <integer> is omitted, it defaults to 1.
if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv))
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(1, true));
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer())
+ // https://drafts.csswg.org/css-grid/#grid-placement-int
+ // [ <integer [−∞,−1]> | <integer [1,∞]> ] && <custom-ident>?
+ // An <integer> value of zero makes the declaration invalid.
+ if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() != 0)
return GridTrackPlacementStyleValue::create(CSS::GridTrackPlacement(static_cast<int>(current_token.number_value())));
return {};
}
@@ -5468,7 +5471,10 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
current_token = tokens.next_token().token();
}
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && !tokens.has_next_token()) {
+ // https://drafts.csswg.org/css-grid/#grid-placement-int
+ // [ <integer [−∞,−1]> | <integer [1,∞]> ] && <custom-ident>?
+ // An <integer> value of zero makes the declaration invalid.
+ if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() != 0 && !tokens.has_next_token()) {
// https://drafts.csswg.org/css-grid/#grid-placement-span-int
// Negative integers or zero are invalid.
if (is_span && static_cast<int>(current_token.number_value()) < 1)
@@ -5490,25 +5496,33 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<Com
// If the <integer> is omitted, it defaults to 1.
if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv))
return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(1, true));
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer())
+ // https://drafts.csswg.org/css-grid/#grid-placement-int
+ // [ <integer [−∞,−1]> | <integer [1,∞]> ] && <custom-ident>?
+ // An <integer> value of zero makes the declaration invalid.
+ if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() != 0)
return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(current_token.number_value()));
return {};
}
- auto calculate_grid_track_placement = [](auto& current_token, auto& tokens) -> CSS::GridTrackPlacement {
+ auto calculate_grid_track_placement = [](auto& current_token, auto& tokens) -> Optional<CSS::GridTrackPlacement> {
auto is_span = false;
if (current_token.is(Token::Type::Ident) && current_token.ident().equals_ignoring_case("span"sv)) {
is_span = true;
tokens.skip_whitespace();
current_token = tokens.next_token().token();
}
- if (current_token.is(Token::Type::Number) && current_token.number().is_integer()) {
+ if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() != 0) {
// https://drafts.csswg.org/css-grid/#grid-placement-span-int
// Negative integers or zero are invalid.
if (is_span && static_cast<int>(current_token.number_value()) < 1)
return CSS::GridTrackPlacement(1, true);
return CSS::GridTrackPlacement(static_cast<int>(current_token.number_value()), is_span);
}
+ // https://drafts.csswg.org/css-grid/#grid-placement-int
+ // [ <integer [−∞,−1]> | <integer [1,∞]> ] && <custom-ident>?
+ // An <integer> value of zero makes the declaration invalid.
+ if (current_token.is(Token::Type::Number) && current_token.number().is_integer() && current_token.number_value() == 0)
+ return {};
// https://drafts.csswg.org/css-grid/#grid-placement-span-int
// If the <integer> is omitted, it defaults to 1.
if (is_span && current_token.is(Token::Type::Delim) && current_token.delim() == "/"sv)
@@ -5517,8 +5531,8 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<Com
};
auto first_grid_track_placement = calculate_grid_track_placement(current_token, tokens);
- if (!tokens.has_next_token())
- return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(first_grid_track_placement));
+ if (!tokens.has_next_token() && first_grid_track_placement.has_value())
+ return GridTrackPlacementShorthandStyleValue::create(CSS::GridTrackPlacement(first_grid_track_placement.value()));
tokens.skip_whitespace();
current_token = tokens.next_token().token();
@@ -5526,8 +5540,8 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<Com
current_token = tokens.next_token().token();
auto second_grid_track_placement = calculate_grid_track_placement(current_token, tokens);
- if (!tokens.has_next_token())
- return GridTrackPlacementShorthandStyleValue::create(GridTrackPlacementStyleValue::create(first_grid_track_placement), GridTrackPlacementStyleValue::create(second_grid_track_placement));
+ if (!tokens.has_next_token() && first_grid_track_placement.has_value() && second_grid_track_placement.has_value())
+ return GridTrackPlacementShorthandStyleValue::create(GridTrackPlacementStyleValue::create(first_grid_track_placement.value()), GridTrackPlacementStyleValue::create(second_grid_track_placement.value()));
return {};
}