mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 18:24:45 -05:00
LibWeb: Add <general-enclosed> support to Media Queries
This commit is contained in:
parent
b03dac99a5
commit
7d5c626276
Notes:
sideshowbarker
2024-07-18 00:42:01 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/7d5c6262764 Pull-request: https://github.com/SerenityOS/serenity/pull/11060
3 changed files with 19 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue