Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add gecko glue for text-emphasis-style
  • Loading branch information
canova committed Oct 22, 2016
1 parent 6102159 commit 769129f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 25 deletions.
51 changes: 50 additions & 1 deletion components/style/properties/gecko.mako.rs
Expand Up @@ -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") %>
Expand Down Expand Up @@ -1671,6 +1671,55 @@ fn static_assert() {

<%call expr="impl_coord_copy('word_spacing', 'mWordSpacing')"></%call>

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>

<%self:impl_trait style_struct_name="Text"
Expand Down
58 changes: 35 additions & 23 deletions components/style/properties/longhand/inherited_text.mako.rs
Expand Up @@ -737,7 +737,7 @@ ${helpers.single_keyword("text-align-last",
}
</%helpers:longhand>

<%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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -888,28 +900,28 @@ ${helpers.single_keyword("text-align-last",

if let Ok(s) = input.try(|input| input.expect_string()) {
// Handle <string>
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()
}))
}
}
</%helpers:longhand>
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/properties.mako.rs
Expand Up @@ -1640,7 +1640,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
PropertyDeclaration::Position(_) |
PropertyDeclaration::Float(_) |
PropertyDeclaration::TextDecoration${'' if product == 'servo' else 'Line'}(_) |
PropertyDeclaration::TextEmphasisStyle(_)
PropertyDeclaration::WritingMode(_)
);
if
% if category_to_cascade_now == "early":
Expand Down

0 comments on commit 769129f

Please sign in to comment.