From 95bda2dff961d642f97bc0de055882f6d3928f8a Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sat, 20 May 2017 11:58:15 +0900 Subject: Combine LengthOrPercentage and Auto into LengthOrPercentageOrAuto for {Min,Max}Length. --- components/style/values/computed/length.rs | 59 +++++++++++++++--------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'components/style/values/computed') diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 89702468570..7b1ec1a288b 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -612,22 +612,25 @@ pub type LengthOrNormal = Either; #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] pub enum MinLength { - LengthOrPercentage(LengthOrPercentage), - Auto, + LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), ExtremumLength(ExtremumLength), } +impl MinLength { + /// Returns the `auto` value. + pub fn auto() -> Self { + MinLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) + } +} + impl ToComputedValue for specified::MinLength { type ComputedValue = MinLength; #[inline] fn to_computed_value(&self, context: &Context) -> MinLength { match *self { - specified::MinLength::LengthOrPercentage(ref lop) => { - MinLength::LengthOrPercentage(lop.to_computed_value(context)) - } - specified::MinLength::Auto => { - MinLength::Auto + specified::MinLength::LengthOrPercentageOrAuto(ref lopoa) => { + MinLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context)) } specified::MinLength::ExtremumLength(ref ext) => { MinLength::ExtremumLength(ext.clone()) @@ -638,10 +641,9 @@ impl ToComputedValue for specified::MinLength { #[inline] fn from_computed_value(computed: &MinLength) -> Self { match *computed { - MinLength::Auto => - specified::MinLength::Auto, - MinLength::LengthOrPercentage(ref lop) => - specified::MinLength::LengthOrPercentage(specified::LengthOrPercentage::from_computed_value(&lop)), + MinLength::LengthOrPercentageOrAuto(ref lopoa) => + specified::MinLength::LengthOrPercentageOrAuto( + specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)), MinLength::ExtremumLength(ref ext) => specified::MinLength::ExtremumLength(ext.clone()), } @@ -651,10 +653,8 @@ impl ToComputedValue for specified::MinLength { impl ToCss for MinLength { fn to_css(&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::LengthOrPercentageOrAuto(lopoa) => + lopoa.to_css(dest), MinLength::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(&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), } -- cgit v1.2.3 From 57c27e5d35e12b5d4822bc9f70a8b3da09f19d38 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sat, 20 May 2017 11:58:58 +0900 Subject: Rename MinLength to MozLength. So that we can reuse this for non-min-prefixed properties (e.g. width). --- components/style/values/computed/length.rs | 38 +++++++++++++++--------------- components/style/values/computed/mod.rs | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'components/style/values/computed') diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 7b1ec1a288b..e2dac197652 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -606,56 +606,56 @@ pub type LengthOrNumber = Either; /// Either a computed `` or the `normal` keyword. pub type LengthOrNormal = Either; -/// 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 { +pub enum MozLength { LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), ExtremumLength(ExtremumLength), } -impl MinLength { +impl MozLength { /// Returns the `auto` value. pub fn auto() -> Self { - MinLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) + MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) } } -impl ToComputedValue for specified::MinLength { - type ComputedValue = MinLength; +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::LengthOrPercentageOrAuto(ref lopoa) => { - MinLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context)) + 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::LengthOrPercentageOrAuto(ref lopoa) => - specified::MinLength::LengthOrPercentageOrAuto( + MozLength::LengthOrPercentageOrAuto(ref lopoa) => + specified::MozLength::LengthOrPercentageOrAuto( specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)), - MinLength::ExtremumLength(ref ext) => - specified::MinLength::ExtremumLength(ext.clone()), + MozLength::ExtremumLength(ref ext) => + specified::MozLength::ExtremumLength(ext.clone()), } } } -impl ToCss for MinLength { +impl ToCss for MozLength { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - MinLength::LengthOrPercentageOrAuto(lopoa) => + MozLength::LengthOrPercentageOrAuto(lopoa) => lopoa.to_css(dest), - MinLength::ExtremumLength(ext) => + MozLength::ExtremumLength(ext) => ext.to_css(dest), } } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 8c537eb3694..9cf143d1f56 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -31,7 +31,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; -- cgit v1.2.3