From 852fdca1c5c849ba9b3fd389cfba3bddb5e5fba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Mon, 21 Nov 2016 23:05:59 +0300 Subject: [PATCH] Implement parsing/serialization of text-emphasis-color and text-emphasis --- .../longhand/inherited_text.mako.rs | 11 ++++ .../shorthand/inherited_text.mako.rs | 57 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index d08d5b1dd0c8..7ac54b042226 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -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", } +// 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", diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index 64ef03b11388..570c41e5e307 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -21,3 +21,60 @@ } } + +// 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 { + 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(&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(()) + } + } +