mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Fix container orientation evaluation
Allow keyword evaluators to return unknown. Do you know of a good test to extend here? Otherwise I can add a new one, though I gotta run atm. Differential Revision: https://phabricator.services.mozilla.com/D165630
This commit is contained in:
parent
2389650734
commit
d30400d3ea
4 changed files with 20 additions and 13 deletions
|
@ -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<KeywordDiscriminant>) -> bool,
|
||||
evaluator: fn(&computed::Context, Option<KeywordDiscriminant>) -> 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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<T>(size: euclid::default::Size2D<T>, value: Option<Self>) -> bool
|
||||
where
|
||||
T: PartialOrd,
|
||||
{
|
||||
pub fn eval(size: Size2D<Au>, value: Option<Self>) -> bool {
|
||||
let query_orientation = match value {
|
||||
Some(v) => v,
|
||||
None => return true,
|
||||
|
|
|
@ -296,6 +296,12 @@ pub struct ContainerInfo {
|
|||
wm: WritingMode,
|
||||
}
|
||||
|
||||
impl ContainerInfo {
|
||||
fn size(&self) -> Option<Size2D<Au>> {
|
||||
Some(Size2D::new(self.size.width?, self.size.height?))
|
||||
}
|
||||
}
|
||||
|
||||
fn eval_width(context: &Context) -> Option<CSSPixelLength> {
|
||||
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<Ratio> {
|
|||
))
|
||||
}
|
||||
|
||||
fn eval_orientation(context: &Context, value: Option<Orientation>) -> bool {
|
||||
let info = match context.container_info.as_ref() {
|
||||
Some(info) => info,
|
||||
None => return false,
|
||||
fn eval_orientation(context: &Context, value: Option<Orientation>) -> 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue