Bug 1356941 - Use IntermediateColor for box-shadow. r?birtles
MozReview-Commit-ID: 67AMYo3Ti8D
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -2155,16 +2155,87 @@ impl Interpolate for IntermediateRGBA {
let blue = try!((self.blue * self.alpha)
.interpolate(&(other.blue * other.alpha), progress))
* 1. / alpha;
Ok(IntermediateRGBA::new(red, green, blue, alpha))
}
}
}
+<%def name="impl_intermediate_type_for_shadow(type)">
+ #[derive(Copy, Clone, Debug, PartialEq)]
+ #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+ #[allow(missing_docs)]
+ /// Intermediate type for box-shadow and text-shadow.
+ /// The difference between normal shadow type is that this type uses
+ /// IntermediateColor instead of ParserColor.
+ pub struct Intermediate${type}Shadow {
+ pub offset_x: Au,
+ pub offset_y: Au,
+ pub blur_radius: Au,
+ pub color: IntermediateColor,
+ % if type == "Box":
+ pub spread_radius: Au,
+ pub inset: bool,
+ % endif
+ }
+
+ #[derive(Clone, Debug, PartialEq)]
+ #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+ #[allow(missing_docs)]
+ /// Intermediate type for box-shadow list and text-shadow list.
+ pub struct Intermediate${type}ShadowList(pub Vec<Intermediate${type}Shadow>);
+
+ impl <'a> From<<&'a Intermediate${type}ShadowList> for ${type}ShadowList {
+ fn from(shadow_list: &Intermediate${type}ShadowList) -> ${type}ShadowList {
+ ${type}ShadowList(shadow_list.0.iter().map(|s| s.into()).collect())
+ }
+ }
+
+ impl <'a> From<<&'a ${type}ShadowList> for Intermediate${type}ShadowList {
+ fn from(shadow_list: &${type}ShadowList) -> Intermediate${type}ShadowList {
+ Intermediate${type}ShadowList(shadow_list.0.iter().map(|s| s.into()).collect())
+ }
+ }
+
+ impl <'a> From<<&'a Intermediate${type}Shadow> for ${type}Shadow {
+ fn from(shadow: &Intermediate${type}Shadow) -> ${type}Shadow {
+ ${type}Shadow {
+ offset_x: shadow.offset_x,
+ offset_y: shadow.offset_y,
+ blur_radius: shadow.blur_radius,
+ color: (&shadow.color).into(),
+ % if type == "Box":
+ spread_radius: shadow.spread_radius,
+ inset: shadow.inset,
+ % endif
+ }
+ }
+ }
+
+ impl <'a> From<<&'a ${type}Shadow> for Intermediate${type}Shadow {
+ fn from(shadow: &${type}Shadow) -> Intermediate${type}Shadow {
+ Intermediate${type}Shadow {
+ offset_x: shadow.offset_x,
+ offset_y: shadow.offset_y,
+ blur_radius: shadow.blur_radius,
+ color: (&shadow.color).into(),
+ % if type == "Box":
+ spread_radius: shadow.spread_radius,
+ inset: shadow.inset,
+ % endif
+ }
+ }
+ }
+ ${impl_interpolate_for_shadow('Intermediate%sShadow' % type,
+ 'IntermediateColor::IntermediateRGBA(IntermediateRGBA::transparent())')}
+</%def>
+
+${impl_intermediate_type_for_shadow('Box')}
+
impl<'a> From<<&'a Either<CSSParserColor, Auto>> for Either<IntermediateColor, Auto> {
fn from(from: &Either<CSSParserColor, Auto>) -> Either<IntermediateColor, Auto> {
match *from {
Either::First(ref from) =>
match *from {
CSSParserColor::RGBA(ref color) =>
Either::First(IntermediateColor::IntermediateRGBA(
IntermediateRGBA::new(color.red_f32(),
--- a/servo/components/style/properties/longhand/effects.mako.rs
+++ b/servo/components/style/properties/longhand/effects.mako.rs
@@ -10,17 +10,18 @@
${helpers.predefined_type("opacity",
"Opacity",
"1.0",
animation_value_type="ComputedValue",
flags="CREATES_STACKING_CONTEXT",
spec="https://drafts.csswg.org/css-color/#opacity")}
<%helpers:vector_longhand name="box-shadow" allow_empty="True"
- animation_value_type="ComputedValue" extra_prefixes="webkit"
+ animation_value_type="IntermediateBoxShadowList"
+ extra_prefixes="webkit"
spec="https://drafts.csswg.org/css-backgrounds/#box-shadow">
use cssparser;
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
pub type SpecifiedValue = specified::Shadow;