mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #16143 - emilio:lops, r=Manishearth
style: Be consistent with naming and serialization of "0" with LenghtOrPercentageOrNumber. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16143) <!-- Reviewable:end -->
This commit is contained in:
commit
c20bbb920c
3 changed files with 12 additions and 10 deletions
|
@ -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",
|
||||
|
|
|
@ -400,7 +400,7 @@ impl ToCss for SVGPaint {
|
|||
}
|
||||
|
||||
/// <length> | <percentage> | <number>
|
||||
pub type LoPOrNumber = Either<LengthOrPercentage, Number>;
|
||||
pub type LengthOrPercentageOrNumber = Either<LengthOrPercentage, Number>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Copy, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
|
|
@ -979,18 +979,18 @@ impl ToComputedValue for SVGPaintKind {
|
|||
}
|
||||
|
||||
/// <length> | <percentage> | <number>
|
||||
pub type LoPOrNumber = Either<LengthOrPercentage, Number>;
|
||||
pub type LengthOrPercentageOrNumber = Either<LengthOrPercentage, Number>;
|
||||
|
||||
impl LoPOrNumber {
|
||||
impl LengthOrPercentageOrNumber {
|
||||
/// parse a <length-percentage> | <number> enforcing that the contents aren't negative
|
||||
pub fn parse_non_negative(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue