mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Move MozLength and MaxLength into generics.
Move MozLength and MaxLength into generics, and drop the manual implementation of ToComputedValue. Differential Revision: https://phabricator.services.mozilla.com/D8291
This commit is contained in:
parent
53eb6cd667
commit
c9d39b2b19
7 changed files with 89 additions and 118 deletions
|
@ -18,6 +18,7 @@ use style_traits::values::specified::AllowedNumericType;
|
|||
use super::{AllowQuirks, Number, Percentage, ToComputedValue};
|
||||
use values::{Auto, CSSFloat, Either, Normal};
|
||||
use values::computed::{self, CSSPixelLength, Context, ExtremumLength};
|
||||
use values::generics::length::{MaxLength as GenericMaxLength, MozLength as GenericMozLength};
|
||||
use values::generics::NonNegative;
|
||||
use values::specified::calc::CalcNode;
|
||||
|
||||
|
@ -1188,18 +1189,8 @@ impl LengthOrNumber {
|
|||
}
|
||||
}
|
||||
|
||||
/// A value suitable for a `min-width` or `min-height` property.
|
||||
///
|
||||
/// Unlike `max-width` or `max-height` properties, a MozLength can be `auto`,
|
||||
/// and cannot be `none`.
|
||||
///
|
||||
/// Note that it only accepts non-negative values.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
pub enum MozLength {
|
||||
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
/// A specified value for `min-width`, `min-height`, `width` or `height` property.
|
||||
pub type MozLength = GenericMozLength<LengthOrPercentageOrAuto>;
|
||||
|
||||
impl Parse for MozLength {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -1219,7 +1210,7 @@ impl MozLength {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let length = LengthOrPercentageOrAuto::parse_non_negative(context, input)?;
|
||||
Ok(MozLength::LengthOrPercentageOrAuto(length))
|
||||
Ok(GenericMozLength::LengthOrPercentageOrAuto(length))
|
||||
}
|
||||
|
||||
/// Parses, with quirks.
|
||||
|
@ -1229,34 +1220,29 @@ impl MozLength {
|
|||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(l) = input.try(ExtremumLength::parse) {
|
||||
return Ok(MozLength::ExtremumLength(l));
|
||||
return Ok(GenericMozLength::ExtremumLength(l));
|
||||
}
|
||||
|
||||
let length =
|
||||
LengthOrPercentageOrAuto::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(MozLength::LengthOrPercentageOrAuto(length))
|
||||
Ok(GenericMozLength::LengthOrPercentageOrAuto(length))
|
||||
}
|
||||
|
||||
/// Returns `auto`.
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::auto())
|
||||
GenericMozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::auto())
|
||||
}
|
||||
|
||||
/// Returns `0%`.
|
||||
#[inline]
|
||||
pub fn zero_percent() -> Self {
|
||||
MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::zero_percent())
|
||||
GenericMozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::zero_percent())
|
||||
}
|
||||
}
|
||||
|
||||
/// A value suitable for a `max-width` or `max-height` property.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
pub enum MaxLength {
|
||||
LengthOrPercentageOrNone(LengthOrPercentageOrNone),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
/// A specified value for `max-width` or `max-height` property.
|
||||
pub type MaxLength = GenericMaxLength<LengthOrPercentageOrNone>;
|
||||
|
||||
impl Parse for MaxLength {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -1276,7 +1262,7 @@ impl MaxLength {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let length = LengthOrPercentageOrNone::parse_non_negative(context, input)?;
|
||||
Ok(MaxLength::LengthOrPercentageOrNone(length))
|
||||
Ok(GenericMaxLength::LengthOrPercentageOrNone(length))
|
||||
}
|
||||
|
||||
/// Parses, with quirks.
|
||||
|
@ -1286,11 +1272,11 @@ impl MaxLength {
|
|||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(l) = input.try(ExtremumLength::parse) {
|
||||
return Ok(MaxLength::ExtremumLength(l));
|
||||
return Ok(GenericMaxLength::ExtremumLength(l));
|
||||
}
|
||||
|
||||
let length =
|
||||
LengthOrPercentageOrNone::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(MaxLength::LengthOrPercentageOrNone(length))
|
||||
Ok(GenericMaxLength::LengthOrPercentageOrNone(length))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue