diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index cb8f2970ca0..0b7cc3db957 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -19,7 +19,6 @@ use properties::{CSSWideKeyword, PropertyDeclaration}; use properties::longhands; use properties::longhands::font_weight::computed_value::T as FontWeight; use properties::longhands::visibility::computed_value::T as Visibility; -use properties::PropertyId; use properties::{LonghandId, ShorthandId}; use servo_arc::Arc; use smallvec::SmallVec; @@ -3008,66 +3007,3 @@ impl ToAnimatedZero for AnimatedFilter { } } } - -/// The category a property falls into for ordering purposes. -/// -/// https://drafts.csswg.org/web-animations/#calculating-computed-keyframes -/// -#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] -enum PropertyCategory { - Custom, - PhysicalLonghand, - LogicalLonghand, - Shorthand, -} - -impl PropertyCategory { - fn of(id: &PropertyId) -> Self { - match *id { - PropertyId::Shorthand(..) | - PropertyId::ShorthandAlias(..) => PropertyCategory::Shorthand, - PropertyId::Longhand(id) | - PropertyId::LonghandAlias(id, ..) => { - if id.is_logical() { - PropertyCategory::LogicalLonghand - } else { - PropertyCategory::PhysicalLonghand - } - } - PropertyId::Custom(..) => PropertyCategory::Custom, - } - } -} - -/// A comparator to sort PropertyIds such that physical longhands are sorted -/// before logical longhands and shorthands, shorthands with fewer components -/// are sorted before shorthands with more components, and otherwise shorthands -/// are sorted by IDL name as defined by [Web Animations][property-order]. -/// -/// Using this allows us to prioritize values specified by longhands (or smaller -/// shorthand subsets) when longhands and shorthands are both specified on the -/// one keyframe. -/// -/// [property-order] https://drafts.csswg.org/web-animations/#calculating-computed-keyframes -pub fn compare_property_priority(a: &PropertyId, b: &PropertyId) -> cmp::Ordering { - let a_category = PropertyCategory::of(a); - let b_category = PropertyCategory::of(b); - - if a_category != b_category { - return a_category.cmp(&b_category); - } - - if a_category != PropertyCategory::Shorthand { - return cmp::Ordering::Equal; - } - - 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/values/animated/mod.rs b/components/style/values/animated/mod.rs index 8944f3fc5f4..41482418b1d 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -10,7 +10,9 @@ use app_units::Au; use euclid::{Point2D, Size2D}; +use properties::PropertyId; use smallvec::SmallVec; +use std::cmp; use values::computed::Angle as ComputedAngle; use values::computed::BorderCornerRadius as ComputedBorderCornerRadius; use values::computed::MaxLength as ComputedMaxLength; @@ -21,6 +23,68 @@ use values::computed::url::ComputedUrl; pub mod color; pub mod effects; +/// The category a property falls into for ordering purposes. +/// +/// https://drafts.csswg.org/web-animations/#calculating-computed-keyframes +#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] +enum PropertyCategory { + Custom, + PhysicalLonghand, + LogicalLonghand, + Shorthand, +} + +impl PropertyCategory { + fn of(id: &PropertyId) -> Self { + match *id { + PropertyId::Shorthand(..) | + PropertyId::ShorthandAlias(..) => PropertyCategory::Shorthand, + PropertyId::Longhand(id) | + PropertyId::LonghandAlias(id, ..) => { + if id.is_logical() { + PropertyCategory::LogicalLonghand + } else { + PropertyCategory::PhysicalLonghand + } + } + PropertyId::Custom(..) => PropertyCategory::Custom, + } + } +} + +/// A comparator to sort PropertyIds such that physical longhands are sorted +/// before logical longhands and shorthands, shorthands with fewer components +/// are sorted before shorthands with more components, and otherwise shorthands +/// are sorted by IDL name as defined by [Web Animations][property-order]. +/// +/// Using this allows us to prioritize values specified by longhands (or smaller +/// shorthand subsets) when longhands and shorthands are both specified on the +/// one keyframe. +/// +/// [property-order] https://drafts.csswg.org/web-animations/#calculating-computed-keyframes +pub fn compare_property_priority(a: &PropertyId, b: &PropertyId) -> cmp::Ordering { + let a_category = PropertyCategory::of(a); + let b_category = PropertyCategory::of(b); + + if a_category != b_category { + return a_category.cmp(&b_category); + } + + if a_category != PropertyCategory::Shorthand { + return cmp::Ordering::Equal; + } + + 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()) + }) +} + /// Animate from one value to another. /// /// This trait is derivable with `#[derive(Animate)]`. The derived