Simplify machinery to serialise optional parts of CSS values

We simply implement ToCss for Option<T>, printing nothing if the value is None,
and we then use SequenceWriter to skip writing of separators around empty parts.
This commit is contained in:
Anthony Ramine 2017-06-21 10:15:31 +02:00
parent cedd5222d2
commit 39e29f557e
8 changed files with 152 additions and 131 deletions

View file

@ -6,13 +6,9 @@
use cssparser::{BasicParseError, Parser, Token};
use parser::{Parse, ParserContext};
#[cfg(feature = "gecko")]
use std::fmt;
use style_traits::ParseError;
#[cfg(not(feature = "gecko"))]
use style_traits::StyleParseError;
#[cfg(feature = "gecko")]
use style_traits::ToCss;
use values::computed::{Context, Number as ComputedNumber, ToComputedValue};
use values::computed::effects::DropShadow as ComputedDropShadow;
use values::generics::effects::Filter as GenericFilter;
@ -55,7 +51,7 @@ pub enum DropShadow {}
/// Contrary to the canonical order from the spec, the color is serialised
/// first, like in Gecko's computed values and in all Webkit's values.
#[cfg(feature = "gecko")]
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
pub struct DropShadow {
/// Color.
pub color: Option<Color>,
@ -220,25 +216,3 @@ impl ToComputedValue for DropShadow {
}
}
}
#[cfg(feature = "gecko")]
impl ToCss for DropShadow {
#[inline]
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
if let Some(ref color) = self.color {
color.to_css(dest)?;
dest.write_str(" ")?;
}
self.horizontal.to_css(dest)?;
dest.write_str(" ")?;
self.vertical.to_css(dest)?;
if let Some(ref blur) = self.blur {
dest.write_str(" ")?;
blur.to_css(dest)?;
}
Ok(())
}
}