summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQuery.cpp8
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQuery.h10
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp6
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.cpp26
4 files changed, 26 insertions, 24 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
index 8fbc3a143d..8d8346bb50 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
+++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
@@ -23,7 +23,7 @@ NonnullRefPtr<MediaQuery> MediaQuery::create_not_all()
String MediaFeatureValue::to_string() const
{
return m_value.visit(
- [](String const& ident) { return serialize_an_identifier(ident); },
+ [](ValueID const& ident) { return String { string_from_value_id(ident) }; },
[](Length const& length) { return length.to_string(); },
[](Ratio const& ratio) { return ratio.to_string(); },
[](Resolution const& resolution) { return resolution.to_string(); },
@@ -33,7 +33,7 @@ String MediaFeatureValue::to_string() const
bool MediaFeatureValue::is_same_type(MediaFeatureValue const& other) const
{
return m_value.visit(
- [&](String const&) { return other.is_ident(); },
+ [&](ValueID const&) { return other.is_ident(); },
[&](Length const&) { return other.is_length(); },
[&](Ratio const&) { return other.is_ratio(); },
[&](Resolution const&) { return other.is_resolution(); },
@@ -96,7 +96,7 @@ bool MediaFeature::evaluate(HTML::Window const& window) const
if (queried_value.is_resolution())
return queried_value.resolution().to_dots_per_pixel() != 0;
if (queried_value.is_ident())
- return queried_value.ident() != "none";
+ return queried_value.ident() != ValueID::None;
return false;
case Type::ExactValue:
@@ -129,7 +129,7 @@ bool MediaFeature::compare(HTML::Window const& window, MediaFeatureValue left, C
if (left.is_ident()) {
if (comparison == Comparison::Equal)
- return left.ident().equals_ignoring_case(right.ident());
+ return left.ident() == right.ident();
return false;
}
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.h b/Userland/Libraries/LibWeb/CSS/MediaQuery.h
index 2045a47d26..44374c6c6d 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQuery.h
+++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.h
@@ -22,7 +22,7 @@ namespace Web::CSS {
// https://www.w3.org/TR/mediaqueries-4/#typedef-mf-value
class MediaFeatureValue {
public:
- explicit MediaFeatureValue(String ident)
+ explicit MediaFeatureValue(ValueID ident)
: m_value(move(ident))
{
}
@@ -49,17 +49,17 @@ public:
String to_string() const;
- bool is_ident() const { return m_value.has<String>(); }
+ bool is_ident() const { return m_value.has<ValueID>(); }
bool is_length() const { return m_value.has<Length>(); }
bool is_number() const { return m_value.has<double>(); }
bool is_ratio() const { return m_value.has<Ratio>(); }
bool is_resolution() const { return m_value.has<Resolution>(); }
bool is_same_type(MediaFeatureValue const& other) const;
- String const& ident() const
+ ValueID const& ident() const
{
VERIFY(is_ident());
- return m_value.get<String>();
+ return m_value.get<ValueID>();
}
Length const& length() const
@@ -87,7 +87,7 @@ public:
}
private:
- Variant<String, Length, Ratio, Resolution, double> m_value;
+ Variant<ValueID, Length, Ratio, Resolution, double> m_value;
};
// https://www.w3.org/TR/mediaqueries-4/#mq-features
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 702c3ec5c8..cdab95a99e 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -1187,8 +1187,10 @@ Optional<MediaFeatureValue> Parser::parse_media_feature_value(TokenStream<StyleC
}
// `<ident>`
- if (first.is(Token::Type::Ident) && !tokens.has_next_token())
- return MediaFeatureValue(first.token().ident());
+ if (first.is(Token::Type::Ident)) {
+ if (auto ident = value_id_from_string(first.token().ident()); ident != ValueID::Invalid)
+ return MediaFeatureValue(ident);
+ }
// `<ratio>`
// Note that a single <number> is a valid <ratio>, but it gets parsed above as a <number>.
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index f712eff310..d016feb793 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -379,15 +379,15 @@ Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID
// MEDIAQUERIES-4 properties - https://www.w3.org/TR/mediaqueries-4/#media-descriptor-table
switch (media_feature) {
case CSS::MediaFeatureID::AnyHover:
- return CSS::MediaFeatureValue("hover");
+ return CSS::MediaFeatureValue(CSS::ValueID::Hover);
case CSS::MediaFeatureID::AnyPointer:
- return CSS::MediaFeatureValue("fine");
+ return CSS::MediaFeatureValue(CSS::ValueID::Fine);
case CSS::MediaFeatureID::AspectRatio:
return CSS::MediaFeatureValue(CSS::Ratio(inner_width(), inner_height()));
case CSS::MediaFeatureID::Color:
return CSS::MediaFeatureValue(8);
case CSS::MediaFeatureID::ColorGamut:
- return CSS::MediaFeatureValue("srgb");
+ return CSS::MediaFeatureValue(CSS::ValueID::Srgb);
case CSS::MediaFeatureID::ColorIndex:
return CSS::MediaFeatureValue(0);
// FIXME: device-aspect-ratio
@@ -398,22 +398,22 @@ Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID
case CSS::MediaFeatureID::Height:
return CSS::MediaFeatureValue(CSS::Length::make_px(inner_height()));
case CSS::MediaFeatureID::Hover:
- return CSS::MediaFeatureValue("hover");
+ return CSS::MediaFeatureValue(CSS::ValueID::Hover);
case CSS::MediaFeatureID::Monochrome:
return CSS::MediaFeatureValue(0);
case CSS::MediaFeatureID::Orientation:
- return CSS::MediaFeatureValue(inner_height() >= inner_width() ? "portrait" : "landscape");
+ return CSS::MediaFeatureValue(inner_height() >= inner_width() ? CSS::ValueID::Portrait : CSS::ValueID::Landscape);
case CSS::MediaFeatureID::OverflowBlock:
- return CSS::MediaFeatureValue("scroll");
+ return CSS::MediaFeatureValue(CSS::ValueID::Scroll);
case CSS::MediaFeatureID::OverflowInline:
- return CSS::MediaFeatureValue("scroll");
+ return CSS::MediaFeatureValue(CSS::ValueID::Scroll);
case CSS::MediaFeatureID::Pointer:
- return CSS::MediaFeatureValue("fine");
+ return CSS::MediaFeatureValue(CSS::ValueID::Fine);
// FIXME: resolution
case CSS::MediaFeatureID::Scan:
- return CSS::MediaFeatureValue("progressive");
+ return CSS::MediaFeatureValue(CSS::ValueID::Progressive);
case CSS::MediaFeatureID::Update:
- return CSS::MediaFeatureValue("fast");
+ return CSS::MediaFeatureValue(CSS::ValueID::Fast);
case CSS::MediaFeatureID::Width:
return CSS::MediaFeatureValue(CSS::Length::make_px(inner_width()));
@@ -422,12 +422,12 @@ Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID
if (auto* page = this->page()) {
switch (page->preferred_color_scheme()) {
case CSS::PreferredColorScheme::Light:
- return CSS::MediaFeatureValue("light");
+ return CSS::MediaFeatureValue(CSS::ValueID::Light);
case CSS::PreferredColorScheme::Dark:
- return CSS::MediaFeatureValue("dark");
+ return CSS::MediaFeatureValue(CSS::ValueID::Dark);
case CSS::PreferredColorScheme::Auto:
default:
- return CSS::MediaFeatureValue(page->palette().is_dark() ? "dark" : "light");
+ return CSS::MediaFeatureValue(page->palette().is_dark() ? CSS::ValueID::Dark : CSS::ValueID::Light);
}
}
return CSS::MediaFeatureValue(CSS::ValueID::Light);