mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Improve parsing for the CSS contain property
This makes us actually respect the grammar and nets us a couple extra WPT passes in the parsing section.
This commit is contained in:
parent
1c075d6039
commit
7c36a82129
|
|
@ -345,6 +345,7 @@ private:
|
|||
};
|
||||
RefPtr<PositionStyleValue const> parse_position_value(TokenStream<ComponentValue>&, PositionParsingMode = PositionParsingMode::Normal);
|
||||
RefPtr<CSSStyleValue const> parse_filter_value_list_value(TokenStream<ComponentValue>&);
|
||||
RefPtr<CSSStyleValue const> parse_contain_value(TokenStream<ComponentValue>&);
|
||||
RefPtr<StringStyleValue const> parse_opentype_tag_value(TokenStream<ComponentValue>&);
|
||||
RefPtr<FontSourceStyleValue const> parse_font_source_value(TokenStream<ComponentValue>&);
|
||||
|
||||
|
|
|
|||
|
|
@ -700,6 +700,10 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue const>> Parser::parse_css_value
|
|||
if (auto parsed_value = parse_scale_value(tokens); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
return ParseError::SyntaxError;
|
||||
case PropertyID::Contain:
|
||||
if (auto parsed_value = parse_contain_value(tokens); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
return ParseError::SyntaxError;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -4609,4 +4613,75 @@ RefPtr<CSSStyleValue const> Parser::parse_filter_value_list_value(TokenStream<Co
|
|||
return FilterValueListStyleValue::create(move(filter_value_list));
|
||||
}
|
||||
|
||||
RefPtr<CSSStyleValue const> Parser::parse_contain_value(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
// none | strict | content | [ [size | inline-size] || layout || style || paint ]
|
||||
auto transaction = tokens.begin_transaction();
|
||||
tokens.discard_whitespace();
|
||||
|
||||
// none
|
||||
if (auto none = parse_all_as_single_keyword_value(tokens, Keyword::None)) {
|
||||
transaction.commit();
|
||||
return none;
|
||||
}
|
||||
|
||||
// strict
|
||||
if (auto strict = parse_all_as_single_keyword_value(tokens, Keyword::Strict)) {
|
||||
transaction.commit();
|
||||
return strict;
|
||||
}
|
||||
|
||||
// content
|
||||
if (auto content = parse_all_as_single_keyword_value(tokens, Keyword::Content)) {
|
||||
transaction.commit();
|
||||
return content;
|
||||
}
|
||||
|
||||
// [ [size | inline-size] || layout || style || paint ]
|
||||
if (!tokens.has_next_token())
|
||||
return {};
|
||||
|
||||
bool has_size = false;
|
||||
bool has_layout = false;
|
||||
bool has_style = false;
|
||||
bool has_paint = false;
|
||||
|
||||
StyleValueVector containments;
|
||||
while (tokens.has_next_token()) {
|
||||
tokens.discard_whitespace();
|
||||
auto keyword = parse_keyword_value(tokens);
|
||||
if (!keyword)
|
||||
return {};
|
||||
switch (keyword->to_keyword()) {
|
||||
case Keyword::Size:
|
||||
case Keyword::InlineSize:
|
||||
if (has_size)
|
||||
return {};
|
||||
has_size = true;
|
||||
break;
|
||||
case Keyword::Layout:
|
||||
if (has_layout)
|
||||
return {};
|
||||
has_layout = true;
|
||||
break;
|
||||
case Keyword::Style:
|
||||
if (has_style)
|
||||
return {};
|
||||
has_style = true;
|
||||
break;
|
||||
case Keyword::Paint:
|
||||
if (has_paint)
|
||||
return {};
|
||||
has_paint = true;
|
||||
break;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
containments.append(*keyword);
|
||||
}
|
||||
transaction.commit();
|
||||
|
||||
return StyleValueList::create(move(containments), StyleValueList::Separator::Space);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1110,7 +1110,6 @@
|
|||
]
|
||||
},
|
||||
"contain": {
|
||||
"__comment": "FIXME: Some values of contain need to be mutually exclusive. The grammar this should adhere to is 'none | strict | content | [ [size | inline-size] || layout || style || paint ]'.",
|
||||
"affects-stacking-context": true,
|
||||
"animation-type": "none",
|
||||
"inherited": false,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ Harness status: OK
|
|||
|
||||
Found 15 tests
|
||||
|
||||
8 Pass
|
||||
7 Fail
|
||||
13 Pass
|
||||
2 Fail
|
||||
Pass Property contain value 'none'
|
||||
Pass Property contain value 'strict'
|
||||
Pass Property contain value 'content'
|
||||
|
|
@ -11,11 +11,11 @@ Pass Property contain value 'size'
|
|||
Pass Property contain value 'layout'
|
||||
Pass Property contain value 'style'
|
||||
Pass Property contain value 'paint'
|
||||
Fail Property contain value 'size layout'
|
||||
Fail Property contain value 'style paint'
|
||||
Pass Property contain value 'size layout'
|
||||
Pass Property contain value 'style paint'
|
||||
Fail Property contain value 'style layout paint'
|
||||
Fail Property contain value 'size style layout paint'
|
||||
Fail Property contain value 'size layout paint'
|
||||
Fail Property contain value 'layout paint'
|
||||
Pass Property contain value 'size layout paint'
|
||||
Pass Property contain value 'layout paint'
|
||||
Pass Property contain value 'inline-size'
|
||||
Fail Property contain value 'inline-size layout style paint'
|
||||
Pass Property contain value 'inline-size layout style paint'
|
||||
|
|
@ -2,8 +2,8 @@ Harness status: OK
|
|||
|
||||
Found 13 tests
|
||||
|
||||
8 Pass
|
||||
5 Fail
|
||||
9 Pass
|
||||
4 Fail
|
||||
Pass e.style['contain'] = "none" should set the property value
|
||||
Pass e.style['contain'] = "strict" should set the property value
|
||||
Pass e.style['contain'] = "content" should set the property value
|
||||
|
|
@ -13,7 +13,7 @@ Pass e.style['contain'] = "style" should set the property value
|
|||
Pass e.style['contain'] = "paint" should set the property value
|
||||
Fail e.style['contain'] = "layout size" should set the property value
|
||||
Fail e.style['contain'] = "paint style" should set the property value
|
||||
Fail e.style['contain'] = "layout style paint" should set the property value
|
||||
Pass e.style['contain'] = "layout style paint" should set the property value
|
||||
Fail e.style['contain'] = "layout paint style size" should set the property value
|
||||
Pass e.style['contain'] = "inline-size" should set the property value
|
||||
Fail e.style['contain'] = "layout inline-size" should set the property value
|
||||
Loading…
Reference in New Issue
Block a user