Bug 1355402 - Combine LengthOrPercentage and Auto into LengthOrPercentageOrAuto for {Min,Max}Length. r?manishearth draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 17 May 2017 12:57:39 +0900
changeset 579242 90ae402234ac8d6f8d64fc93a69b17383fe0f625
parent 579241 19c4f1bf59e3c45359f6c835f2ce23484ed095b7
child 579243 f4fb8567c2777007b5230e440df9c9594c5652dd
push id59173
push userhikezoe@mozilla.com
push dateWed, 17 May 2017 04:47:54 +0000
reviewersmanishearth
bugs1355402
milestone55.0a1
Bug 1355402 - Combine LengthOrPercentage and Auto into LengthOrPercentageOrAuto for {Min,Max}Length. r?manishearth MozReview-Commit-ID: 3UBY872eSEI
servo/components/style/gecko/values.rs
servo/components/style/properties/helpers/animated_properties.mako.rs
servo/components/style/properties/longhand/position.mako.rs
servo/components/style/values/computed/length.rs
servo/components/style/values/specified/length.rs
--- a/servo/components/style/gecko/values.rs
+++ b/servo/components/style/gecko/values.rs
@@ -333,48 +333,38 @@ impl GeckoStyleCoordConvertible for Extr
             _ => None,
         }
     }
 }
 
 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,
-            })
     }
 }
 
 /// Convert a given RGBA value to `nscolor`.
 pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
     ((rgba.alpha as u32) << 24) |
     ((rgba.blue as u32) << 16) |
     ((rgba.green as u32) << 8) |
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -1237,56 +1237,56 @@ impl Animatable for LengthOrPercentageOr
     }
 }
 
 /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
 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(()),
         }
     }
 
     #[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(()),
         }
     }
 }
 
 /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
 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(()),
         }
     }
 
     #[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(()),
         }
     }
 }
 
 /// https://drafts.csswg.org/css-transitions/#animtype-number
--- a/servo/components/style/properties/longhand/position.mako.rs
+++ b/servo/components/style/properties/longhand/position.mako.rs
@@ -159,17 +159,17 @@
                               "parse_non_negative",
                               spec=spec % size,
                               allow_quirks=not logical,
                               animation_value_type="ComputedValue", logical = logical)}
     % if product == "gecko":
         % 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,
             // max-width, max-height, max-block-size, max-inline-size
             //
             // Keyword values are only valid in the inline direction; they must
             // be replaced with auto/none in block.
             <%helpers:longhand name="${min_max}-${size}" spec="${spec % ('%s-%s' % (min_max, size))}"
--- a/servo/components/style/values/computed/length.rs
+++ b/servo/components/style/values/computed/length.rs
@@ -562,111 +562,110 @@ pub type LengthOrNumber = Either<Length,
 pub type LengthOrNormal = Either<Length, Normal>;
 
 /// A value suitable for a `min-width` or `min-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,
+    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())
             }
         }
     }
 
     #[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()),
         }
     }
 }
 
 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),
         }
     }
 }
 
 /// A value suitable for a `max-width` or `max-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 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())
             }
         }
     }
 
     #[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()),
         }
     }
 }
 
 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),
         }
     }
 }
--- a/servo/components/style/values/specified/length.rs
+++ b/servo/components/style/values/specified/length.rs
@@ -1229,37 +1229,34 @@ impl LengthOrNumber {
 
 /// A value suitable for a `min-width` or `min-height` property.
 /// Unlike `max-width` or `max-height` properties, a MinLength can be
 /// `auto`, and cannot be `none`.
 #[derive(Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 #[allow(missing_docs)]
 pub enum MinLength {
-    LengthOrPercentage(LengthOrPercentage),
-    Auto,
+    LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
     ExtremumLength(ExtremumLength),
 }
 
 impl HasViewportPercentage for MinLength {
     fn has_viewport_percentage(&self) -> bool {
         match *self {
-            MinLength::LengthOrPercentage(ref lop) => lop.has_viewport_percentage(),
+            MinLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.has_viewport_percentage(),
             _ => false
         }
     }
 }
 
 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),
         }
     }
 }
 
 impl Parse for MinLength {
     fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
@@ -1268,48 +1265,44 @@ impl Parse for MinLength {
 }
 
 impl MinLength {
     /// 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))
+            .or_else(|()| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks))
+                               .map(MinLength::LengthOrPercentageOrAuto))
     }
 }
 
 /// A value suitable for a `max-width` or `max-height` property.
 #[derive(Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 #[allow(missing_docs)]
 pub enum MaxLength {
-    LengthOrPercentage(LengthOrPercentage),
-    None,
+    LengthOrPercentageOrNone(LengthOrPercentageOrNone),
     ExtremumLength(ExtremumLength),
 }
 
 impl HasViewportPercentage for MaxLength {
     fn has_viewport_percentage(&self) -> bool {
         match *self {
-            MaxLength::LengthOrPercentage(ref lop) => lop.has_viewport_percentage(),
+            MaxLength::LengthOrPercentageOrNone(ref lopon) => lopon.has_viewport_percentage(),
             _ => false
         }
     }
 }
 
 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),
         }
     }
 }
 
 impl Parse for MaxLength {
     fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
@@ -1318,19 +1311,12 @@ impl Parse for MaxLength {
 }
 
 impl MaxLength {
     /// Parses, with quirks.
     pub fn parse_quirky(context: &ParserContext,
                         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))
     }
 }