servo: Merge #14851 - animation-iteration-count property is a number instead of integer (from hiikezoe:float-iteration-count-rebased); r=emilio
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Thu, 05 Jan 2017 03:44:20 -0800
changeset 340481 f8efa65177f569d09e3f2ab8ea5cc97622cae7f6
parent 340480 92687a59268d009dcf60d1718887514832f1bd08
child 340482 0951b0e0964a92574ddcbe371ff0e52926e8d441
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
servo: Merge #14851 - animation-iteration-count property is a number instead of integer (from hiikezoe:float-iteration-count-rebased); r=emilio <!-- Please describe your changes on the following line: --> This is a revised PR for #14732. @emilio? --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 1d9bbfa07b5aef22a318808e3796872ee12e665c
servo/components/style/animation.rs
servo/components/style/properties/longhand/box.mako.rs
servo/tests/unit/style/parsing/animation.rs
servo/tests/unit/style/parsing/mod.rs
--- a/servo/components/style/animation.rs
+++ b/servo/components/style/animation.rs
@@ -27,17 +27,17 @@ use values::computed::Time;
 ///
 /// If the iteration count is infinite, there's no other state, otherwise we
 /// have to keep track the current iteration and the max iteration count.
 #[derive(Debug, Clone)]
 pub enum KeyframesIterationState {
     /// Infinite iterations, so no need to track a state.
     Infinite,
     /// Current and max iterations.
-    Finite(u32, u32),
+    Finite(f32, f32),
 }
 
 /// This structure represents wether an animation is actually running.
 ///
 /// An animation can be running, or paused at a given time.
 #[derive(Debug, Clone)]
 pub enum KeyframesRunningState {
     /// This animation is paused. The inner field is the percentage of progress
@@ -87,17 +87,17 @@ impl KeyframesAnimationState {
         self.started_at += self.duration + self.delay;
         match self.running_state {
             // If it's paused, don't update direction or iteration count.
             KeyframesRunningState::Paused(_) => return true,
             KeyframesRunningState::Running => {},
         }
 
         if let KeyframesIterationState::Finite(ref mut current, ref max) = self.iteration_state {
-            *current += 1;
+            *current += 1.0;
             // NB: This prevent us from updating the direction, which might be
             // needed for the correct handling of animation-fill-mode.
             if *current >= *max {
                 return false;
             }
         }
 
         // Update the next iteration direction if applicable.
@@ -469,17 +469,17 @@ pub fn maybe_start_animations(context: &
             }
 
             let delay = box_style.animation_delay_mod(i).seconds();
             let now = context.timer.seconds();
             let animation_start = now + delay as f64;
             let duration = box_style.animation_duration_mod(i).seconds();
             let iteration_state = match box_style.animation_iteration_count_mod(i) {
                 AnimationIterationCount::Infinite => KeyframesIterationState::Infinite,
-                AnimationIterationCount::Number(n) => KeyframesIterationState::Finite(0, n),
+                AnimationIterationCount::Number(n) => KeyframesIterationState::Finite(0.0, n),
             };
 
             let animation_direction = box_style.animation_direction_mod(i);
 
             let initial_direction = match animation_direction {
                 AnimationDirection::normal |
                 AnimationDirection::alternate => AnimationDirection::normal,
                 AnimationDirection::reverse |
--- a/servo/components/style/properties/longhand/box.mako.rs
+++ b/servo/components/style/properties/longhand/box.mako.rs
@@ -823,35 +823,36 @@
 
     pub mod computed_value {
         use parser::{Parse, ParserContext};
         use std::fmt;
         use style_traits::ToCss;
 
         pub use self::AnimationIterationCount as SingleComputedValue;
 
+        // https://drafts.csswg.org/css-animations/#animation-iteration-count
         #[derive(Debug, Clone, PartialEq)]
         #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
         pub enum AnimationIterationCount {
-            Number(u32),
+            Number(f32),
             Infinite,
         }
 
         impl Parse for AnimationIterationCount {
             fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
                 if input.try(|input| input.expect_ident_matching("infinite")).is_ok() {
                     return Ok(AnimationIterationCount::Infinite)
                 }
 
-                let number = try!(input.expect_integer());
-                if number < 0 {
+                let number = try!(input.expect_number());
+                if number < 0.0 {
                     return Err(());
                 }
 
-                Ok(AnimationIterationCount::Number(number as u32))
+                Ok(AnimationIterationCount::Number(number))
             }
         }
 
         impl ToCss for AnimationIterationCount {
             fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
                 match *self {
                     AnimationIterationCount::Number(n) => write!(dest, "{}", n),
                     AnimationIterationCount::Infinite => dest.write_str("infinite"),
@@ -881,17 +882,17 @@
 
     pub use self::computed_value::AnimationIterationCount;
     pub use self::computed_value::AnimationIterationCount as SingleSpecifiedValue;
     pub use self::computed_value::T as SpecifiedValue;
     impl NoViewportPercentage for SpecifiedValue {}
 
     #[inline]
     pub fn get_initial_single_value() -> AnimationIterationCount {
-        AnimationIterationCount::Number(1)
+        AnimationIterationCount::Number(1.0)
     }
 
     #[inline]
     pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
         Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| {
             AnimationIterationCount::parse(context, i)
         }))))
     }
new file mode 100644
--- /dev/null
+++ b/servo/tests/unit/style/parsing/animation.rs
@@ -0,0 +1,21 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use cssparser::Parser;
+use media_queries::CSSErrorReporterTest;
+use parsing::parse;
+use style::parser::{Parse, ParserContext};
+use style::properties::longhands::animation_iteration_count::computed_value::AnimationIterationCount;
+use style::stylesheets::Origin;
+use style_traits::ToCss;
+
+#[test]
+fn test_animation_iteration() {
+    assert_roundtrip_with_context!(AnimationIterationCount::parse, "0", "0");
+    assert_roundtrip_with_context!(AnimationIterationCount::parse, "0.1", "0.1");
+    assert_roundtrip_with_context!(AnimationIterationCount::parse, "infinite", "infinite");
+
+    // Negative numbers are invalid
+    assert!(parse(AnimationIterationCount::parse, "-1").is_err());
+}
--- a/servo/tests/unit/style/parsing/mod.rs
+++ b/servo/tests/unit/style/parsing/mod.rs
@@ -42,16 +42,17 @@ macro_rules! assert_roundtrip_with_conte
 macro_rules! parse_longhand {
     ($name:ident, $s:expr) => {{
         let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
         let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
         $name::parse(&context, &mut Parser::new($s)).unwrap()
     }};
 }
 
+mod animation;
 mod background;
 mod basic_shape;
 mod border;
 mod font;
 mod image;
 mod inherited_box;
 mod inherited_text;
 mod mask;