mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Derive ToComputedValue for keywords without extra specified values
This commit is contained in:
parent
ccc932ad10
commit
70a99cef15
3 changed files with 65 additions and 87 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 [
|
||||||
|
@ -625,7 +598,7 @@
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
|
||||||
% if not extra_specified:
|
% if not extra_specified:
|
||||||
#[derive(Parse)]
|
#[derive(Parse, ToComputedValue)]
|
||||||
% endif
|
% endif
|
||||||
pub enum T {
|
pub enum T {
|
||||||
${variants(data.longhands_by_name[name].keyword.values_for(product), not extra_specified)}
|
${variants(data.longhands_by_name[name].keyword.values_for(product), not extra_specified)}
|
||||||
|
@ -658,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,7 +54,8 @@ ${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
|
||||||
|
name="float"
|
||||||
values="none left right"
|
values="none left right"
|
||||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||||
extra_specified="inline-start inline-end"
|
extra_specified="inline-start inline-end"
|
||||||
|
@ -64,7 +65,8 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
|
||||||
gecko_inexhaustive="True"
|
gecko_inexhaustive="True"
|
||||||
gecko_ffi_name="mFloat"
|
gecko_ffi_name="mFloat"
|
||||||
flags="APPLIES_TO_FIRST_LETTER"
|
flags="APPLIES_TO_FIRST_LETTER"
|
||||||
spec="https://drafts.csswg.org/css-box/#propdef-float">
|
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,9 +107,10 @@ ${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
|
||||||
|
name="clear"
|
||||||
values="none left right both"
|
values="none left right both"
|
||||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||||
extra_specified="inline-start inline-end"
|
extra_specified="inline-start inline-end"
|
||||||
|
@ -116,7 +119,8 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
|
||||||
animation_value_type="discrete"
|
animation_value_type="discrete"
|
||||||
gecko_enum_prefix="StyleClear"
|
gecko_enum_prefix="StyleClear"
|
||||||
gecko_ffi_name="mBreakType"
|
gecko_ffi_name="mBreakType"
|
||||||
spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control">
|
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,7 +60,8 @@ ${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
|
||||||
|
name="text-justify"
|
||||||
values="auto none inter-word"
|
values="auto none inter-word"
|
||||||
extra_gecko_values="inter-character"
|
extra_gecko_values="inter-character"
|
||||||
extra_specified="${'distribute' if product == 'gecko' else ''}"
|
extra_specified="${'distribute' if product == 'gecko' else ''}"
|
||||||
|
@ -68,38 +69,34 @@ ${helpers.single_keyword("word-break",
|
||||||
animation_value_type="discrete"
|
animation_value_type="discrete"
|
||||||
gecko_pref="layout.css.text-justify.enabled"
|
gecko_pref="layout.css.text-justify.enabled"
|
||||||
flags="APPLIES_TO_PLACEHOLDER",
|
flags="APPLIES_TO_PLACEHOLDER",
|
||||||
spec="https://drafts.csswg.org/css-text/#propdef-text-justify">
|
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":
|
|
||||||
SpecifiedValue::InterCharacter => computed_value::T::InterCharacter,
|
|
||||||
// https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute
|
// https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute
|
||||||
SpecifiedValue::Distribute => computed_value::T::InterCharacter,
|
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
|
% endif
|
||||||
}
|
</%helpers:single_keyword>
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:single_keyword_computed>
|
|
||||||
|
|
||||||
${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
|
||||||
|
name="white-space"
|
||||||
values="normal pre nowrap pre-wrap pre-line"
|
values="normal pre nowrap pre-wrap pre-line"
|
||||||
extra_gecko_values="-moz-pre-space"
|
extra_gecko_values="-moz-pre-space"
|
||||||
gecko_enum_prefix="StyleWhiteSpace"
|
gecko_enum_prefix="StyleWhiteSpace"
|
||||||
needs_conversion="True"
|
needs_conversion="True"
|
||||||
animation_value_type="discrete"
|
animation_value_type="discrete"
|
||||||
// Only allowed for UA sheets, which set it
|
// Only allowed for UA sheets, which set it !important.
|
||||||
// !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