diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 9e9c27ee72b..99efd55c60f 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -206,93 +206,15 @@ ${helpers.predefined_type( spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style", )} -<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko" - spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position"> - #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)] - #[derive(ToComputedValue, ToCss)] - pub enum HorizontalWritingModeValue { - Over, - Under, - } - - #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)] - #[derive(ToComputedValue, ToCss)] - pub enum VerticalWritingModeValue { - Right, - Left, - } - - #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] - pub struct SpecifiedValue(pub HorizontalWritingModeValue, pub VerticalWritingModeValue); - - pub mod computed_value { - pub type T = super::SpecifiedValue; - } - - pub fn get_initial_value() -> computed_value::T { - SpecifiedValue(HorizontalWritingModeValue::Over, VerticalWritingModeValue::Right) - } - - pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - if let Ok(horizontal) = input.try(|input| HorizontalWritingModeValue::parse(input)) { - let vertical = VerticalWritingModeValue::parse(input)?; - Ok(SpecifiedValue(horizontal, vertical)) - } else { - let vertical = VerticalWritingModeValue::parse(input)?; - let horizontal = HorizontalWritingModeValue::parse(input)?; - Ok(SpecifiedValue(horizontal, vertical)) - } - } - - % if product == "gecko": - impl SpecifiedValue { - pub fn from_gecko_keyword(kw: u32) -> Self { - use gecko_bindings::structs; - - let vert = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT != 0 { - VerticalWritingModeValue::Right - } else { - debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT != 0); - VerticalWritingModeValue::Left - }; - let horiz = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER != 0 { - HorizontalWritingModeValue::Over - } else { - debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER != 0); - HorizontalWritingModeValue::Under - }; - SpecifiedValue(horiz, vert) - } - } - - impl From for SpecifiedValue { - fn from(bits: u8) -> SpecifiedValue { - SpecifiedValue::from_gecko_keyword(bits as u32) - } - } - - impl From for u8 { - fn from(v: SpecifiedValue) -> u8 { - use gecko_bindings::structs; - - let mut result = match v.0 { - HorizontalWritingModeValue::Over => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER, - HorizontalWritingModeValue::Under => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER, - }; - match v.1 { - VerticalWritingModeValue::Right => { - result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT; - } - VerticalWritingModeValue::Left => { - result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT; - } - }; - result as u8 - } - } - % endif - +${helpers.predefined_type( + "text-emphasis-position", + "TextEmphasisPosition", + "computed::TextEmphasisPosition::over_right()", + initial_specified_value="specified::TextEmphasisPosition::over_right()", + products="gecko", + animation_value_type="discrete", + spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position", +)} ${helpers.predefined_type( "text-emphasis-color", diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index d095079f467..e81b94bd9f7 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -75,7 +75,7 @@ pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::MozContextProperties; pub use self::table::XSpan; pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize}; -pub use self::text::{TextAlign, TextEmphasisStyle, TextOverflow, WordSpacing}; +pub use self::text::{TextAlign, TextEmphasisPosition, TextEmphasisStyle, TextOverflow, WordSpacing}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation}; pub use self::transform::{TransformOrigin, TransformStyle, Translate}; diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index bbef98ae4bd..597fbbd588d 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -18,6 +18,7 @@ use values::generics::text::Spacing; use values::specified::text::{TextDecorationLine, TextEmphasisFillMode, TextEmphasisShapeKeyword, TextOverflowSide}; pub use values::specified::TextAlignKeyword as TextAlign; +pub use values::specified::TextEmphasisPosition; /// A computed value for the `initial-letter` property. pub type InitialLetter = GenericInitialLetter; diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 16d4c512995..4d7ce151eec 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -71,7 +71,8 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::MozContextProperties; pub use self::table::XSpan; -pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign, TextEmphasisStyle}; +pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign}; +pub use self::text::{TextEmphasisStyle, TextEmphasisPosition}; pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform}; diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index fcb15650110..f16ca275bfd 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -666,6 +666,106 @@ impl Parse for TextEmphasisStyle { } } +/// The allowed horizontal values for the `text-emphasis-position` property. +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)] +#[derive(ToComputedValue, ToCss)] +pub enum TextEmphasisHorizontalWritingModeValue { + /// Draw marks over the text in horizontal writing mode. + Over, + /// Draw marks under the text in horizontal writing mode. + Under, +} + +/// The allowed vertical values for the `text-emphasis-position` property. +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)] +#[derive(ToComputedValue, ToCss)] +pub enum TextEmphasisVerticalWritingModeValue { + /// Draws marks to the right of the text in vertical writing mode. + Right, + /// Draw marks to the left of the text in vertical writing mode. + Left, +} + +/// Specified value of `text-emphasis-position` property. +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] +pub struct TextEmphasisPosition( + pub TextEmphasisHorizontalWritingModeValue, + pub TextEmphasisVerticalWritingModeValue +); + +impl TextEmphasisPosition { + #[inline] + /// Returns the initial value of `text-emphasis-position` + pub fn over_right() -> Self { + TextEmphasisPosition(TextEmphasisHorizontalWritingModeValue::Over, + TextEmphasisVerticalWritingModeValue::Right) + } + + #[cfg(feature = "gecko")] + /// Converts an enumerated value coming from Gecko to a `TextEmphasisPosition`. + pub fn from_gecko_keyword(kw: u32) -> Self { + use gecko_bindings::structs; + + let vert = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT != 0 { + TextEmphasisVerticalWritingModeValue::Right + } else { + debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT != 0); + TextEmphasisVerticalWritingModeValue::Left + }; + let horiz = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER != 0 { + TextEmphasisHorizontalWritingModeValue::Over + } else { + debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER != 0); + TextEmphasisHorizontalWritingModeValue::Under + }; + TextEmphasisPosition(horiz, vert) + } +} + +impl Parse for TextEmphasisPosition { + fn parse<'i, 't>( + _context: &ParserContext, + input: &mut Parser<'i, 't> + ) -> Result> { + if let Ok(horizontal) = input.try(|input| TextEmphasisHorizontalWritingModeValue::parse(input)) { + let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?; + Ok(TextEmphasisPosition(horizontal, vertical)) + } else { + let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?; + let horizontal = TextEmphasisHorizontalWritingModeValue::parse(input)?; + Ok(TextEmphasisPosition(horizontal, vertical)) + } + } +} + +#[cfg(feature = "gecko")] +impl From for TextEmphasisPosition { + fn from(bits: u8) -> Self { + TextEmphasisPosition::from_gecko_keyword(bits as u32) + } +} + +#[cfg(feature = "gecko")] +impl From for u8 { + fn from(v: TextEmphasisPosition) -> u8 { + use gecko_bindings::structs; + + let mut result = match v.0 { + TextEmphasisHorizontalWritingModeValue::Over => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER, + TextEmphasisHorizontalWritingModeValue::Under => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER, + }; + match v.1 { + TextEmphasisVerticalWritingModeValue::Right => { + result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT; + } + TextEmphasisVerticalWritingModeValue::Left => { + result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT; + } + }; + result as u8 + } +} + /// A specified value for the `-moz-tab-size` property. pub type MozTabSize = GenericMozTabSize;