mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +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 cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use std::fmt::{self, Write};
|
use style_traits::{ParseError, StyleParseErrorKind};
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
|
||||||
use values::{Either, None_};
|
use values::{Either, None_};
|
||||||
use values::computed::NumberOrPercentage;
|
use values::computed::NumberOrPercentage;
|
||||||
use values::computed::length::LengthOrPercentage;
|
use values::computed::length::LengthOrPercentage;
|
||||||
|
@ -199,41 +198,16 @@ pub enum SVGLength<LengthType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generic value for stroke-dasharray.
|
/// Generic value for stroke-dasharray.
|
||||||
#[derive(Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq, ToAnimatedValue,
|
#[derive(Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)]
|
||||||
ToComputedValue)]
|
#[derive(ToAnimatedValue, ToComputedValue, ToCss)]
|
||||||
pub enum SVGStrokeDashArray<LengthType> {
|
pub enum SVGStrokeDashArray<LengthType> {
|
||||||
/// `[ <length> | <percentage> | <number> ]#`
|
/// `[ <length> | <percentage> | <number> ]#`
|
||||||
Values(Vec<LengthType>),
|
#[css(comma)]
|
||||||
|
Values(#[css(if_empty = "none", iterable)] Vec<LengthType>),
|
||||||
/// `context-value`
|
/// `context-value`
|
||||||
ContextValue,
|
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
|
/// An SVG opacity value accepts `context-{fill,stroke}-opacity` in
|
||||||
/// addition to opacity value.
|
/// addition to opacity value.
|
||||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
|
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue