Derive ToComputedValue for keywords without extra specified values

This commit is contained in:
Anthony Ramine 2018-02-03 17:40:49 +01:00
parent ccc932ad10
commit 70a99cef15
3 changed files with 65 additions and 87 deletions

View file

@ -490,33 +490,6 @@
</%call>
</%def>
<%def name="single_keyword(name, values, vector=False, **kwargs)">
<%call expr="single_keyword_computed(name, values, vector, **kwargs)">
// FIXME(emilio): WTF is this even trying to do? Those are no-ops,
// should be derived instead!
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self {
% for value in data.longhands_by_name[name].keyword.values_for(product):
SpecifiedValue::${to_camel_case(value)} => computed_value::T::${to_camel_case(value)},
% endfor
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
% for value in data.longhands_by_name[name].keyword.values_for(product):
computed_value::T::${to_camel_case(value)} => SpecifiedValue::${to_camel_case(value)},
% endfor
}
}
}
</%call>
</%def>
<%def name="gecko_keyword_conversion(keyword, values=None, type='SpecifiedValue', cast_to=None)">
<%
if not values:
@ -584,7 +557,7 @@
}
</%def>
<%def name="single_keyword_computed(name, values, vector=False,
<%def name="single_keyword(name, values, vector=False,
extra_specified=None, needs_conversion=False, **kwargs)">
<%
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
@ -625,7 +598,7 @@
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
% if not extra_specified:
#[derive(Parse)]
#[derive(Parse, ToComputedValue)]
% endif
pub enum T {
${variants(data.longhands_by_name[name].keyword.values_for(product), not extra_specified)}
@ -658,13 +631,17 @@
% if vector:
<%call expr="vector_longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
${inner_body(Keyword(name, values, **keyword_kwargs))}
% if caller:
${caller.body()}
% endif
</%call>
% 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)}
% if caller:
${caller.body()}
% endif
</%call>
% endif
</%def>

View file

@ -54,17 +54,19 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
flags="CREATES_STACKING_CONTEXT ABSPOS_CB",
spec="https://drafts.csswg.org/css-position/#position-property")}
<%helpers:single_keyword_computed name="float"
values="none left right"
// https://drafts.csswg.org/css-logical-props/#float-clear
extra_specified="inline-start inline-end"
needs_conversion="True"
animation_value_type="discrete"
gecko_enum_prefix="StyleFloat"
gecko_inexhaustive="True"
gecko_ffi_name="mFloat"
flags="APPLIES_TO_FIRST_LETTER"
spec="https://drafts.csswg.org/css-box/#propdef-float">
<%helpers:single_keyword
name="float"
values="none left right"
// https://drafts.csswg.org/css-logical-props/#float-clear
extra_specified="inline-start inline-end"
needs_conversion="True"
animation_value_type="discrete"
gecko_enum_prefix="StyleFloat"
gecko_inexhaustive="True"
gecko_ffi_name="mFloat"
flags="APPLIES_TO_FIRST_LETTER"
spec="https://drafts.csswg.org/css-box/#propdef-float"
>
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -105,18 +107,20 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
}
}
}
</%helpers:single_keyword_computed>
</%helpers:single_keyword>
<%helpers:single_keyword_computed name="clear"
values="none left right both"
// https://drafts.csswg.org/css-logical-props/#float-clear
extra_specified="inline-start inline-end"
needs_conversion="True"
gecko_inexhaustive="True"
animation_value_type="discrete"
gecko_enum_prefix="StyleClear"
gecko_ffi_name="mBreakType"
spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control">
<%helpers:single_keyword
name="clear"
values="none left right both"
// https://drafts.csswg.org/css-logical-props/#float-clear
extra_specified="inline-start inline-end"
needs_conversion="True"
gecko_inexhaustive="True"
animation_value_type="discrete"
gecko_enum_prefix="StyleClear"
gecko_ffi_name="mBreakType"
spec="https://drafts.csswg.org/css-box/#propdef-clear"
>
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -157,7 +161,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
}
}
}
</%helpers:single_keyword_computed>
</%helpers:single_keyword>
${helpers.predefined_type(
"vertical-align",

View file

@ -60,46 +60,43 @@ ${helpers.single_keyword("word-break",
spec="https://drafts.csswg.org/css-text/#propdef-word-break")}
// TODO(pcwalton): Support `text-justify: distribute`.
<%helpers:single_keyword_computed name="text-justify"
values="auto none inter-word"
extra_gecko_values="inter-character"
extra_specified="${'distribute' if product == 'gecko' else ''}"
gecko_enum_prefix="StyleTextJustify"
animation_value_type="discrete"
gecko_pref="layout.css.text-justify.enabled"
flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-text/#propdef-text-justify">
<%helpers:single_keyword
name="text-justify"
values="auto none inter-word"
extra_gecko_values="inter-character"
extra_specified="${'distribute' if product == 'gecko' else ''}"
gecko_enum_prefix="StyleTextJustify"
animation_value_type="discrete"
gecko_pref="layout.css.text-justify.enabled"
flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-text/#propdef-text-justify"
>
% if product == '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 InterWord".split():
SpecifiedValue::${value} => computed_value::T::${value},
% for value in "Auto None InterCharacter InterWord".split():
SpecifiedValue::${value} => computed_value::T::${value},
% endfor
% if product == "gecko":
SpecifiedValue::InterCharacter => computed_value::T::InterCharacter,
// https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute
SpecifiedValue::Distribute => computed_value::T::InterCharacter,
% endif
// 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 InterWord".split():
computed_value::T::${value} => SpecifiedValue::${value},
% for value in "Auto None InterCharacter InterWord".split():
computed_value::T::${value} => SpecifiedValue::${value},
% endfor
% if product == "gecko":
computed_value::T::InterCharacter => SpecifiedValue::InterCharacter,
% endif
}
}
}
</%helpers:single_keyword_computed>
% endif
</%helpers:single_keyword>
${helpers.single_keyword("text-align-last",
"auto start end left right center justify",
@ -132,17 +129,17 @@ ${helpers.predefined_type("word-spacing",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-text/#propdef-word-spacing")}
<%helpers:single_keyword_computed name="white-space"
values="normal pre nowrap pre-wrap pre-line"
extra_gecko_values="-moz-pre-space"
gecko_enum_prefix="StyleWhiteSpace"
needs_conversion="True"
animation_value_type="discrete"
// Only allowed for UA sheets, which set it
// !important.
flags="APPLIES_TO_PLACEHOLDER"
spec="https://drafts.csswg.org/css-text/#propdef-white-space">
trivial_to_computed_value!(SpecifiedValue);
<%helpers:single_keyword
name="white-space"
values="normal pre nowrap pre-wrap pre-line"
extra_gecko_values="-moz-pre-space"
gecko_enum_prefix="StyleWhiteSpace"
needs_conversion="True"
animation_value_type="discrete"
// Only allowed for UA sheets, which set it !important.
flags="APPLIES_TO_PLACEHOLDER"
spec="https://drafts.csswg.org/css-text/#propdef-white-space"
>
% if product != "gecko":
impl SpecifiedValue {
pub fn allow_wrap(&self) -> bool {
@ -176,7 +173,7 @@ ${helpers.predefined_type("word-spacing",
}
}
% endif
</%helpers:single_keyword_computed>
</%helpers:single_keyword>
${helpers.predefined_type(
"text-shadow",