diff --git a/components/style/gecko/media_features.rs b/components/style/gecko/media_features.rs index c80ace2015b..66722af6c72 100644 --- a/components/style/gecko/media_features.rs +++ b/components/style/gecko/media_features.rs @@ -396,16 +396,31 @@ fn eval_overflow_inline(device: &Device, query_value: Option) -> } } -/// https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme -fn eval_prefers_color_scheme(device: &Device, query_value: Option) -> bool { +fn do_eval_prefers_color_scheme( + device: &Device, + use_content: bool, + query_value: Option, +) -> bool { let prefers_color_scheme = - unsafe { bindings::Gecko_MediaFeatures_PrefersColorScheme(device.document()) }; + unsafe { bindings::Gecko_MediaFeatures_PrefersColorScheme(device.document(), use_content) }; match query_value { Some(v) => prefers_color_scheme == v, None => true, } } +/// https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme +fn eval_prefers_color_scheme(device: &Device, query_value: Option) -> bool { + do_eval_prefers_color_scheme(device, /* use_content = */ false, query_value) +} + +fn eval_content_prefers_color_scheme( + device: &Device, + query_value: Option, +) -> bool { + do_eval_prefers_color_scheme(device, /* use_content = */ true, query_value) +} + bitflags! { /// https://drafts.csswg.org/mediaqueries-4/#mf-interaction struct PointerCapabilities: u8 { @@ -652,7 +667,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; 57] = [ +pub static MEDIA_FEATURES: [MediaFeatureDescription; 58] = [ feature!( atom!("width"), AllowsRanges::Yes, @@ -805,6 +820,15 @@ pub static MEDIA_FEATURES: [MediaFeatureDescription; 57] = [ keyword_evaluator!(eval_prefers_color_scheme, PrefersColorScheme), 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. + feature!( + atom!("-moz-content-prefers-color-scheme"), + AllowsRanges::No, + keyword_evaluator!(eval_content_prefers_color_scheme, PrefersColorScheme), + ParsingRequirements::CHROME_AND_UA_ONLY, + ), feature!( atom!("pointer"), AllowsRanges::No,