mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Make SVGPaint generic
This commit is contained in:
parent
9987cb159f
commit
74f3284c69
4 changed files with 148 additions and 178 deletions
|
@ -532,23 +532,15 @@ impl IntegerOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// An SVG paint value
|
||||
///
|
||||
/// https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SVGPaint {
|
||||
/// The paint source
|
||||
pub kind: SVGPaintKind,
|
||||
/// The fallback color
|
||||
pub fallback: Option<CSSColor>,
|
||||
}
|
||||
/// Computed SVG Paint value
|
||||
pub type SVGPaint = ::values::generics::SVGPaint<CSSColor>;
|
||||
/// Computed SVG Paint Kind value
|
||||
pub type SVGPaintKind = ::values::generics::SVGPaintKind<CSSColor>;
|
||||
|
||||
impl Default for SVGPaint {
|
||||
fn default() -> Self {
|
||||
SVGPaint {
|
||||
kind: SVGPaintKind::None,
|
||||
kind: ::values::generics::SVGPaintKind::None,
|
||||
fallback: None,
|
||||
}
|
||||
}
|
||||
|
@ -559,54 +551,12 @@ impl SVGPaint {
|
|||
pub fn black() -> Self {
|
||||
let rgba = RGBA::from_floats(0., 0., 0., 1.);
|
||||
SVGPaint {
|
||||
kind: SVGPaintKind::Color(CSSColor::RGBA(rgba)),
|
||||
kind: ::values::generics::SVGPaintKind::Color(CSSColor::RGBA(rgba)),
|
||||
fallback: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An SVG paint value without the fallback
|
||||
///
|
||||
/// Whereas the spec only allows PaintServer
|
||||
/// to have a fallback, Gecko lets the context
|
||||
/// properties have a fallback as well.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SVGPaintKind {
|
||||
/// `none`
|
||||
None,
|
||||
/// `<color>`
|
||||
Color(CSSColor),
|
||||
/// `url(...)`
|
||||
PaintServer(SpecifiedUrl),
|
||||
/// `context-fill`
|
||||
ContextFill,
|
||||
/// `context-stroke`
|
||||
ContextStroke,
|
||||
}
|
||||
|
||||
impl ToCss for SVGPaintKind {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SVGPaintKind::None => dest.write_str("none"),
|
||||
SVGPaintKind::ContextStroke => dest.write_str("context-stroke"),
|
||||
SVGPaintKind::ContextFill => dest.write_str("context-fill"),
|
||||
SVGPaintKind::Color(ref color) => color.to_css(dest),
|
||||
SVGPaintKind::PaintServer(ref server) => server.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SVGPaint {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.kind.to_css(dest)?;
|
||||
if let Some(ref fallback) = self.fallback {
|
||||
fallback.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// <length> | <percentage> | <number>
|
||||
pub type LengthOrPercentageOrNumber = Either<Number, LengthOrPercentage>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue