Minor codegen refactor for auto-generating some predefined types

This commit is contained in:
Ravi Shankar 2016-10-22 12:24:09 +05:30
parent 6c28d4446a
commit caa745cb81
2 changed files with 23 additions and 10 deletions

View file

@ -63,7 +63,7 @@ class Longhand(object):
def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None,
predefined_type=None, custom_cascade=False, experimental=False, internal=False,
need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False,
allowed_in_keyframe_block=True):
allowed_in_keyframe_block=True, complex_color=False):
self.name = name
self.keyword = keyword
self.predefined_type = predefined_type
@ -77,6 +77,7 @@ class Longhand(object):
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
self.depend_on_viewport_size = depend_on_viewport_size
self.derived_from = (derived_from or "").split()
self.complex_color = complex_color
# https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property

View file

@ -480,16 +480,29 @@ impl Debug for ${style_struct.gecko_struct_name} {
# Types used with predefined_type()-defined properties that we can auto-generate.
predefined_types = {
"LengthOrPercentage": impl_style_coord,
"LengthOrPercentageOrAuto": impl_style_coord,
"LengthOrPercentageOrNone": impl_style_coord,
"Number": impl_simple,
"Opacity": impl_simple,
"Length": impl_style_coord,
"LengthOrPercentage": impl_style_coord,
"LengthOrPercentageOrAuto": impl_style_coord,
"LengthOrPercentageOrNone": impl_style_coord,
"Number": impl_simple,
"Opacity": impl_simple,
"CSSColor": impl_color,
}
keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub]
def predefined_type_method(longhand):
args = dict(ident=longhand.ident, gecko_ffi_name=longhand.gecko_ffi_name,
need_clone=longhand.need_clone)
method = predefined_types[longhand.predefined_type]
# additional type-specific arguments
if longhand.predefined_type in ["CSSColor"]:
args.update(complex_color=longhand.complex_color)
method(**args)
keyword_longhands = [x for x in longhands if x.keyword and x.name not in force_stub]
predefined_longhands = [x for x in longhands
if x.predefined_type in predefined_types and not x.name in force_stub]
if x.predefined_type in predefined_types and x.name not in force_stub]
stub_longhands = [x for x in longhands if x not in keyword_longhands + predefined_longhands]
# If one of the longhands is not handled
@ -522,8 +535,7 @@ impl ${style_struct.gecko_struct_name} {
for longhand in keyword_longhands:
impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)
for longhand in predefined_longhands:
impl_fn = predefined_types[longhand.predefined_type]
impl_fn(longhand.ident, longhand.gecko_ffi_name, need_clone=longhand.need_clone)
predefined_type_method(longhand)
%>
/*