diff options
Diffstat (limited to 'components/style/values')
-rw-r--r-- | components/style/values/computed/length.rs | 83 | ||||
-rw-r--r-- | components/style/values/computed/mod.rs | 2 | ||||
-rw-r--r-- | components/style/values/specified/length.rs | 51 | ||||
-rw-r--r-- | components/style/values/specified/mod.rs | 2 |
4 files changed, 61 insertions, 77 deletions
diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 89702468570..e2dac197652 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -606,56 +606,56 @@ pub type LengthOrNumber = Either<Length, Number>; /// Either a computed `<length>` or the `normal` keyword. pub type LengthOrNormal = Either<Length, Normal>; -/// A value suitable for a `min-width` or `min-height` property. +/// A value suitable for a `min-width`, `min-height`, `width` or `height` property. /// See specified/values/length.rs for more details. #[derive(Debug, Copy, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] -pub enum MinLength { - LengthOrPercentage(LengthOrPercentage), - Auto, +pub enum MozLength { + LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), ExtremumLength(ExtremumLength), } -impl ToComputedValue for specified::MinLength { - type ComputedValue = MinLength; +impl MozLength { + /// Returns the `auto` value. + pub fn auto() -> Self { + MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) + } +} + +impl ToComputedValue for specified::MozLength { + type ComputedValue = MozLength; #[inline] - fn to_computed_value(&self, context: &Context) -> MinLength { + fn to_computed_value(&self, context: &Context) -> MozLength { match *self { - specified::MinLength::LengthOrPercentage(ref lop) => { - MinLength::LengthOrPercentage(lop.to_computed_value(context)) - } - specified::MinLength::Auto => { - MinLength::Auto + specified::MozLength::LengthOrPercentageOrAuto(ref lopoa) => { + MozLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context)) } - specified::MinLength::ExtremumLength(ref ext) => { - MinLength::ExtremumLength(ext.clone()) + specified::MozLength::ExtremumLength(ref ext) => { + MozLength::ExtremumLength(ext.clone()) } } } #[inline] - fn from_computed_value(computed: &MinLength) -> Self { + fn from_computed_value(computed: &MozLength) -> Self { match *computed { - MinLength::Auto => - specified::MinLength::Auto, - MinLength::LengthOrPercentage(ref lop) => - specified::MinLength::LengthOrPercentage(specified::LengthOrPercentage::from_computed_value(&lop)), - MinLength::ExtremumLength(ref ext) => - specified::MinLength::ExtremumLength(ext.clone()), + MozLength::LengthOrPercentageOrAuto(ref lopoa) => + specified::MozLength::LengthOrPercentageOrAuto( + specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)), + MozLength::ExtremumLength(ref ext) => + specified::MozLength::ExtremumLength(ext.clone()), } } } -impl ToCss for MinLength { +impl ToCss for MozLength { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - MinLength::LengthOrPercentage(lop) => - lop.to_css(dest), - MinLength::Auto => - dest.write_str("auto"), - MinLength::ExtremumLength(ext) => + MozLength::LengthOrPercentageOrAuto(lopoa) => + lopoa.to_css(dest), + MozLength::ExtremumLength(ext) => ext.to_css(dest), } } @@ -667,22 +667,24 @@ impl ToCss for MinLength { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] pub enum MaxLength { - LengthOrPercentage(LengthOrPercentage), - None, + LengthOrPercentageOrNone(LengthOrPercentageOrNone), ExtremumLength(ExtremumLength), } +impl MaxLength { + /// Returns the `none` value. + 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::LengthOrPercentage(ref lop) => { - MaxLength::LengthOrPercentage(lop.to_computed_value(context)) - } - specified::MaxLength::None => { - MaxLength::None + specified::MaxLength::LengthOrPercentageOrNone(ref lopon) => { + MaxLength::LengthOrPercentageOrNone(lopon.to_computed_value(context)) } specified::MaxLength::ExtremumLength(ref ext) => { MaxLength::ExtremumLength(ext.clone()) @@ -693,10 +695,9 @@ impl ToComputedValue for specified::MaxLength { #[inline] fn from_computed_value(computed: &MaxLength) -> Self { match *computed { - MaxLength::None => - specified::MaxLength::None, - MaxLength::LengthOrPercentage(ref lop) => - specified::MaxLength::LengthOrPercentage(specified::LengthOrPercentage::from_computed_value(&lop)), + MaxLength::LengthOrPercentageOrNone(ref lopon) => + specified::MaxLength::LengthOrPercentageOrNone( + specified::LengthOrPercentageOrNone::from_computed_value(&lopon)), MaxLength::ExtremumLength(ref ext) => specified::MaxLength::ExtremumLength(ext.clone()), } @@ -706,10 +707,8 @@ impl ToComputedValue for specified::MaxLength { impl ToCss for MaxLength { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - MaxLength::LengthOrPercentage(lop) => - lop.to_css(dest), - MaxLength::None => - dest.write_str("none"), + MaxLength::LengthOrPercentageOrNone(lopon) => + lopon.to_css(dest), MaxLength::ExtremumLength(ext) => ext.to_css(dest), } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 94042158c48..4a56a7b4872 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -32,7 +32,7 @@ pub use super::specified::{BorderStyle, GridLine, Percentage, UrlOrNone}; pub use super::specified::url::SpecifiedUrl; pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone}; -pub use self::length::{MaxLength, MinLength}; +pub use self::length::{MaxLength, MozLength}; pub use self::position::Position; pub mod basic_shape; diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 56b1d903d9a..e37aad81f0e 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1183,45 +1183,41 @@ impl LengthOrNumber { } /// A value suitable for a `min-width` or `min-height` property. -/// Unlike `max-width` or `max-height` properties, a MinLength can be +/// Unlike `max-width` or `max-height` properties, a MozLength can be /// `auto`, and cannot be `none`. #[derive(Clone, Debug, HasViewportPercentage, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] -pub enum MinLength { - LengthOrPercentage(LengthOrPercentage), - Auto, +pub enum MozLength { + LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), ExtremumLength(ExtremumLength), } -impl ToCss for MinLength { +impl ToCss for MozLength { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - MinLength::LengthOrPercentage(ref lop) => - lop.to_css(dest), - MinLength::Auto => - dest.write_str("auto"), - MinLength::ExtremumLength(ref ext) => + MozLength::LengthOrPercentageOrAuto(ref lopoa) => + lopoa.to_css(dest), + MozLength::ExtremumLength(ref ext) => ext.to_css(dest), } } } -impl Parse for MinLength { +impl Parse for MozLength { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { - MinLength::parse_quirky(context, input, AllowQuirks::No) + MozLength::parse_quirky(context, input, AllowQuirks::No) } } -impl MinLength { +impl MozLength { /// Parses, with quirks. pub fn parse_quirky(context: &ParserContext, input: &mut Parser, allow_quirks: AllowQuirks) -> Result<Self, ()> { - input.try(ExtremumLength::parse).map(MinLength::ExtremumLength) - .or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks)) - .map(MinLength::LengthOrPercentage)) - .or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto)) + input.try(ExtremumLength::parse).map(MozLength::ExtremumLength) + .or_else(|()| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks)) + .map(MozLength::LengthOrPercentageOrAuto)) } } @@ -1230,19 +1226,15 @@ impl MinLength { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] pub enum MaxLength { - LengthOrPercentage(LengthOrPercentage), - None, + LengthOrPercentageOrNone(LengthOrPercentageOrNone), ExtremumLength(ExtremumLength), } - impl ToCss for MaxLength { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - MaxLength::LengthOrPercentage(ref lop) => - lop.to_css(dest), - MaxLength::None => - dest.write_str("none"), + MaxLength::LengthOrPercentageOrNone(ref lopon) => + lopon.to_css(dest), MaxLength::ExtremumLength(ref ext) => ext.to_css(dest), } @@ -1261,14 +1253,7 @@ impl MaxLength { input: &mut Parser, allow_quirks: AllowQuirks) -> Result<Self, ()> { input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength) - .or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks)) - .map(MaxLength::LengthOrPercentage)) - .or_else(|()| { - match_ignore_ascii_case! { &try!(input.expect_ident()), - "none" => - Ok(MaxLength::None), - _ => Err(()) - } - }) + .or_else(|()| input.try(|i| LengthOrPercentageOrNone::parse_non_negative_quirky(context, i, allow_quirks)) + .map(MaxLength::LengthOrPercentageOrNone)) } } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index d687c4aaff9..88a44b50b3e 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -37,7 +37,7 @@ pub use self::length::AbsoluteLength; pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage}; pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength}; -pub use self::length::{MaxLength, MinLength}; +pub use self::length::{MaxLength, MozLength}; pub use self::position::{Position, PositionComponent}; #[cfg(feature = "gecko")] |