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:
Emilio Cobos Álvarez 2023-08-11 14:14:39 +02:00 committed by Martin Robinson
parent 989f8d89c4
commit 1003d644aa
16 changed files with 205 additions and 79 deletions

View file

@ -6,14 +6,20 @@
//!
//! [container]: https://drafts.csswg.org/css-contain-3/#container-rule
use crate::logical_geometry::{WritingMode, LogicalSize};
use crate::queries::QueryCondition;
use crate::shared_lock::{
DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard,
};
use crate::values::specified::ContainerName;
use crate::values::computed::{Context, CSSPixelLength, Ratio};
use crate::str::CssStringWriter;
use crate::stylesheets::CssRules;
use crate::queries::feature::{AllowsRanges, Evaluator, ParsingRequirements, QueryFeatureDescription};
use crate::queries::values::Orientation;
use app_units::Au;
use cssparser::SourceLocation;
use euclid::default::Size2D;
#[cfg(feature = "gecko")]
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
use servo_arc::Arc;
@ -77,3 +83,79 @@ impl ToCssWithGuard for ContainerRule {
/// TODO: Factor out the media query code to work with containers.
pub type ContainerCondition = QueryCondition;
fn get_container(_context: &Context) -> (Size2D<Au>, WritingMode) {
unimplemented!("TODO: implement container matching");
}
fn eval_width(context: &Context) -> CSSPixelLength {
let (size, _wm) = get_container(context);
CSSPixelLength::new(size.width.to_f32_px())
}
fn eval_height(context: &Context) -> CSSPixelLength {
let (size, _wm) = get_container(context);
CSSPixelLength::new(size.height.to_f32_px())
}
fn eval_inline_size(context: &Context) -> CSSPixelLength {
let (size, wm) = get_container(context);
CSSPixelLength::new(LogicalSize::from_physical(wm, size).inline.to_f32_px())
}
fn eval_block_size(context: &Context) -> CSSPixelLength {
let (size, wm) = get_container(context);
CSSPixelLength::new(LogicalSize::from_physical(wm, size).block.to_f32_px())
}
fn eval_aspect_ratio(context: &Context) -> Ratio {
let (size, _wm) = get_container(context);
Ratio::new(size.width.0 as f32, size.height.0 as f32)
}
fn eval_orientation(context: &Context, value: Option<Orientation>) -> bool {
let (size, _wm) = get_container(context);
Orientation::eval(size, value)
}
/// https://drafts.csswg.org/css-contain-3/#container-features
///
/// TODO: Support style queries, perhaps.
pub static CONTAINER_FEATURES: [QueryFeatureDescription; 6] = [
feature!(
atom!("width"),
AllowsRanges::Yes,
Evaluator::Length(eval_width),
ParsingRequirements::empty(),
),
feature!(
atom!("height"),
AllowsRanges::Yes,
Evaluator::Length(eval_height),
ParsingRequirements::empty(),
),
feature!(
atom!("inline-size"),
AllowsRanges::Yes,
Evaluator::Length(eval_inline_size),
ParsingRequirements::empty(),
),
feature!(
atom!("block-size"),
AllowsRanges::Yes,
Evaluator::Length(eval_block_size),
ParsingRequirements::empty(),
),
feature!(
atom!("aspect-ratio"),
AllowsRanges::Yes,
Evaluator::NumberRatio(eval_aspect_ratio),
ParsingRequirements::empty(),
),
feature!(
atom!("orientation"),
AllowsRanges::No,
keyword_evaluator!(eval_orientation, Orientation),
ParsingRequirements::empty(),
),
];

View file

@ -10,6 +10,7 @@ use crate::font_face::parse_font_face_block;
use crate::media_queries::MediaList;
use crate::parser::{Parse, ParserContext};
use crate::properties::parse_property_declaration_list;
use crate::queries::FeatureType;
use crate::selector_parser::{SelectorImpl, SelectorParser};
use crate::shared_lock::{Locked, SharedRwLock};
use crate::str::starts_with_ignore_ascii_case;
@ -450,7 +451,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
let name = input.try_parse(|input| {
ContainerName::parse(self.context, input)
}).ok().unwrap_or_else(ContainerName::none);
let condition = ContainerCondition::parse(self.context, input)?;
let condition = ContainerCondition::parse(self.context, input, FeatureType::Container)?;
AtRulePrelude::Container(name, condition)
},
"layer" => {

View file

@ -206,7 +206,6 @@ impl Default for ScrollDirection {
}
}
// Avoid name collision in cbindgen with StyleOrientation.
pub use self::ScrollDirection as Orientation;
/// Scroll-timeline offsets. We treat None as an empty vector.