diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-11-24 15:11:59 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-24 22:57:46 +0100 |
commit | 7d5c62627647ceb3cd42f76ab43a1a21bfe0a049 (patch) | |
tree | 9a8147528ac3cd92bbef51fbb1f96147a07df04b /Userland/Libraries/LibWeb | |
parent | b03dac99a53483b04304e9a70ff849708091aec7 (diff) | |
download | serenity-7d5c62627647ceb3cd42f76ab43a1a21bfe0a049.zip |
LibWeb: Add <general-enclosed> support to Media Queries
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/MediaQuery.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/MediaQuery.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 13 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp index a22e93a11d..225af000d9 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp @@ -106,6 +106,9 @@ String MediaQuery::MediaCondition::to_string() const case Type::Or: builder.join(" or ", conditions); break; + case Type::GeneralEnclosed: + builder.append(general_enclosed->to_string()); + break; } builder.append(')'); return builder.to_string(); @@ -122,6 +125,8 @@ MatchResult MediaQuery::MediaCondition::evaluate(DOM::Window const& window) cons return evaluate_and(conditions, [&](auto& child) { return child.evaluate(window); }); case Type::Or: return evaluate_or(conditions, [&](auto& child) { return child.evaluate(window); }); + case Type::GeneralEnclosed: + return general_enclosed->evaluate(); } VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.h b/Userland/Libraries/LibWeb/CSS/MediaQuery.h index 279f65a906..eb2b7598f8 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.h +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.h @@ -65,11 +65,13 @@ public: And, Or, Not, + GeneralEnclosed, }; Type type; MediaFeature feature; NonnullOwnPtrVector<MediaCondition> conditions; + Optional<GeneralEnclosed> general_enclosed; MatchResult evaluate(DOM::Window const&) const; String to_string() const; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 008caf2783..1d511ce0eb 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -752,6 +752,7 @@ NonnullRefPtr<MediaQuery> Parser::parse_media_query(TokenStream<StyleComponentVa OwnPtr<MediaQuery::MediaCondition> Parser::consume_media_condition(TokenStream<StyleComponentValueRule>& tokens) { // "not <media-condition>" + // ( `<media-not>` in the grammar ) auto position = tokens.position(); auto& first_token = tokens.peek_token(); if (first_token.is(Token::Type::Ident) && first_token.token().ident().equals_ignoring_case("not"sv)) { @@ -770,6 +771,7 @@ OwnPtr<MediaQuery::MediaCondition> Parser::consume_media_condition(TokenStream<S } // "<media-condition> ([and | or] <media-condition>)*" + // ( `<media-in-parens> [ <media-and>* | <media-or>* ]` in the grammar ) NonnullOwnPtrVector<MediaQuery::MediaCondition> child_conditions; Optional<MediaQuery::MediaCondition::Type> condition_type {}; auto as_condition_type = [](auto& token) -> Optional<MediaQuery::MediaCondition::Type> { @@ -836,7 +838,7 @@ OwnPtr<MediaQuery::MediaCondition> Parser::consume_media_condition(TokenStream<S return adopt_own(*condition); } - // "<media-feature>" + // `<media-feature>` tokens.rewind_to_position(position); if (auto feature = consume_media_feature(tokens); feature.has_value()) { auto condition = new MediaQuery::MediaCondition; @@ -845,6 +847,15 @@ OwnPtr<MediaQuery::MediaCondition> Parser::consume_media_condition(TokenStream<S return adopt_own(*condition); } + // `<general-enclosed>` + tokens.rewind_to_position(position); + if (auto general_enclosed = parse_general_enclosed(tokens); general_enclosed.has_value()) { + auto condition = new MediaQuery::MediaCondition; + condition->type = MediaQuery::MediaCondition::Type::GeneralEnclosed; + condition->general_enclosed = general_enclosed.release_value(); + return adopt_own(*condition); + } + tokens.rewind_to_position(position); return {}; } |