diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-06-06 00:12:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-06 00:12:51 -0700 |
commit | 2da8eb0342f6701b5365116b96113c83a1599b1f (patch) | |
tree | ac1192ac4299bca4804a32c0c4b3f623faaf6b20 | |
parent | eaa01223a7add99ce4cc241b686100856b7594d6 (diff) | |
parent | 3cd48d5b1a2a3c081b972dff299ff614f3f0883d (diff) | |
download | servo-2da8eb0342f6701b5365116b96113c83a1599b1f.tar.gz servo-2da8eb0342f6701b5365116b96113c83a1599b1f.zip |
Auto merge of #17180 - Manishearth:stylo-fill-stroke, r=birtles
stylo: Animate fill and stroke
r=birtles https://bugzilla.mozilla.org/show_bug.cgi?id=1369277
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17180)
<!-- Reviewable:end -->
-rw-r--r-- | components/style/properties/gecko.mako.rs | 29 | ||||
-rw-r--r-- | components/style/properties/helpers/animated_properties.mako.rs | 70 | ||||
-rw-r--r-- | components/style/properties/longhand/inherited_svg.mako.rs | 4 |
3 files changed, 101 insertions, 2 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 3328e682f1c..2186967279a 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -461,6 +461,35 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor { ); } } + + #[allow(non_snake_case)] + pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { + use values::generics::{SVGPaint, SVGPaintKind}; + use self::structs::nsStyleSVGPaintType; + use self::structs::nsStyleSVGFallbackType; + let ref paint = ${get_gecko_property(gecko_ffi_name)}; + let fallback = if let nsStyleSVGFallbackType::eStyleSVGFallbackType_Color = paint.mFallbackType { + Some(Color::RGBA(convert_nscolor_to_rgba(paint.mFallbackColor))) + } else { + None + }; + let kind = match paint.mType { + nsStyleSVGPaintType::eStyleSVGPaintType_None => SVGPaintKind::None, + nsStyleSVGPaintType::eStyleSVGPaintType_ContextFill => SVGPaintKind::ContextFill, + nsStyleSVGPaintType::eStyleSVGPaintType_ContextStroke => SVGPaintKind::ContextStroke, + nsStyleSVGPaintType::eStyleSVGPaintType_Server => { + // FIXME (bug 1353966) this should animate + SVGPaintKind::None + } + nsStyleSVGPaintType::eStyleSVGPaintType_Color => { + unsafe { SVGPaintKind::Color(Color::RGBA(convert_nscolor_to_rgba(*paint.mPaint.mColor.as_ref()))) } + } + }; + SVGPaint { + kind: kind, + fallback: fallback, + } + } </%def> <%def name="impl_app_units(ident, gecko_ffi_name, need_clone, inherit_from=None, round_to_pixels=False)"> diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index e76c0caabbb..f018967fb9a 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -42,6 +42,7 @@ use values::computed::{BorderCornerRadius, ClipRect}; use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage}; use values::computed::{MaxLength, MozLength}; use values::computed::ToComputedValue; +use values::generics::{SVGPaint, SVGPaintKind}; use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius; use values::generics::position as generic_position; @@ -2849,6 +2850,75 @@ impl From<IntermediateColor> for CSSParserColor { } } +/// Animatable SVGPaint +pub type IntermediateSVGPaint = SVGPaint<IntermediateColor>; +/// Animatable SVGPaintKind +pub type IntermediateSVGPaintKind = SVGPaintKind<IntermediateColor>; + +impl From<::values::computed::SVGPaint> for IntermediateSVGPaint { + fn from(paint: ::values::computed::SVGPaint) -> IntermediateSVGPaint { + paint.convert(|color| (*color).into()) + } +} + +impl From<IntermediateSVGPaint> for ::values::computed::SVGPaint { + fn from(paint: IntermediateSVGPaint) -> ::values::computed::SVGPaint { + paint.convert(|color| (*color).into()) + } +} + + +impl Animatable for IntermediateSVGPaint { + #[inline] + fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { + Ok(IntermediateSVGPaint { + kind: self.kind.add_weighted(&other.kind, self_portion, other_portion)?, + fallback: self.fallback.add_weighted(&other.fallback, self_portion, other_portion)?, + }) + } + + #[inline] + fn compute_distance(&self, other: &Self) -> Result<f64, ()> { + self.compute_squared_distance(other).map(|sq| sq.sqrt()) + } + + #[inline] + fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { + Ok(self.kind.compute_squared_distance(&other.kind)? + + self.fallback.compute_squared_distance(&other.fallback)?) + } +} + +impl Animatable for IntermediateSVGPaintKind { + #[inline] + fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { + match (self, other) { + (&SVGPaintKind::Color(ref self_color), &SVGPaintKind::Color(ref other_color)) => { + Ok(SVGPaintKind::Color(self_color.add_weighted(other_color, self_portion, other_portion)?)) + } + // FIXME context values should be interpolable with colors + // Gecko doesn't implement this behavior either. + (&SVGPaintKind::None, &SVGPaintKind::None) => Ok(SVGPaintKind::None), + (&SVGPaintKind::ContextFill, &SVGPaintKind::ContextFill) => Ok(SVGPaintKind::ContextFill), + (&SVGPaintKind::ContextStroke, &SVGPaintKind::ContextStroke) => Ok(SVGPaintKind::ContextStroke), + _ => Err(()) + } + } + + #[inline] + fn compute_distance(&self, other: &Self) -> Result<f64, ()> { + match (self, other) { + (&SVGPaintKind::Color(ref self_color), &SVGPaintKind::Color(ref other_color)) => { + self_color.compute_distance(other_color) + } + (&SVGPaintKind::None, &SVGPaintKind::None) | + (&SVGPaintKind::ContextFill, &SVGPaintKind::ContextFill) | + (&SVGPaintKind::ContextStroke, &SVGPaintKind::ContextStroke)=> Ok(0.0), + _ => Err(()) + } + } +} + <%def name="impl_intermediate_type_for_shadow(type)"> #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs index 2dfa696c2dc..4c57a13f43c 100644 --- a/components/style/properties/longhand/inherited_svg.mako.rs +++ b/components/style/properties/longhand/inherited_svg.mako.rs @@ -35,7 +35,7 @@ ${helpers.predefined_type( "fill", "SVGPaint", "::values::computed::SVGPaint::black()", products="gecko", - animation_value_type="none", + animation_value_type="IntermediateSVGPaint", boxed=True, spec="https://www.w3.org/TR/SVG2/painting.html#SpecifyingFillPaint")} @@ -59,7 +59,7 @@ ${helpers.predefined_type( "stroke", "SVGPaint", "Default::default()", products="gecko", - animation_value_type="none", + animation_value_type="IntermediateSVGPaint", boxed=True, spec="https://www.w3.org/TR/SVG2/painting.html#SpecifyingStrokePaint")} |