style: Support media queries for dynamic-range and video-dynamic-range

This is a stub that only matches "standard" for all platforms.

Differential Revision: https://phabricator.services.mozilla.com/D141053
This commit is contained in:
Brad Werth 2023-06-18 13:19:57 +02:00 committed by Martin Robinson
parent 2b123e20ec
commit 6edcfe9558

View file

@ -283,6 +283,18 @@ pub enum PrefersColorScheme {
Dark, Dark,
} }
/// Values for the dynamic-range and video-dynamic-range media features.
/// https://drafts.csswg.org/mediaqueries-5/#dynamic-range
/// This implements PartialOrd so that lower values will correctly match
/// higher capabilities.
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, PartialOrd, ToCss)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum DynamicRange {
Standard,
High,
}
/// https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion /// https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion
fn eval_prefers_reduced_motion(device: &Device, query_value: Option<PrefersReducedMotion>) -> bool { fn eval_prefers_reduced_motion(device: &Device, query_value: Option<PrefersReducedMotion>) -> bool {
let prefers_reduced = let prefers_reduced =
@ -420,6 +432,25 @@ fn eval_content_prefers_color_scheme(
do_eval_prefers_color_scheme(device, /* use_content = */ true, query_value) do_eval_prefers_color_scheme(device, /* use_content = */ true, query_value)
} }
/// https://drafts.csswg.org/mediaqueries-5/#dynamic-range
fn eval_dynamic_range(device: &Device, query_value: Option<DynamicRange>) -> bool {
let dynamic_range =
unsafe { bindings::Gecko_MediaFeatures_DynamicRange(device.document()) };
match query_value {
Some(v) => dynamic_range >= v,
None => false,
}
}
/// https://drafts.csswg.org/mediaqueries-5/#video-dynamic-range
fn eval_video_dynamic_range(device: &Device, query_value: Option<DynamicRange>) -> bool {
let dynamic_range =
unsafe { bindings::Gecko_MediaFeatures_VideoDynamicRange(device.document()) };
match query_value {
Some(v) => dynamic_range >= v,
None => false,
}
}
bitflags! { bitflags! {
/// https://drafts.csswg.org/mediaqueries-4/#mf-interaction /// https://drafts.csswg.org/mediaqueries-4/#mf-interaction
struct PointerCapabilities: u8 { struct PointerCapabilities: u8 {
@ -682,7 +713,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: [MediaFeatureDescription; 58] = [ pub static MEDIA_FEATURES: [MediaFeatureDescription; 60] = [
feature!( feature!(
atom!("width"), atom!("width"),
AllowsRanges::Yes, AllowsRanges::Yes,
@ -835,6 +866,18 @@ pub static MEDIA_FEATURES: [MediaFeatureDescription; 58] = [
keyword_evaluator!(eval_prefers_color_scheme, PrefersColorScheme), keyword_evaluator!(eval_prefers_color_scheme, PrefersColorScheme),
ParsingRequirements::empty(), ParsingRequirements::empty(),
), ),
feature!(
atom!("dynamic-range"),
AllowsRanges::No,
keyword_evaluator!(eval_dynamic_range, DynamicRange),
ParsingRequirements::empty(),
),
feature!(
atom!("video-dynamic-range"),
AllowsRanges::No,
keyword_evaluator!(eval_video_dynamic_range, DynamicRange),
ParsingRequirements::empty(),
),
// Evaluates to the preferred color scheme for content. Only useful in // Evaluates to the preferred color scheme for content. Only useful in
// chrome context, where the chrome color-scheme and the content // chrome context, where the chrome color-scheme and the content
// color-scheme might differ. // color-scheme might differ.