Bug 1341372 - Part 5: Add TransitionProperty::any. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 14 Apr 2017 10:41:04 +0800
changeset 563240 fc5e7ff70ba599718002f1a09c5fba567b20953b
parent 562568 d4d944d551ff6f41da27284ca7630b0a62a23f45
child 563241 18f6a5cb29665670e685504500a341e69224f8d8
child 563254 11cc9435b34d9c9e2dcf0d85d73581a043fac61e
child 563260 fad33133b13b12235c0769b48752a2ad0c4c4eea
child 563350 c99869c661b25cd5da51d6b1f434dbaa77ae46e0
push id54249
push userbmo:boris.chiou@gmail.com
push dateSat, 15 Apr 2017 18:25:11 +0000
bugs1341372
milestone55.0a1
Bug 1341372 - Part 5: Add TransitionProperty::any. TransitionProperty::any returns true if one of its closure returns true. MozReview-Commit-ID: 4YsKkHaWCYq
servo/components/style/properties/helpers/animated_properties.mako.rs
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -61,16 +61,29 @@ impl TransitionProperty {
     pub fn each<F: FnMut(TransitionProperty) -> ()>(mut cb: F) {
         % for prop in data.longhands:
             % if prop.animatable:
                 cb(TransitionProperty::${prop.camel_case});
             % endif
         % endfor
     }
 
+    /// Iterates over each property that is not `All`, and will return true if any of the cb
+    /// returns true.
+    pub fn any<F: FnMut(TransitionProperty) -> bool>(mut cb: F) -> bool {
+        % for prop in data.longhands:
+            % if prop.animatable:
+                if cb(TransitionProperty::${prop.camel_case}) {
+                    return true;
+                }
+            % endif
+        % endfor
+        false
+    }
+
     /// Parse a transition-property value.
     pub fn parse(input: &mut Parser) -> Result<Self, ()> {
         match_ignore_ascii_case! { &try!(input.expect_ident()),
             "all" => Ok(TransitionProperty::All),
             % for prop in data.longhands:
                 % if prop.animatable:
                     "${prop.name}" => Ok(TransitionProperty::${prop.camel_case}),
                 % endif