diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index b906cfa808c..481ea4e9222 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -4795,10 +4795,10 @@ fn static_assert() { use values::Either; match v { - Either::Second(non_negative_number) => { + Either::First(non_negative_number) => { self.gecko.mTabSize.set_value(CoordDataValue::Factor(non_negative_number.0)); } - Either::First(non_negative_length) => { + Either::Second(non_negative_length) => { self.gecko.mTabSize.set(non_negative_length); } } @@ -4809,8 +4809,8 @@ fn static_assert() { use values::Either; match self.gecko.mTabSize.as_value() { - CoordDataValue::Coord(coord) => Either::First(Au(coord).into()), - CoordDataValue::Factor(number) => Either::Second(From::from(number)), + CoordDataValue::Coord(coord) => Either::Second(Au(coord).into()), + CoordDataValue::Factor(number) => Either::First(From::from(number)), _ => unreachable!(), } } diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 6bc9bf8e621..daf2abd0abe 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -511,7 +511,6 @@ ${helpers.single_keyword("resize", ${helpers.predefined_type("perspective", "LengthOrNone", "Either::Second(None_)", - "parse_non_negative_length", gecko_ffi_name="mChildPerspective", spec="https://drafts.csswg.org/css-transforms/#perspective", extra_prefixes="moz webkit", diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 3594cab8463..8bebe90c876 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -488,7 +488,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "-moz-tab-size", "length::NonNegativeLengthOrNumber", - "::values::Either::Second(From::from(8.0))", + "::values::Either::First(From::from(8.0))", products="gecko", animation_value_type="::values::computed::length::NonNegativeLengthOrNumber", spec="https://drafts.csswg.org/css-text-3/#tab-size-property")} diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index b482c8aeb17..002e863f757 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -902,7 +902,7 @@ pub type NonNegativeLengthOrAuto = Either; pub type NonNegativeLengthOrNormal = Either; /// Either a computed NonNegativeLength or a NonNegativeNumber value. -pub type NonNegativeLengthOrNumber = Either; +pub type NonNegativeLengthOrNumber = Either; /// A type for possible values for min- and max- flavors of width, height, /// block-size, and inline-size. diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 0db823acd45..aa2ac34e61e 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -640,21 +640,19 @@ impl Length { } } -impl Either { - /// Parse a non-negative length - #[inline] - pub fn parse_non_negative_length<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - if let Ok(v) = input.try(|input| T::parse(context, input)) { - return Ok(Either::Second(v)); - } - Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No).map(Either::First) - } -} - /// A wrapper of Length, whose value must be >= 0. pub type NonNegativeLength = NonNegative; +impl Parse for NonNegativeLength { + #[inline] + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + Ok(NonNegative(Length::parse_non_negative(context, input)?)) + } +} + impl From for NonNegativeLength { #[inline] fn from(len: NoCalcLength) -> Self { @@ -669,17 +667,6 @@ impl From for NonNegativeLength { } } -impl Parse for Either { - #[inline] - fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - if let Ok(v) = input.try(|input| T::parse(context, input)) { - return Ok(Either::Second(v)); - } - Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No) - .map(NonNegative::).map(Either::First) - } -} - impl NonNegativeLength { /// Returns a `zero` length. #[inline] @@ -701,7 +688,10 @@ pub type NonNegativeLengthOrNormal = Either; pub type NonNegativeLengthOrAuto = Either; /// Either a NonNegativeLength or a NonNegativeNumber value. -pub type NonNegativeLengthOrNumber = Either; +/// +/// The order is important, because `0` must be parsed as the number `0` and not +/// the length `0px`. +pub type NonNegativeLengthOrNumber = Either; /// A length or a percentage value. #[allow(missing_docs)]