LibWeb: Use a string instead of an internal Parser class in Supports

Now that we can serialize CSS tokens, we can just hold a string and then
re-parse it when the Supports is evaluated. This feels a little weird,
but it only happens once so it's not going to slow it down much, and it
keep the API cleaner.
This commit is contained in:
Sam Atkins 2021-11-24 16:11:04 +00:00 committed by Andreas Kling
parent 7d5c626276
commit dea4f83037
Notes: sideshowbarker 2024-07-18 00:41:57 +09:00
4 changed files with 4 additions and 7 deletions

View file

@ -1113,7 +1113,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<StyleComp
TokenStream block_tokens { first_token.block().values() };
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
return Supports::Feature {
.declaration = declaration.release_value()
.declaration = declaration->to_string()
};
}
}

View file

@ -113,9 +113,6 @@ public:
RefPtr<StyleValue> parse_as_css_value(PropertyID);
// FIXME: This is a hack, while CSS::Supports is using a StyleDeclarationRule
[[nodiscard]] Optional<StyleProperty> convert_to_style_property(StyleDeclarationRule const&);
private:
enum class ParsingResult {
Done,
@ -175,6 +172,7 @@ private:
[[nodiscard]] RefPtr<CSSRule> convert_to_rule(NonnullRefPtr<StyleRule>);
[[nodiscard]] RefPtr<PropertyOwningCSSStyleDeclaration> convert_to_declaration(NonnullRefPtr<StyleBlockRule>);
[[nodiscard]] Optional<StyleProperty> convert_to_style_property(StyleDeclarationRule const&);
Optional<Color> parse_color(StyleComponentValueRule const&);
Optional<Length> parse_length(StyleComponentValueRule const&);

View file

@ -48,7 +48,7 @@ MatchResult Supports::InParens::evaluate() const
MatchResult Supports::Feature::evaluate() const
{
auto style_property = Parser({}, "").convert_to_style_property(declaration);
auto style_property = Parser({}, declaration).parse_as_declaration();
if (style_property.has_value())
return MatchResult::True;
return MatchResult::False;

View file

@ -21,8 +21,7 @@ class Supports final : public RefCounted<Supports> {
public:
struct Feature {
// FIXME: Using this internal parser class is a bit of a hack.
StyleDeclarationRule declaration;
String declaration;
MatchResult evaluate() const;
};