diff --git a/components/style/queries/feature.rs b/components/style/queries/feature.rs index 23a12713baa..c2bfee7db41 100644 --- a/components/style/queries/feature.rs +++ b/components/style/queries/feature.rs @@ -8,6 +8,7 @@ use crate::parser::ParserContext; use crate::values::computed::{self, CSSPixelLength, Ratio, Resolution}; use crate::Atom; use cssparser::Parser; +use super::condition::KleeneValue; use std::fmt; use style_traits::ParseError; @@ -54,7 +55,7 @@ pub enum Evaluator { serializer: KeywordSerializer, /// The evaluator itself. This is guaranteed to be called with a /// keyword that `parser` has produced. - evaluator: fn(&computed::Context, Option) -> bool, + evaluator: fn(&computed::Context, Option) -> KleeneValue, }, } @@ -84,12 +85,12 @@ macro_rules! keyword_evaluator { fn __evaluate( context: &$crate::values::computed::Context, value: Option<$crate::queries::feature::KeywordDiscriminant>, - ) -> bool { + ) -> $crate::queries::condition::KleeneValue { // This unwrap is ok because the only discriminants that get // back to us is the ones that `parse` produces. let value: Option<$keyword_type> = value.map(|kw| ::num_traits::cast::FromPrimitive::from_u8(kw).unwrap()); - $actual_evaluator(context, value) + $crate::queries::condition::KleeneValue::from($actual_evaluator(context, value)) } $crate::queries::feature::Evaluator::Enumerated { diff --git a/components/style/queries/feature_expression.rs b/components/style/queries/feature_expression.rs index c38fecc8c1b..b4715c00739 100644 --- a/components/style/queries/feature_expression.rs +++ b/components/style/queries/feature_expression.rs @@ -637,7 +637,7 @@ impl QueryFeatureExpression { .kind .non_ranged_value() .map(|v| *expect!(Enumerated, v)); - evaluator(context, computed) + return evaluator(context, computed) }, Evaluator::BoolInteger(eval) => { let computed = self diff --git a/components/style/queries/values.rs b/components/style/queries/values.rs index 5bd1cede48b..f4934408c4d 100644 --- a/components/style/queries/values.rs +++ b/components/style/queries/values.rs @@ -4,6 +4,9 @@ //! Common feature values between media and container features. +use app_units::Au; +use euclid::default::Size2D; + /// The orientation media / container feature. /// https://drafts.csswg.org/mediaqueries-5/#orientation /// https://drafts.csswg.org/css-contain-3/#orientation @@ -17,10 +20,7 @@ pub enum Orientation { impl Orientation { /// A helper to evaluate a orientation query given a generic size getter. - pub fn eval(size: euclid::default::Size2D, value: Option) -> bool - where - T: PartialOrd, - { + pub fn eval(size: Size2D, value: Option) -> bool { let query_orientation = match value { Some(v) => v, None => return true, diff --git a/components/style/stylesheets/container_rule.rs b/components/style/stylesheets/container_rule.rs index 3734e73c770..f9d488b9b49 100644 --- a/components/style/stylesheets/container_rule.rs +++ b/components/style/stylesheets/container_rule.rs @@ -296,6 +296,12 @@ pub struct ContainerInfo { wm: WritingMode, } +impl ContainerInfo { + fn size(&self) -> Option> { + Some(Size2D::new(self.size.width?, self.size.height?)) + } +} + fn eval_width(context: &Context) -> Option { let info = context.container_info.as_ref()?; Some(CSSPixelLength::new(info.size.width?.to_f32_px())) @@ -332,12 +338,12 @@ fn eval_aspect_ratio(context: &Context) -> Option { )) } -fn eval_orientation(context: &Context, value: Option) -> bool { - let info = match context.container_info.as_ref() { - Some(info) => info, - None => return false, +fn eval_orientation(context: &Context, value: Option) -> KleeneValue { + let size = match context.container_info.as_ref().and_then(|info| info.size()) { + Some(size) => size, + None => return KleeneValue::Unknown, }; - Orientation::eval(info.size, value) + KleeneValue::from(Orientation::eval(size, value)) } /// https://drafts.csswg.org/css-contain-3/#container-features