diff options
author | Hiroyuki Ikezoe <hikezoe@mozilla.com> | 2017-05-20 11:58:15 +0900 |
---|---|---|
committer | Hiroyuki Ikezoe <hikezoe@mozilla.com> | 2017-05-21 08:33:12 +0900 |
commit | 95bda2dff961d642f97bc0de055882f6d3928f8a (patch) | |
tree | 84ecf898c3ba960f4ee08959e8b69d4348bd2263 | |
parent | 323760f47e79b49ef8db4484cca1969bc26b5413 (diff) | |
download | servo-95bda2dff961d642f97bc0de055882f6d3928f8a.tar.gz servo-95bda2dff961d642f97bc0de055882f6d3928f8a.zip |
Combine LengthOrPercentage and Auto into LengthOrPercentageOrAuto for {Min,Max}Length.
-rw-r--r-- | components/style/gecko/values.rs | 18 | ||||
-rw-r--r-- | components/style/properties/helpers/animated_properties.mako.rs | 20 | ||||
-rw-r--r-- | components/style/properties/longhand/position.mako.rs | 2 | ||||
-rw-r--r-- | components/style/values/computed/length.rs | 59 | ||||
-rw-r--r-- | components/style/values/specified/length.rs | 35 |
5 files changed, 54 insertions, 80 deletions
diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 1126d4787d9..040d4752849 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -338,38 +338,28 @@ impl GeckoStyleCoordConvertible for ExtremumLength { impl GeckoStyleCoordConvertible for MinLength { fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) { match *self { - MinLength::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord), - MinLength::Auto => coord.set_value(CoordDataValue::Auto), + MinLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord), MinLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> { - LengthOrPercentage::from_gecko_style_coord(coord).map(MinLength::LengthOrPercentage) + LengthOrPercentageOrAuto::from_gecko_style_coord(coord).map(MinLength::LengthOrPercentageOrAuto) .or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MinLength::ExtremumLength)) - .or_else(|| match coord.as_value() { - CoordDataValue::Auto => Some(MinLength::Auto), - _ => None, - }) } } impl GeckoStyleCoordConvertible for MaxLength { fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) { match *self { - MaxLength::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord), - MaxLength::None => coord.set_value(CoordDataValue::None), + MaxLength::LengthOrPercentageOrNone(ref lopon) => lopon.to_gecko_style_coord(coord), MaxLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> { - LengthOrPercentage::from_gecko_style_coord(coord).map(MaxLength::LengthOrPercentage) + LengthOrPercentageOrNone::from_gecko_style_coord(coord).map(MaxLength::LengthOrPercentageOrNone) .or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength)) - .or_else(|| match coord.as_value() { - CoordDataValue::None => Some(MaxLength::None), - _ => None, - }) } } diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 11fa3956a8a..402662d92ea 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -1241,10 +1241,10 @@ impl Animatable for MinLength { #[inline] fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { match (*self, *other) { - (MinLength::LengthOrPercentage(ref this), - MinLength::LengthOrPercentage(ref other)) => { + (MinLength::LengthOrPercentageOrAuto(ref this), + MinLength::LengthOrPercentageOrAuto(ref other)) => { this.add_weighted(other, self_portion, other_portion) - .map(MinLength::LengthOrPercentage) + .map(MinLength::LengthOrPercentageOrAuto) } _ => Err(()), } @@ -1253,8 +1253,8 @@ impl Animatable for MinLength { #[inline] fn compute_distance(&self, other: &Self) -> Result<f64, ()> { match (*self, *other) { - (MinLength::LengthOrPercentage(ref this), - MinLength::LengthOrPercentage(ref other)) => { + (MinLength::LengthOrPercentageOrAuto(ref this), + MinLength::LengthOrPercentageOrAuto(ref other)) => { this.compute_distance(other) }, _ => Err(()), @@ -1267,10 +1267,10 @@ impl Animatable for MaxLength { #[inline] fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { match (*self, *other) { - (MaxLength::LengthOrPercentage(ref this), - MaxLength::LengthOrPercentage(ref other)) => { + (MaxLength::LengthOrPercentageOrNone(ref this), + MaxLength::LengthOrPercentageOrNone(ref other)) => { this.add_weighted(other, self_portion, other_portion) - .map(MaxLength::LengthOrPercentage) + .map(MaxLength::LengthOrPercentageOrNone) } _ => Err(()), } @@ -1279,8 +1279,8 @@ impl Animatable for MaxLength { #[inline] fn compute_distance(&self, other: &Self) -> Result<f64, ()> { match (*self, *other) { - (MaxLength::LengthOrPercentage(ref this), - MaxLength::LengthOrPercentage(ref other)) => { + (MaxLength::LengthOrPercentageOrNone(ref this), + MaxLength::LengthOrPercentageOrNone(ref other)) => { this.compute_distance(other) }, _ => Err(()), diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index da7fe080604..7fa4d3b2ba0 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -164,7 +164,7 @@ ${helpers.predefined_type("flex-basis", % for min_max in ["min", "max"]: <% MinMax = min_max.title() - initial = "None" if "max" == min_max else "Auto" + initial = "none()" if "max" == min_max else "auto()" %> // min-width, min-height, min-block-size, min-inline-size, 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<Length, Normal>; #[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<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::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<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/specified/length.rs b/components/style/values/specified/length.rs index 331901bf8c6..6481d0686ea 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1182,18 +1182,15 @@ impl LengthOrNumber { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] pub enum MinLength { - LengthOrPercentage(LengthOrPercentage), - Auto, + LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), ExtremumLength(ExtremumLength), } impl ToCss for MinLength { 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::LengthOrPercentageOrAuto(ref lopoa) => + lopoa.to_css(dest), MinLength::ExtremumLength(ref ext) => ext.to_css(dest), } @@ -1212,9 +1209,8 @@ impl MinLength { 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)) + .or_else(|()| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks)) + .map(MinLength::LengthOrPercentageOrAuto)) } } @@ -1223,19 +1219,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), } @@ -1254,14 +1246,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)) } } |