Bug 1367274 - Part 2: Implement ToComputedValue for SpecifiedLineDirection and SpecifiedGradientKind. r?xidorn
MozReview-Commit-ID: KH2vMMlpi0s
--- 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)))