values.rs (1400B)
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 7 use crate::derives::*; 8 use app_units::Au; 9 use euclid::default::Size2D; 10 11 /// The orientation media / container feature. 12 /// https://drafts.csswg.org/mediaqueries-5/#orientation 13 /// https://drafts.csswg.org/css-contain-3/#orientation 14 #[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)] 15 #[repr(u8)] 16 #[allow(missing_docs)] 17 pub enum Orientation { 18 Portrait, 19 Landscape, 20 } 21 22 impl Orientation { 23 /// A helper to evaluate a orientation query given a generic size getter. 24 pub fn eval(size: Size2D<Au>, value: Option<Self>) -> bool { 25 let query_orientation = match value { 26 Some(v) => v, 27 None => return true, 28 }; 29 30 // Per spec, square viewports should be 'portrait' 31 let is_landscape = size.width > size.height; 32 match query_orientation { 33 Self::Landscape => is_landscape, 34 Self::Portrait => !is_landscape, 35 } 36 } 37 } 38 39 /// Values for the prefers-color-scheme media feature. 40 #[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)] 41 #[repr(u8)] 42 #[allow(missing_docs)] 43 pub enum PrefersColorScheme { 44 Light, 45 Dark, 46 }