mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Derive ToComputedValue for SVGPaint
This commit is contained in:
parent
20a3b0236d
commit
1eb51daba6
2 changed files with 2 additions and 65 deletions
|
@ -255,7 +255,7 @@ impl ToCss for FontSettingTagFloat {
|
|||
///
|
||||
/// https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, ToAnimatedValue)]
|
||||
#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToComputedValue)]
|
||||
pub struct SVGPaint<ColorType> {
|
||||
/// The paint source
|
||||
pub kind: SVGPaintKind<ColorType>,
|
||||
|
@ -269,7 +269,7 @@ pub struct SVGPaint<ColorType> {
|
|||
/// to have a fallback, Gecko lets the context
|
||||
/// properties have a fallback as well.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToCss)]
|
||||
#[derive(Clone, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)]
|
||||
pub enum SVGPaintKind<ColorType> {
|
||||
/// `none`
|
||||
None,
|
||||
|
@ -283,35 +283,6 @@ pub enum SVGPaintKind<ColorType> {
|
|||
ContextStroke,
|
||||
}
|
||||
|
||||
impl<ColorType> SVGPaintKind<ColorType> {
|
||||
/// Convert to a value with a different kind of color
|
||||
pub fn convert<F, OtherColor>(&self, f: F) -> SVGPaintKind<OtherColor>
|
||||
where F: Fn(&ColorType) -> OtherColor {
|
||||
match *self {
|
||||
SVGPaintKind::None => SVGPaintKind::None,
|
||||
SVGPaintKind::ContextStroke => SVGPaintKind::ContextStroke,
|
||||
SVGPaintKind::ContextFill => SVGPaintKind::ContextFill,
|
||||
SVGPaintKind::Color(ref color) => {
|
||||
SVGPaintKind::Color(f(color))
|
||||
}
|
||||
SVGPaintKind::PaintServer(ref server) => {
|
||||
SVGPaintKind::PaintServer(server.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<ColorType> SVGPaint<ColorType> {
|
||||
/// Convert to a value with a different kind of color
|
||||
pub fn convert<F, OtherColor>(&self, f: F) -> SVGPaint<OtherColor>
|
||||
where F: Fn(&ColorType) -> OtherColor {
|
||||
SVGPaint {
|
||||
kind: self.kind.convert(&f),
|
||||
fallback: self.fallback.as_ref().map(|color| f(color))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<ColorType> SVGPaintKind<ColorType> {
|
||||
/// Parse a keyword value only
|
||||
fn parse_ident<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
|
|
|
@ -701,40 +701,6 @@ pub type SVGPaint = ::values::generics::SVGPaint<RGBAColor>;
|
|||
/// Specified SVG Paint Kind value
|
||||
pub type SVGPaintKind = ::values::generics::SVGPaintKind<RGBAColor>;
|
||||
|
||||
impl ToComputedValue for SVGPaint {
|
||||
type ComputedValue = super::computed::SVGPaint;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
super::computed::SVGPaint {
|
||||
kind: self.kind.to_computed_value(context),
|
||||
fallback: self.fallback.as_ref().map(|f| f.to_computed_value(context))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
SVGPaint {
|
||||
kind: ToComputedValue::from_computed_value(&computed.kind),
|
||||
fallback: computed.fallback.as_ref().map(ToComputedValue::from_computed_value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SVGPaintKind {
|
||||
type ComputedValue = super::computed::SVGPaintKind;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
self.convert(|color| color.to_computed_value(context))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
computed.convert(ToComputedValue::from_computed_value)
|
||||
}
|
||||
}
|
||||
|
||||
/// <length> | <percentage> | <number>
|
||||
pub type LengthOrPercentageOrNumber = Either<Number, LengthOrPercentage>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue