mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Bug 1374233 - Part 7: Add NonNegativeLengthOrPercentage.
For padding-{*} and grid-{*}-gap. MozReview-Commit-ID: 81G0b1k6JnD
This commit is contained in:
parent
9d69cb2866
commit
e72a0f126e
14 changed files with 123 additions and 20 deletions
|
@ -1224,6 +1224,41 @@ impl Parse for LengthOrPercentageOrNone {
|
|||
}
|
||||
}
|
||||
|
||||
/// A wrapper of LengthOrPercentage, whose value must be >= 0.
|
||||
pub type NonNegativeLengthOrPercentage = NonNegative<LengthOrPercentage>;
|
||||
|
||||
impl From<NoCalcLength> for NonNegativeLengthOrPercentage {
|
||||
#[inline]
|
||||
fn from(len: NoCalcLength) -> Self {
|
||||
NonNegative::<LengthOrPercentage>(LengthOrPercentage::from(len))
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for NonNegativeLengthOrPercentage {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
LengthOrPercentage::parse_non_negative(context, input).map(NonNegative::<LengthOrPercentage>)
|
||||
}
|
||||
}
|
||||
|
||||
impl NonNegativeLengthOrPercentage {
|
||||
#[inline]
|
||||
/// Returns a `zero` length.
|
||||
pub fn zero() -> Self {
|
||||
NonNegative::<LengthOrPercentage>(LengthOrPercentage::zero())
|
||||
}
|
||||
|
||||
/// Parses a length or a percentage, allowing the unitless length quirk.
|
||||
/// https://quirks.spec.whatwg.org/#the-unitless-length-quirk
|
||||
#[inline]
|
||||
pub fn parse_quirky<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks) -> Result<Self, ParseError<'i>> {
|
||||
LengthOrPercentage::parse_non_negative_quirky(context, input, allow_quirks)
|
||||
.map(NonNegative::<LengthOrPercentage>)
|
||||
}
|
||||
}
|
||||
|
||||
/// Either a `<length>` or the `none` keyword.
|
||||
pub type LengthOrNone = Either<Length, None_>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue