mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Streamline parsing of NonNegativeLengthOrNumber a bit
This commit is contained in:
parent
f097dfad59
commit
4a98fa70bf
5 changed files with 20 additions and 31 deletions
|
@ -4795,10 +4795,10 @@ fn static_assert() {
|
|||
use values::Either;
|
||||
|
||||
match v {
|
||||
Either::Second(non_negative_number) => {
|
||||
Either::First(non_negative_number) => {
|
||||
self.gecko.mTabSize.set_value(CoordDataValue::Factor(non_negative_number.0));
|
||||
}
|
||||
Either::First(non_negative_length) => {
|
||||
Either::Second(non_negative_length) => {
|
||||
self.gecko.mTabSize.set(non_negative_length);
|
||||
}
|
||||
}
|
||||
|
@ -4809,8 +4809,8 @@ fn static_assert() {
|
|||
use values::Either;
|
||||
|
||||
match self.gecko.mTabSize.as_value() {
|
||||
CoordDataValue::Coord(coord) => Either::First(Au(coord).into()),
|
||||
CoordDataValue::Factor(number) => Either::Second(From::from(number)),
|
||||
CoordDataValue::Coord(coord) => Either::Second(Au(coord).into()),
|
||||
CoordDataValue::Factor(number) => Either::First(From::from(number)),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -511,7 +511,6 @@ ${helpers.single_keyword("resize",
|
|||
${helpers.predefined_type("perspective",
|
||||
"LengthOrNone",
|
||||
"Either::Second(None_)",
|
||||
"parse_non_negative_length",
|
||||
gecko_ffi_name="mChildPerspective",
|
||||
spec="https://drafts.csswg.org/css-transforms/#perspective",
|
||||
extra_prefixes="moz webkit",
|
||||
|
|
|
@ -488,7 +488,7 @@ ${helpers.predefined_type(
|
|||
|
||||
${helpers.predefined_type(
|
||||
"-moz-tab-size", "length::NonNegativeLengthOrNumber",
|
||||
"::values::Either::Second(From::from(8.0))",
|
||||
"::values::Either::First(From::from(8.0))",
|
||||
products="gecko", animation_value_type="::values::computed::length::NonNegativeLengthOrNumber",
|
||||
spec="https://drafts.csswg.org/css-text-3/#tab-size-property")}
|
||||
|
||||
|
|
|
@ -902,7 +902,7 @@ pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>;
|
|||
pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
|
||||
|
||||
/// Either a computed NonNegativeLength or a NonNegativeNumber value.
|
||||
pub type NonNegativeLengthOrNumber = Either<NonNegativeLength, NonNegativeNumber>;
|
||||
pub type NonNegativeLengthOrNumber = Either<NonNegativeNumber, NonNegativeLength>;
|
||||
|
||||
/// A type for possible values for min- and max- flavors of width, height,
|
||||
/// block-size, and inline-size.
|
||||
|
|
|
@ -640,21 +640,19 @@ impl Length {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Parse> Either<Length, T> {
|
||||
/// Parse a non-negative length
|
||||
#[inline]
|
||||
pub fn parse_non_negative_length<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
if let Ok(v) = input.try(|input| T::parse(context, input)) {
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper of Length, whose value must be >= 0.
|
||||
pub type NonNegativeLength = NonNegative<Length>;
|
||||
|
||||
impl Parse for NonNegativeLength {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(NonNegative(Length::parse_non_negative(context, input)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NoCalcLength> for NonNegativeLength {
|
||||
#[inline]
|
||||
fn from(len: NoCalcLength) -> Self {
|
||||
|
@ -669,17 +667,6 @@ impl From<Length> for NonNegativeLength {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Parse> Parse for Either<NonNegativeLength, T> {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(v) = input.try(|input| T::parse(context, input)) {
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No)
|
||||
.map(NonNegative::<Length>).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
||||
impl NonNegativeLength {
|
||||
/// Returns a `zero` length.
|
||||
#[inline]
|
||||
|
@ -701,7 +688,10 @@ pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
|
|||
pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>;
|
||||
|
||||
/// Either a NonNegativeLength or a NonNegativeNumber value.
|
||||
pub type NonNegativeLengthOrNumber = Either<NonNegativeLength, NonNegativeNumber>;
|
||||
///
|
||||
/// The order is important, because `0` must be parsed as the number `0` and not
|
||||
/// the length `0px`.
|
||||
pub type NonNegativeLengthOrNumber = Either<NonNegativeNumber, NonNegativeLength>;
|
||||
|
||||
/// A length or a percentage value.
|
||||
#[allow(missing_docs)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue