diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index c8e72ca1df4..cb8f2970ca0 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -3057,32 +3057,17 @@ pub fn compare_property_priority(a: &PropertyId, b: &PropertyId) -> cmp::Orderin return a_category.cmp(&b_category); } - if a_category == PropertyCategory::Shorthand { - let a = a.as_shorthand().unwrap(); - let b = b.as_shorthand().unwrap(); - // Within shorthands, sort by the number of subproperties, then by IDL - // name. - let subprop_count_a = a.longhands().count(); - let subprop_count_b = b.longhands().count(); - return subprop_count_a.cmp(&subprop_count_b).then_with(|| { - get_idl_name_sort_order(a).cmp(&get_idl_name_sort_order(b)) - }); + if a_category != PropertyCategory::Shorthand { + return cmp::Ordering::Equal; } - cmp::Ordering::Equal -} - -fn get_idl_name_sort_order(shorthand: ShorthandId) -> u32 { -<% -# Sort by IDL name. -sorted_shorthands = sorted(data.shorthands, key=lambda p: to_idl_name(p.ident)) - -# Annotate with sorted position -sorted_shorthands = [(p, position) for position, p in enumerate(sorted_shorthands)] -%> - match shorthand { - % for property, position in sorted_shorthands: - ShorthandId::${property.camel_case} => ${position}, - % endfor - } + let a = a.as_shorthand().unwrap(); + let b = b.as_shorthand().unwrap(); + // Within shorthands, sort by the number of subproperties, then by IDL + // name. + let subprop_count_a = a.longhands().count(); + let subprop_count_b = b.longhands().count(); + subprop_count_a.cmp(&subprop_count_b).then_with(|| { + a.idl_name_sort_order().cmp(&b.idl_name_sort_order()) + }) } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 027a3eba28b..6676e956e38 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1453,6 +1453,25 @@ impl ShorthandId { } } + /// Returns the order in which this property appears relative to other + /// shorthands in idl-name-sorting order. + #[inline] + pub fn idl_name_sort_order(self) -> u32 { + <% + from data import to_idl_name + ordered = {} + sorted_shorthands = sorted(data.shorthands, key=lambda p: to_idl_name(p.ident)) + for order, shorthand in enumerate(sorted_shorthands): + ordered[shorthand.ident] = order + %> + static IDL_NAME_SORT_ORDER: [u32; ${len(data.shorthands)}] = [ + % for property in data.shorthands: + ${ordered[property.ident]}, + % endfor + ]; + IDL_NAME_SORT_ORDER[self as usize] + } + fn parse_into<'i, 't>( &self, declarations: &mut SourcePropertyDeclaration,