commit e155129069c8c8fed793ec5349b874a6a3474443 parent 9410cde6f7ced04a01b7d24a464a64e80278995a Author: Jan Varga <jan.varga@gmail.com> Date: Mon, 20 Oct 2025 05:08:20 +0000 Bug 1991631 - Demonstrate ToTyped derive on struct type (letter-spacing); r=firefox-style-system-reviewers,dshin This patch demonstrates the new struct-handling support in the ToTyped derive by enabling it for the letter-spacing property. To make the test pass, an explicit ToTyped implementation was added for the computed value type. This verifies that the derive correctly handles structs with inner fields when derive_fields is enabled. Differential Revision: https://phabricator.services.mozilla.com/D268163 Diffstat:
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/servo/components/style/values/computed/text.rs b/servo/components/style/values/computed/text.rs @@ -15,7 +15,7 @@ use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyw use crate::values::{CSSFloat, CSSInteger}; use crate::Zero; use std::fmt::{self, Write}; -use style_traits::{CssWriter, ToCss}; +use style_traits::{CssString, CssWriter, ToCss, ToTyped, TypedValue}; pub use crate::values::specified::text::{ HyphenateCharacter, LineBreak, MozControlCharacterVisibility, OverflowWrap, RubyPosition, @@ -66,7 +66,6 @@ impl HyphenateLimitChars { ToAnimatedValue, ToAnimatedZero, ToResolvedValue, - ToTyped, )] pub struct GenericLetterSpacing<L>(pub L); /// This is generic just to make the #[derive()] code do the right thing for lengths. @@ -96,6 +95,23 @@ impl ToCss for LetterSpacing { } } +impl ToTyped for LetterSpacing { + // XXX The specification does not currently define how this property should + // be reified into Typed OM. The current behavior follows existing WPT + // coverage (letter-spacing.html). We may file a spec issue once more data + // is collected to update the Property-specific Rules section to align with + // observed test expectations. + fn to_typed(&self) -> Option<TypedValue> { + if self.0.is_zero() { + return Some(TypedValue::Keyword(CssString::from("normal"))); + } + // XXX According to the test, should return TypedValue::Numeric with + // unit "px" or "percent" once that variant is available. Tracked in + // bug 1990419. + None + } +} + /// A computed value for the `word-spacing` property. pub type WordSpacing = LengthPercentage; diff --git a/servo/components/style/values/specified/text.rs b/servo/components/style/values/specified/text.rs @@ -28,7 +28,7 @@ use style_traits::{KeywordsCollectFn, SpecifiedValueInfo}; pub type InitialLetter = GenericInitialLetter<Number, Integer>; /// A spacing value used by either the `letter-spacing` or `word-spacing` properties. -#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] +#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, ToTyped)] pub enum Spacing { /// `normal` Normal, @@ -55,6 +55,7 @@ impl Parse for Spacing { #[derive( Clone, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, ToTyped, )] +#[typed_value(derive_fields)] pub struct LetterSpacing(pub Spacing); impl ToComputedValue for LetterSpacing { diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/properties/letter-spacing.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/properties/letter-spacing.html.ini @@ -3,9 +3,6 @@ [Can set 'letter-spacing' to var() references: ] expected: FAIL - [Can set 'letter-spacing' to the 'normal' keyword: ] - expected: FAIL - [Can set 'letter-spacing' to a length: ] expected: FAIL