mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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
This commit is contained in:
parent
df6b6ba675
commit
0307500c3d
1 changed files with 28 additions and 4 deletions
|
@ -396,16 +396,31 @@ fn eval_overflow_inline(device: &Device, query_value: Option<OverflowInline>) ->
|
|||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme
|
||||
fn eval_prefers_color_scheme(device: &Device, query_value: Option<PrefersColorScheme>) -> bool {
|
||||
fn do_eval_prefers_color_scheme(
|
||||
device: &Device,
|
||||
use_content: bool,
|
||||
query_value: Option<PrefersColorScheme>,
|
||||
) -> 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<PrefersColorScheme>) -> bool {
|
||||
do_eval_prefers_color_scheme(device, /* use_content = */ false, query_value)
|
||||
}
|
||||
|
||||
fn eval_content_prefers_color_scheme(
|
||||
device: &Device,
|
||||
query_value: Option<PrefersColorScheme>,
|
||||
) -> 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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue