Navigation Menu

Skip to content

Commit

Permalink
Implement parsing/serialization of text-emphasis-color and text-emphasis
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Nov 22, 2016
1 parent 61431b7 commit 852fdca
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions components/style/properties/longhand/inherited_text.mako.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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",
Expand Down
57 changes: 57 additions & 0 deletions components/style/properties/shorthand/inherited_text.mako.rs
Expand Up @@ -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>

0 comments on commit 852fdca

Please sign in to comment.