LibWeb/CSS: Handle whitespace properly for scrollbar properties

Imported a WPT test that regressed without these changes.
This commit is contained in:
Sam Atkins 2025-10-31 10:23:28 +00:00
parent 60a46b86e4
commit 971c0d0126
Notes: github-actions[bot] 2025-11-03 11:26:40 +00:00
4 changed files with 39 additions and 9 deletions

View file

@ -5145,35 +5145,39 @@ RefPtr<StyleValue const> Parser::parse_scrollbar_color_value(TokenStream<Compone
RefPtr<StyleValue const> Parser::parse_scrollbar_gutter_value(TokenStream<ComponentValue>& tokens) RefPtr<StyleValue const> Parser::parse_scrollbar_gutter_value(TokenStream<ComponentValue>& tokens)
{ {
// auto | stable && both-edges? // auto | stable && both-edges?
tokens.discard_whitespace();
if (!tokens.has_next_token()) if (!tokens.has_next_token())
return nullptr; return nullptr;
auto transaction = tokens.begin_transaction(); auto transaction = tokens.begin_transaction();
auto parse_stable = [&]() -> Optional<bool> { auto parse_stable = [&]() -> Optional<bool> {
auto transaction = tokens.begin_transaction(); auto stable_transaction = tokens.begin_transaction();
tokens.discard_whitespace();
auto const& token = tokens.consume_a_token(); auto const& token = tokens.consume_a_token();
if (!token.is(Token::Type::Ident)) if (!token.is(Token::Type::Ident))
return {}; return {};
auto const& ident = token.token().ident(); auto const& ident = token.token().ident();
if (ident.equals_ignoring_ascii_case("auto"sv)) { if (ident.equals_ignoring_ascii_case("auto"sv)) {
transaction.commit(); stable_transaction.commit();
return false; return false;
} else if (ident.equals_ignoring_ascii_case("stable"sv)) { }
transaction.commit(); if (ident.equals_ignoring_ascii_case("stable"sv)) {
stable_transaction.commit();
return true; return true;
} }
return {}; return {};
}; };
auto parse_both_edges = [&]() -> Optional<bool> { auto parse_both_edges = [&]() -> Optional<bool> {
auto transaction = tokens.begin_transaction(); auto edges_transaction = tokens.begin_transaction();
tokens.discard_whitespace();
auto const& token = tokens.consume_a_token(); auto const& token = tokens.consume_a_token();
if (!token.is(Token::Type::Ident)) if (!token.is(Token::Type::Ident))
return {}; return {};
auto const& ident = token.token().ident(); auto const& ident = token.token().ident();
if (ident.equals_ignoring_ascii_case("both-edges"sv)) { if (ident.equals_ignoring_ascii_case("both-edges"sv)) {
transaction.commit(); edges_transaction.commit();
return true; return true;
} }
return {}; return {};
@ -5190,6 +5194,7 @@ RefPtr<StyleValue const> Parser::parse_scrollbar_gutter_value(TokenStream<Compon
return nullptr; return nullptr;
} }
tokens.discard_whitespace();
if (tokens.has_next_token()) if (tokens.has_next_token())
return nullptr; return nullptr;

View file

@ -3445,14 +3445,12 @@
"affects-stacking-context": true "affects-stacking-context": true
}, },
"scrollbar-color": { "scrollbar-color": {
"strip-whitespace": true,
"affects-layout": false, "affects-layout": false,
"animation-type": "by-computed-value", "animation-type": "by-computed-value",
"inherited": "yes", "inherited": "yes",
"initial": "auto" "initial": "auto"
}, },
"scrollbar-gutter": { "scrollbar-gutter": {
"strip-whitespace": true,
"affects-layout": false, "affects-layout": false,
"animation-type": "discrete", "animation-type": "discrete",
"__comment": "This property should affect layout per-spec, but ladybird always uses overlay scrollbars so it doesn't in practice.", "__comment": "This property should affect layout per-spec, but ladybird always uses overlay scrollbars so it doesn't in practice.",
@ -3460,7 +3458,6 @@
"initial": "auto" "initial": "auto"
}, },
"scrollbar-width": { "scrollbar-width": {
"strip-whitespace": true,
"affects-layout": false, "affects-layout": false,
"animation-type": "by-computed-value", "animation-type": "by-computed-value",
"inherited": false, "inherited": false,

View file

@ -0,0 +1,9 @@
Harness status: OK
Found 4 tests
4 Pass
Pass e.style['scrollbar-gutter'] = "auto" should set the property value
Pass e.style['scrollbar-gutter'] = "stable" should set the property value
Pass e.style['scrollbar-gutter'] = "stable both-edges" should set the property value
Pass e.style['scrollbar-gutter'] = "both-edges stable" should set the property value

View file

@ -0,0 +1,19 @@
<!doctype html>
<meta charset="utf-8">
<title>CSS Overflow: parsing valid scrollbar-gutter declarations</title>
<link rel="author" title="Felipe Erias Morandeira" href="mailto:felipeerias@gmail.com"/>
<link rel="help" href="https://www.w3.org/TR/css-overflow-4/#scollbar-gutter-property"/>
<meta name="assert" content="Parsing valid scrollbar-gutter declarations">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../css/support/parsing-testcommon.js"></script>
<script>
test_valid_value("scrollbar-gutter", "auto");
test_valid_value("scrollbar-gutter", "stable");
test_valid_value("scrollbar-gutter", "stable both-edges");
test_valid_value("scrollbar-gutter", "both-edges stable", "stable both-edges");
</script>