mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
style: Add support for parsing container-query-specific features
There are some mediaqueries-5 features that we still don't support and explain the remaining failures in at-container-{parsing,serialization}. Differential Revision: https://phabricator.services.mozilla.com/D144446
This commit is contained in:
parent
989f8d89c4
commit
1003d644aa
16 changed files with 205 additions and 79 deletions
36
components/style/queries/values.rs
Normal file
36
components/style/queries/values.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Common feature values between media and container features.
|
||||
|
||||
/// The orientation media / container feature.
|
||||
/// https://drafts.csswg.org/mediaqueries-5/#orientation
|
||||
/// https://drafts.csswg.org/css-contain-3/#orientation
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
|
||||
#[repr(u8)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum Orientation {
|
||||
Portrait,
|
||||
Landscape,
|
||||
}
|
||||
|
||||
impl Orientation {
|
||||
/// A helper to evaluate a orientation query given a generic size getter.
|
||||
pub fn eval<T>(size: euclid::default::Size2D<T>, value: Option<Self>) -> bool
|
||||
where
|
||||
T: PartialOrd,
|
||||
{
|
||||
let query_orientation = match value {
|
||||
Some(v) => v,
|
||||
None => return true,
|
||||
};
|
||||
|
||||
// Per spec, square viewports should be 'portrait'
|
||||
let is_landscape = size.width > size.height;
|
||||
match query_orientation {
|
||||
Self::Landscape => is_landscape,
|
||||
Self::Portrait => !is_landscape,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue