From aba0a4bce07c455e38a143793a677d8164e0fafd Mon Sep 17 00:00:00 2001 From: Ziran Sun Date: Wed, 2 Nov 2022 14:15:35 +0000 Subject: [PATCH] style: Only a single name allowed in @container rule Differential Revision: https://phabricator.services.mozilla.com/D158775 --- .../style/stylesheets/container_rule.rs | 6 +-- components/style/values/specified/box.rs | 41 ++++++++++++++----- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/components/style/stylesheets/container_rule.rs b/components/style/stylesheets/container_rule.rs index 751636d1030..381025e5e0f 100644 --- a/components/style/stylesheets/container_rule.rs +++ b/components/style/stylesheets/container_rule.rs @@ -157,12 +157,8 @@ impl ContainerCondition { context: &ParserContext, input: &mut Parser<'a, '_>, ) -> Result> { - use crate::parser::Parse; - - // FIXME: This is a bit ambiguous: - // https://github.com/w3c/csswg-drafts/issues/7203 let name = input - .try_parse(|input| ContainerName::parse(context, input)) + .try_parse(|input| ContainerName::parse_for_query(context, input)) .ok() .unwrap_or_else(ContainerName::none); let condition = QueryCondition::parse(context, input, FeatureType::Container)?; diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 29a1a056566..0bcc5876beb 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -1539,17 +1539,15 @@ impl ContainerName { pub fn is_none(&self) -> bool { self.0.is_empty() } -} -impl Parse for ContainerName { - fn parse<'i, 't>( - _: &ParserContext, - input: &mut Parser<'i, 't>, + fn parse_internal<'i>( + input: &mut Parser<'i, '_>, + for_query: bool, ) -> Result> { let mut idents = vec![]; let location = input.current_source_location(); let first = input.expect_ident()?; - if first.eq_ignore_ascii_case("none") { + if !for_query && first.eq_ignore_ascii_case("none") { return Ok(Self::none()); } const DISALLOWED_CONTAINER_NAMES: &'static [&'static str] = @@ -1559,14 +1557,35 @@ impl Parse for ContainerName { first, DISALLOWED_CONTAINER_NAMES, )?); - while let Ok(name) = input.try_parse(|input| { - let ident = input.expect_ident()?; - CustomIdent::from_ident(location, &ident, DISALLOWED_CONTAINER_NAMES) - }) { - idents.push(name); + if !for_query { + while let Ok(name) = input.try_parse(|input| { + let ident = input.expect_ident()?; + CustomIdent::from_ident(location, &ident, DISALLOWED_CONTAINER_NAMES) + }) { + idents.push(name); + } } Ok(ContainerName(idents.into())) } + + /// https://github.com/w3c/csswg-drafts/issues/7203 + /// Only a single name allowed in @container rule. + /// Disallow none for container-name in @container rule. + pub fn parse_for_query<'i, 't>( + _: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + Self::parse_internal(input, /* for_query = */ true) + } +} + +impl Parse for ContainerName { + fn parse<'i, 't>( + _: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + Self::parse_internal(input, /* for_query = */ false) + } } /// A specified value for the `perspective` property.