style: Add parsing for <general-enclosed> in queries conditions

See https://drafts.csswg.org/mediaqueries-5/#typedef-general-enclosed

Differential Revision: https://phabricator.services.mozilla.com/D158662
This commit is contained in:
Ziran Sun 2022-11-30 10:19:07 +00:00 committed by Martin Robinson
parent a298c296e4
commit bee44a5259
7 changed files with 164 additions and 30 deletions

View file

@ -17,6 +17,7 @@ use cssparser::{Parser, Token};
use std::cmp::{Ordering, PartialOrd};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use crate::error_reporting::ContextualParseError;
/// Whether we're parsing a media or container query feature.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)]
@ -502,11 +503,13 @@ impl QueryFeatureExpression {
}
/// Parse a feature expression where we've already consumed the parenthesis.
/// For unknown features, we keeps the warning even though they might be parsed "correctly" because of <general-enclosed>
pub fn parse_in_parenthesis_block<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
) -> Result<Self, ParseError<'i>> {
let start_position = input.position();
let (feature_index, range) =
match input.try_parse(|input| Self::parse_feature_name(context, input, feature_type)) {
Ok(v) => v,
@ -514,6 +517,12 @@ impl QueryFeatureExpression {
if let Ok(expr) = Self::parse_multi_range_syntax(context, input, feature_type) {
return Ok(expr);
}
let location = e.location;
let error = ContextualParseError::UnsupportedRule(
input.slice_from(start_position),
e.clone(),
);
context.log_css_error(location, error);
return Err(e);
},
};