Bug 1367274 - Part 2: Implement ToComputedValue for SpecifiedLineDirection and SpecifiedGradientKind. r?xidorn draft
authorFernando Jimenez Moreno <ferjmoreno@gmail.com>
Thu, 13 Jul 2017 11:10:24 +0200
changeset 608223 836db91fc5b948cedb463ebeb52796221dc762f2
parent 608222 86a5728c5fc777c199401c5fee7354cea155de52
child 608224 2c412cec5113053163d133ca2363d2401f473d71
push id68209
push userferjmoreno@gmail.com
push dateThu, 13 Jul 2017 09:38:41 +0000
reviewersxidorn
bugs1367274
milestone56.0a1
Bug 1367274 - Part 2: Implement ToComputedValue for SpecifiedLineDirection and SpecifiedGradientKind. r?xidorn MozReview-Commit-ID: KH2vMMlpi0s
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)))