Bug 1338388 - Part 10: stylo: Support nonstandard CSS_PROPERTY_NUMBERS_ARE_PIXELS behavior; r?heycam
MozReview-Commit-ID: 4QKKzJ1DVYP
--- a/servo/components/style/properties/longhand/inherited_svg.mako.rs
+++ b/servo/components/style/properties/longhand/inherited_svg.mako.rs
@@ -63,17 +63,17 @@
products="gecko",
animatable=False,
boxed=True,
spec="https://www.w3.org/TR/SVG2/painting.html#SpecifyingStrokePaint")}
${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,
boxed=True,
spec="https://www.w3.org/TR/SVG2/painting.html#StrokeWidth")}
${helpers.single_keyword("stroke-linecap", "butt round square",
products="gecko", animatable=False,
@@ -99,19 +99,21 @@
products="gecko",
animatable="False",
space_separated_allowed="True",
spec="https://www.w3.org/TR/SVG2/painting.html#StrokeDashing")}
${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
${helpers.single_keyword("clip-rule", "nonzero evenodd",
products="gecko",
gecko_enum_prefix="StyleFillRule",
gecko_inexhaustive=True,
animatable=False,
--- a/servo/components/style/values/specified/length.rs
+++ b/servo/components/style/values/specified/length.rs
@@ -982,16 +982,44 @@ impl LengthOrPercentage {
}
/// Parse a non-negative length.
#[inline]
pub fn parse_non_negative(input: &mut Parser) -> Result<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<LengthOrPercentage, ()> {
+ 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<LengthOrPercentage, ()> {
+ 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
#[inline]
pub fn take(&mut self) -> Self {
mem::replace(self, LengthOrPercentage::zero())
}
}