mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Implement prefers-reduced-transparency media query
Implemented the prefers-reduced-transparency media query for all platforms. Windows and Mac have specific settings which are used, others (Android and Linux/GTK) have it enabled if prefers-reduced-motion is also enabled as there is no dedicated setting to check. Locked behind new pref `layout.css.prefers-reduced-transparency.enabled`, off by default always for now. Also added new WPT tests (none previously). Demo video: https://goose.icu/firefox_prt.mp4 Test page: https://goose.icu/prefers-reduced-transparency Differential Revision: https://phabricator.services.mozilla.com/D172424
This commit is contained in:
parent
9509f84bc0
commit
0e5eca1f00
2 changed files with 39 additions and 1 deletions
|
@ -188,6 +188,13 @@ enum PrefersReducedMotion {
|
||||||
Reduce,
|
Reduce,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
|
||||||
|
#[repr(u8)]
|
||||||
|
enum PrefersReducedTransparency {
|
||||||
|
NoPreference,
|
||||||
|
Reduce,
|
||||||
|
}
|
||||||
|
|
||||||
/// Values for the prefers-color-scheme media feature.
|
/// Values for the prefers-color-scheme media feature.
|
||||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
@ -227,6 +234,24 @@ fn eval_prefers_reduced_motion(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-transparency
|
||||||
|
fn eval_prefers_reduced_transparency(
|
||||||
|
context: &Context,
|
||||||
|
query_value: Option<PrefersReducedTransparency>,
|
||||||
|
) -> bool {
|
||||||
|
let prefers_reduced =
|
||||||
|
unsafe { bindings::Gecko_MediaFeatures_PrefersReducedTransparency(context.device().document()) };
|
||||||
|
let query_value = match query_value {
|
||||||
|
Some(v) => v,
|
||||||
|
None => return prefers_reduced,
|
||||||
|
};
|
||||||
|
|
||||||
|
match query_value {
|
||||||
|
PrefersReducedTransparency::NoPreference => !prefers_reduced,
|
||||||
|
PrefersReducedTransparency::Reduce => prefers_reduced,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Possible values for prefers-contrast media query.
|
/// Possible values for prefers-contrast media query.
|
||||||
/// https://drafts.csswg.org/mediaqueries-5/#prefers-contrast
|
/// https://drafts.csswg.org/mediaqueries-5/#prefers-contrast
|
||||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
|
||||||
|
@ -618,7 +643,7 @@ macro_rules! bool_pref_feature {
|
||||||
/// to support new types in these entries and (2) ensuring that either
|
/// to support new types in these entries and (2) ensuring that either
|
||||||
/// nsPresContext::MediaFeatureValuesChanged is called when the value that
|
/// nsPresContext::MediaFeatureValuesChanged is called when the value that
|
||||||
/// would be returned by the evaluator function could change.
|
/// would be returned by the evaluator function could change.
|
||||||
pub static MEDIA_FEATURES: [QueryFeatureDescription; 63] = [
|
pub static MEDIA_FEATURES: [QueryFeatureDescription; 64] = [
|
||||||
feature!(
|
feature!(
|
||||||
atom!("width"),
|
atom!("width"),
|
||||||
AllowsRanges::Yes,
|
AllowsRanges::Yes,
|
||||||
|
@ -742,6 +767,12 @@ pub static MEDIA_FEATURES: [QueryFeatureDescription; 63] = [
|
||||||
keyword_evaluator!(eval_prefers_reduced_motion, PrefersReducedMotion),
|
keyword_evaluator!(eval_prefers_reduced_motion, PrefersReducedMotion),
|
||||||
FeatureFlags::empty(),
|
FeatureFlags::empty(),
|
||||||
),
|
),
|
||||||
|
feature!(
|
||||||
|
atom!("prefers-reduced-transparency"),
|
||||||
|
AllowsRanges::No,
|
||||||
|
keyword_evaluator!(eval_prefers_reduced_transparency, PrefersReducedTransparency),
|
||||||
|
FeatureFlags::empty(),
|
||||||
|
),
|
||||||
feature!(
|
feature!(
|
||||||
atom!("prefers-contrast"),
|
atom!("prefers-contrast"),
|
||||||
AllowsRanges::No,
|
AllowsRanges::No,
|
||||||
|
|
|
@ -322,6 +322,13 @@ fn disabled_by_pref(feature: &Atom, context: &ParserContext) -> bool {
|
||||||
return !context.in_ua_or_chrome_sheet() &&
|
return !context.in_ua_or_chrome_sheet() &&
|
||||||
!static_prefs::pref!("layout.css.prefers-contrast.enabled");
|
!static_prefs::pref!("layout.css.prefers-contrast.enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prefers-reduced-transparency is always enabled in the ua and chrome. On
|
||||||
|
// the web it is hidden behind a preference (see Bug 1822176).
|
||||||
|
if *feature == atom!("prefers-reduced-transparency") {
|
||||||
|
return !context.in_ua_or_chrome_sheet() &&
|
||||||
|
!static_prefs::pref!("layout.css.prefers-reduced-transparency.enabled");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue