diff --git a/components/style/properties/longhands/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs index 40b247f226d..18f5c466d1a 100644 --- a/components/style/properties/longhands/inherited_text.mako.rs +++ b/components/style/properties/longhands/inherited_text.mako.rs @@ -382,8 +382,8 @@ ${helpers.single_keyword( // text underline offset ${helpers.predefined_type( "text-underline-offset", - "LengthOrAuto", - "computed::LengthOrAuto::auto()", + "TextDecorationLength", + "generics::text::GenericTextDecorationLength::Auto", engines="gecko", animation_value_type="ComputedValue", gecko_pref="layout.css.text-underline-offset.enabled", diff --git a/components/style/properties/longhands/text.mako.rs b/components/style/properties/longhands/text.mako.rs index 9f0d3f38213..b77e17dd6b7 100644 --- a/components/style/properties/longhands/text.mako.rs +++ b/components/style/properties/longhands/text.mako.rs @@ -71,10 +71,10 @@ ${helpers.predefined_type( ${helpers.predefined_type( "text-decoration-thickness", - "LengthOrAuto", - "computed::LengthOrAuto::auto()", + "TextDecorationLength", + "generics::text::GenericTextDecorationLength::Auto", engines="gecko", - initial_specified_value="specified::LengthOrAuto::auto()", + initial_specified_value="generics::text::GenericTextDecorationLength::Auto", animation_value_type="ComputedValue", gecko_pref="layout.css.text-decoration-thickness.enabled", spec="https://drafts.csswg.org/css-text-decor-4/#text-decoration-width-property" diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 5decee9654e..a7a449a10ff 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -76,7 +76,7 @@ pub use self::svg::MozContextProperties; pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::table::XSpan; -pub use self::text::TextDecorationSkipInk; +pub use self::text::{TextDecorationLength, TextDecorationSkipInk}; pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight}; pub use self::text::{OverflowWrap, TextOverflow, WordBreak, WordSpacing}; pub use self::text::{TextAlign, TextEmphasisPosition, TextEmphasisStyle}; diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index d2a619a3a20..53c236e4761 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -10,7 +10,7 @@ use crate::values::computed::length::{Length, LengthPercentage}; use crate::values::computed::{Context, NonNegativeLength, NonNegativeNumber, ToComputedValue}; use crate::values::generics::text::InitialLetter as GenericInitialLetter; use crate::values::generics::text::LineHeight as GenericLineHeight; -use crate::values::generics::text::Spacing; +use crate::values::generics::text::{Spacing, GenericTextDecorationLength}; use crate::values::specified::text::{self as specified, TextOverflowSide}; use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword}; use crate::values::{CSSFloat, CSSInteger}; @@ -26,6 +26,9 @@ pub use crate::values::specified::{TextDecorationSkipInk, TextTransform}; /// A computed value for the `initial-letter` property. pub type InitialLetter = GenericInitialLetter; +/// Implements type for `text-underline-offset` and `text-decoration-thickness` properties +pub type TextDecorationLength = GenericTextDecorationLength; + /// A computed value for the `letter-spacing` property. #[repr(transparent)] #[derive( diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 50db1a1017e..fd434cc1273 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -122,3 +122,33 @@ impl LineHeight { LineHeight::Normal } } + +/// Implements type for text-underline-offset and text-decoration-thickness +/// which take the grammar of auto | from-font | +/// +/// https://drafts.csswg.org/css-text-decor-4/ +#[repr(C, u8)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] +#[derive( + Animate, + Clone, + Copy, + ComputeSquaredDistance, + ToAnimatedZero, + Debug, + Eq, + MallocSizeOf, + Parse, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[allow(missing_docs)] +pub enum GenericTextDecorationLength { + Length(L), + Auto, + FromFont, +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 21dd4f0d9b0..16897043da9 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -82,7 +82,7 @@ pub use self::table::XSpan; pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight, TextAlign}; pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle, WordBreak}; pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing}; -pub use self::text::{TextDecorationSkipInk, TextTransform}; +pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextTransform}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, Transform}; pub use self::transform::{TransformOrigin, TransformStyle, Translate}; diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index d72b139043a..b4fbc42c848 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -12,7 +12,7 @@ use crate::values::computed::text::TextOverflow as ComputedTextOverflow; use crate::values::computed::{Context, ToComputedValue}; use crate::values::generics::text::InitialLetter as GenericInitialLetter; use crate::values::generics::text::LineHeight as GenericLineHeight; -use crate::values::generics::text::Spacing; +use crate::values::generics::text::{Spacing, GenericTextDecorationLength}; use crate::values::specified::length::NonNegativeLengthPercentage; use crate::values::specified::length::{FontRelativeLength, Length}; use crate::values::specified::length::{LengthPercentage, NoCalcLength}; @@ -1039,3 +1039,20 @@ pub enum TextDecorationSkipInk { Auto, None, } + +/// Implements type for `text-underline-offset` and `text-decoration-thickness` properties +pub type TextDecorationLength = GenericTextDecorationLength; + +impl TextDecorationLength { + /// `Auto` value. + #[inline] + pub fn auto() -> Self { + GenericTextDecorationLength::Auto + } + + /// Whether this is the `Auto` value. + #[inline] + pub fn is_auto(&self) -> bool { + matches!(*self, GenericTextDecorationLength::Auto) + } +}