From 0307500c3d1bd9bf7042a78df31188d45c8c1768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 6 Jun 2023 23:37:35 +0200 Subject: [PATCH] style: Choose tabpanel background based on content preferred color-scheme If the theme is dark but user prefers light pages, the background of the tabpanel should arguably be light, since it can be seen across some navigations. Expose a -moz-content-prefers-color-scheme media query to chrome pages so that our UI can correctly query it (and remove the unused -moz-proton atom while at it). Differential Revision: https://phabricator.services.mozilla.com/D136437 --- components/style/gecko/media_features.rs | 32 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) 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,