diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 680dd340869..1f3e862df49 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2578,97 +2578,15 @@ fn static_assert() { <%self:impl_trait style_struct_name="InheritedText" - skip_longhands="text-align text-emphasis-style - -webkit-text-stroke-width text-emphasis-position"> + skip_longhands="text-align -webkit-text-stroke-width text-emphasis-position"> <% text_align_keyword = Keyword("text-align", "start end left right center justify -moz-center -moz-left -moz-right char", gecko_strip_moz_prefix=False) %> ${impl_keyword('text_align', 'mTextAlign', text_align_keyword)} - fn clear_text_emphasis_style_if_string(&mut self) { - if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING as u8 { - self.gecko.mTextEmphasisStyleString.truncate(); - self.gecko.mTextEmphasisStyle = structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE as u8; - } - } - ${impl_simple_type_with_conversion("text_emphasis_position")} - pub fn set_text_emphasis_style(&mut self, v: values::computed::TextEmphasisStyle) { - use crate::values::computed::TextEmphasisStyle; - use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword}; - - self.clear_text_emphasis_style_if_string(); - let (te, s) = match v { - TextEmphasisStyle::None => (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE, ""), - TextEmphasisStyle::Keyword { fill, shape } => { - let gecko_fill = match fill { - TextEmphasisFillMode::Filled => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED, - TextEmphasisFillMode::Open => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN, - }; - - let gecko_shape = match shape { - TextEmphasisShapeKeyword::Dot => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT, - TextEmphasisShapeKeyword::Circle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE, - TextEmphasisShapeKeyword::DoubleCircle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE, - TextEmphasisShapeKeyword::Triangle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE, - TextEmphasisShapeKeyword::Sesame => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME, - }; - - (gecko_shape | gecko_fill, shape.char(fill)) - }, - TextEmphasisStyle::String(ref s) => { - (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING, &**s) - }, - }; - self.gecko.mTextEmphasisStyleString.assign_str(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; - } - - pub fn reset_text_emphasis_style(&mut self, other: &Self) { - self.copy_text_emphasis_style_from(other) - } - - pub fn clone_text_emphasis_style(&self) -> values::computed::TextEmphasisStyle { - use crate::values::computed::TextEmphasisStyle; - use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword}; - - if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE as u8 { - return TextEmphasisStyle::None; - } - - if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING as u8 { - return TextEmphasisStyle::String(self.gecko.mTextEmphasisStyleString.to_string().into()); - } - - let fill = - self.gecko.mTextEmphasisStyle & structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN as u8 == 0; - - let fill = if fill { TextEmphasisFillMode::Filled } else { TextEmphasisFillMode::Open }; - - let shape = - match self.gecko.mTextEmphasisStyle as u32 & !structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN { - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT => TextEmphasisShapeKeyword::Dot, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE => TextEmphasisShapeKeyword::Circle, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE => TextEmphasisShapeKeyword::DoubleCircle, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE => TextEmphasisShapeKeyword::Triangle, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME => TextEmphasisShapeKeyword::Sesame, - _ => panic!("Unexpected value in style struct for text-emphasis-style property") - }; - - TextEmphasisStyle::Keyword { fill, shape } - } - ${impl_non_negative_length('_webkit_text_stroke_width', 'mWebkitTextStrokeWidth')} diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 343d5f31f09..d2a619a3a20 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -195,8 +195,11 @@ impl TextDecorationsInEffect { } /// Computed value for the text-emphasis-style property +/// +/// cbindgen:derive-tagged-enum-copy-constructor=true #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue)] #[allow(missing_docs)] +#[repr(C, u8)] pub enum TextEmphasisStyle { /// [ || ] Keyword { diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index feb1b2124c7..f780715443c 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -671,6 +671,7 @@ pub enum TextEmphasisStyle { /// Fill mode for the text-emphasis-style property #[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] +#[repr(u8)] pub enum TextEmphasisFillMode { /// `filled` Filled, @@ -690,6 +691,7 @@ impl TextEmphasisFillMode { #[derive( Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, )] +#[repr(u8)] pub enum TextEmphasisShapeKeyword { /// `dot` Dot, @@ -703,50 +705,6 @@ pub enum TextEmphasisShapeKeyword { Sesame, } -impl TextEmphasisShapeKeyword { - /// converts fill mode to a unicode char - pub fn char(&self, fill: TextEmphasisFillMode) -> &'static str { - let fill = fill == TextEmphasisFillMode::Filled; - match *self { - TextEmphasisShapeKeyword::Dot => { - if fill { - "\u{2022}" - } else { - "\u{25e6}" - } - }, - TextEmphasisShapeKeyword::Circle => { - if fill { - "\u{25cf}" - } else { - "\u{25cb}" - } - }, - TextEmphasisShapeKeyword::DoubleCircle => { - if fill { - "\u{25c9}" - } else { - "\u{25ce}" - } - }, - TextEmphasisShapeKeyword::Triangle => { - if fill { - "\u{25b2}" - } else { - "\u{25b3}" - } - }, - TextEmphasisShapeKeyword::Sesame => { - if fill { - "\u{fe45}" - } else { - "\u{fe46}" - } - }, - } - } -} - impl ToComputedValue for TextEmphasisStyle { type ComputedValue = ComputedTextEmphasisStyle;