From 2aee174b6d38201758efd0748528f54e4ec03b4a Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 11 Apr 2018 15:55:09 +1000 Subject: [PATCH 1/2] Put alias instances into {longhand,shorthand}.alias. --- components/style/properties/data.py | 6 +++-- .../style/properties/properties.mako.rs | 22 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index c0b6d255fa4..12e833ec907 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -460,7 +460,8 @@ class PropertiesData(object): longhand = Longhand(self.current_style_struct, name, **kwargs) self.add_prefixed_aliases(longhand) - self.longhand_aliases += list(map(lambda x: Alias(x, longhand), longhand.alias)) + longhand.alias = list(map(lambda x: Alias(x, longhand), longhand.alias)) + self.longhand_aliases += longhand.alias self.current_style_struct.longhands.append(longhand) self.longhands.append(longhand) self.longhands_by_name[name] = longhand @@ -475,7 +476,8 @@ class PropertiesData(object): sub_properties = [self.longhands_by_name[s] for s in sub_properties] shorthand = Shorthand(name, sub_properties, *args, **kwargs) self.add_prefixed_aliases(shorthand) - self.shorthand_aliases += list(map(lambda x: Alias(x, shorthand), shorthand.alias)) + shorthand.alias = list(map(lambda x: Alias(x, shorthand), shorthand.alias)) + self.shorthand_aliases += shorthand.alias self.shorthands.append(shorthand) return shorthand diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 39e9b25fa1f..59f9fa20dc6 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1578,10 +1578,10 @@ impl PropertyId { % for (kind, properties) in [("Longhand", data.longhands), ("Shorthand", data.shorthands)]: % for property in properties: "${property.name}" => StaticId::${kind}(${kind}Id::${property.camel_case}), - % for name in property.alias: - "${name}" => { + % for alias in property.alias: + "${alias.name}" => { StaticId::${kind}Alias(${kind}Id::${property.camel_case}, - AliasId::${to_camel_case(name)}) + AliasId::${alias.camel_case}) }, % endfor % endfor @@ -1621,10 +1621,10 @@ impl PropertyId { Ok(PropertyId::Longhand(LonghandId::${property.camel_case})) } % for alias in property.alias: - ${helpers.alias_to_nscsspropertyid(alias)} => { + ${helpers.alias_to_nscsspropertyid(alias.name)} => { Ok(PropertyId::LonghandAlias( LonghandId::${property.camel_case}, - AliasId::${to_camel_case(alias)} + AliasId::${alias.camel_case} )) } % endfor @@ -1634,10 +1634,10 @@ impl PropertyId { Ok(PropertyId::Shorthand(ShorthandId::${property.camel_case})) } % for alias in property.alias: - ${helpers.alias_to_nscsspropertyid(alias)} => { + ${helpers.alias_to_nscsspropertyid(alias.name)} => { Ok(PropertyId::ShorthandAlias( ShorthandId::${property.camel_case}, - AliasId::${to_camel_case(alias)} + AliasId::${alias.camel_case} )) } % endfor @@ -3868,12 +3868,12 @@ macro_rules! css_properties_accessors { % for kind, props in [("Longhand", data.longhands), ("Shorthand", data.shorthands)]: % for property in props: % if property.enabled_in_content(): - % for name in [property.name] + property.alias: - % if '-' in name: - [${to_rust_ident(name).capitalize()}, Set${to_rust_ident(name).capitalize()}, + % for prop in [property] + property.alias: + % if '-' in prop.name: + [${prop.ident.capitalize()}, Set${prop.ident.capitalize()}, PropertyId::${kind}(${kind}Id::${property.camel_case})], % endif - [${to_camel_case(name)}, Set${to_camel_case(name)}, + [${prop.camel_case}, Set${prop.camel_case}, PropertyId::${kind}(${kind}Id::${property.camel_case})], % endfor % endif From 1599357cffb03fc2e890c3f91e79f471b3f9bf8f Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 11 Apr 2018 15:55:11 +1000 Subject: [PATCH 2/2] Make nscssproperty a method of longhand/shorthand/alias class. --- components/style/properties/data.py | 12 ++++++++++++ components/style/properties/helpers.mako.rs | 14 -------------- .../helpers/animated_properties.mako.rs | 8 ++++---- components/style/properties/properties.mako.rs | 18 ++++++------------ 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 12e833ec907..823f611638b 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -299,6 +299,12 @@ class Longhand(object): return computed return "<{} as ToAnimatedValue>::AnimatedValue".format(computed) + def nscsspropertyid(self): + ident = self.ident + if ident == "float": + ident = "float_" + return "nsCSSPropertyID::eCSSProperty_%s" % ident + class Shorthand(object): def __init__(self, name, sub_properties, spec=None, servo_pref=None, gecko_pref=None, @@ -362,6 +368,9 @@ class Shorthand(object): def enabled_in_content(self): return self.enabled_in == "content" + def nscsspropertyid(self): + return "nsCSSPropertyID::eCSSProperty_%s" % self.ident + class Alias(object): def __init__(self, name, original): @@ -388,6 +397,9 @@ class Alias(object): def enabled_in_content(self): return self.enabled_in == "content" + def nscsspropertyid(self): + return "nsCSSPropertyID::eCSSPropertyAlias_%s" % self.camel_case + class Method(object): def __init__(self, name, return_type=None, arg_types=None, is_mut=False): diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 43c912516f3..90e070d03c4 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -872,17 +872,3 @@ } - -<%def name="alias_to_nscsspropertyid(alias)"> - <% - return "nsCSSPropertyID::eCSSPropertyAlias_%s" % to_camel_case(alias) - %> - - -<%def name="to_nscsspropertyid(ident)"> - <% - if ident == "float": - ident = "float_" - return "nsCSSPropertyID::eCSSProperty_%s" % ident - %> - diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 237cf021bea..a06d9f62f71 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -68,7 +68,7 @@ pub fn nscsspropertyid_is_animatable(property: nsCSSPropertyID) -> bool { match property { % for prop in data.longhands + data.shorthands_except_all(): % if prop.animatable: - ${helpers.to_nscsspropertyid(prop.ident)} => true, + ${prop.nscsspropertyid()} => true, % endif % endfor _ => false @@ -154,12 +154,12 @@ impl From for TransitionProperty { fn from(property: nsCSSPropertyID) -> TransitionProperty { match property { % for prop in data.longhands: - ${helpers.to_nscsspropertyid(prop.ident)} => { + ${prop.nscsspropertyid()} => { TransitionProperty::Longhand(LonghandId::${prop.camel_case}) } % endfor % for prop in data.shorthands_except_all(): - ${helpers.to_nscsspropertyid(prop.ident)} => { + ${prop.nscsspropertyid()} => { TransitionProperty::Shorthand(ShorthandId::${prop.camel_case}) } % endfor @@ -179,7 +179,7 @@ pub fn nscsspropertyid_is_transitionable(property: nsCSSPropertyID) -> bool { match property { % for prop in data.longhands + data.shorthands_except_all(): % if prop.transitionable: - ${helpers.to_nscsspropertyid(prop.ident)} => true, + ${prop.nscsspropertyid()} => true, % endif % endfor _ => false diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 59f9fa20dc6..a27a2d2e579 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -424,14 +424,8 @@ impl NonCustomPropertyId { #[cfg(feature = "gecko")] fn to_nscsspropertyid(self) -> nsCSSPropertyID { static MAP: [nsCSSPropertyID; ${len(data.longhands) + len(data.shorthands) + len(data.all_aliases())}] = [ - % for property in data.longhands: - ${helpers.to_nscsspropertyid(property.ident)}, - % endfor - % for property in data.shorthands: - ${helpers.to_nscsspropertyid(property.ident)}, - % endfor - % for property in data.all_aliases(): - ${helpers.alias_to_nscsspropertyid(property.ident)}, + % for property in data.longhands + data.shorthands + data.all_aliases(): + ${property.nscsspropertyid()}, % endfor ]; @@ -1617,11 +1611,11 @@ impl PropertyId { use gecko_bindings::structs::*; match id { % for property in data.longhands: - ${helpers.to_nscsspropertyid(property.ident)} => { + ${property.nscsspropertyid()} => { Ok(PropertyId::Longhand(LonghandId::${property.camel_case})) } % for alias in property.alias: - ${helpers.alias_to_nscsspropertyid(alias.name)} => { + ${alias.nscsspropertyid()} => { Ok(PropertyId::LonghandAlias( LonghandId::${property.camel_case}, AliasId::${alias.camel_case} @@ -1630,11 +1624,11 @@ impl PropertyId { % endfor % endfor % for property in data.shorthands: - ${helpers.to_nscsspropertyid(property.ident)} => { + ${property.nscsspropertyid()} => { Ok(PropertyId::Shorthand(ShorthandId::${property.camel_case})) } % for alias in property.alias: - ${helpers.alias_to_nscsspropertyid(alias.name)} => { + ${alias.nscsspropertyid()} => { Ok(PropertyId::ShorthandAlias( ShorthandId::${property.camel_case}, AliasId::${alias.camel_case}