diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs index 61665a65520..be6721d0906 100644 --- a/components/style/properties/longhand/inherited_svg.mako.rs +++ b/components/style/properties/longhand/inherited_svg.mako.rs @@ -68,7 +68,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "stroke-width", "LengthOrPercentage", "computed::LengthOrPercentage::one()", - "parse_non_negative", + "parse_numbers_are_pixels_non_negative", products="gecko", animatable=True, needs_context=False, @@ -104,9 +104,11 @@ ${helpers.predefined_type("stroke-dasharray", "LoPOrNumber", "Either::Second(0.0 ${helpers.predefined_type( "stroke-dashoffset", "LengthOrPercentage", "computed::LengthOrPercentage::zero()", + "parse_numbers_are_pixels", products="gecko", animatable=True, boxed=True, + needs_context=False, spec="https://www.w3.org/TR/SVG2/painting.html#StrokeDashing")} // Section 14 - Clipping, Masking and Compositing diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index fb4ac9c0b60..d2e64481a39 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -987,6 +987,34 @@ impl LengthOrPercentage { LengthOrPercentage::parse_internal(input, AllowedNumericType::NonNegative) } + /// Parse a length, treating dimensionless numbers as pixels + /// + /// https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value + pub fn parse_numbers_are_pixels(input: &mut Parser) -> Result { + if let Ok(lop) = input.try(|i| Self::parse_internal(i, AllowedNumericType::All)) { + Ok(lop) + } else { + let num = input.expect_number()?; + Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(Au((AU_PER_PX * num) as i32)))) + } + } + + /// Parse a non-negative length, treating dimensionless numbers as pixels + /// + /// This is nonstandard behavior used by Firefox for SVG + pub fn parse_numbers_are_pixels_non_negative(input: &mut Parser) -> Result { + if let Ok(lop) = input.try(|i| Self::parse_internal(i, AllowedNumericType::NonNegative)) { + Ok(lop) + } else { + let num = input.expect_number()?; + if num >= 0. { + Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(Au((AU_PER_PX * num) as i32)))) + } else { + Err(()) + } + } + } + /// Extract value from ref without a clone, replacing it with a 0 Au /// /// Use when you need to move out of a length array without cloning