From 769129f5c23dcd86a34ea6a2ae6311875bb80e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Sat, 22 Oct 2016 01:37:52 +0300 Subject: [PATCH] Add gecko glue for text-emphasis-style --- components/style/properties/gecko.mako.rs | 51 +++++++++++++++- .../longhand/inherited_text.mako.rs | 58 +++++++++++-------- .../style/properties/properties.mako.rs | 2 +- 3 files changed, 86 insertions(+), 25 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 24602685308d..52e547640bed 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1573,7 +1573,7 @@ fn static_assert() { <%self:impl_trait style_struct_name="InheritedText" - skip_longhands="text-align text-shadow line-height letter-spacing word-spacing"> + skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing"> <% text_align_keyword = Keyword("text-align", "start end left right center justify -moz-center -moz-left " + "-moz-right match-parent") %> @@ -1671,6 +1671,55 @@ fn static_assert() { <%call expr="impl_coord_copy('word_spacing', 'mWordSpacing')"> + fn clear_text_emphasis_style_if_string(&mut self) { + use nsstring::nsString; + if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING as u8 { + self.gecko.mTextEmphasisStyleString.assign(&nsString::new()); + self.gecko.mTextEmphasisStyle = structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE as u8; + } + } + + pub fn set_text_emphasis_style(&mut self, v: longhands::text_emphasis_style::computed_value::T) { + use nsstring::nsCString; + use properties::longhands::text_emphasis_style::computed_value::T; + use properties::longhands::text_emphasis_style::ShapeKeyword; + + self.clear_text_emphasis_style_if_string(); + let (te, s) = match v { + T::None => (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE, ""), + T::Keyword(ref keyword) => { + let fill = if keyword.fill { + structs::NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED + } else { + structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN + }; + let shape = match keyword.shape { + ShapeKeyword::Dot => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT, + ShapeKeyword::Circle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE, + ShapeKeyword::DoubleCircle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE, + ShapeKeyword::Triangle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE, + ShapeKeyword::Sesame => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME, + }; + + (shape | fill, keyword.shape.char(keyword.fill)) + }, + T::String(ref s) => { + (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING, &**s) + }, + }; + self.gecko.mTextEmphasisStyleString.assign_utf8(&nsCString::from(s)); + self.gecko.mTextEmphasisStyle = te as u8; + } + + pub fn copy_text_emphasis_style_from(&mut self, other: &Self) { + self.clear_text_emphasis_style_if_string(); + if other.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING as u8 { + self.gecko.mTextEmphasisStyleString + .assign(&other.gecko.mTextEmphasisStyleString) + } + self.gecko.mTextEmphasisStyle = other.gecko.mTextEmphasisStyle; + } + <%self:impl_trait style_struct_name="Text" diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 0a6e1266b592..535486ea48ed 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -737,7 +737,7 @@ ${helpers.single_keyword("text-align-last", } -<%helpers:longhand name="text-emphasis-style" products="none" animatable="False"> +<%helpers:longhand name="text-emphasis-style" products="gecko" need_clone="True" animatable="False"> use computed_values::writing_mode::T as writing_mode; use cssparser::ToCss; use std::fmt; @@ -836,6 +836,18 @@ ${helpers.single_keyword("text-align-last", "triangle" => Triangle, "sesame" => Sesame); + impl ShapeKeyword { + pub fn char(&self, fill: bool) -> &str { + match *self { + ShapeKeyword::Dot => if fill { "\u{2022}" } else { "\u{25e6}" }, + ShapeKeyword::Circle => if fill { "\u{25cf}" } else { "\u{25cb}" }, + ShapeKeyword::DoubleCircle => if fill { "\u{25c9}" } else { "\u{25ce}" }, + ShapeKeyword::Triangle => if fill { "\u{25b2}" } else { "\u{25b3}" }, + ShapeKeyword::Sesame => if fill { "\u{fe45}" } else { "\u{fe46}" }, + } + } + } + #[inline] pub fn get_initial_value() -> computed_value::T { computed_value::T::None @@ -849,7 +861,7 @@ ${helpers.single_keyword("text-align-last", match *self { SpecifiedValue::Keyword(ref keyword) => { let default_shape = if context.style().get_inheritedbox() - .writing_mode == writing_mode::horizontal_tb { + .clone_writing_mode() == writing_mode::horizontal_tb { ShapeKeyword::Circle } else { ShapeKeyword::Sesame @@ -888,28 +900,28 @@ ${helpers.single_keyword("text-align-last", if let Ok(s) = input.try(|input| input.expect_string()) { // Handle - Ok(SpecifiedValue::String(s.into_owned())) + return Ok(SpecifiedValue::String(s.into_owned())); + } + + // Handle a pair of keywords + let mut shape = input.try(ShapeKeyword::parse); + let fill = if input.try(|input| input.expect_ident_matching("filled")).is_ok() { + Some(true) + } else if input.try(|input| input.expect_ident_matching("open")).is_ok() { + Some(false) + } else { None }; + if let Err(_) = shape { + shape = input.try(ShapeKeyword::parse); + } + + // At least one of shape or fill must be handled + if let (None, Err(_)) = (fill, shape) { + Err(()) } else { - // Handle a pair of keywords - let mut shape = input.try(ShapeKeyword::parse); - let fill = if input.try(|input| input.expect_ident_matching("filled")).is_ok() { - Some(true) - } else if input.try(|input| input.expect_ident_matching("open")).is_ok() { - Some(false) - } else { None }; - if let Err(_) = shape { - shape = input.try(ShapeKeyword::parse); - } - - // At least one of shape or fill must be handled - if let (None, Err(_)) = (fill, shape) { - Err(()) - } else { - Ok(SpecifiedValue::Keyword(Keyword { - fill: fill, - shape: shape.ok() - })) - } + Ok(SpecifiedValue::Keyword(Keyword { + fill: fill, + shape: shape.ok() + })) } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index b8f0d4ebd9fb..bfa7c7e9edf4 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1640,7 +1640,7 @@ pub fn cascade(viewport_size: Size2D, PropertyDeclaration::Position(_) | PropertyDeclaration::Float(_) | PropertyDeclaration::TextDecoration${'' if product == 'servo' else 'Line'}(_) | - PropertyDeclaration::TextEmphasisStyle(_) + PropertyDeclaration::WritingMode(_) ); if % if category_to_cascade_now == "early":