diff options
author | Martin Robinson <mrobinson@igalia.com> | 2020-05-05 13:36:57 +0200 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2020-05-05 20:08:44 +0200 |
commit | 3a74013abcec241d67d2685e52a031409dc59dd4 (patch) | |
tree | 0fc6791d087797120dd960aa0fb1e0a9a6ebce92 /components/style/timer.rs | |
parent | b585ce5b1f181996b2f8109a4e045eb6f5b3e2a0 (diff) | |
download | servo-3a74013abcec241d67d2685e52a031409dc59dd4.tar.gz servo-3a74013abcec241d67d2685e52a031409dc59dd4.zip |
Start having animations conform to the HTML spec
This is a small step toward fixing #19242. The main idea is that the
clock for animations should advance as the event loop ticks. We
accomplish this by moving the clock from layout and naming it the
"animation timeline" which is the spec language. This should fix
flakiness with animations and transitions tests where a reflow could
move animations forward while script was running.
This change also starts to break out transition and animation events
into their own data structure, because it's quite likely that the next
step in fixing #19242 is to no longer send these events through a
channel.
Diffstat (limited to 'components/style/timer.rs')
-rw-r--r-- | components/style/timer.rs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/components/style/timer.rs b/components/style/timer.rs deleted file mode 100644 index 1b5ff8d370c..00000000000 --- a/components/style/timer.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* 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 https://mozilla.org/MPL/2.0/. */ - -#![deny(missing_docs)] - -//! A timer module, used to define a `Timer` type, that is controlled by script. - -use time; - -/// The `TimerMode` is used to determine what time should the `Timer` return. -#[derive(Clone, Debug)] -enum TimerMode { - /// The timer should return a fixed value. - Test(f64), - /// The timer should return the actual time. - Current, -} - -/// A `Timer` struct that takes care of giving the current time for animations. -/// -/// This is needed to be allowed to hook the time in the animations' test-mode. -#[derive(Clone, Debug)] -pub struct Timer { - mode: TimerMode, -} - -impl Timer { - /// Creates a new "normal" timer, i.e., a "Current" mode timer. - #[inline] - pub fn new() -> Self { - Timer { - mode: TimerMode::Current, - } - } - - /// Creates a new "test mode" timer, with initial time 0. - #[inline] - pub fn test_mode() -> Self { - Timer { - mode: TimerMode::Test(0.), - } - } - - /// Returns the current time, at least from the caller's perspective. In - /// test mode returns whatever the value is. - pub fn seconds(&self) -> f64 { - match self.mode { - TimerMode::Test(test_value) => test_value, - TimerMode::Current => time::precise_time_s(), - } - } - - /// Increments the current clock. Panics if the clock is not on test mode. - pub fn increment(&mut self, by: f64) { - match self.mode { - TimerMode::Test(ref mut val) => *val += by, - TimerMode::Current => { - panic!("Timer::increment called for a non-test mode timer. This is a bug.") - }, - } - } -} |