Implement parsing/serialization of text-emphasis-color and text-emphasis

This commit is contained in:
Nazım Can Altınova 2016-11-21 23:05:59 +03:00
parent 61431b7fd6
commit 852fdca1c5
2 changed files with 68 additions and 0 deletions

View file

@ -866,6 +866,11 @@ ${helpers.single_keyword("text-align-last",
computed_value::T::None
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::None
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -985,6 +990,12 @@ ${helpers.single_keyword("text-align-last",
}
</%helpers:longhand>
// https://drafts.csswg.org/css-text-decor-3/#text-emphasis-color-property
${helpers.predefined_type("text-emphasis-color", "CSSColor",
"::cssparser::Color::CurrentColor",
products="gecko",animatable=True,
complex_color=True, need_clone=True)}
// TODO(pcwalton): `full-width`
${helpers.single_keyword("text-transform",
"none capitalize uppercase lowercase",

View file

@ -21,3 +21,60 @@
}
}
</%helpers:shorthand>
// https://drafts.csswg.org/css-text-decor-3/#text-emphasis-property
<%helpers:shorthand name="text-emphasis" products="gecko" sub_properties="text-emphasis-color
text-emphasis-style">
use properties::longhands::{text_emphasis_color, text_emphasis_style};
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let mut color = None;
let mut style = None;
loop {
if color.is_none() {
if let Ok(value) = input.try(|input| text_emphasis_color::parse(context, input)) {
color = Some(value);
continue
}
}
if style.is_none() {
if let Ok(value) = input.try(|input| text_emphasis_style::parse(context, input)) {
style = Some(value);
continue
}
}
break
}
if color.is_some() || style.is_some() {
if style.is_none() {
style = Some(text_emphasis_style::get_initial_specified_value());
}
Ok(Longhands {
text_emphasis_color: color,
text_emphasis_style: style,
})
} else {
Err(())
}
}
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut style_present = false;
if let DeclaredValue::Value(ref value) = *self.text_emphasis_style {
style_present = true;
try!(value.to_css(dest));
}
if let DeclaredValue::Value(ref color) = *self.text_emphasis_color {
if style_present {
try!(write!(dest, " "));
}
try!(color.to_css(dest));
}
Ok(())
}
}
</%helpers:shorthand>