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/script/animation_timeline.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/script/animation_timeline.rs')
-rw-r--r-- | components/script/animation_timeline.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/components/script/animation_timeline.rs b/components/script/animation_timeline.rs new file mode 100644 index 00000000000..e0ad520db61 --- /dev/null +++ b/components/script/animation_timeline.rs @@ -0,0 +1,49 @@ +/* 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 timeline module, used to specify an `AnimationTimeline` which determines +//! the time used for synchronizing animations in the script thread. + +use time; + +/// A `AnimationTimeline` which is used to synchronize animations during the script +/// event loop. +#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf)] +pub struct AnimationTimeline { + current_value: f64, +} + +impl AnimationTimeline { + /// Creates a new "normal" timeline, i.e., a "Current" mode timer. + #[inline] + pub fn new() -> Self { + Self { + current_value: time::precise_time_s(), + } + } + + /// Creates a new "test mode" timeline, with initial time 0. + #[inline] + pub fn new_for_testing() -> Self { + Self { current_value: 0. } + } + + /// Returns the current value of the timeline in seconds. + pub fn current_value(&self) -> f64 { + self.current_value + } + + /// Updates the value of the `AnimationTimeline` to the current clock time. + pub fn update(&mut self) { + self.current_value = time::precise_time_s(); + } + + /// Increments the current value of the timeline by a specific number of seconds. + /// This is used for testing. + pub fn advance_specific(&mut self, by: f64) { + self.current_value += by; + } +} |