Bug 1367274 - Part 2: Implement ToComputedValue for SpecifiedLineDirection and SpecifiedGradientKind. r?xidorn draft
authorFernando Jimenez Moreno <ferjmoreno@gmail.com>
Wed, 12 Jul 2017 10:47:31 +0200
changeset 607485 2f96dc3110c00cf5aad9116129f82ca029aae5df
parent 607484 d6da6fc04f7e02aa159102ef6595b05f73dd538d
child 607486 966221ea306551f90d280c06d3a07f6841662608
push id67988
push userferjmoreno@gmail.com
push dateWed, 12 Jul 2017 08:47:57 +0000
reviewersxidorn
bugs1367274
milestone56.0a1
Bug 1367274 - Part 2: Implement ToComputedValue for SpecifiedLineDirection and SpecifiedGradientKind. r?xidorn MozReview-Commit-ID: 3Mso9mSfojy
servo/components/style/values/computed/image.rs
--- a/servo/components/style/values/computed/image.rs
+++ b/servo/components/style/values/computed/image.rs
@@ -129,19 +129,20 @@ impl GenericLineDirection for LineDirect
                     angle.to_css(dest)?;
                 }
                 Ok(())
             }
         }
     }
 }
 
-impl SpecifiedLineDirection {
-    /// Manually derived to_computed_value
-    fn to_computed_value(&self, context: &Context, _: CompatMode) -> LineDirection {
+impl ToComputedValue for SpecifiedLineDirection {
+    type ComputedValue = LineDirection;
+
+    fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
         match *self {
             SpecifiedLineDirection::Angle(ref angle) => {
                 LineDirection::Angle(angle.to_computed_value(context))
             },
             SpecifiedLineDirection::Horizontal(x) => {
                 LineDirection::Horizontal(x)
             },
             SpecifiedLineDirection::Vertical(y) => {
@@ -153,17 +154,17 @@ impl SpecifiedLineDirection {
             #[cfg(feature = "gecko")]
             SpecifiedLineDirection::MozPosition(ref position, ref angle) => {
                 LineDirection::MozPosition(position.to_computed_value(context),
                                            angle.to_computed_value(context))
             },
         }
     }
 
-    fn from_computed_value(computed: &LineDirection) -> Self {
+    fn from_computed_value(computed: &Self::ComputedValue) -> Self {
         match *computed {
             LineDirection::Angle(ref angle) => {
                 SpecifiedLineDirection::Angle(ToComputedValue::from_computed_value(angle))
             },
             LineDirection::Horizontal(x) => {
                 SpecifiedLineDirection::Horizontal(x)
             },
             LineDirection::Vertical(y) => {
@@ -181,50 +182,50 @@ impl SpecifiedLineDirection {
     }
 }
 
 impl ToComputedValue for SpecifiedGradient {
     type ComputedValue = Gradient;
 
     fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
         Self::ComputedValue {
-            kind: self.kind.to_computed_value(context, self.compat_mode),
+            kind: self.kind.to_computed_value(context),
             items: self.items.to_computed_value(context),
             repeating: self.repeating,
             compat_mode: self.compat_mode
         }
     }
 
     fn from_computed_value(computed: &Self::ComputedValue) -> Self {
         Self {
             kind: SpecifiedGradientKind::from_computed_value(&computed.kind),
             items: ToComputedValue::from_computed_value(&computed.items),
             repeating: computed.repeating,
             compat_mode: computed.compat_mode
         }
     }
 }
 
-impl SpecifiedGradientKind {
-    /// Manually derived to_computed_value
-    pub fn to_computed_value(&self, context: &Context, compat_mode: CompatMode) -> GradientKind {
+impl ToComputedValue for SpecifiedGradientKind {
+    type ComputedValue = GradientKind;
+
+    fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
         match self {
             &GenericGradientKind::Linear(ref line_direction) => {
-                GenericGradientKind::Linear(line_direction.to_computed_value(context, compat_mode))
+                GenericGradientKind::Linear(line_direction.to_computed_value(context))
             },
             &GenericGradientKind::Radial(ref ending_shape, ref position, ref angle) => {
                 GenericGradientKind::Radial(ending_shape.to_computed_value(context),
                                             position.to_computed_value(context),
                                             angle.map(|angle| angle.to_computed_value(context)))
             }
         }
     }
 
-    /// Manually derived from_computed_value
-    pub fn from_computed_value(computed: &GradientKind) -> SpecifiedGradientKind {
+    fn from_computed_value(computed: &Self::ComputedValue) -> Self {
         match *computed {
             GenericGradientKind::Linear(line_direction) => {
                 GenericGradientKind::Linear(SpecifiedLineDirection::from_computed_value(&line_direction))
             },
             GenericGradientKind::Radial(ending_shape, position, angle) => {
                 GenericGradientKind::Radial(ToComputedValue::from_computed_value(&ending_shape),
                                             ToComputedValue::from_computed_value(&position),
                                             angle.map(|angle| ToComputedValue::from_computed_value(&angle)))