Skip to content

Commit 971c0d0

Browse files
committed
LibWeb/CSS: Handle whitespace properly for scrollbar properties
Imported a WPT test that regressed without these changes.
1 parent 60a46b8 commit 971c0d0

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5145,35 +5145,39 @@ RefPtr<StyleValue const> Parser::parse_scrollbar_color_value(TokenStream<Compone
51455145
RefPtr<StyleValue const> Parser::parse_scrollbar_gutter_value(TokenStream<ComponentValue>& tokens)
51465146
{
51475147
// auto | stable && both-edges?
5148+
tokens.discard_whitespace();
51485149
if (!tokens.has_next_token())
51495150
return nullptr;
51505151

51515152
auto transaction = tokens.begin_transaction();
51525153

51535154
auto parse_stable = [&]() -> Optional<bool> {
5154-
auto transaction = tokens.begin_transaction();
5155+
auto stable_transaction = tokens.begin_transaction();
5156+
tokens.discard_whitespace();
51555157
auto const& token = tokens.consume_a_token();
51565158
if (!token.is(Token::Type::Ident))
51575159
return {};
51585160
auto const& ident = token.token().ident();
51595161
if (ident.equals_ignoring_ascii_case("auto"sv)) {
5160-
transaction.commit();
5162+
stable_transaction.commit();
51615163
return false;
5162-
} else if (ident.equals_ignoring_ascii_case("stable"sv)) {
5163-
transaction.commit();
5164+
}
5165+
if (ident.equals_ignoring_ascii_case("stable"sv)) {
5166+
stable_transaction.commit();
51645167
return true;
51655168
}
51665169
return {};
51675170
};
51685171

51695172
auto parse_both_edges = [&]() -> Optional<bool> {
5170-
auto transaction = tokens.begin_transaction();
5173+
auto edges_transaction = tokens.begin_transaction();
5174+
tokens.discard_whitespace();
51715175
auto const& token = tokens.consume_a_token();
51725176
if (!token.is(Token::Type::Ident))
51735177
return {};
51745178
auto const& ident = token.token().ident();
51755179
if (ident.equals_ignoring_ascii_case("both-edges"sv)) {
5176-
transaction.commit();
5180+
edges_transaction.commit();
51775181
return true;
51785182
}
51795183
return {};
@@ -5190,6 +5194,7 @@ RefPtr<StyleValue const> Parser::parse_scrollbar_gutter_value(TokenStream<Compon
51905194
return nullptr;
51915195
}
51925196

5197+
tokens.discard_whitespace();
51935198
if (tokens.has_next_token())
51945199
return nullptr;
51955200

Libraries/LibWeb/CSS/Properties.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,22 +3445,19 @@
34453445
"affects-stacking-context": true
34463446
},
34473447
"scrollbar-color": {
3448-
"strip-whitespace": true,
34493448
"affects-layout": false,
34503449
"animation-type": "by-computed-value",
34513450
"inherited": "yes",
34523451
"initial": "auto"
34533452
},
34543453
"scrollbar-gutter": {
3455-
"strip-whitespace": true,
34563454
"affects-layout": false,
34573455
"animation-type": "discrete",
34583456
"__comment": "This property should affect layout per-spec, but ladybird always uses overlay scrollbars so it doesn't in practice.",
34593457
"inherited": false,
34603458
"initial": "auto"
34613459
},
34623460
"scrollbar-width": {
3463-
"strip-whitespace": true,
34643461
"affects-layout": false,
34653462
"animation-type": "by-computed-value",
34663463
"inherited": false,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Harness status: OK
2+
3+
Found 4 tests
4+
5+
4 Pass
6+
Pass e.style['scrollbar-gutter'] = "auto" should set the property value
7+
Pass e.style['scrollbar-gutter'] = "stable" should set the property value
8+
Pass e.style['scrollbar-gutter'] = "stable both-edges" should set the property value
9+
Pass e.style['scrollbar-gutter'] = "both-edges stable" should set the property value
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>CSS Overflow: parsing valid scrollbar-gutter declarations</title>
4+
<link rel="author" title="Felipe Erias Morandeira" href="mailto:felipeerias@gmail.com"/>
5+
<link rel="help" href="https://www.w3.org/TR/css-overflow-4/#scollbar-gutter-property"/>
6+
<meta name="assert" content="Parsing valid scrollbar-gutter declarations">
7+
<script src="../../../resources/testharness.js"></script>
8+
<script src="../../../resources/testharnessreport.js"></script>
9+
<script src="../../../css/support/parsing-testcommon.js"></script>
10+
11+
<script>
12+
13+
test_valid_value("scrollbar-gutter", "auto");
14+
test_valid_value("scrollbar-gutter", "stable");
15+
test_valid_value("scrollbar-gutter", "stable both-edges");
16+
17+
test_valid_value("scrollbar-gutter", "both-edges stable", "stable both-edges");
18+
19+
</script>

0 commit comments

Comments
 (0)