diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 39b41ab9a4d..35911564ca7 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -736,3 +736,26 @@ %> +/// Macro for defining Interpolate trait for tuple struct which has Option, +/// e.g. struct T(pub Option). +<%def name="impl_interpolate_for_option_tuple(value_for_none)"> + impl Interpolate for T { + #[inline] + fn interpolate(&self, other: &Self, progress: f64) -> Result { + match (self, other) { + (&T(Some(ref this)), &T(Some(ref other))) => { + Ok(T(this.interpolate(other, progress).ok())) + }, + (&T(Some(ref this)), &T(None)) => { + Ok(T(this.interpolate(&${value_for_none}, progress).ok())) + }, + (&T(None), &T(Some(ref other))) => { + Ok(T(${value_for_none}.interpolate(other, progress).ok())) + }, + (&T(None), &T(None)) => { + Ok(T(None)) + }, + } + } + } + diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index d1557ff70e8..383ea838031 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -445,26 +445,7 @@ ${helpers.single_keyword("text-align-last", #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct T(pub Option); - impl Interpolate for T { - #[inline] - fn interpolate(&self, other: &Self, progress: f64) -> Result { - match (self, other) { - (&T(Some(ref this)), &T(Some(ref other))) => { - Ok(T(this.interpolate(other, progress).ok())) - }, - (&T(Some(ref this)), &T(None)) => { - Ok(T(this.interpolate(&Au(0), progress).ok())) - }, - (&T(None), &T(Some(ref other))) => { - Ok(T(Au(0).interpolate(other, progress).ok())) - }, - (&T(None), &T(None)) => { - Ok(T(None)) - }, - } - } - } - + ${helpers.impl_interpolate_for_option_tuple('Au(0)')} } impl ToCss for computed_value::T {