Skip to content

Truly independent web browser

LibWeb: Have clock lanes read the paint-order tree of their frame

Aliaksandr Kalenika46809ab4628
diff --git a/Libraries/LibWeb/Compositor/NavigablePresenter.cpp b/Libraries/LibWeb/Compositor/NavigablePresenter.cpp
index 70f9ef7ddfb..1bdb283fa0a 100644
--- a/Libraries/LibWeb/Compositor/NavigablePresenter.cpp
+++ b/Libraries/LibWeb/Compositor/NavigablePresenter.cpp
@@ -179,7 +179,7 @@ OwnPtr<SealedPresentation> NavigablePresenter::seal_for_clock_lane(SealedPresent
sealed->recording = Painting::DisplayListRecording {
.visual_context_tree = *m_compositor_visual_context_tree,
.surface_clear_color = m_compositor_display_list->surface_clear_color(),
- .cache_mode = Painting::PaintCommandCacheMode::ReadWrite,
+ .cache_mode = Painting::PaintCommandCacheMode::ReadOnly,
.in_flight = true,
.async_scrolling_metadata = m_compositor_display_list->async_scrolling_metadata(),
.paint_command_cache_source = m_compositor_display_list,
diff --git a/Libraries/LibWeb/Rust/src/painting/record/recorder_state.rs b/Libraries/LibWeb/Rust/src/painting/record/recorder_state.rs
index 1d267387b3f..9c14cc8ded1 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/recorder_state.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/recorder_state.rs
@@ -7,11 +7,67 @@
use crate::css::css_pixels::CssPixelRect;
use crate::layout::node_data::NodeSlotId;
use crate::painting::record::inputs::RecordingInputs;
-use crate::painting::record::order_tree::PaintOrderTree;
+use crate::painting::record::order_tree::{PaintOrderTree, PaintOrderTreeAccess};
use crate::painting::record::scratch::RecordingScratch;
use crate::painting::record::{PublishedHitTestItems, RecordingOutput};
use std::cell::RefCell;
-use std::sync::Arc;
+use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
+
+#[derive(Default)]
+struct VersionedPaintOrderTree {
+ tree: PaintOrderTree,
+ rewrites: u64,
+}
+
+/// A hold on a document's one paint-order tree, which only the recordings of its host rewrite. A fork of the recorder
+/// state reads the tree as the recording it forked from left it, up to the next recording that rewrites it.
+#[derive(Default)]
+pub(crate) struct PaintOrderTreeHandle {
+ shared: Arc<Mutex<VersionedPaintOrderTree>>,
+ reads_as_of: Option<u64>,
+}
+
+impl PaintOrderTreeHandle {
+ fn lock(&self) -> MutexGuard<'_, VersionedPaintOrderTree> {
+ self.shared.lock().unwrap_or_else(PoisonError::into_inner)
+ }
+
+ fn reader(&self) -> Self {
+ Self {
+ shared: Arc::clone(&self.shared),
+ reads_as_of: Some(self.lock().rewrites),
+ }
+ }
+
+ pub(crate) fn is_reader(&self) -> bool {
+ self.reads_as_of.is_some()
+ }
+
+ /// Whether the tree is as this hold first found it, or this hold is the host's, which always reads it as it is.
+ pub(crate) fn reads_current_tree(&self) -> bool {
+ self.reads_as_of.is_none_or(|rewrites| rewrites == self.lock().rewrites)
+ }
+
+ /// Runs `recording` on the tree, which it rewrites where `publishes_recording` and this hold is the host's, and
+ /// otherwise only reads. Answers what it answered, and whether it rewrote the tree.
+ pub(crate) fn with_access<R>(
+ &self,
+ publishes_recording: bool,
+ recording: impl FnOnce(PaintOrderTreeAccess<'_>) -> R,
+ ) -> (R, bool) {
+ let mut held = self.lock();
+ let held = &mut *held;
+ let rewrites = publishes_recording && !self.is_reader();
+ let access = match rewrites {
+ true => {
+ held.rewrites += 1;
+ PaintOrderTreeAccess::Rewrites(&mut held.tree)
+ }
+ false => PaintOrderTreeAccess::Reads(&held.tree),
+ };
+ (recording(access), rewrites)
+ }
+}
/// What the display list recording keeps from one recording of a document to the next. Only the
/// recording and its publication write it, and nothing the document publishes for the paint side
@@ -23,7 +79,7 @@ pub(crate) struct RecorderState {
pub(crate) published_hit_test_items: Option<Arc<PublishedHitTestItems>>,
/// The paint-order tree describing the published recording; a recording that publishes
/// appends to it and publication or discarding decides what stays.
- pub(crate) paint_order_tree: PaintOrderTree,
+ pub(crate) paint_order_tree: PaintOrderTreeHandle,
/// The recording's workspace, whose tables one recording leaves for the next to reuse.
pub(crate) scratch: RecordingScratch,
/// The absolute rects the recordings computed, which stay valid while the document's geometry
@@ -35,12 +91,12 @@ pub(crate) struct RecorderState {
impl RecorderState {
/// A fork of the recorder state, for a fork of the document's render state to record with: it copies clean output
- /// from the same recording, and keeps no scratch or memo of its own.
+ /// from the same recording, reads the same paint-order tree, and keeps no scratch or memo of its own.
pub(crate) fn fork(&self) -> Self {
Self {
published_recording: self.published_recording.clone(),
published_hit_test_items: self.published_hit_test_items.clone(),
- paint_order_tree: self.paint_order_tree.clone(),
+ paint_order_tree: self.paint_order_tree.reader(),
scratch: Default::default(),
absolute_rects: Default::default(),
published_inputs: self.published_inputs.clone(),
@@ -84,3 +140,55 @@ impl RecorderState {
self.paint_order_tree = Default::default();
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::painting::paint_order_plan::PaintScope;
+ use crate::painting::record::order_tree::{ChildEntry, OutputSize, ScopeId};
+
+ fn publish_a_tree(handle: &PaintOrderTreeHandle) -> bool {
+ let (_, rewrote) = handle.with_access(true, |mut access| {
+ if let Some(tree) = access.rewrites() {
+ let scope = PaintScope::stacking_context(NodeSlotId::new(1, 1));
+ let root = tree.allocate_scope(scope, ScopeId::NONE);
+ tree.finish_recording(root, ChildEntry::scope(root, OutputSize::default()));
+ }
+ });
+ rewrote
+ }
+
+ fn scope_count(handle: &PaintOrderTreeHandle) -> usize {
+ handle.with_access(false, |access| access.read().scope_count()).0
+ }
+
+ #[test]
+ fn a_fork_reads_the_tree_of_its_frame_until_the_host_rewrites_it() {
+ let mut host = RecorderState::default();
+ assert!(publish_a_tree(&host.paint_order_tree));
+ let fork = host.fork();
+ assert!(fork.paint_order_tree.is_reader());
+ assert!(!host.paint_order_tree.is_reader());
+ assert_eq!(scope_count(&fork.paint_order_tree), 1);
+
+ // A recording of the host that publishes nothing leaves the tree as the fork read it.
+ scope_count(&host.paint_order_tree);
+ assert!(fork.paint_order_tree.reads_current_tree());
+
+ // The fork never rewrites the tree, whatever its recording publishes.
+ assert!(!publish_a_tree(&fork.paint_order_tree));
+ assert!(fork.paint_order_tree.reads_current_tree());
+
+ assert!(publish_a_tree(&host.paint_order_tree));
+ assert!(!fork.paint_order_tree.reads_current_tree());
+ assert!(host.paint_order_tree.reads_current_tree());
+
+ // Forgetting the published recording starts a tree of the host's own, and leaves the one the fork holds.
+ let fork = host.fork();
+ let scopes_the_fork_reads = scope_count(&fork.paint_order_tree);
+ host.forget_published_recording();
+ assert_eq!(scope_count(&host.paint_order_tree), 0);
+ assert_eq!(scope_count(&fork.paint_order_tree), scopes_the_fork_reads);
+ assert!(fork.paint_order_tree.reads_current_tree());
+ }
+}
diff --git a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs b/Libraries/LibWeb/Rust/src/painting/recording_slot.rs
index 42cad0aaef9..930d5ee6935 100644
--- a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs
+++ b/Libraries/LibWeb/Rust/src/painting/recording_slot.rs
@@ -26,7 +26,6 @@ use crate::painting::paint_state::{PendingRecording, PendingRecordingTrace};
use crate::painting::presentation::Presentation;
use crate::painting::presentation::VectorImageResources;
use crate::painting::published_frame::PublishedFrame;
-use crate::painting::record::order_tree::PaintOrderTreeAccess;
use crate::painting::record::publish::PresentedOutput;
use crate::painting::record::recorder_state::RecorderState;
use crate::painting::record::vector_images::VectorImageRenderRequest;
@@ -450,28 +449,25 @@ pub(crate) fn record_frame(
published_inputs,
} = recorder;
let source = PaintSource::new(&frame, absolute_rects);
- let tree = match inputs.publishes_recording {
- true => PaintOrderTreeAccess::Rewrites(paint_order_tree),
- false => PaintOrderTreeAccess::Reads(paint_order_tree),
- };
- let recording = crate::painting::record::traversal::record_display_list(
- &source,
- scratch,
- tree,
- viewport,
- &inputs,
- published_recording.clone(),
- published_hit_test_items.clone(),
- trace_recordings,
- );
+ let (recording, publishes_recording) = paint_order_tree.with_access(inputs.publishes_recording, |tree| {
+ crate::painting::record::traversal::record_display_list(
+ &source,
+ scratch,
+ tree,
+ viewport,
+ &inputs,
+ published_recording.clone(),
+ published_hit_test_items.clone(),
+ trace_recordings,
+ )
+ });
let trace = trace_recordings.then_some(PendingRecordingTrace {
viewport,
should_paint_overlay: inputs.should_paint_overlay,
});
let svg_paint_resources = frame.svg_paint_resources().clone();
drop(frame);
- let publishes_recording = inputs.publishes_recording;
- if publishes_recording {
+ if inputs.publishes_recording {
*published_inputs = Some(inputs);
}
(
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rs
index 6dd83d58d98..29fbda77d88 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs
@@ -47,10 +47,10 @@ use crate::painting::presentation::Presentation;
use crate::painting::record::damage::PaintDamage;
use crate::painting::record::inputs::UnframedRecordingInputs;
use crate::painting::record::publish::{
- published_vector_image_display_lists, renders_vector_images, take_in_published_output, take_in_recording,
+ PresentedOutput, published_vector_image_display_lists, renders_vector_images, take_in_recording,
};
use crate::painting::record::recorder_state::RecorderState;
-use crate::painting::record::{RecordingInputs, RecordingOutput};
+use crate::painting::record::{PublishedHitTestItems, RecordingInputs, RecordingOutput};
use crate::painting::recording_slot::{
FrameInputs, FrozenFrame, RecordingAnswer, RecordingJob, freeze_recording_frame, present,
present_with_vector_images, record_frame, wait_while_recording_is_held_for_testing,
@@ -347,6 +347,8 @@ pub(crate) struct Lane {
/// Whether a tick left its frame to the host, after which the fork may hold what no frame the lane presented shows,
/// such as visual contexts of another structure than the compositor has: the lane presents no other frame.
frame_left_to_host: bool,
+ /// Whether a tick had a frame presented.
+ presented_a_tick: bool,
/// What the lane's hover moved.
hovered: hover::LaneHover,
/// What the move a tick's hover made started, with the time it made it at, until the tick presents the frame that
@@ -452,6 +454,9 @@ pub(crate) struct ClockRecorder {
pub(super) recorder: RecorderState,
pub(super) presentation: Presentation,
pub(super) presented: TickPresented,
+ /// The hit-test items of the frame a tick presented last. The recorder's stay those of the lane's frame, which every
+ /// tick's frame copies clean output from.
+ pub(super) presented_hit_test_items: Option<Arc<PublishedHitTestItems>>,
}
/// What the recording of a tick's frame presented.
@@ -465,7 +470,7 @@ pub(crate) enum TickPresented {
publishes: bool,
},
/// Nothing: the frame renders an SVG image the recording published last did not draw, which only the host renders,
- /// and the lane samples no more.
+ /// or a recording of the host rewrote the paint-order tree the lane reads, and the lane samples no more.
LeftToHost,
}
@@ -1306,6 +1311,7 @@ impl Lane {
settling_frames: 0,
parked,
frame_left_to_host: false,
+ presented_a_tick: false,
hovered: hover::LaneHover::default(),
unshown_move: None,
samples_restored: false,
@@ -1332,9 +1338,22 @@ impl Lane {
if self.samples_nothing() && self.state.rejoin_the_state() {
self.hovered.installs.clear();
self.selection_focus_shown = None;
+ // The compositor shows visual contexts of what the ticks presented, which the state the lane rejoins may not
+ // have the structure of.
+ if self.presented_a_tick {
+ self.leave_frame_to_host();
+ }
}
}
+ /// Has the lane present no other frame: the frame is the host's.
+ fn leave_frame_to_host(&mut self) {
+ self.parked = true;
+ self.frame_left_to_host = true;
+ self.hovered.park();
+ self.forget_unshown_move();
+ }
+
/// Has the lane follow no plan, as a rendering update that sealed none leaves it: it ticks nothing until the plan of
/// a later update that presents no frame of its own.
fn unplan(&mut self) {
@@ -1500,10 +1519,7 @@ impl Lane {
if hover::logs_hover() {
eprintln!("{} hover lane: frame left to the host: {reason}", hover::log_time());
}
- self.parked = true;
- self.frame_left_to_host = true;
- self.hovered.park();
- self.forget_unshown_move();
+ self.leave_frame_to_host();
}
}
}
@@ -1548,10 +1564,7 @@ impl Lane {
if hover::logs_hover() {
eprintln!("{} hover lane: frame left to the host: {reason}", hover::log_time());
}
- self.parked = true;
- self.frame_left_to_host = true;
- self.hovered.park();
- self.forget_unshown_move();
+ self.leave_frame_to_host();
}
}
}
@@ -1679,6 +1692,7 @@ impl Lane {
self.recording = TickRecording(crate::paint_stage::ride_presenting(frame, move |frame, presenting| {
clock_recorder.record(frame, presenting)
}));
+ self.presented_a_tick = true;
}
Err(park) => {
self.recording = TickRecording(Riding::landed(clock_recorder));
@@ -1796,7 +1810,7 @@ fn freeze_tick_frame(
let frame_inputs = FrameInputs {
viewport,
css_viewport_rect: inputs.css_viewport_rect,
- publishes_recording: true,
+ publishes_recording: false,
published_root_background_canvas_rect: recorder
.published_recording
.as_ref()
@@ -1818,48 +1832,57 @@ impl ClockRecorder {
/// Paint thread. Only the host renders an SVG image: the frame draws those the recording published last drew, as the
/// host rendered them for it, and leaves the frame to the host where it draws another.
fn record(mut self, frame: SampledFrame<RecordedFrame>, presenting: &mut Presenting) -> Self {
- let Self {
- recorder,
- presentation,
- presented,
- } = &mut self;
+ debug_assert!(self.recorder.paint_order_tree.is_reader());
+ if !self.recorder.paint_order_tree.reads_current_tree() {
+ self.leave_frame_to_host();
+ return self;
+ }
let SampledFrame(RecordedFrame {
frozen,
viewport,
inputs,
visual_contexts,
}) = frame;
- let (pending, _) = record_frame(frozen.frame, recorder, viewport, false, inputs);
+ let (pending, _) = record_frame(frozen.frame, &mut self.recorder, viewport, false, inputs);
let vector_image_display_lists = match renders_vector_images(&pending) {
- true => match published_vector_image_display_lists(&pending, recorder) {
+ true => match published_vector_image_display_lists(&pending, &self.recorder) {
Some(display_list_ids) => Some(display_list_ids),
None => {
- // The recording wrote the paint-order tree, which no longer describes the recording published last.
- recorder.forget_published_recording();
- *presented = TickPresented::LeftToHost;
+ self.leave_frame_to_host();
return self;
}
},
false => None,
};
if let Some(visual_contexts) = visual_contexts {
- presentation.take_visual_context_tree(visual_contexts);
+ self.presentation.take_visual_context_tree(visual_contexts);
}
let output = match vector_image_display_lists {
- Some(display_list_ids) => {
- present_with_vector_images(presentation, pending, recorder, presenting, &display_list_ids)
- }
- None => present(presentation, pending, recorder, presenting),
+ Some(display_list_ids) => present_with_vector_images(
+ &mut self.presentation,
+ pending,
+ &self.recorder,
+ presenting,
+ &display_list_ids,
+ ),
+ None => present(&mut self.presentation, pending, &self.recorder, presenting),
+ };
+ let output = PresentedOutput::of(output);
+ self.presented_hit_test_items = Some(output.published_hit_test_items());
+ self.presented = TickPresented::Frame {
+ output: output.output,
+ hit_test_list_changed: true,
+ publishes: false,
};
- take_in_published_output(recorder, &mut None, output, true, |output, hit_test_list_changed| {
- *presented = TickPresented::Frame {
- output,
- hit_test_list_changed,
- publishes: true,
- };
- });
self
}
+
+ /// Leaves the frame to the host, which a lane that presents no other frame finds no more items to hit test.
+ fn leave_frame_to_host(&mut self) {
+ self.recorder.published_hit_test_items = None;
+ self.presented_hit_test_items = None;
+ self.presented = TickPresented::LeftToHost;
+ }
}
/// Hands the lanes `ticks` belong to a display tick at `frame_time_nanoseconds`, at which the compositor had scrolled to
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
index 49b8fc31ec2..7434eb2ac29 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
@@ -1322,9 +1322,12 @@ impl Lane {
/// The hit-test items of the frame the lane presented last, which come back with its recording.
fn published_hit_test_items(&mut self) -> Option<Arc<PublishedHitTestItems>> {
let recorder = self.recording.0.take(WaitsForTickRecording(()));
- let published = recorder.recorder.published_hit_test_items.clone();
+ let presented = recorder
+ .presented_hit_test_items
+ .clone()
+ .or_else(|| recorder.recorder.published_hit_test_items.clone());
self.recording = TickRecording(Riding::landed(recorder));
- published
+ presented
}
/// The hit-test items of the frame the lane presented last, with the tree of visual contexts of `state` they name as
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs
index 4e7bacd291c..c35c31f7b4b 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs
@@ -179,6 +179,7 @@ impl LaneDelivery {
recorder,
presentation,
presented,
+ presented_hit_test_items: None,
};
let (ticks, frame) = (Arc::clone(&self.ticks), self.frame);
super::super::post_to_render_side(move || {
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-copies-past-a-restructured-tree.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-copies-past-a-restructured-tree.txt
new file mode 100644
index 00000000000..1c4c9056a66
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-copies-past-a-restructured-tree.txt
@@ -0,0 +1,5 @@
+hovering the box that takes a transform: clock
+hovering nothing: clock
+after a tick: animated height 80
+over the transformed box: cursor Crosshair
+last frame presented by: clock
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-keeps-what-an-earlier-tick-moved.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-keeps-what-an-earlier-tick-moved.txt
new file mode 100644
index 00000000000..9a8a7f52251
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-keeps-what-an-earlier-tick-moved.txt
@@ -0,0 +1,6 @@
+after the hover: box at y 200
+after a tick: animated height 70, box at y 200
+over the moved box: cursor Hand
+after a tick: animated height 90
+over the revealed box: cursor IBeam
+last frame presented by: clock
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-copies-past-a-restructured-tree.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-copies-past-a-restructured-tree.html
new file mode 100644
index 00000000000..07435e319c4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-copies-past-a-restructured-tree.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ #restructures, #transformed, #animated { position: absolute; width: 100px; height: 50px; }
+ #restructures { left: 0; top: 0; }
+ #restructures:hover { transform: translateX(10px); }
+ #transformed { left: 0; top: 100px; transform: translateY(10px); cursor: cell; }
+ #animated { left: 200px; top: 0; width: 50px; }
+ #animated.active { animation: grow 10s linear infinite; }
+ @keyframes grow { from { height: 50px; } to { height: 150px; } }
+</style>
+<div id="restructures"></div>
+<div id="transformed"></div>
+<div id="animated"></div>
+<script>
+ // Every tick of a lane records from the lane's own frame, whose clean output names the visual contexts of the tree it
+ // was recorded against. A hover builds the tree with a new structure and another takes that node away again, and the
+ // frames after them still copy that output: the compositor replays them, and hit tests find what they show.
+ asyncTest(async done => {
+ const result = await whileLaneAnimates(() => {
+ animated.classList.add("active");
+ return animated.getAnimations()[0];
+ }, (frameTime, animation, startTime) => {
+ const lines = [];
+ internals.injectHoverPointer(50, 25, startTime + 1000);
+ lines.push(`hovering the box that takes a transform: ${internals.lastFramePresentedBy(document)}`);
+ internals.injectHoverPointer(50, 300, startTime + 2000);
+ lines.push(`hovering nothing: ${internals.lastFramePresentedBy(document)}`);
+ internals.injectClockTick(startTime + 3000);
+ lines.push(`after a tick: animated height ${internals.presentedBorderBox(animated)?.height}`);
+ internals.injectHoverPointer(50, 130, startTime + 4000);
+ lines.push(`over the transformed box: cursor ${internals.currentCursor()}`);
+ lines.push(`last frame presented by: ${internals.lastFramePresentedBy(document)}`);
+ return lines;
+ });
+ for (const line of result)
+ println(line);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-keeps-what-an-earlier-tick-moved.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-keeps-what-an-earlier-tick-moved.html
new file mode 100644
index 00000000000..eb77e97b488
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-keeps-what-an-earlier-tick-moved.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ #hoverer { position: absolute; left: 0; top: 0; width: 100px; height: 50px; }
+ #moved { position: absolute; left: 200px; top: 0; width: 100px; height: 50px; cursor: pointer; }
+ #hoverer:hover #moved { top: 200px; }
+ #revealed { display: none; position: absolute; left: 400px; top: 200px; width: 100px; height: 50px; cursor: text; }
+ #hoverer:hover #revealed { display: block; }
+ #animated { position: absolute; left: 600px; top: 0; width: 50px; height: 50px; }
+ #animated.active { animation: grow 10s linear infinite; }
+ @keyframes grow { from { height: 50px; } to { height: 150px; } }
+</style>
+<div id="hoverer">
+ <div id="moved"></div>
+ <div id="revealed"></div>
+</div>
+<div id="animated"></div>
+<script>
+ // Every tick of a lane records from the lane's own frame. A hover moves one box and reveals another, and ticks that
+ // only move a third box follow. Each frame still has the first two where the hover left them, which the hit tests of
+ // the moves after those ticks find.
+ asyncTest(async done => {
+ const result = await whileLaneAnimates(() => {
+ animated.classList.add("active");
+ return animated.getAnimations()[0];
+ }, (frameTime, animation, startTime) => {
+ const lines = [];
+ internals.injectHoverPointer(50, 25, startTime + 1000);
+ lines.push(`after the hover: box at y ${internals.presentedBorderBox(moved)?.y}`);
+ internals.injectClockTick(startTime + 2000);
+ lines.push(`after a tick: animated height ${internals.presentedBorderBox(animated)?.height}, box at y ${internals.presentedBorderBox(moved)?.y}`);
+ internals.injectHoverPointer(250, 225, startTime + 3000);
+ lines.push(`over the moved box: cursor ${internals.currentCursor()}`);
+ internals.injectClockTick(startTime + 4000);
+ lines.push(`after a tick: animated height ${internals.presentedBorderBox(animated)?.height}`);
+ internals.injectHoverPointer(450, 225, startTime + 5000);
+ lines.push(`over the revealed box: cursor ${internals.currentCursor()}`);
+ lines.push(`last frame presented by: ${internals.lastFramePresentedBy(document)}`);
+ return lines;
+ });
+ for (const line of result)
+ println(line);
+ done();
+ });
+</script>