diff --git a/components/style/gecko/media_features.rs b/components/style/gecko/media_features.rs index af57be431f9..c873ac92b87 100644 --- a/components/style/gecko/media_features.rs +++ b/components/style/gecko/media_features.rs @@ -283,6 +283,18 @@ pub enum PrefersColorScheme { Dark, } +/// Values for the dynamic-range and video-dynamic-range media features. +/// https://drafts.csswg.org/mediaqueries-5/#dynamic-range +/// This implements PartialOrd so that lower values will correctly match +/// higher capabilities. +#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, PartialOrd, ToCss)] +#[repr(u8)] +#[allow(missing_docs)] +pub enum DynamicRange { + Standard, + High, +} + /// https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion fn eval_prefers_reduced_motion(device: &Device, query_value: Option) -> bool { let prefers_reduced = @@ -420,6 +432,25 @@ fn eval_content_prefers_color_scheme( do_eval_prefers_color_scheme(device, /* use_content = */ true, query_value) } +/// https://drafts.csswg.org/mediaqueries-5/#dynamic-range +fn eval_dynamic_range(device: &Device, query_value: Option) -> bool { + let dynamic_range = + unsafe { bindings::Gecko_MediaFeatures_DynamicRange(device.document()) }; + match query_value { + Some(v) => dynamic_range >= v, + None => false, + } +} +/// https://drafts.csswg.org/mediaqueries-5/#video-dynamic-range +fn eval_video_dynamic_range(device: &Device, query_value: Option) -> bool { + let dynamic_range = + unsafe { bindings::Gecko_MediaFeatures_VideoDynamicRange(device.document()) }; + match query_value { + Some(v) => dynamic_range >= v, + None => false, + } +} + bitflags! { /// https://drafts.csswg.org/mediaqueries-4/#mf-interaction struct PointerCapabilities: u8 { @@ -682,7 +713,7 @@ macro_rules! bool_pref_feature { /// to support new types in these entries and (2) ensuring that either /// nsPresContext::MediaFeatureValuesChanged is called when the value that /// would be returned by the evaluator function could change. -pub static MEDIA_FEATURES: [MediaFeatureDescription; 58] = [ +pub static MEDIA_FEATURES: [MediaFeatureDescription; 60] = [ feature!( atom!("width"), AllowsRanges::Yes, @@ -835,6 +866,18 @@ pub static MEDIA_FEATURES: [MediaFeatureDescription; 58] = [ keyword_evaluator!(eval_prefers_color_scheme, PrefersColorScheme), ParsingRequirements::empty(), ), + feature!( + atom!("dynamic-range"), + AllowsRanges::No, + keyword_evaluator!(eval_dynamic_range, DynamicRange), + ParsingRequirements::empty(), + ), + feature!( + atom!("video-dynamic-range"), + AllowsRanges::No, + keyword_evaluator!(eval_video_dynamic_range, DynamicRange), + ParsingRequirements::empty(), + ), // Evaluates to the preferred color scheme for content. Only useful in // chrome context, where the chrome color-scheme and the content // color-scheme might differ.