Add context-{fill,stroke}-opacity support to {fill,stroke}-opacity.

This commit is contained in:
Xidorn Quan 2017-08-02 09:27:49 +10:00
parent 7827ca6bb5
commit ef4352d2a5
8 changed files with 149 additions and 7 deletions

View file

@ -46,7 +46,7 @@ use values::computed::{LengthOrPercentage, MaxLength, MozLength, Percentage, ToC
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
use values::generics::effects::Filter;
use values::generics::position as generic_position;
use values::generics::svg::{SVGLength, SVGPaint, SVGPaintKind, SVGStrokeDashArray};
use values::generics::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray};
/// A trait used to implement various procedures used during animation.
pub trait Animatable: Sized {
@ -3116,6 +3116,45 @@ impl<LengthType> ToAnimatedZero for SVGStrokeDashArray<LengthType>
}
}
impl<OpacityType> Animatable for SVGOpacity<OpacityType>
where OpacityType: Animatable + Clone
{
#[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
match (self, other) {
(&SVGOpacity::Opacity(ref this), &SVGOpacity::Opacity(ref other)) => {
this.add_weighted(other, self_portion, other_portion).map(SVGOpacity::Opacity)
}
_ => {
Ok(if self_portion > other_portion { self.clone() } else { other.clone() })
}
}
}
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (self, other) {
(&SVGOpacity::Opacity(ref this), &SVGOpacity::Opacity(ref other)) => {
this.compute_distance(other)
}
_ => Err(())
}
}
}
impl<OpacityType> ToAnimatedZero for SVGOpacity<OpacityType>
where OpacityType: ToAnimatedZero + Clone
{
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
match self {
&SVGOpacity::Opacity(ref opacity) =>
opacity.to_animated_zero().map(SVGOpacity::Opacity),
other => Ok(other.clone()),
}
}
}
<%
FILTER_FUNCTIONS = [ 'Blur', 'Brightness', 'Contrast', 'Grayscale',
'HueRotate', 'Invert', 'Opacity', 'Saturate',