diff --git a/components/style/properties/shorthands/background.mako.rs b/components/style/properties/shorthands/background.mako.rs index af98342bfe692..7986201e423a2 100644 --- a/components/style/properties/shorthands/background.mako.rs +++ b/components/style/properties/shorthands/background.mako.rs @@ -15,7 +15,7 @@ use crate::properties::longhands::background_clip; use crate::properties::longhands::background_clip::single_value::computed_value::T as Clip; use crate::properties::longhands::background_origin::single_value::computed_value::T as Origin; - use crate::values::specified::{Color, Position, PositionComponent}; + use crate::values::specified::{AllowQuirks, Color, Position, PositionComponent}; use crate::parser::Parse; // FIXME(emilio): Should be the same type! @@ -64,7 +64,9 @@ } } if position.is_none() { - if let Ok(value) = input.try(|input| Position::parse(context, input)) { + if let Ok(value) = input.try(|input| { + Position::parse_three_value_quirky(context, input, AllowQuirks::No) + }) { position = Some(value); // Parse background size, if applicable. @@ -211,7 +213,7 @@ let mut any = false; input.parse_comma_separated(|input| { - let value = Position::parse_quirky(context, input, AllowQuirks::Yes)?; + let value = Position::parse_three_value_quirky(context, input, AllowQuirks::Yes)?; position_x.push(value.horizontal); position_y.push(value.vertical); any = true; diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index 85516790c4f7e..e4ab6536a6532 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -94,13 +94,17 @@ impl Parse for Position { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - Self::parse_quirky(context, input, AllowQuirks::No) + let position = Self::parse_three_value_quirky(context, input, AllowQuirks::No)?; + if position.is_three_value_syntax() { + return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); + } + Ok(position) } } impl Position { - /// Parses a ``, with quirks. - pub fn parse_quirky<'i, 't>( + /// Parses a ``, with quirks. + pub fn parse_three_value_quirky<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, @@ -183,6 +187,12 @@ impl Position { pub fn center() -> Self { Self::new(PositionComponent::Center, PositionComponent::Center) } + + /// Returns true if this uses a 3 value syntax. + #[inline] + fn is_three_value_syntax(&self) -> bool { + self.horizontal.component_count() != self.vertical.component_count() + } } impl ToCss for Position { @@ -252,6 +262,17 @@ impl PositionComponent { pub fn zero() -> Self { PositionComponent::Length(LengthPercentage::Percentage(Percentage::zero())) } + + /// Returns the count of this component. + fn component_count(&self) -> usize { + match *self { + PositionComponent::Length(..) | + PositionComponent::Center => 1, + PositionComponent::Side(_, ref lp) => { + if lp.is_some() { 2 } else { 1 } + } + } + } } impl ToComputedValue for PositionComponent {