summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_cpp.cpp24
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_h.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp6
3 files changed, 29 insertions, 3 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_cpp.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_cpp.cpp
index 88c6e156a9..f31cf387d6 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_cpp.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_cpp.cpp
@@ -60,6 +60,30 @@ char const* string_from_media_feature_id(MediaFeatureID media_feature_id)
VERIFY_NOT_REACHED();
}
+bool media_feature_type_is_range(MediaFeatureID media_feature_id)
+{
+ switch (media_feature_id) {)~~~");
+
+ json.as_object().for_each_member([&](auto& name, auto& value) {
+ VERIFY(value.is_object());
+ auto& feature = value.as_object();
+
+ auto member_generator = generator.fork();
+ member_generator.set("name:titlecase", title_casify(name));
+ VERIFY(feature.has("type"));
+ auto feature_type = feature.get("type");
+ VERIFY(feature_type.is_string());
+ member_generator.set("is_range", feature_type.as_string() == "range" ? "true" : "false");
+ member_generator.append(R"~~~(
+ case MediaFeatureID::@name:titlecase@:
+ return @is_range@;)~~~");
+ });
+
+ generator.append(R"~~~(
+ }
+ VERIFY_NOT_REACHED();
+}
+
}
)~~~");
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_h.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_h.cpp
index b94288345a..72d0f3cce9 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_h.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_MediaFeatureID_h.cpp
@@ -43,6 +43,8 @@ enum class MediaFeatureID {)~~~");
Optional<MediaFeatureID> media_feature_id_from_string(StringView);
char const* string_from_media_feature_id(MediaFeatureID);
+bool media_feature_type_is_range(MediaFeatureID);
+
}
)~~~");
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 26bafb7251..702c3ec5c8 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -896,7 +896,7 @@ Optional<MediaFeature> Parser::parse_media_feature(TokenStream<StyleComponentVal
if (allow_min_max_prefix && (name.starts_with("min-", CaseSensitivity::CaseInsensitive) || name.starts_with("max-", CaseSensitivity::CaseInsensitive))) {
auto adjusted_name = name.substring_view(4);
- if (auto id = media_feature_id_from_string(adjusted_name); id.has_value()) {
+ if (auto id = media_feature_id_from_string(adjusted_name); id.has_value() && media_feature_type_is_range(id.value())) {
tokens.next_token();
return MediaFeatureName {
name.starts_with("min-", CaseSensitivity::CaseInsensitive) ? MediaFeatureName::Type::Min : MediaFeatureName::Type::Max,
@@ -1028,7 +1028,7 @@ Optional<MediaFeature> Parser::parse_media_feature(TokenStream<StyleComponentVal
// `<mf-name> <mf-comparison> <mf-value>`
// NOTE: We have to check for <mf-name> first, since all <mf-name>s will also parse as <mf-value>.
- if (auto maybe_name = parse_mf_name(tokens, false); maybe_name.has_value()) {
+ if (auto maybe_name = parse_mf_name(tokens, false); maybe_name.has_value() && media_feature_type_is_range(maybe_name->id)) {
tokens.skip_whitespace();
if (auto maybe_comparison = parse_comparison(tokens); maybe_comparison.has_value()) {
tokens.skip_whitespace();
@@ -1047,7 +1047,7 @@ Optional<MediaFeature> Parser::parse_media_feature(TokenStream<StyleComponentVal
tokens.skip_whitespace();
if (auto maybe_left_comparison = parse_comparison(tokens); maybe_left_comparison.has_value()) {
tokens.skip_whitespace();
- if (auto maybe_name = parse_mf_name(tokens, false); maybe_name.has_value()) {
+ if (auto maybe_name = parse_mf_name(tokens, false); maybe_name.has_value() && media_feature_type_is_range(maybe_name->id)) {
tokens.skip_whitespace();
if (!tokens.has_next_token())