summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-11-22 17:27:09 +0000
committerAndreas Kling <kling@serenityos.org>2021-11-24 22:57:46 +0100
commite76026372844004bc0d6a5876363093d272d4c7f (patch)
treeba7d724df2ce79f12e76f72d32c36341a10759d1 /Userland/Libraries/LibWeb
parent42176d37fce566cf0df09251e4cd11e091562458 (diff)
downloadserenity-e76026372844004bc0d6a5876363093d272d4c7f.zip
LibWeb: Parse CSS `<general-enclosed>`
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp22
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.h6
2 files changed, 21 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 6248325a0f..d56ad35bd2 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -1111,10 +1111,26 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<StyleComp
return {};
}
-template<typename T>
-Optional<Parser::GeneralEnclosed> Parser::parse_general_enclosed(TokenStream<T>&)
+// https://www.w3.org/TR/mediaqueries-4/#typedef-general-enclosed
+Optional<GeneralEnclosed> Parser::parse_general_enclosed(TokenStream<StyleComponentValueRule>& tokens)
{
- // FIXME: Actually parse this! https://www.w3.org/TR/mediaqueries-5/#typedef-general-enclosed
+ tokens.skip_whitespace();
+ auto start_position = tokens.position();
+
+ auto& first_token = tokens.next_token();
+
+ // `[ <function-token> <any-value> ) ]`
+ if (first_token.is_function())
+ return GeneralEnclosed { first_token.to_string() };
+
+ // `( <ident> <any-value> )`
+ if (first_token.is_block() && first_token.block().is_paren()) {
+ auto& block = first_token.block();
+ if (!block.values().is_empty() && block.values().first().is(Token::Type::Ident))
+ return GeneralEnclosed { first_token.to_string() };
+ }
+
+ tokens.rewind_to_position(start_position);
return {};
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
index 4f028b6053..191d5da917 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
@@ -13,6 +13,7 @@
#include <AK/Result.h>
#include <AK/Vector.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
+#include <LibWeb/CSS/GeneralEnclosed.h>
#include <LibWeb/CSS/MediaQuery.h>
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
@@ -170,10 +171,7 @@ private:
template<typename T>
[[nodiscard]] NonnullRefPtr<StyleFunctionRule> consume_a_function(TokenStream<T>&);
- struct GeneralEnclosed {
- };
- template<typename T>
- [[nodiscard]] Optional<GeneralEnclosed> parse_general_enclosed(TokenStream<T>&);
+ [[nodiscard]] Optional<GeneralEnclosed> parse_general_enclosed(TokenStream<StyleComponentValueRule>&);
[[nodiscard]] RefPtr<CSSRule> convert_to_rule(NonnullRefPtr<StyleRule>);
[[nodiscard]] RefPtr<PropertyOwningCSSStyleDeclaration> convert_to_declaration(NonnullRefPtr<StyleBlockRule>);