mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Derive ToCss for SVGStrokeDashArray<T>
This commit is contained in:
parent
36db6f9cdd
commit
2074e8902a
1 changed files with 5 additions and 31 deletions
|
@ -6,8 +6,7 @@
|
|||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use values::{Either, None_};
|
||||
use values::computed::NumberOrPercentage;
|
||||
use values::computed::length::LengthOrPercentage;
|
||||
|
@ -199,41 +198,16 @@ pub enum SVGLength<LengthType> {
|
|||
}
|
||||
|
||||
/// Generic value for stroke-dasharray.
|
||||
#[derive(Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq, ToAnimatedValue,
|
||||
ToComputedValue)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)]
|
||||
#[derive(ToAnimatedValue, ToComputedValue, ToCss)]
|
||||
pub enum SVGStrokeDashArray<LengthType> {
|
||||
/// `[ <length> | <percentage> | <number> ]#`
|
||||
Values(Vec<LengthType>),
|
||||
#[css(comma)]
|
||||
Values(#[css(if_empty = "none", iterable)] Vec<LengthType>),
|
||||
/// `context-value`
|
||||
ContextValue,
|
||||
}
|
||||
|
||||
impl<LengthType> ToCss for SVGStrokeDashArray<LengthType> where LengthType: ToCss {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match self {
|
||||
&SVGStrokeDashArray::Values(ref values) => {
|
||||
let mut iter = values.iter();
|
||||
if let Some(first) = iter.next() {
|
||||
first.to_css(dest)?;
|
||||
for item in iter {
|
||||
dest.write_str(", ")?;
|
||||
item.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
dest.write_str("none")
|
||||
}
|
||||
}
|
||||
&SVGStrokeDashArray::ContextValue => {
|
||||
dest.write_str("context-value")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An SVG opacity value accepts `context-{fill,stroke}-opacity` in
|
||||
/// addition to opacity value.
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue