style: More container queries plumbing

Provide container information in computed::Context and use it to resolve
the container queries.

This still fails a lot of tests because we are not ensuring that layout
is up-to-date when we style the container descendants, but that's
expected.

Differential Revision: https://phabricator.services.mozilla.com/D146478
This commit is contained in:
Emilio Cobos Álvarez 2023-08-14 23:29:47 +02:00 committed by Martin Robinson
parent 5c2fac087f
commit bbf10a43b8
18 changed files with 420 additions and 143 deletions

View file

@ -7,7 +7,7 @@
//! https://drafts.csswg.org/mediaqueries-4/#typedef-media-condition
//! https://drafts.csswg.org/css-contain-3/#typedef-container-condition
use super::{QueryFeatureExpression, FeatureType};
use super::{QueryFeatureExpression, FeatureType, FeatureFlags};
use crate::parser::ParserContext;
use crate::values::computed;
use cssparser::{Parser, Token};
@ -85,6 +85,35 @@ impl QueryCondition {
Self::parse_internal(context, input, feature_type, AllowOr::Yes)
}
fn visit<F>(&self, visitor: &mut F)
where
F: FnMut(&Self),
{
visitor(self);
match *self {
Self::Feature(..) => {},
Self::Not(ref cond) => cond.visit(visitor),
Self::Operation(ref conds, _op) => {
for cond in conds.iter() {
cond.visit(visitor);
}
},
Self::InParens(ref cond) => cond.visit(visitor),
}
}
/// Returns the union of all flags in the expression. This is useful for
/// container queries.
pub fn cumulative_flags(&self) -> FeatureFlags {
let mut result = FeatureFlags::empty();
self.visit(&mut |condition| {
if let Self::Feature(ref f) = condition {
result.insert(f.feature_flags())
}
});
result
}
/// Parse a single condition, disallowing `or` expressions.
///
/// To be used from the legacy query syntax.