mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
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:
parent
cedd5222d2
commit
39e29f557e
8 changed files with 152 additions and 131 deletions
|
@ -27,7 +27,7 @@ pub type VerticalPosition = PositionComponent<Y>;
|
|||
|
||||
/// The specified value of a component of a CSS `<position>`.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||
pub enum PositionComponent<S> {
|
||||
/// `center`
|
||||
Center,
|
||||
|
@ -197,27 +197,6 @@ impl<S> PositionComponent<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: ToCss> ToCss for PositionComponent<S> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
PositionComponent::Center => {
|
||||
dest.write_str("center")
|
||||
},
|
||||
PositionComponent::Length(ref lop) => {
|
||||
lop.to_css(dest)
|
||||
},
|
||||
PositionComponent::Side(ref keyword, ref lop) => {
|
||||
keyword.to_css(dest)?;
|
||||
if let Some(ref lop) = *lop {
|
||||
dest.write_str(" ")?;
|
||||
lop.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Side> ToComputedValue for PositionComponent<S> {
|
||||
type ComputedValue = ComputedLengthOrPercentage;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue