diff --git a/components/style/properties/data.py b/components/style/properties/data.py index dd64f799fdd..559048913b6 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -511,6 +511,7 @@ class Longhand(Property): "TextAlignLast", "TextDecorationLine", "TextEmphasisPosition", + "TextJustify", "TextTransform", "TextUnderlinePosition", "TouchAction", diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index c3987874dc1..74161793e4e 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -707,8 +707,8 @@ <%def name="single_keyword(name, values, vector=False, - extra_specified=None, needs_conversion=False, - gecko_pref_controlled_initial_value=None, **kwargs)"> + needs_conversion=False, gecko_pref_controlled_initial_value=None, + **kwargs)"> <% keyword_kwargs = {a: kwargs.pop(a, None) for a in [ 'gecko_constant_prefix', @@ -725,11 +725,10 @@ ]} %> - <%def name="inner_body(keyword, extra_specified=None, needs_conversion=False, + <%def name="inner_body(keyword, needs_conversion=False, gecko_pref_controlled_initial_value=None)"> - <%def name="variants(variants, include_aliases)"> + <%def name="variants(variants)"> % for variant in variants: - % if include_aliases: <% aliases = [] for alias, v in keyword.aliases_for(engine).items(): @@ -739,38 +738,15 @@ % if aliases: #[parse(aliases = "${','.join(sorted(aliases))}")] % endif - % endif ${to_camel_case(variant)}, % endfor - % if extra_specified: - #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] - #[derive( - Clone, - Copy, - Debug, - Eq, - MallocSizeOf, - Parse, - PartialEq, - SpecifiedValueInfo, - ToCss, - ToShmem, - )] - pub enum SpecifiedValue { - ${variants(keyword.values_for(engine) + extra_specified.split(), bool(extra_specified))} - } - % else: - pub use self::computed_value::T as SpecifiedValue; - % endif + pub use self::computed_value::T as SpecifiedValue; pub mod computed_value { #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] - #[derive(Clone, Copy, Debug, Eq, FromPrimitive, MallocSizeOf, PartialEq, ToCss, ToResolvedValue)] - % if not extra_specified: - #[derive(Parse, SpecifiedValueInfo, ToComputedValue, ToShmem)] - % endif + #[derive(Clone, Copy, Debug, Eq, FromPrimitive, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)] pub enum T { - ${variants(data.longhands_by_name[name].keyword.values_for(engine), not extra_specified)} + ${variants(data.longhands_by_name[name].keyword.values_for(engine))} } } #[inline] @@ -799,10 +775,7 @@ % if needs_conversion: <% - conversion_values = keyword.values_for(engine) - if extra_specified: - conversion_values += extra_specified.split() - conversion_values += keyword.aliases_for(engine).keys() + conversion_values = keyword.values_for(engine) + list(keyword.aliases_for(engine).keys()) %> ${gecko_keyword_conversion(keyword, values=conversion_values)} % endif @@ -817,7 +790,7 @@ % else: <%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)"> ${inner_body(Keyword(name, values, **keyword_kwargs), - extra_specified=extra_specified, needs_conversion=needs_conversion, + needs_conversion=needs_conversion, gecko_pref_controlled_initial_value=gecko_pref_controlled_initial_value)} % if caller: ${caller.body()} diff --git a/components/style/properties/longhands/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs index 6e6bd79c0e6..b0407054ddd 100644 --- a/components/style/properties/longhands/inherited_text.mako.rs +++ b/components/style/properties/longhands/inherited_text.mako.rs @@ -96,45 +96,16 @@ ${helpers.predefined_type( servo_restyle_damage="rebuild_and_reflow", )} -// TODO(pcwalton): Support `text-justify: distribute`. -<%helpers:single_keyword - name="text-justify" - values="auto none inter-word" +${helpers.predefined_type( + "text-justify", + "TextJustify", + "computed::TextJustify::Auto", engines="gecko servo-2013 servo-2020", servo_2020_pref="layout.2020.unimplemented", - extra_gecko_values="inter-character" - extra_specified="${'distribute' if engine == 'gecko' else ''}" - gecko_enum_prefix="StyleTextJustify" - animation_value_type="discrete" - spec="https://drafts.csswg.org/css-text/#propdef-text-justify" - servo_restyle_damage="rebuild_and_reflow" -> - % if engine == 'gecko': - impl ToComputedValue for SpecifiedValue { - type ComputedValue = computed_value::T; - - #[inline] - fn to_computed_value(&self, _: &Context) -> computed_value::T { - match *self { - % for value in "Auto None InterCharacter InterWord".split(): - SpecifiedValue::${value} => computed_value::T::${value}, - % endfor - // https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute - SpecifiedValue::Distribute => computed_value::T::InterCharacter, - } - } - - #[inline] - fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue { - match *computed { - % for value in "Auto None InterCharacter InterWord".split(): - computed_value::T::${value} => SpecifiedValue::${value}, - % endfor - } - } - } - % endif - + animation_value_type="discrete", + spec="https://drafts.csswg.org/css-text/#propdef-text-justify", + servo_restyle_damage="rebuild_and_reflow", +)} ${helpers.predefined_type( "text-align-last", diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 5ed404cf5e3..826bb2a2448 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -89,7 +89,7 @@ pub use self::text::TextUnderlinePosition; pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight}; pub use self::text::{OverflowWrap, RubyPosition, TextOverflow, WordBreak, WordSpacing}; pub use self::text::{TextAlign, TextAlignLast, TextEmphasisPosition, TextEmphasisStyle}; -pub use self::text::{TextDecorationLength, TextDecorationSkipInk}; +pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextJustify}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, 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 4f952fa21cc..c0331643fa7 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -21,7 +21,7 @@ use style_traits::{CssWriter, ToCss}; pub use crate::values::specified::text::{TextAlignLast, TextUnderlinePosition}; pub use crate::values::specified::{LineBreak, OverflowWrap, RubyPosition, WordBreak}; pub use crate::values::specified::{TextDecorationLine, TextEmphasisPosition}; -pub use crate::values::specified::{TextDecorationSkipInk, TextTransform}; +pub use crate::values::specified::{TextDecorationSkipInk, TextJustify, TextTransform}; /// 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 6341d495d6c..8a9cb73f4da 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -90,7 +90,7 @@ pub use self::text::RubyPosition; 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::{TextDecorationLength, TextDecorationSkipInk, TextTransform}; +pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextJustify, 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 7ee4dbedda3..7af55b81258 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -1001,6 +1001,33 @@ pub enum WordBreak { BreakWord, } +/// Values for the `text-justify` CSS property. +#[repr(u8)] +#[derive( + Clone, + Copy, + Debug, + Eq, + MallocSizeOf, + Parse, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[allow(missing_docs)] +pub enum TextJustify { + Auto, + None, + InterWord, + // See https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute + // and https://github.com/w3c/csswg-drafts/issues/6156 for the alias. + #[parse(aliases = "distribute")] + InterCharacter, +} + /// Values for the `line-break` property. #[repr(u8)] #[derive(