mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add serialize_four_sides, use for serializing BorderRadius
This commit is contained in:
parent
c6feae3c5c
commit
d1e45f78af
5 changed files with 110 additions and 27 deletions
|
@ -73,7 +73,8 @@ pub mod longhands {
|
|||
}
|
||||
|
||||
pub mod shorthands {
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ToCss};
|
||||
use std::fmt;
|
||||
use parser::ParserContext;
|
||||
use values::specified;
|
||||
|
||||
|
@ -120,6 +121,33 @@ pub mod shorthands {
|
|||
Ok((top, right, bottom, left))
|
||||
}
|
||||
|
||||
/// Serialize a set of top,left,bottom,right values, in <margin>-shorthand style,
|
||||
/// attempting to minimize the output
|
||||
pub fn serialize_four_sides<T, W>(sides: (&T, &T, &T, &T), dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write, T: ToCss+PartialEq {
|
||||
if sides.0 == sides.1 && sides.0 == sides.2 && sides.0 == sides.3 {
|
||||
sides.0.to_css(dest)
|
||||
} else if sides.0 == sides.2 && sides.1 == sides.3 {
|
||||
try!(sides.0.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
sides.1.to_css(dest)
|
||||
} else if sides.1 == sides.3 {
|
||||
try!(sides.0.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(sides.1.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
sides.2.to_css(dest)
|
||||
} else {
|
||||
try!(sides.0.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(sides.1.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(sides.2.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
sides.3.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
<%include file="/shorthand/background.mako.rs" />
|
||||
<%include file="/shorthand/border.mako.rs" />
|
||||
<%include file="/shorthand/box.mako.rs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue