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
|
@ -14,6 +14,7 @@ use super::{Context, Number, Percentage, ToComputedValue};
|
|||
use values::{specified, Auto, CSSFloat, Either, Normal};
|
||||
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use values::generics::length::{MaxLength as GenericMaxLength, MozLength as GenericMozLength};
|
||||
use values::generics::NonNegative;
|
||||
use values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength};
|
||||
use values::specified::length::ViewportPercentageLength;
|
||||
|
@ -949,7 +950,8 @@ pub type NonNegativeLengthOrPercentageOrNormal = Either<NonNegativeLengthOrPerce
|
|||
/// block-size, and inline-size.
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo,
|
||||
ToComputedValue, ToCss)]
|
||||
pub enum ExtremumLength {
|
||||
MozMaxContent,
|
||||
MozMinContent,
|
||||
|
@ -957,94 +959,24 @@ pub enum ExtremumLength {
|
|||
MozAvailable,
|
||||
}
|
||||
|
||||
/// A value suitable for a `min-width`, `min-height`, `width` or `height`
|
||||
/// property.
|
||||
///
|
||||
/// See values/specified/length.rs for more details.
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToAnimatedZero, ToCss)]
|
||||
pub enum MozLength {
|
||||
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
|
||||
#[animation(error)]
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
/// A computed value for `min-width`, `min-height`, `width` or `height` property.
|
||||
pub type MozLength = GenericMozLength<LengthOrPercentageOrAuto>;
|
||||
|
||||
impl MozLength {
|
||||
/// Returns the `auto` value.
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)
|
||||
GenericMozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::MozLength {
|
||||
type ComputedValue = MozLength;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> MozLength {
|
||||
match *self {
|
||||
specified::MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
|
||||
MozLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context))
|
||||
},
|
||||
specified::MozLength::ExtremumLength(ext) => MozLength::ExtremumLength(ext),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &MozLength) -> Self {
|
||||
match *computed {
|
||||
MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
|
||||
specified::MozLength::LengthOrPercentageOrAuto(
|
||||
specified::LengthOrPercentageOrAuto::from_computed_value(lopoa),
|
||||
)
|
||||
},
|
||||
MozLength::ExtremumLength(ext) => specified::MozLength::ExtremumLength(ext),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A value suitable for a `max-width` or `max-height` property.
|
||||
/// See values/specified/length.rs for more details.
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToCss)]
|
||||
pub enum MaxLength {
|
||||
LengthOrPercentageOrNone(LengthOrPercentageOrNone),
|
||||
#[animation(error)]
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
/// A computed value for `max-width` or `min-height` property.
|
||||
pub type MaxLength = GenericMaxLength<LengthOrPercentageOrNone>;
|
||||
|
||||
impl MaxLength {
|
||||
/// Returns the `none` value.
|
||||
#[inline]
|
||||
pub fn none() -> Self {
|
||||
MaxLength::LengthOrPercentageOrNone(LengthOrPercentageOrNone::None)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::MaxLength {
|
||||
type ComputedValue = MaxLength;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> MaxLength {
|
||||
match *self {
|
||||
specified::MaxLength::LengthOrPercentageOrNone(ref lopon) => {
|
||||
MaxLength::LengthOrPercentageOrNone(lopon.to_computed_value(context))
|
||||
},
|
||||
specified::MaxLength::ExtremumLength(ext) => MaxLength::ExtremumLength(ext),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &MaxLength) -> Self {
|
||||
match *computed {
|
||||
MaxLength::LengthOrPercentageOrNone(ref lopon) => {
|
||||
specified::MaxLength::LengthOrPercentageOrNone(
|
||||
specified::LengthOrPercentageOrNone::from_computed_value(&lopon),
|
||||
)
|
||||
},
|
||||
MaxLength::ExtremumLength(ext) => specified::MaxLength::ExtremumLength(ext),
|
||||
}
|
||||
GenericMaxLength::LengthOrPercentageOrNone(LengthOrPercentageOrNone::None)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue