mirror of
https://github.com/servo/servo.git
synced 2025-08-24 06:45:33 +01:00
Introduce ComputeSquaredDistance
This allows us to merge the former Animatable methods compute_distance and compute_squared_distance, reducing code size.
This commit is contained in:
parent
b14e68f915
commit
51b740033b
21 changed files with 641 additions and 551 deletions
|
@ -6,8 +6,10 @@
|
|||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use properties::animated_properties::RepeatableListAnimatable;
|
||||
use std::fmt;
|
||||
use style_traits::{ParseError, StyleParseError, ToCss};
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
|
||||
/// An SVG paint value
|
||||
///
|
||||
|
@ -105,6 +107,25 @@ pub enum SVGLength<LengthType> {
|
|||
ContextValue,
|
||||
}
|
||||
|
||||
impl<L> ComputeSquaredDistance for SVGLength<L>
|
||||
where
|
||||
L: ComputeSquaredDistance,
|
||||
{
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
match (self, other) {
|
||||
(&SVGLength::Length(ref this), &SVGLength::Length(ref other)) => {
|
||||
this.compute_squared_distance(other)
|
||||
},
|
||||
_ => {
|
||||
// FIXME(nox): Should this return `Ok(SquaredDistance::Value(0.))`
|
||||
// if `self` and `other` are the same keyword value?
|
||||
Err(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generic value for stroke-dasharray.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, HasViewportPercentage, ToAnimatedValue, ToComputedValue)]
|
||||
|
@ -115,6 +136,25 @@ pub enum SVGStrokeDashArray<LengthType> {
|
|||
ContextValue,
|
||||
}
|
||||
|
||||
impl<L> ComputeSquaredDistance for SVGStrokeDashArray<L>
|
||||
where
|
||||
L: ComputeSquaredDistance + RepeatableListAnimatable,
|
||||
{
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
match (self, other) {
|
||||
(&SVGStrokeDashArray::Values(ref this), &SVGStrokeDashArray::Values(ref other)) => {
|
||||
this.compute_squared_distance(other)
|
||||
},
|
||||
_ => {
|
||||
// FIXME(nox): Should this return `Ok(SquaredDistance::Value(0.))`
|
||||
// if `self` and `other` are the same keyword value?
|
||||
Err(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<LengthType> ToCss for SVGStrokeDashArray<LengthType> where LengthType: ToCss {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self {
|
||||
|
@ -150,3 +190,22 @@ pub enum SVGOpacity<OpacityType> {
|
|||
/// `context-stroke-opacity`
|
||||
ContextStrokeOpacity,
|
||||
}
|
||||
|
||||
impl<L> ComputeSquaredDistance for SVGOpacity<L>
|
||||
where
|
||||
L: ComputeSquaredDistance,
|
||||
{
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
match (self, other) {
|
||||
(&SVGOpacity::Opacity(ref this), &SVGOpacity::Opacity(ref other)) => {
|
||||
this.compute_squared_distance(other)
|
||||
}
|
||||
_ => {
|
||||
// FIXME(nox): Should this return `Ok(SquaredDistance::Value(0.))`
|
||||
// if `self` and `other` are the same keyword value?
|
||||
Err(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue