mirror of
https://github.com/servo/servo.git
synced 2025-08-30 01:28:21 +01:00
Adding support for correct shorthand serialization
This commit is contained in:
parent
49431be44a
commit
3831c0650c
23 changed files with 1186 additions and 643 deletions
|
@ -13,34 +13,61 @@
|
|||
use properties::longhands::{text_decoration_color, text_decoration_line, text_decoration_style};
|
||||
use values::specified::CSSColor;
|
||||
|
||||
let (mut color, mut line, mut style, mut any) = (None, None, None, false);
|
||||
loop {
|
||||
macro_rules! parse_component {
|
||||
($value:ident, $module:ident) => (
|
||||
if $value.is_none() {
|
||||
if let Ok(value) = input.try(|input| $module::parse(context, input)) {
|
||||
$value = Some(value);
|
||||
any = true;
|
||||
continue;
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let (mut color, mut line, mut style, mut any) = (None, None, None, false);
|
||||
loop {
|
||||
macro_rules! parse_component {
|
||||
($value:ident, $module:ident) => (
|
||||
if $value.is_none() {
|
||||
if let Ok(value) = input.try(|input| $module::parse(context, input)) {
|
||||
$value = Some(value);
|
||||
any = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
parse_component!(color, text_decoration_color);
|
||||
parse_component!(line, text_decoration_line);
|
||||
parse_component!(style, text_decoration_style);
|
||||
break;
|
||||
}
|
||||
|
||||
parse_component!(color, text_decoration_color);
|
||||
parse_component!(line, text_decoration_line);
|
||||
parse_component!(style, text_decoration_style);
|
||||
break;
|
||||
if !any {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
Ok(Longhands {
|
||||
text_decoration_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor,
|
||||
authored: None })),
|
||||
text_decoration_line: line.or(Some(text_decoration_line::computed_value::none)),
|
||||
text_decoration_style: style.or(Some(text_decoration_style::computed_value::T::solid)),
|
||||
})
|
||||
}
|
||||
|
||||
if !any {
|
||||
return Err(());
|
||||
}
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self.text_decoration_line {
|
||||
DeclaredValue::Value(ref line) => {
|
||||
try!(line.to_css(dest));
|
||||
},
|
||||
_ => {
|
||||
try!(write!(dest, "none"));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Longhands {
|
||||
text_decoration_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor,
|
||||
authored: None })),
|
||||
text_decoration_line: line.or(Some(text_decoration_line::computed_value::none)),
|
||||
text_decoration_style: style.or(Some(text_decoration_style::computed_value::T::solid)),
|
||||
})
|
||||
if let DeclaredValue::Value(ref style) = *self.text_decoration_style {
|
||||
try!(write!(dest, " "));
|
||||
try!(style.to_css(dest));
|
||||
}
|
||||
|
||||
if let DeclaredValue::Value(ref color) = *self.text_decoration_color {
|
||||
try!(write!(dest, " "));
|
||||
try!(color.to_css(dest));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue