mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Make MozLength / MaxLength a bit more clear and do a bit less work.
This commit is contained in:
parent
2cf0077be1
commit
45ba167030
2 changed files with 21 additions and 6 deletions
|
@ -888,6 +888,7 @@ pub enum MozLength {
|
||||||
|
|
||||||
impl MozLength {
|
impl MozLength {
|
||||||
/// Returns the `auto` value.
|
/// Returns the `auto` value.
|
||||||
|
#[inline]
|
||||||
pub fn auto() -> Self {
|
pub fn auto() -> Self {
|
||||||
MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)
|
MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1131,9 +1131,16 @@ impl MozLength {
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
allow_quirks: AllowQuirks,
|
allow_quirks: AllowQuirks,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
input.try(ExtremumLength::parse).map(MozLength::ExtremumLength)
|
if let Ok(l) = input.try(ExtremumLength::parse) {
|
||||||
.or_else(|_| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks))
|
return Ok(MozLength::ExtremumLength(l));
|
||||||
.map(MozLength::LengthOrPercentageOrAuto))
|
}
|
||||||
|
|
||||||
|
let length = LengthOrPercentageOrAuto::parse_non_negative_quirky(
|
||||||
|
context,
|
||||||
|
input,
|
||||||
|
allow_quirks,
|
||||||
|
)?;
|
||||||
|
Ok(MozLength::LengthOrPercentageOrAuto(length))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1158,8 +1165,15 @@ impl MaxLength {
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
allow_quirks: AllowQuirks,
|
allow_quirks: AllowQuirks,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength)
|
if let Ok(l) = input.try(ExtremumLength::parse) {
|
||||||
.or_else(|_| input.try(|i| LengthOrPercentageOrNone::parse_non_negative_quirky(context, i, allow_quirks))
|
return Ok(MaxLength::ExtremumLength(l));
|
||||||
.map(MaxLength::LengthOrPercentageOrNone))
|
}
|
||||||
|
|
||||||
|
let length = LengthOrPercentageOrNone::parse_non_negative_quirky(
|
||||||
|
context,
|
||||||
|
input,
|
||||||
|
allow_quirks,
|
||||||
|
)?;
|
||||||
|
Ok(MaxLength::LengthOrPercentageOrNone(length))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue