mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Generate geckolib setters for properties with simple predefined types.
This commit is contained in:
parent
a8e82440ff
commit
d69763b0c1
3 changed files with 24 additions and 3 deletions
|
@ -46,10 +46,11 @@ class Keyword(object):
|
||||||
|
|
||||||
class Longhand(object):
|
class Longhand(object):
|
||||||
def __init__(self, style_struct, name, derived_from=None, keyword=None,
|
def __init__(self, style_struct, name, derived_from=None, keyword=None,
|
||||||
custom_cascade=False, experimental=False, internal=False,
|
predefined_type=None, custom_cascade=False, experimental=False, internal=False,
|
||||||
need_clone=False, gecko_ffi_name=None):
|
need_clone=False, gecko_ffi_name=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.keyword = keyword
|
self.keyword = keyword
|
||||||
|
self.predefined_type = predefined_type
|
||||||
self.ident = to_rust_ident(name)
|
self.ident = to_rust_ident(name)
|
||||||
self.camel_case = to_camel_case(self.ident)
|
self.camel_case = to_camel_case(self.ident)
|
||||||
self.style_struct = style_struct
|
self.style_struct = style_struct
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse', **kwargs)">
|
<%def name="predefined_type(name, type, initial_value, parse_method='parse', **kwargs)">
|
||||||
<%call expr="longhand(name, **kwargs)">
|
<%call expr="longhand(name, predefined_type=type, **kwargs)">
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
pub type SpecifiedValue = specified::${type};
|
pub type SpecifiedValue = specified::${type};
|
||||||
|
|
|
@ -128,6 +128,12 @@ pub struct ${style_struct.gecko_struct_name} {
|
||||||
}
|
}
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="impl_simple_setter(ident, gecko_ffi_name)">
|
||||||
|
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||||
|
${set_gecko_property(gecko_ffi_name, "v")}
|
||||||
|
}
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="impl_simple_copy(ident, gecko_ffi_name)">
|
<%def name="impl_simple_copy(ident, gecko_ffi_name)">
|
||||||
fn copy_${ident}_from(&mut self, other: &Self) {
|
fn copy_${ident}_from(&mut self, other: &Self) {
|
||||||
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
|
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
|
||||||
|
@ -186,6 +192,11 @@ def set_gecko_property(ffi_name, expr):
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="impl_simple(ident, gecko_ffi_name)">
|
||||||
|
<%call expr="impl_simple_setter(ident, gecko_ffi_name)"></%call>
|
||||||
|
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="impl_app_units(ident, gecko_ffi_name, need_clone)">
|
<%def name="impl_app_units(ident, gecko_ffi_name, need_clone)">
|
||||||
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||||
self.gecko.${gecko_ffi_name} = v.0;
|
self.gecko.${gecko_ffi_name} = v.0;
|
||||||
|
@ -284,8 +295,14 @@ impl Debug for ${style_struct.gecko_ffi_name} {
|
||||||
# These are booleans.
|
# These are booleans.
|
||||||
force_stub += ["page-break-after", "page-break-before"]
|
force_stub += ["page-break-after", "page-break-before"]
|
||||||
|
|
||||||
|
simple_types = []
|
||||||
|
|
||||||
keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub]
|
keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub]
|
||||||
stub_longhands = [x for x in longhands if x not in keyword_longhands]
|
simple_longhands = [x for x in longhands
|
||||||
|
if x.predefined_type in simple_types and not x.name in force_stub]
|
||||||
|
|
||||||
|
autogenerated_longhands = keyword_longhands + simple_longhands
|
||||||
|
stub_longhands = [x for x in longhands if x not in autogenerated_longhands]
|
||||||
%>
|
%>
|
||||||
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
||||||
/*
|
/*
|
||||||
|
@ -299,6 +316,9 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
||||||
% for longhand in keyword_longhands:
|
% for longhand in keyword_longhands:
|
||||||
<%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"></%call>
|
<%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"></%call>
|
||||||
% endfor
|
% endfor
|
||||||
|
% for longhand in simple_longhands:
|
||||||
|
<%call expr="impl_simple(longhand.ident, longhand.gecko_ffi_name)"></%call>
|
||||||
|
% endfor
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stubs.
|
* Stubs.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue