diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 7b5a791de90..f7317829d97 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -20,7 +20,7 @@ class Keyword(object): def __init__(self, name, values, gecko_constant_prefix=None, extra_gecko_values=None, extra_servo_values=None): self.name = name - self.values = values + self.values = values.split() self.gecko_constant_prefix = gecko_constant_prefix or \ "NS_STYLE_" + self.name.upper().replace("-", "_") self.extra_gecko_values = (extra_gecko_values or "").split() diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 6140ce1f050..8f1a7820e1f 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -170,7 +170,7 @@ 'gecko_constant_prefix', 'extra_gecko_values', 'extra_servo_values' ]} %> - <%call expr="longhand(name, keyword=Keyword(name, values.split(), **keyword_kwargs), **kwargs)"> + <%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)"> pub use self::computed_value::T as SpecifiedValue; ${caller.body()} pub mod computed_value { diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 61ee565e477..3faa645cbcf 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -6,6 +6,7 @@ <%! from data import to_rust_ident + from data import Keyword %> use app_units::Au; @@ -111,6 +112,47 @@ pub struct ${style_struct.gecko_struct_name}; % endif +<%def name="impl_simple_copy(ident, gecko_ffi_name)"> + fn copy_${ident}_from(&mut self, other: &Self) { + self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name}; + } + + +<%def name="impl_keyword_setter(ident, gecko_ffi_name, keyword)"> + fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { + use gecko_style_structs as gss; + use style::properties::longhands::${ident}::computed_value::T as Keyword; + // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts + self.gecko.${gecko_ffi_name} = match v { + % for value in keyword.values_for('gecko'): + Keyword::${to_rust_ident(value)} => gss::${keyword.gecko_constant(value)} as u8, + % endfor + }; + } + + +<%def name="impl_keyword_clone(ident, gecko_ffi_name, keyword)"> + fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { + use gecko_style_structs as gss; + use style::properties::longhands::${ident}::computed_value::T as Keyword; + // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts + match self.gecko.${gecko_ffi_name} as u32 { + % for value in keyword.values_for('gecko'): + gss::${keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)}, + % endfor + x => panic!("Found unexpected value in style struct for ${ident} property: {}", x), + } + } + + +<%def name="impl_keyword(ident, gecko_ffi_name, keyword, need_clone)"> +<%call expr="impl_keyword_setter(ident, gecko_ffi_name, keyword)"> +<%call expr="impl_simple_copy(ident, gecko_ffi_name)"> +%if need_clone: +<%call expr="impl_keyword_clone(ident, gecko_ffi_name, keyword)"> +% endif + + <%def name="impl_style_struct(style_struct)"> impl ${style_struct.gecko_struct_name} { #[allow(dead_code, unused_variables)] @@ -206,34 +248,7 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} { * Auto-Generated Methods. */ % for longhand in keyword_longhands: - fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T) { - use gecko_style_structs as gss; - use style::properties::longhands::${longhand.ident}::computed_value::T as Keyword; - // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts - self.gecko.${longhand.gecko_ffi_name} = match v { - % for value in longhand.keyword.values_for('gecko'): - Keyword::${to_rust_ident(value)} => gss::${longhand.keyword.gecko_constant(value)} as u8, - % endfor - }; - } - fn copy_${longhand.ident}_from(&mut self, other: &Self) { - self.gecko.${longhand.gecko_ffi_name} = other.gecko.${longhand.gecko_ffi_name}; - } - - %if longhand.need_clone: - fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T { - use gecko_style_structs as gss; - use style::properties::longhands::${longhand.ident}::computed_value::T as Keyword; - // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts - match self.gecko.${longhand.gecko_ffi_name} as u32 { - % for value in longhand.keyword.values_for('gecko'): - gss::${longhand.keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)}, - % endfor - x => panic!("Found unexpected value in style struct for ${longhand.name} property: {}", x), - } - } - - % endif + <%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"> % endfor /* @@ -296,6 +311,16 @@ ${caller.body()} } +<%self:impl_trait style_struct_name="Box" skip_longhands="display"> + + // We manually-implement the |display| property until we get general + // infrastructure for preffing certain values. + <% display_keyword = Keyword("display", "inline block inline-block table inline-table table-row-group " + + "table-header-group table-footer-group table-row table-column-group " + + "table-column table-cell table-caption list-item flex none") %> + <%call expr="impl_keyword('display', 'mDisplay', display_keyword, True)"> + + % for style_struct in data.style_structs: ${declare_style_struct(style_struct)} ${impl_style_struct(style_struct)}