mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #19938 - servo:single-keyword, r=emilio
Simplify single_keyword <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19938) <!-- Reviewable:end -->
This commit is contained in:
commit
bad455138f
3 changed files with 87 additions and 103 deletions
|
@ -490,33 +490,6 @@
|
||||||
</%call>
|
</%call>
|
||||||
</%def>
|
</%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)">
|
<%def name="gecko_keyword_conversion(keyword, values=None, type='SpecifiedValue', cast_to=None)">
|
||||||
<%
|
<%
|
||||||
if not values:
|
if not values:
|
||||||
|
@ -584,7 +557,7 @@
|
||||||
}
|
}
|
||||||
</%def>
|
</%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)">
|
extra_specified=None, needs_conversion=False, **kwargs)">
|
||||||
<%
|
<%
|
||||||
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
||||||
|
@ -596,33 +569,39 @@
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%def name="inner_body(keyword, extra_specified=None, needs_conversion=False)">
|
<%def name="inner_body(keyword, extra_specified=None, needs_conversion=False)">
|
||||||
% if extra_specified or keyword.aliases_for(product):
|
<%def name="variants(variants, include_aliases)">
|
||||||
|
% for variant in variants:
|
||||||
|
% if include_aliases:
|
||||||
|
<%
|
||||||
|
aliases = []
|
||||||
|
for alias, v in keyword.aliases_for(product).iteritems():
|
||||||
|
if variant == v:
|
||||||
|
aliases.append(alias)
|
||||||
|
%>
|
||||||
|
% if aliases:
|
||||||
|
#[css(aliases = "${','.join(aliases)}")]
|
||||||
|
% endif
|
||||||
|
% endif
|
||||||
|
${to_camel_case(variant)},
|
||||||
|
% endfor
|
||||||
|
</%def>
|
||||||
|
% if extra_specified:
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
|
||||||
pub enum SpecifiedValue {
|
pub enum SpecifiedValue {
|
||||||
% for value in keyword.values_for(product) + (extra_specified or "").split():
|
${variants(keyword.values_for(product) + extra_specified.split(), bool(extra_specified))}
|
||||||
<%
|
|
||||||
aliases = []
|
|
||||||
for alias, v in keyword.aliases_for(product).iteritems():
|
|
||||||
if value == v:
|
|
||||||
aliases.append(alias)
|
|
||||||
%>
|
|
||||||
% if aliases:
|
|
||||||
#[css(aliases = "${','.join(aliases)}")]
|
|
||||||
% endif
|
|
||||||
${to_camel_case(value)},
|
|
||||||
% endfor
|
|
||||||
}
|
}
|
||||||
% else:
|
% else:
|
||||||
pub use self::computed_value::T as SpecifiedValue;
|
pub use self::computed_value::T as SpecifiedValue;
|
||||||
% endif
|
% endif
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
% if not extra_specified:
|
||||||
|
#[derive(Parse, ToComputedValue)]
|
||||||
|
% endif
|
||||||
pub enum T {
|
pub enum T {
|
||||||
% for value in data.longhands_by_name[name].keyword.values_for(product):
|
${variants(data.longhands_by_name[name].keyword.values_for(product), not extra_specified)}
|
||||||
${to_camel_case(value)},
|
|
||||||
% endfor
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -652,13 +631,17 @@
|
||||||
% if vector:
|
% if vector:
|
||||||
<%call expr="vector_longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
|
<%call expr="vector_longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
|
||||||
${inner_body(Keyword(name, values, **keyword_kwargs))}
|
${inner_body(Keyword(name, values, **keyword_kwargs))}
|
||||||
|
% if caller:
|
||||||
${caller.body()}
|
${caller.body()}
|
||||||
|
% endif
|
||||||
</%call>
|
</%call>
|
||||||
% else:
|
% else:
|
||||||
<%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
|
<%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
|
||||||
${inner_body(Keyword(name, values, **keyword_kwargs),
|
${inner_body(Keyword(name, values, **keyword_kwargs),
|
||||||
extra_specified=extra_specified, needs_conversion=needs_conversion)}
|
extra_specified=extra_specified, needs_conversion=needs_conversion)}
|
||||||
|
% if caller:
|
||||||
${caller.body()}
|
${caller.body()}
|
||||||
|
% endif
|
||||||
</%call>
|
</%call>
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -54,17 +54,19 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
|
||||||
flags="CREATES_STACKING_CONTEXT ABSPOS_CB",
|
flags="CREATES_STACKING_CONTEXT ABSPOS_CB",
|
||||||
spec="https://drafts.csswg.org/css-position/#position-property")}
|
spec="https://drafts.csswg.org/css-position/#position-property")}
|
||||||
|
|
||||||
<%helpers:single_keyword_computed name="float"
|
<%helpers:single_keyword
|
||||||
values="none left right"
|
name="float"
|
||||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
values="none left right"
|
||||||
extra_specified="inline-start inline-end"
|
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||||
needs_conversion="True"
|
extra_specified="inline-start inline-end"
|
||||||
animation_value_type="discrete"
|
needs_conversion="True"
|
||||||
gecko_enum_prefix="StyleFloat"
|
animation_value_type="discrete"
|
||||||
gecko_inexhaustive="True"
|
gecko_enum_prefix="StyleFloat"
|
||||||
gecko_ffi_name="mFloat"
|
gecko_inexhaustive="True"
|
||||||
flags="APPLIES_TO_FIRST_LETTER"
|
gecko_ffi_name="mFloat"
|
||||||
spec="https://drafts.csswg.org/css-box/#propdef-float">
|
flags="APPLIES_TO_FIRST_LETTER"
|
||||||
|
spec="https://drafts.csswg.org/css-box/#propdef-float"
|
||||||
|
>
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
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"
|
<%helpers:single_keyword
|
||||||
values="none left right both"
|
name="clear"
|
||||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
values="none left right both"
|
||||||
extra_specified="inline-start inline-end"
|
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||||
needs_conversion="True"
|
extra_specified="inline-start inline-end"
|
||||||
gecko_inexhaustive="True"
|
needs_conversion="True"
|
||||||
animation_value_type="discrete"
|
gecko_inexhaustive="True"
|
||||||
gecko_enum_prefix="StyleClear"
|
animation_value_type="discrete"
|
||||||
gecko_ffi_name="mBreakType"
|
gecko_enum_prefix="StyleClear"
|
||||||
spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control">
|
gecko_ffi_name="mBreakType"
|
||||||
|
spec="https://drafts.csswg.org/css-box/#propdef-clear"
|
||||||
|
>
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
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(
|
${helpers.predefined_type(
|
||||||
"vertical-align",
|
"vertical-align",
|
||||||
|
|
|
@ -60,46 +60,43 @@ ${helpers.single_keyword("word-break",
|
||||||
spec="https://drafts.csswg.org/css-text/#propdef-word-break")}
|
spec="https://drafts.csswg.org/css-text/#propdef-word-break")}
|
||||||
|
|
||||||
// TODO(pcwalton): Support `text-justify: distribute`.
|
// TODO(pcwalton): Support `text-justify: distribute`.
|
||||||
<%helpers:single_keyword_computed name="text-justify"
|
<%helpers:single_keyword
|
||||||
values="auto none inter-word"
|
name="text-justify"
|
||||||
extra_gecko_values="inter-character"
|
values="auto none inter-word"
|
||||||
extra_specified="${'distribute' if product == 'gecko' else ''}"
|
extra_gecko_values="inter-character"
|
||||||
gecko_enum_prefix="StyleTextJustify"
|
extra_specified="${'distribute' if product == 'gecko' else ''}"
|
||||||
animation_value_type="discrete"
|
gecko_enum_prefix="StyleTextJustify"
|
||||||
gecko_pref="layout.css.text-justify.enabled"
|
animation_value_type="discrete"
|
||||||
flags="APPLIES_TO_PLACEHOLDER",
|
gecko_pref="layout.css.text-justify.enabled"
|
||||||
spec="https://drafts.csswg.org/css-text/#propdef-text-justify">
|
flags="APPLIES_TO_PLACEHOLDER",
|
||||||
|
spec="https://drafts.csswg.org/css-text/#propdef-text-justify"
|
||||||
|
>
|
||||||
|
% if product == 'gecko':
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, _: &Context) -> computed_value::T {
|
fn to_computed_value(&self, _: &Context) -> computed_value::T {
|
||||||
match *self {
|
match *self {
|
||||||
% for value in "Auto None InterWord".split():
|
% for value in "Auto None InterCharacter InterWord".split():
|
||||||
SpecifiedValue::${value} => computed_value::T::${value},
|
SpecifiedValue::${value} => computed_value::T::${value},
|
||||||
% endfor
|
% endfor
|
||||||
% if product == "gecko":
|
// https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute
|
||||||
SpecifiedValue::InterCharacter => computed_value::T::InterCharacter,
|
SpecifiedValue::Distribute => computed_value::T::InterCharacter,
|
||||||
// https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute
|
|
||||||
SpecifiedValue::Distribute => computed_value::T::InterCharacter,
|
|
||||||
% endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
|
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
|
||||||
match *computed {
|
match *computed {
|
||||||
% for value in "Auto None InterWord".split():
|
% for value in "Auto None InterCharacter InterWord".split():
|
||||||
computed_value::T::${value} => SpecifiedValue::${value},
|
computed_value::T::${value} => SpecifiedValue::${value},
|
||||||
% endfor
|
% 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",
|
${helpers.single_keyword("text-align-last",
|
||||||
"auto start end left right center justify",
|
"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",
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||||
spec="https://drafts.csswg.org/css-text/#propdef-word-spacing")}
|
spec="https://drafts.csswg.org/css-text/#propdef-word-spacing")}
|
||||||
|
|
||||||
<%helpers:single_keyword_computed name="white-space"
|
<%helpers:single_keyword
|
||||||
values="normal pre nowrap pre-wrap pre-line"
|
name="white-space"
|
||||||
extra_gecko_values="-moz-pre-space"
|
values="normal pre nowrap pre-wrap pre-line"
|
||||||
gecko_enum_prefix="StyleWhiteSpace"
|
extra_gecko_values="-moz-pre-space"
|
||||||
needs_conversion="True"
|
gecko_enum_prefix="StyleWhiteSpace"
|
||||||
animation_value_type="discrete"
|
needs_conversion="True"
|
||||||
// Only allowed for UA sheets, which set it
|
animation_value_type="discrete"
|
||||||
// !important.
|
// Only allowed for UA sheets, which set it !important.
|
||||||
flags="APPLIES_TO_PLACEHOLDER"
|
flags="APPLIES_TO_PLACEHOLDER"
|
||||||
spec="https://drafts.csswg.org/css-text/#propdef-white-space">
|
spec="https://drafts.csswg.org/css-text/#propdef-white-space"
|
||||||
trivial_to_computed_value!(SpecifiedValue);
|
>
|
||||||
% if product != "gecko":
|
% if product != "gecko":
|
||||||
impl SpecifiedValue {
|
impl SpecifiedValue {
|
||||||
pub fn allow_wrap(&self) -> bool {
|
pub fn allow_wrap(&self) -> bool {
|
||||||
|
@ -176,7 +173,7 @@ ${helpers.predefined_type("word-spacing",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
</%helpers:single_keyword_computed>
|
</%helpers:single_keyword>
|
||||||
|
|
||||||
${helpers.predefined_type(
|
${helpers.predefined_type(
|
||||||
"text-shadow",
|
"text-shadow",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue