mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Parse unknown media type in media queries
Prevent media query parser from falling back into MediaQuery::create_not_all() for queries with unknown media type. With this change following test works correctly: http://wpt.live/css/css-conditional/at-media-001.html
This commit is contained in:
parent
7f527ddde3
commit
2675b9390b
Notes:
sideshowbarker
2024-07-17 04:28:17 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/2675b9390b Pull-request: https://github.com/SerenityOS/serenity/pull/15898 Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 11 additions and 9 deletions
|
@ -350,6 +350,8 @@ bool MediaQuery::evaluate(HTML::Window const& window)
|
|||
case MediaType::Screen:
|
||||
// FIXME: Disable for printing, when we have printing!
|
||||
return MatchResult::True;
|
||||
case MediaType::Unknown:
|
||||
return MatchResult::False;
|
||||
// Deprecated, must never match:
|
||||
case MediaType::TTY:
|
||||
case MediaType::TV:
|
||||
|
@ -444,7 +446,7 @@ bool is_media_feature_name(StringView name)
|
|||
return false;
|
||||
}
|
||||
|
||||
Optional<MediaQuery::MediaType> media_type_from_string(StringView name)
|
||||
MediaQuery::MediaType media_type_from_string(StringView name)
|
||||
{
|
||||
if (name.equals_ignoring_case("all"sv))
|
||||
return MediaQuery::MediaType::All;
|
||||
|
@ -468,7 +470,7 @@ Optional<MediaQuery::MediaType> media_type_from_string(StringView name)
|
|||
return MediaQuery::MediaType::TTY;
|
||||
if (name.equals_ignoring_case("tv"sv))
|
||||
return MediaQuery::MediaType::TV;
|
||||
return {};
|
||||
return MediaQuery::MediaType::Unknown;
|
||||
}
|
||||
|
||||
StringView to_string(MediaQuery::MediaType media_type)
|
||||
|
@ -496,6 +498,8 @@ StringView to_string(MediaQuery::MediaType media_type)
|
|||
return "tty"sv;
|
||||
case MediaQuery::MediaType::TV:
|
||||
return "tv"sv;
|
||||
case MediaQuery::MediaType::Unknown:
|
||||
return "unknown"sv;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -223,6 +223,7 @@ public:
|
|||
All,
|
||||
Print,
|
||||
Screen,
|
||||
Unknown,
|
||||
|
||||
// Deprecated, must never match:
|
||||
TTY,
|
||||
|
@ -258,7 +259,7 @@ String serialize_a_media_query_list(NonnullRefPtrVector<MediaQuery> const&);
|
|||
|
||||
bool is_media_feature_name(StringView name);
|
||||
|
||||
Optional<MediaQuery::MediaType> media_type_from_string(StringView);
|
||||
MediaQuery::MediaType media_type_from_string(StringView);
|
||||
StringView to_string(MediaQuery::MediaType);
|
||||
|
||||
}
|
||||
|
|
|
@ -1142,13 +1142,10 @@ Optional<MediaQuery::MediaType> Parser::parse_media_type(TokenStream<ComponentVa
|
|||
if (!token.is(Token::Type::Ident))
|
||||
return {};
|
||||
|
||||
auto ident = token.token().ident();
|
||||
if (auto media_type = media_type_from_string(ident); media_type.has_value()) {
|
||||
transaction.commit();
|
||||
return media_type.release_value();
|
||||
}
|
||||
transaction.commit();
|
||||
|
||||
return {};
|
||||
auto ident = token.token().ident();
|
||||
return media_type_from_string(ident);
|
||||
}
|
||||
|
||||
// `<media-in-parens>`, https://www.w3.org/TR/mediaqueries-4/#typedef-media-in-parens
|
||||
|
|
Loading…
Reference in a new issue