stylo: Support nonstandard CSS_PROPERTY_NUMBERS_ARE_PIXELS behavior

MozReview-Commit-ID: 4QKKzJ1DVYP
This commit is contained in:
Manish Goregaokar 2017-02-09 17:43:52 -08:00 committed by Manish Goregaokar
parent ff08de8ad1
commit 895fcb222b
2 changed files with 31 additions and 1 deletions

View file

@ -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

View file

@ -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<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