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.
This commit is contained in:
Martin Robinson 2020-05-05 13:36:57 +02:00
parent b585ce5b1f
commit 3a74013abc
45 changed files with 159 additions and 2094 deletions

View file

@ -71,7 +71,6 @@ use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
use servo_arc::Arc as ServoArc;
use servo_atoms::Atom;
use servo_config::opts;
use servo_config::pref;
use servo_url::{ImmutableOrigin, ServoUrl};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
@ -98,7 +97,6 @@ use style::stylesheets::{
};
use style::stylist::Stylist;
use style::thread_state::{self, ThreadState};
use style::timer::Timer;
use style::traversal::DomTraversal;
use style::traversal_flags::TraversalFlags;
use style_traits::CSSPixel;
@ -195,10 +193,6 @@ pub struct LayoutThread {
/// Webrender document.
webrender_document: webrender_api::DocumentId,
/// The timer object to control the timing of the animations. This should
/// only be a test-mode timer during testing for animations.
timer: Timer,
/// Paint time metrics.
paint_time_metrics: PaintTimeMetrics,
@ -545,11 +539,6 @@ impl LayoutThread {
inner_window_dimensions_response: None,
})),
webrender_image_cache: Default::default(),
timer: if pref!(layout.animations.test.enabled) {
Timer::test_mode()
} else {
Timer::new()
},
paint_time_metrics: paint_time_metrics,
busy,
load_webfonts_synchronously,
@ -582,6 +571,7 @@ impl LayoutThread {
guards: StylesheetGuards<'a>,
snapshot_map: &'a SnapshotMap,
origin: ImmutableOrigin,
animation_timeline_value: f64,
) -> LayoutContext<'a> {
LayoutContext {
id: self.id,
@ -593,7 +583,7 @@ impl LayoutThread {
visited_styles_enabled: false,
animation_states: Default::default(),
registered_speculative_painters: &self.registered_painters,
timer: self.timer.clone(),
current_time_for_animations: animation_timeline_value,
traversal_flags: TraversalFlags::empty(),
snapshot_map: snapshot_map,
},
@ -977,12 +967,6 @@ impl LayoutThread {
let device = Device::new(MediaType::screen(), initial_viewport, device_pixel_ratio);
let sheet_origins_affected_by_device_change = self.stylist.set_device(device, &guards);
if pref!(layout.animations.test.enabled) {
if let Some(delta) = data.advance_clock_delta {
self.timer.increment(delta as f64 / 1000.0);
}
}
self.stylist
.force_stylesheet_origins_dirty(sheet_origins_affected_by_device_change);
self.viewport_size =
@ -1082,7 +1066,8 @@ impl LayoutThread {
self.stylist.flush(&guards, Some(element), Some(&map));
// Create a layout context for use throughout the following passes.
let mut layout_context = self.build_layout_context(guards.clone(), &map, origin);
let mut layout_context =
self.build_layout_context(guards.clone(), &map, origin, data.animation_timeline_value);
let traversal = RecalcStyle::new(layout_context);
let token = {