From 5ca16a844c4337ca11146f5a26e4370c2d13fe20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 26 Mar 2017 20:09:56 +0200 Subject: [PATCH] style: Be consistent with naming and serialization of "0" with LenghtOrPercentageOrNumber. --- .../properties/longhand/inherited_svg.mako.rs | 4 +++- components/style/values/computed/mod.rs | 2 +- components/style/values/specified/mod.rs | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs index 5c2fee9a427..31d393f13fc 100644 --- a/components/style/properties/longhand/inherited_svg.mako.rs +++ b/components/style/properties/longhand/inherited_svg.mako.rs @@ -92,7 +92,9 @@ ${helpers.predefined_type("stroke-opacity", "Opacity", "1.0", products="gecko", animatable=False, spec="https://www.w3.org/TR/SVG11/painting.html#StrokeOpacityProperty")} -${helpers.predefined_type("stroke-dasharray", "LoPOrNumber", "Either::Second(0.0)", +${helpers.predefined_type("stroke-dasharray", + "LengthOrPercentageOrNumber", + "Either::Second(0.0)", "parse_non_negative", vector="True", products="gecko", diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 9ed8f81ee13..6436c7ffff7 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -400,7 +400,7 @@ impl ToCss for SVGPaint { } /// | | -pub type LoPOrNumber = Either; +pub type LengthOrPercentageOrNumber = Either; #[derive(Clone, PartialEq, Eq, Copy, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 1a7fda7a673..f8786166103 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -980,18 +980,18 @@ impl ToComputedValue for SVGPaintKind { } /// | | -pub type LoPOrNumber = Either; +pub type LengthOrPercentageOrNumber = Either; -impl LoPOrNumber { +impl LengthOrPercentageOrNumber { /// parse a | enforcing that the contents aren't negative pub fn parse_non_negative(_: &ParserContext, input: &mut Parser) -> Result { - if let Ok(lop) = input.try(LengthOrPercentage::parse_non_negative) { - Ok(Either::First(lop)) - } else if let Ok(num) = input.try(Number::parse_non_negative) { - Ok(Either::Second(num)) - } else { - Err(()) + // NB: Parse numbers before Lengths so we are consistent about how to + // recognize and serialize "0". + if let Ok(num) = input.try(Number::parse_non_negative) { + return Ok(Either::Second(num)) } + + LengthOrPercentage::parse_non_negative(input).map(Either::First) } }