style/queries/
values.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Common feature values between media and container features.
6
7use app_units::Au;
8use euclid::default::Size2D;
9
10/// The orientation media / container feature.
11/// https://drafts.csswg.org/mediaqueries-5/#orientation
12/// https://drafts.csswg.org/css-contain-3/#orientation
13#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
14#[repr(u8)]
15#[allow(missing_docs)]
16pub enum Orientation {
17    Portrait,
18    Landscape,
19}
20
21impl Orientation {
22    /// A helper to evaluate a orientation query given a generic size getter.
23    pub fn eval(size: Size2D<Au>, value: Option<Self>) -> bool {
24        let query_orientation = match value {
25            Some(v) => v,
26            None => return true,
27        };
28
29        // Per spec, square viewports should be 'portrait'
30        let is_landscape = size.width > size.height;
31        match query_orientation {
32            Self::Landscape => is_landscape,
33            Self::Portrait => !is_landscape,
34        }
35    }
36}
37
38/// Values for the prefers-color-scheme media feature.
39#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
40#[repr(u8)]
41#[allow(missing_docs)]
42pub enum PrefersColorScheme {
43    Light,
44    Dark,
45}