diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-11-24 16:11:04 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-24 22:57:46 +0100 |
commit | dea4f830379891f30641213e6c71223bce7e2e4f (patch) | |
tree | aaaa101a9243264126623fa818ba105c7404e2d9 /Userland | |
parent | 7d5c62627647ceb3cd42f76ab43a1a21bfe0a049 (diff) | |
download | serenity-dea4f830379891f30641213e6c71223bce7e2e4f.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Supports.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Supports.h | 3 |
4 files changed, 4 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 1d511ce0eb..f684647903 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -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() }; } } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 191d5da917..7229a6bf40 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -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&); diff --git a/Userland/Libraries/LibWeb/CSS/Supports.cpp b/Userland/Libraries/LibWeb/CSS/Supports.cpp index 3ba725be03..ed375d7a11 100644 --- a/Userland/Libraries/LibWeb/CSS/Supports.cpp +++ b/Userland/Libraries/LibWeb/CSS/Supports.cpp @@ -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; diff --git a/Userland/Libraries/LibWeb/CSS/Supports.h b/Userland/Libraries/LibWeb/CSS/Supports.h index b0d1f8a5ca..bf7d671313 100644 --- a/Userland/Libraries/LibWeb/CSS/Supports.h +++ b/Userland/Libraries/LibWeb/CSS/Supports.h @@ -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; }; |