From 7c4402ba92f7df8e422e4cef9e5b87439e93317b Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 16 Mar 2022 17:24:14 +0000 Subject: [PATCH] LibWeb: Evaluate `no-preference` media-features as false As noted, this is not 100% to the spec, but effectively the same - `no-preference` is only allowed to appear in features that evaluate it as false in a boolean context. This is also the only identifier besides `none` that evaluates to false. If other identifiers gain this property in the future, we can make it more robust then. --- Userland/Libraries/LibWeb/CSS/MediaQuery.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp index e358ece64c..38331ec12e 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp @@ -95,8 +95,14 @@ bool MediaFeature::evaluate(HTML::Window const& window) const return !queried_value.ratio().is_degenerate(); if (queried_value.is_resolution()) return queried_value.resolution().to_dots_per_pixel() != 0; - if (queried_value.is_ident()) - return queried_value.ident() != ValueID::None; + if (queried_value.is_ident()) { + // NOTE: It is not technically correct to always treat `no-preference` as false, but every + // media-feature that accepts it as a value treats it as false, so good enough. :^) + // If other features gain this property for other identifiers in the future, we can + // add more robust handling for them then. + return queried_value.ident() != ValueID::None + && queried_value.ident() != ValueID::NoPreference; + } return false; case Type::ExactValue: