style/servo/
media_features.rs1use crate::derives::*;
8use crate::queries::feature::{AllowsRanges, Evaluator, FeatureFlags, QueryFeatureDescription};
9use crate::queries::values::PrefersColorScheme;
10use crate::values::computed::{CSSPixelLength, Context, Resolution};
11use std::fmt::Debug;
12
13fn eval_width(context: &Context) -> CSSPixelLength {
15 CSSPixelLength::new(context.device().au_viewport_size().width.to_f32_px())
16}
17
18#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
19#[repr(u8)]
20enum Scan {
21 Progressive,
22 Interlace,
23}
24
25fn eval_scan(_: &Context, _: Option<Scan>) -> bool {
27 false
30}
31
32fn eval_resolution(context: &Context) -> Resolution {
34 Resolution::from_dppx(context.device().device_pixel_ratio().0)
35}
36
37fn eval_device_pixel_ratio(context: &Context) -> f32 {
39 eval_resolution(context).dppx()
40}
41
42fn eval_prefers_color_scheme(context: &Context, query_value: Option<PrefersColorScheme>) -> bool {
43 match query_value {
44 Some(v) => context.device().color_scheme() == v,
45 None => true,
46 }
47}
48
49pub static MEDIA_FEATURES: [QueryFeatureDescription; 6] = [
51 feature!(
52 atom!("width"),
53 AllowsRanges::Yes,
54 Evaluator::Length(eval_width),
55 FeatureFlags::empty(),
56 ),
57 feature!(
58 atom!("scan"),
59 AllowsRanges::No,
60 keyword_evaluator!(eval_scan, Scan),
61 FeatureFlags::empty(),
62 ),
63 feature!(
64 atom!("resolution"),
65 AllowsRanges::Yes,
66 Evaluator::Resolution(eval_resolution),
67 FeatureFlags::empty(),
68 ),
69 feature!(
70 atom!("device-pixel-ratio"),
71 AllowsRanges::Yes,
72 Evaluator::Float(eval_device_pixel_ratio),
73 FeatureFlags::WEBKIT_PREFIX,
74 ),
75 feature!(
76 atom!("-moz-device-pixel-ratio"),
77 AllowsRanges::Yes,
78 Evaluator::Float(eval_device_pixel_ratio),
79 FeatureFlags::empty(),
80 ),
81 feature!(
82 atom!("prefers-color-scheme"),
83 AllowsRanges::No,
84 keyword_evaluator!(eval_prefers_color_scheme, PrefersColorScheme),
85 FeatureFlags::empty(),
86 ),
87];