mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Add automatic generation of geckolib property setters for keyword properties.
This adds gecko support for ~45 CSS properties.
This commit is contained in:
parent
1bbdadc1ba
commit
e12ee065dc
2 changed files with 54 additions and 4 deletions
|
@ -62,7 +62,8 @@ try:
|
||||||
style_template.render(PRODUCT='gecko')
|
style_template.render(PRODUCT='gecko')
|
||||||
|
|
||||||
geckolib_template = Template(filename=os.environ['GECKOLIB_TEMPLATE'], input_encoding='utf8')
|
geckolib_template = Template(filename=os.environ['GECKOLIB_TEMPLATE'], input_encoding='utf8')
|
||||||
output = geckolib_template.render(STYLE_STRUCTS = style_template.module.STYLE_STRUCTS)
|
output = geckolib_template.render(STYLE_STRUCTS = style_template.module.STYLE_STRUCTS,
|
||||||
|
to_rust_ident = style_template.module.to_rust_ident)
|
||||||
print(output.encode('utf8'))
|
print(output.encode('utf8'))
|
||||||
except:
|
except:
|
||||||
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
|
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
|
||||||
|
|
|
@ -13,6 +13,7 @@ use bindings::Gecko_CopyConstruct_${style_struct.gecko_ffi_name};
|
||||||
use bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
|
use bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
use gecko_style_structs;
|
||||||
use heapsize::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use std::mem::zeroed;
|
use std::mem::zeroed;
|
||||||
|
@ -165,6 +166,37 @@ impl Debug for ${style_struct.gecko_ffi_name} {
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="raw_impl_trait(style_struct, skip_longhands=None, skip_additionals=None)">
|
<%def name="raw_impl_trait(style_struct, skip_longhands=None, skip_additionals=None)">
|
||||||
|
<%
|
||||||
|
longhands = [x for x in style_struct.longhands
|
||||||
|
if not (skip_longhands and x.name in skip_longhands)]
|
||||||
|
|
||||||
|
#
|
||||||
|
# Make a list of types we can't auto-generate.
|
||||||
|
#
|
||||||
|
force_stub = [];
|
||||||
|
# These are currently being shuffled to a different style struct on the gecko side.
|
||||||
|
force_stub += ["backface-visibility", "transform-box", "transform-style"]
|
||||||
|
# These live in nsStyleImageLayers in gecko. Need to figure out what to do about that.
|
||||||
|
force_stub += ["background-repeat", "background-attachment", "background-clip", "background-origin"];
|
||||||
|
# These live in an nsFont member in Gecko. Should be straightforward to do manually.
|
||||||
|
force_stub += ["font-kerning", "font-stretch", "font-style", "font-variant"]
|
||||||
|
# These have unusual representations in gecko.
|
||||||
|
force_stub += ["list-style-type", "text-overflow"]
|
||||||
|
# Enum class instead of NS_STYLE_...
|
||||||
|
force_stub += ["box-sizing"]
|
||||||
|
# Inconsistent constant naming in gecko
|
||||||
|
force_stub += ["unicode-bidi"]
|
||||||
|
# Need to figure out why servo has sideways-left computed value and gecko doesn't
|
||||||
|
force_stub += ["text-orientation"]
|
||||||
|
# Automatic mapping generates NS_STYLE_TEXT_DECORATION_STYLE__MOZ_NONE instead of
|
||||||
|
# NS_STYLE_TEXT_DECORATION_STYLE__NONE
|
||||||
|
force_stub += ["text-decoration-style"]
|
||||||
|
# These are booleans.
|
||||||
|
force_stub += ["page-break-after", "page-break-before"]
|
||||||
|
|
||||||
|
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]
|
||||||
|
%>
|
||||||
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
||||||
/*
|
/*
|
||||||
* Manually-Implemented Methods.
|
* Manually-Implemented Methods.
|
||||||
|
@ -174,9 +206,26 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
||||||
/*
|
/*
|
||||||
* Auto-Generated Methods.
|
* Auto-Generated Methods.
|
||||||
*/
|
*/
|
||||||
<% longhands = [x for x in style_struct.longhands
|
% for longhand in keyword_longhands:
|
||||||
if not (skip_longhands and x.name in skip_longhands)] %>
|
fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T) {
|
||||||
% for longhand in longhands:
|
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};
|
||||||
|
}
|
||||||
|
% endfor
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stubs.
|
||||||
|
*/
|
||||||
|
% for longhand in stub_longhands:
|
||||||
fn set_${longhand.ident}(&mut self, _: longhands::${longhand.ident}::computed_value::T) {
|
fn set_${longhand.ident}(&mut self, _: longhands::${longhand.ident}::computed_value::T) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue