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:
Zeke Medley 2020-08-17 20:50:49 +00:00 committed by Emilio Cobos Álvarez
parent cf496e4727
commit 9fd3d9a5e9
2 changed files with 30 additions and 1 deletions

View file

@ -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,