style: Clean up text-justify, and make distribute a parse-time alias

Since it's simpler, as discussed in the CSSWG issue.

Differential Revision: https://phabricator.services.mozilla.com/D111346
This commit is contained in:
Oriol Brufau 2023-05-16 23:14:19 +02:00
parent bbc03a2577
commit b40f4b6fec
7 changed files with 48 additions and 76 deletions

View file

@ -511,6 +511,7 @@ class Longhand(Property):
"TextAlignLast",
"TextDecorationLine",
"TextEmphasisPosition",
"TextJustify",
"TextTransform",
"TextUnderlinePosition",
"TouchAction",

View file

@ -707,8 +707,8 @@
</%def>
<%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
</%def>
% 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()}

View file

@ -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
</%helpers:single_keyword>
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",