Skip to content

Commit

Permalink
Handle enum classes for clonable properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
bholley committed Aug 10, 2016
1 parent 7afe037 commit 1cd76c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions components/style/properties/data.py
Expand Up @@ -58,6 +58,9 @@ def gecko_constant(self, value):
def needs_cast(self):
return self.gecko_enum_prefix is None

def maybe_cast(self, type_str):
return "as " + type_str if self.needs_cast() else ""


class Longhand(object):
def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None,
Expand Down
10 changes: 3 additions & 7 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -220,11 +220,7 @@ def set_gecko_property(ffi_name, expr):
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
let result = match v {
% for value in keyword.values_for('gecko'):
% if keyword.needs_cast():
Keyword::${to_rust_ident(value)} => structs::${keyword.gecko_constant(value)} as u8,
% else:
Keyword::${to_rust_ident(value)} => structs::${keyword.gecko_constant(value)},
% endif
Keyword::${to_rust_ident(value)} => structs::${keyword.gecko_constant(value)} ${keyword.maybe_cast("u8")},
% endfor
};
${set_gecko_property(gecko_ffi_name, "result")}
Expand All @@ -236,11 +232,11 @@ def set_gecko_property(ffi_name, expr):
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use properties::longhands::${ident}::computed_value::T as Keyword;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match ${get_gecko_property(gecko_ffi_name)} as u32 {
match ${get_gecko_property(gecko_ffi_name)} ${keyword.maybe_cast("u32")} {
% for value in keyword.values_for('gecko'):
structs::${keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)},
% endfor
x => panic!("Found unexpected value in style struct for ${ident} property: {}", x),
x => panic!("Found unexpected value in style struct for ${ident} property: {:?}", x),
}
}
</%def>
Expand Down

0 comments on commit 1cd76c2

Please sign in to comment.