mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Support forced colors media feature.
Enabled behind layout.css.forced-colors.enabled pending finalization of the spec: <https://drafts.csswg.org/mediaqueries-5/#forced-colors> Differential Revision: https://phabricator.services.mozilla.com/D87147
This commit is contained in:
parent
cf496e4727
commit
9fd3d9a5e9
2 changed files with 30 additions and 1 deletions
|
@ -353,6 +353,26 @@ fn eval_prefers_contrast(device: &Device, query_value: Option<PrefersContrast>)
|
|||
}
|
||||
}
|
||||
|
||||
/// Possible values for the forced-colors media query.
|
||||
/// https://drafts.csswg.org/mediaqueries-5/#forced-colors
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, PartialEq, Parse, ToCss)]
|
||||
#[repr(u8)]
|
||||
pub enum ForcedColors {
|
||||
/// Page colors are not being forced.
|
||||
None,
|
||||
/// Page colors are being forced.
|
||||
Active,
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/mediaqueries-5/#forced-colors
|
||||
fn eval_forced_colors(device: &Device, query_value: Option<ForcedColors>) -> bool {
|
||||
let forced = !device.use_document_colors();
|
||||
match query_value {
|
||||
Some(query_value) => forced == (query_value == ForcedColors::Active),
|
||||
None => forced,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
|
||||
#[repr(u8)]
|
||||
enum OverflowBlock {
|
||||
|
@ -593,7 +613,7 @@ macro_rules! system_metric_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; 54] = [
|
||||
pub static MEDIA_FEATURES: [MediaFeatureDescription; 55] = [
|
||||
feature!(
|
||||
atom!("width"),
|
||||
AllowsRanges::Yes,
|
||||
|
@ -722,6 +742,12 @@ pub static MEDIA_FEATURES: [MediaFeatureDescription; 54] = [
|
|||
// is done.
|
||||
ParsingRequirements::empty(),
|
||||
),
|
||||
feature!(
|
||||
atom!("forced-colors"),
|
||||
AllowsRanges::No,
|
||||
keyword_evaluator!(eval_forced_colors, ForcedColors),
|
||||
ParsingRequirements::empty(),
|
||||
),
|
||||
feature!(
|
||||
atom!("overflow-block"),
|
||||
AllowsRanges::No,
|
||||
|
|
|
@ -224,6 +224,9 @@ fn disabled_by_pref(feature: &Atom, context: &ParserContext) -> bool {
|
|||
if *feature == atom!("-moz-touch-enabled") {
|
||||
return !static_prefs::pref!("layout.css.moz-touch-enabled.enabled");
|
||||
}
|
||||
if *feature == atom!("forced-colors") {
|
||||
return !static_prefs::pref!("layout.css.forced-colors.enabled");
|
||||
}
|
||||
// prefers-contrast is always enabled in the ua and chrome. On
|
||||
// the web it is hidden behind a preference.
|
||||
if *feature == atom!("prefers-contrast") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue