Skip to content

Truly independent web browser

LibWeb+Compositor: Hover again as a compositor animation moves content

Zaggy10241c7a2a9b367f
diff --git a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp
index 167ee9f7aaf..9e1621c9815 100644
--- a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp
+++ b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp
@@ -130,6 +130,12 @@ bool AccumulatedVisualContextTree::has_active_visual_animation_at(i64 monotonic_
return Compositing::RustFFI::visual_context_tree_has_active_visual_animation_at(m_rust_tree, monotonic_time_ns);
}
+bool AccumulatedVisualContextTree::running_transform_animation_covers_point(i64 monotonic_time_ns, Gfx::FloatPoint screen_point, ScrollStateSnapshot const& scroll_state) const
+{
+ auto scroll_offsets = scroll_state.device_offsets();
+ return Compositing::RustFFI::visual_context_tree_running_transform_animation_covers_point(m_rust_tree, monotonic_time_ns, screen_point, scroll_offsets.data(), scroll_offsets.size());
+}
+
VisualAnimationSummary AccumulatedVisualContextTree::visual_animation_summary() const
{
auto summary = Compositing::RustFFI::visual_context_tree_visual_animation_summary(m_rust_tree);
diff --git a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h
index a6dbc76ae24..1631c99530a 100644
--- a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h
+++ b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h
@@ -67,6 +67,9 @@ public:
bool has_visual_animations() const;
bool has_active_visual_animation_at(i64 monotonic_time_ns) const;
+ // Whether the point lies in the bounds of a node that a transform animation running at the time moves, through the
+ // values this tree holds: those of a sample at the time, where a frame shows it.
+ bool running_transform_animation_covers_point(i64 monotonic_time_ns, Gfx::FloatPoint screen_point, ScrollStateSnapshot const&) const;
VisualAnimationSummary visual_animation_summary() const;
// One flag per spatial node: whether a transform animation moves the node or an ancestor.
Vector<bool> spatial_nodes_in_subtrees_of_transform_animations() const;
diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
index 0a7a44283dd..b0d77088e8c 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
@@ -1911,6 +1911,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}
}
diff --git a/Libraries/LibCompositing/Rust/src/display_list/effect_clip_plan.rs b/Libraries/LibCompositing/Rust/src/display_list/effect_clip_plan.rs
index 7b1f2e68ce4..c21180d2da3 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/effect_clip_plan.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/effect_clip_plan.rs
@@ -99,6 +99,7 @@ mod tests {
role: TransformDataRole::CssTransform,
sorting_context_root_index: None,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
synthetic_plane: false,
})
}
diff --git a/Libraries/LibCompositing/Rust/src/display_list/effect_geometry.rs b/Libraries/LibCompositing/Rust/src/display_list/effect_geometry.rs
index aad7981d869..0592ba79534 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/effect_geometry.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/effect_geometry.rs
@@ -256,6 +256,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}
}
diff --git a/Libraries/LibCompositing/Rust/src/display_list/replay.rs b/Libraries/LibCompositing/Rust/src/display_list/replay.rs
index b0d3f9ae13c..ba80c26fe91 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/replay.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/replay.rs
@@ -971,6 +971,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
};
let translated = |x: f32, y: f32| {
SpatialData::Transform(TransformData {
@@ -1154,6 +1155,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
})
}
diff --git a/Libraries/LibCompositing/Rust/src/ffi.rs b/Libraries/LibCompositing/Rust/src/ffi.rs
index bb9e1b66800..6640d5eba2b 100644
--- a/Libraries/LibCompositing/Rust/src/ffi.rs
+++ b/Libraries/LibCompositing/Rust/src/ffi.rs
@@ -508,6 +508,23 @@ pub unsafe extern "C" fn visual_context_tree_has_active_visual_animation_at(
unsafe { tree_from_handle(tree) }.has_active_visual_animation_at(sample_time_ns)
}
+/// # Safety
+///
+/// `tree` must be a live retained tree handle, and `scroll_offsets` must address `scroll_offsets_len` points.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn visual_context_tree_running_transform_animation_covers_point(
+ tree: *const c_void,
+ sample_time_ns: i64,
+ screen_point: libgfx_rust::FloatPoint,
+ scroll_offsets: *const libgfx_rust::FloatPoint,
+ scroll_offsets_len: usize,
+) -> bool {
+ let tree = unsafe { tree_from_handle(tree) };
+ // SAFETY: The caller guarantees the offsets address `scroll_offsets_len` points.
+ let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len) };
+ tree.running_transform_animation_covers_point(sample_time_ns, screen_point, scroll_offsets)
+}
+
/// # Safety
///
/// `tree` must be a live retained tree handle.
@@ -593,6 +610,7 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_create() -> *mut c_voi
role: crate::visual_context::TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect::default(),
});
Box::into_raw(Box::new(tree)).cast()
}
@@ -625,6 +643,7 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_append_transform(
role: crate::visual_context::TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect::default(),
}),
SpatialNodeIndex(parent),
)
diff --git a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs b/Libraries/LibCompositing/Rust/src/visual_context/mod.rs
index 442836340c7..96c64826b11 100644
--- a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs
+++ b/Libraries/LibCompositing/Rust/src/visual_context/mod.rs
@@ -41,6 +41,9 @@ pub struct TransformData {
pub role: TransformDataRole,
pub synthetic_plane: bool,
pub establishes_sorting_context: bool,
+ /// The box the node transforms, with what overflows it, in the node's space: what a transform animation of the
+ /// node moves. Empty where the node transforms no box.
+ pub bounds: FloatRect,
}
impl TransformData {
@@ -1480,6 +1483,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}
}
diff --git a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs b/Libraries/LibCompositing/Rust/src/visual_context/queries.rs
index 409b6bcd6a1..afb929023ce 100644
--- a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs
+++ b/Libraries/LibCompositing/Rust/src/visual_context/queries.rs
@@ -886,6 +886,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}
}
diff --git a/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs b/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs
index 709b884b837..227a943823d 100644
--- a/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs
+++ b/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs
@@ -28,7 +28,7 @@ use libgfx_rust::{
};
const SERIALIZED_TREE_MAGIC: u32 = 0x5443_5641;
-const SERIALIZED_TREE_FORMAT: u32 = 9;
+const SERIALIZED_TREE_FORMAT: u32 = 10;
const SPATIAL_KIND_SCROLL: u8 = 0;
const SPATIAL_KIND_STICKY: u8 = 1;
@@ -111,6 +111,12 @@ impl TreeByteWriter {
self.f32(point.x);
self.f32(point.y);
}
+ fn rect(&mut self, rect: FloatRect) {
+ self.f32(rect.x);
+ self.f32(rect.y);
+ self.f32(rect.width);
+ self.f32(rect.height);
+ }
fn size(&mut self, size: FloatSize) {
self.f32(size.width);
self.f32(size.height);
@@ -226,6 +232,14 @@ impl<'a> TreeByteReader<'a> {
y: self.f32()?,
})
}
+ fn rect(&mut self) -> Option<FloatRect> {
+ Some(FloatRect {
+ x: self.f32()?,
+ y: self.f32()?,
+ width: self.f32()?,
+ height: self.f32()?,
+ })
+ }
fn size(&mut self) -> Option<FloatSize> {
Some(FloatSize {
width: self.f32()?,
@@ -335,6 +349,7 @@ fn write_spatial_data(writer: &mut TreeByteWriter, data: &SpatialData) {
writer.u8(transform.role as u8);
writer.bool(transform.synthetic_plane);
writer.bool(transform.establishes_sorting_context);
+ writer.rect(transform.bounds);
}
SpatialData::Perspective(perspective) => {
writer.u8(SPATIAL_KIND_PERSPECTIVE);
@@ -393,6 +408,7 @@ fn read_spatial_data(reader: &mut TreeByteReader<'_>) -> Option<SpatialData> {
role: reader.transform_role()?,
synthetic_plane: reader.bool()?,
establishes_sorting_context: reader.bool()?,
+ bounds: reader.rect()?,
}),
SPATIAL_KIND_PERSPECTIVE => SpatialData::Perspective(PerspectiveData {
matrix: reader.matrix()?,
@@ -953,6 +969,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}
}
diff --git a/Libraries/LibCompositing/Rust/src/visual_context/visual_animations.rs b/Libraries/LibCompositing/Rust/src/visual_context/visual_animations.rs
index 2cf09faf847..fd9f8babb71 100644
--- a/Libraries/LibCompositing/Rust/src/visual_context/visual_animations.rs
+++ b/Libraries/LibCompositing/Rust/src/visual_context/visual_animations.rs
@@ -6,9 +6,13 @@
//! The compositor animations a visual context tree carries, and the trees derived by sampling them.
-use super::{EffectNodeData, EffectNodeIndex, EffectsData, SpatialData, SpatialNodeIndex, VisualContextTree};
+use super::{
+ ClipBehavior, ClipNodeIndex, ContextRef, EffectNodeData, EffectNodeIndex, EffectsData, SpatialData,
+ SpatialNodeIndex, VisualContextTree,
+};
use crate::host::{FfiVisualAnimationSummary, FfiVisualAnimationTargetKind, FfiVisualAnimationTransformOperationKind};
use crate::visual_animation::{VisualAnimation, VisualAnimationSample, VisualAnimationValue};
+use libgfx_rust::FloatPoint;
/// What a frame scheduler needs to bound the content the running animations move: the nodes of the
/// animations whose swept area is bounded, sorted by how the bound is computed, and whether every
@@ -103,6 +107,34 @@ impl VisualContextTree {
.any(|animation| animation.is_active_at(sample_time_ns))
}
+ /// Whether `screen_point` lies in the bounds of a node that a transform animation running at `sample_time_ns`
+ /// moves, through the values the nodes hold: those of this tree sampled at that time, where a frame shows it.
+ pub fn running_transform_animation_covers_point(
+ &self,
+ sample_time_ns: i64,
+ screen_point: FloatPoint,
+ scroll_offsets: &[FloatPoint],
+ ) -> bool {
+ self.visual_animations.iter().any(|animation| {
+ animation.target_kind == FfiVisualAnimationTargetKind::Transform
+ && animation.is_active_at(sample_time_ns)
+ && animation.node_indices.iter().any(|&node_index| {
+ let Some(SpatialData::Transform(transform)) =
+ self.spatial_nodes.get(node_index as usize).map(|node| &node.data)
+ else {
+ return false;
+ };
+ let context = ContextRef {
+ spatial: SpatialNodeIndex(node_index),
+ clip: ClipNodeIndex::NONE,
+ effect: EffectNodeIndex::NONE,
+ };
+ self.transform_point_for_hit_test(context, screen_point, scroll_offsets, ClipBehavior::Ignore)
+ .is_some_and(|local_point| transform.bounds.contains_point(local_point))
+ })
+ })
+ }
+
pub fn visual_animations_target_valid_nodes(&self) -> bool {
self.visual_animations
.iter()
@@ -208,6 +240,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect::default(),
}
}
@@ -314,6 +347,39 @@ mod tests {
assert_eq!(sampled_transform.matrix, translation_matrix(5.0, 0.0, 0.0));
}
+ #[test]
+ fn a_running_transform_animation_covers_a_point_in_the_bounds_it_moves() {
+ let mut tree = VisualContextTree::create(transform_data(FloatMatrix4x4::identity()));
+ // A box from x 150 to 1150 slides 150 pixels a second to the left: it covers x 50 from 2/3 s to 7 1/3 s in.
+ let spatial = tree.append_spatial(
+ SpatialData::Transform(TransformData {
+ bounds: libgfx_rust::FloatRect::new(150.0, 0.0, 1000.0, 100.0),
+ ..transform_data(FloatMatrix4x4::identity())
+ }),
+ VISUAL_VIEWPORT_NODE_INDEX,
+ );
+ tree.set_visual_animations(vec![VisualAnimation {
+ target_kind: FfiVisualAnimationTargetKind::Transform,
+ node_indices: vec![spatial.0],
+ iteration_duration_ms: 10000.0,
+ iteration_count: 1.0,
+ keyframes: vec![keyframe(0.0, translate_x(0.0)), keyframe(1.0, translate_x(-1500.0))],
+ ..VisualAnimation::default()
+ }]);
+ let point = FloatPoint { x: 50.0, y: 50.0 };
+ let covers_at = |time_ns: i64| {
+ tree.with_visual_animation_samples(time_ns)
+ .running_transform_animation_covers_point(time_ns, point, &[])
+ };
+ assert!(!covers_at(milliseconds(0)));
+ assert!(covers_at(milliseconds(2000)));
+ assert!(!covers_at(milliseconds(9000)));
+ // The animation over, the node holds the value the main thread published, which has the box beside the point.
+ assert!(!covers_at(milliseconds(11000)));
+ // The tree answers for the values it holds: unsampled, the box is where the main thread published it.
+ assert!(!tree.running_transform_animation_covers_point(milliseconds(2000), point, &[]));
+ }
+
#[test]
fn the_summary_reports_the_shared_anchor_and_the_targets() {
let mut tree = VisualContextTree::create(transform_data(FloatMatrix4x4::identity()));
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index 35bba25d5b9..7d180a3e814 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -21,6 +21,7 @@
#include <LibWeb/Compositor/RenderClock.h>
#include <LibWeb/HTML/HTMLCanvasElement.h>
#include <LibWeb/HTML/LocalNavigable.h>
+#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Page.h>
// The Paint stage presents frames, and only the connection hands it the sink it presents them through, and the
@@ -875,6 +876,16 @@ void CompositorConnection::rendering_opportunity(Web::CompositorContextId contex
}
}
+void CompositorConnection::animated_content_moved_under_pointer(Web::CompositorContextId context_id, i64 frame_time_nanoseconds)
+{
+ for (auto& navigable : Web::HTML::all_local_navigables()) {
+ if (!navigable->has_compositor_context() || navigable->compositor_context().id() != context_id)
+ continue;
+ navigable->event_handler().note_animated_content_moved_under_pointer(frame_time_nanoseconds);
+ return;
+ }
+}
+
void CompositorConnection::overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> visibilities)
{
// Each scroller belongs to the active document of one of our navigables, which takes its scrollbar's visibility.
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.h
index 6c8b5f88cc9..9ca5b673753 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -118,6 +118,7 @@ private:
virtual void request_rendering_update() override;
virtual void rendering_opportunity(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds) override;
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates) override;
+ virtual void animated_content_moved_under_pointer(Web::CompositorContextId, i64 frame_time_nanoseconds) override;
virtual void did_complete_screenshot(Compositing::ScreenshotRequestId) override;
virtual void did_fail_screenshot(Compositing::ScreenshotRequestId) override;
virtual void did_lose_compositor() override;
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 5aac32fb393..7932135a222 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -11713,7 +11713,7 @@ void Document::set_caret_hit_test_debug_rect(Optional<CSSPixelRect> rect)
page().client().request_frame();
}
-Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunRead const& read)
+Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunRead const& read, Optional<i64> visual_animation_sample_time_nanoseconds)
{
update_paint_and_hit_testing_properties_if_needed();
@@ -11744,18 +11744,22 @@ Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunR
return {};
}
+ auto visual_context_tree = paint_state().visual_context_tree_without_update(read, *this);
+ if (visual_animation_sample_time_nanoseconds.has_value() && visual_context_tree.has_visual_animations())
+ visual_context_tree = visual_context_tree.with_visual_animation_samples(*visual_animation_sample_time_nanoseconds);
return Painting::HitTestQuery {
*m_hit_test_display_list,
- paint_state().visual_context_tree_without_update(read, *this),
+ move(visual_context_tree),
scroll_state_snapshot(),
page().client().device_pixels_per_css_pixel(),
page().chrome_metrics(),
+ visual_animation_sample_time_nanoseconds,
};
}
-Optional<Painting::HitTestResult> Document::hit_test(Layout::BegunRead const& read, CSSPixelPoint position)
+Optional<Painting::HitTestResult> Document::hit_test(Layout::BegunRead const& read, CSSPixelPoint position, Optional<i64> visual_animation_sample_time_nanoseconds)
{
- auto query = prepare_hit_test_query(read);
+ auto query = prepare_hit_test_query(read, visual_animation_sample_time_nanoseconds);
if (!query.has_value())
return {};
// https://w3c.github.io/pointerevents/#hit-test
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index a18fc4d8236..a24f9662fdf 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -1604,8 +1604,10 @@ public:
Painting::HitTestListAdoption adopt_published_recording(Optional<Layout::BegunRead const&> hit_test_list_read, Painting::DisplayListRecording const&, NonnullRefPtr<Compositing::DisplayList>, Function<Compositing::DisplayListResourceSet()> const& referenced_resources);
// Indicates whether a query of the hit test list would require a synchronous update to it.
[[nodiscard]] bool hit_test_display_list_is_current(Layout::BegunRead const& read);
- Optional<Painting::HitTestQuery> prepare_hit_test_query(Layout::BegunRead const& read);
- Optional<Painting::HitTestResult> hit_test(Layout::BegunRead const& read, CSSPixelPoint);
+ // Where a visual animation sample time is given, the hit test reads the compositor's animations at that time, as a
+ // frame of the compositor's shows them.
+ Optional<Painting::HitTestQuery> prepare_hit_test_query(Layout::BegunRead const& read, Optional<i64> visual_animation_sample_time_nanoseconds = {});
+ Optional<Painting::HitTestResult> hit_test(Layout::BegunRead const& read, CSSPixelPoint, Optional<i64> visual_animation_sample_time_nanoseconds = {});
Optional<Painting::CaretPosition> caret_position_from_point(Layout::BegunRead const& read, CSSPixelPoint);
Optional<Painting::CaretPosition> caret_position_from_point_for_selection_start(Layout::BegunRead const& read, CSSPixelPoint);
Optional<Painting::CaretPosition> caret_position_from_point_for_selection(Layout::BegunRead const& read, CSSPixelPoint, GC::Ptr<Node const> constraint_scope = nullptr);
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 9f0695839dc..792c162b66c 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -1576,9 +1576,18 @@ bool EventLoop::let_layout_of_rendering_update_fly()
void EventLoop::note_hover_may_be_stale(LocalNavigable& navigable)
{
- if (any_of(m_navigables_with_hover_that_may_be_stale, [&](auto const& entry) { return entry.ptr() == &navigable; }))
+ if (!queue_hover_that_may_be_stale(navigable))
return;
+ // An idle loop comes between two tasks only as the next task comes: this makes it come now.
+ schedule();
+}
+
+bool EventLoop::queue_hover_that_may_be_stale(LocalNavigable& navigable)
+{
+ if (any_of(m_navigables_with_hover_that_may_be_stale, [&](auto const& entry) { return entry.ptr() == &navigable; }))
+ return false;
m_navigables_with_hover_that_may_be_stale.append(navigable);
+ return true;
}
void EventLoop::update_hovers_that_may_be_stale(HoverUpdatePoint hover_update_point)
@@ -1588,8 +1597,9 @@ void EventLoop::update_hovers_that_may_be_stale(HoverUpdatePoint hover_update_po
for (auto& navigable : navigables) {
if (navigable->has_been_destroyed())
continue;
+ // A hover that waits for a frame, or for a rendering update, comes here again as it lands or begins.
if (navigable->event_handler().update_hover_where_the_pointer_rests(hover_update_point))
- note_hover_may_be_stale(*navigable);
+ queue_hover_that_may_be_stale(*navigable);
}
}
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index cc9cec9bbab..58b9c776308 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -252,6 +252,7 @@ private:
// Goes on with the rendering update in flight where it has landed, and presents the recordings that have landed.
void take_finished_frames_in();
void update_hovers_that_may_be_stale(HoverUpdatePoint);
+ bool queue_hover_that_may_be_stale(LocalNavigable&);
bool let_layout_of_rendering_update_fly();
void note_clock_lanes(ClockAnimations);
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 025bfdb0f84..1f276f7ee31 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -2433,6 +2433,14 @@ void Internals::inject_hover_pointer(double x, double y, Optional<double> frame_
Layout::RustFFI::document_host_inject_pointer(document.layout_node_arena().host(), static_cast<float>(x * device_pixels_per_css_pixel), static_cast<float>(y * device_pixels_per_css_pixel), static_cast<i64>(frame_time * 1'000'000.0), input_event_id.value_or(0));
}
+void Internals::note_animated_content_moved_under_pointer(double frame_time_ms)
+{
+ auto& document = window().associated_document();
+ auto frame_time = document.relevant_settings_object().time_origin() + frame_time_ms;
+ if (auto navigable = document.navigable())
+ navigable->event_handler().note_animated_content_moved_under_pointer(static_cast<i64>(frame_time * 1'000'000.0));
+}
+
u64 Internals::queue_mouse_move(double x, double y, u32 buttons)
{
// NB: Above every id a UI process hands out in a test.
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 5e1cc718670..dd64a3698fd 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -293,6 +293,7 @@ public:
void inject_clock_tick(double frame_time_ms, Optional<double> viewport_scroll_y);
void inject_clock_tick_scrolling_element(double frame_time_ms, DOM::Element& scroller, double x, double y);
void inject_hover_pointer(double x, double y, Optional<double> frame_time_ms, Optional<u64> input_event_id);
+ void note_animated_content_moved_under_pointer(double frame_time_ms);
u64 queue_mouse_move(double x, double y, u32 buttons);
void move_hover_pointer(double x, double y, Optional<u64> input_event_id);
Utf16String clock_lane_state(DOM::Document&);
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 8084ec7648c..6feab6a3f63 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -312,6 +312,9 @@ interface Internals {
// would, beside the mouse event with the given input event id, if any, and waits until the tick that hovers what is
// under it has run, at the given frame time, or now.
undefined injectHoverPointer(double x, double y, optional double frameTimeMs, optional unsigned long long inputEventId);
+ // Reports to the current document's navigable, as the compositor would, that a frame of a transform animation it
+ // runs moved content under the pointer at rest, or away from it, as of the given frame time.
+ undefined noteAnimatedContentMovedUnderPointer(double frameTimeMs);
// Queues a mouse move to the given point in CSS pixels, with the given mouse buttons held, as the UI process would
// send it, which the next rendering update handles, and answers its input event id.
unsigned long long queueMouseMove(double x, double y, optional unsigned long buttons = 0);
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 6bd1ff2185b..cdcbba5fe27 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -1384,14 +1384,14 @@ void EventHandler::update_nested_navigable_under_pointer(GC::Ptr<HTML::LocalNavi
(void)previous->event_handler().handle_mouseleave();
}
-void EventHandler::update_hover_at_last_known_mouse_position()
+void EventHandler::update_hover_at_last_known_mouse_position(Optional<i64> visual_animation_sample_time_nanoseconds)
{
if (!m_last_known_mouse_visual_viewport_position.has_value())
return;
if (m_mousedown_target)
return;
- update_hover_after_scroll(*m_last_known_mouse_visual_viewport_position, m_last_known_mouse_screen_position, UIEvents::MouseButton::None, m_last_known_mouse_buttons, m_last_known_mouse_modifiers);
+ update_hover_after_scroll(*m_last_known_mouse_visual_viewport_position, m_last_known_mouse_screen_position, UIEvents::MouseButton::None, m_last_known_mouse_buttons, m_last_known_mouse_modifiers, {}, visual_animation_sample_time_nanoseconds);
}
// AD-HOC: `hover_target`, where given, is the element the render clock's lane hovered at the position, which the screen
@@ -1436,6 +1436,13 @@ void EventHandler::note_hover_may_be_stale()
HTML::main_thread_event_loop().note_hover_may_be_stale(*m_navigable);
}
+void EventHandler::note_animated_content_moved_under_pointer(i64 frame_time_nanoseconds)
+{
+ note_hover_may_be_stale();
+ if (m_hover_may_be_stale)
+ m_visual_animation_sample_time_nanoseconds = frame_time_nanoseconds;
+}
+
bool EventHandler::update_hover_where_the_pointer_rests(HTML::HoverUpdatePoint hover_update_point)
{
if (!m_hover_may_be_stale)
@@ -1466,11 +1473,13 @@ bool EventHandler::update_hover_where_the_pointer_rests(HTML::HoverUpdatePoint h
return true;
}
m_hover_may_be_stale = false;
+ auto visual_animation_sample_time_nanoseconds = m_visual_animation_sample_time_nanoseconds;
+ m_visual_animation_sample_time_nanoseconds.clear();
if (should_ignore_device_input_event() || !document->is_fully_active() || !has_committed_root_box())
return false;
// The hover moves where another node is under the pointer. Where the same node is, only its cursor may have
// changed, which is shown without the boundary events and the style work of a hover.
- auto target = target_for_mouse_position(*m_last_known_mouse_visual_viewport_position);
+ auto target = target_for_mouse_position(*m_last_known_mouse_visual_viewport_position, visual_animation_sample_time_nanoseconds);
auto node = target.has_value() ? target->dom_node() : nullptr;
auto* target_layout_node = target.has_value() ? target->layout_node(read) : nullptr;
if (node && target_layout_node && node.ptr() == document->hovered_node() && !Painting::is_navigable_container_viewport_paintable(*target_layout_node)) {
@@ -1479,11 +1488,11 @@ bool EventHandler::update_hover_where_the_pointer_rests(HTML::HoverUpdatePoint h
update_cursor(read, target_layout_node, *node, target->chrome_widget, target->is_text_fragment);
return false;
}
- update_hover_at_last_known_mouse_position();
+ update_hover_at_last_known_mouse_position(visual_animation_sample_time_nanoseconds);
return false;
}
-void EventHandler::update_hover_after_scroll(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, GC::Ptr<DOM::Node> hover_target)
+void EventHandler::update_hover_after_scroll(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, GC::Ptr<DOM::Node> hover_target, Optional<i64> visual_animation_sample_time_nanoseconds)
{
if (m_effective_legacy_mouse_pointer_type != PointerType::Mouse)
return;
@@ -1514,7 +1523,7 @@ void EventHandler::update_hover_after_scroll(CSSPixelPoint visual_viewport_posit
auto nested_navigable = [&]() -> GC::Ptr<HTML::LocalNavigable> {
if (hover_target)
return hover_target_nested_navigable();
- auto hit = target_for_mouse_position(visual_viewport_position);
+ auto hit = target_for_mouse_position(visual_viewport_position, visual_animation_sample_time_nanoseconds);
auto* layout_node = hit.has_value() ? hit->layout_node(read) : nullptr;
return layout_node ? local_nested_navigable_at(*layout_node, hit->dom_node()) : nullptr;
}();
@@ -1532,7 +1541,7 @@ void EventHandler::update_hover_after_scroll(CSSPixelPoint visual_viewport_posit
RefPtr<Painting::ChromeWidget> chrome_widget;
GC::Ptr<DOM::Node> node;
bool hit_text_fragment = false;
- if (auto result = target_for_mouse_position(visual_viewport_position); result.has_value()) {
+ if (auto result = target_for_mouse_position(visual_viewport_position, visual_animation_sample_time_nanoseconds); result.has_value()) {
target = move(*result);
chrome_widget = target->chrome_widget;
node = target->dom_node();
@@ -3387,14 +3396,14 @@ Layout::Node* EventHandler::validated_latched_wheel_event_target_layout_node(Lay
return layout_node;
}
-Optional<EventHandler::Target> EventHandler::target_for_mouse_position(CSSPixelPoint position)
+Optional<EventHandler::Target> EventHandler::target_for_mouse_position(CSSPixelPoint position, Optional<i64> visual_animation_sample_time_nanoseconds)
{
auto document = m_navigable->active_document();
if (!document)
return {};
Layout::ForcedReadScope read { *document };
- if (auto result = document->hit_test(read, position); result.has_value()) {
+ if (auto result = document->hit_test(read, position, visual_animation_sample_time_nanoseconds); result.has_value()) {
return Target {
.hit_node = result->hit_node,
.arena = result->arena,
@@ -5727,6 +5736,7 @@ void EventHandler::clear_per_test_input_state(Badge<Internals::Internals>)
m_native_mouse_hover_target = nullptr;
m_drag_and_drop_event_handler->reset();
m_mousemove_previous_screen_position.clear();
+ m_visual_animation_sample_time_nanoseconds.clear();
m_last_known_mouse_visual_viewport_position.clear();
m_hover_may_be_stale = false;
// The lanes carry the pointer over to the next document, which the host then hovers where it rests.
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index 22866b49eb4..eaf1b138763 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -90,7 +90,7 @@ public:
#if defined(AK_OS_MACOS)
bool select_word_for_dictionary_lookup(CSSPixelPoint visual_viewport_position);
#endif
- void update_hover_at_last_known_mouse_position();
+ void update_hover_at_last_known_mouse_position(Optional<i64> visual_animation_sample_time_nanoseconds = {});
void update_hover_at(CSSPixelPoint visual_viewport_position, GC::Ptr<DOM::Node> hover_target = {});
// Call once per rendering update, after its layout and before it paints.
void update_hover_after_rendering_update();
@@ -105,6 +105,9 @@ public:
// Call where the hover may be stale (see EventLoop::note_hover_may_be_stale). Answers whether it still is: a
// frame to come shows what it waits for.
bool update_hover_where_the_pointer_rests(HTML::HoverUpdatePoint);
+ // Call as the compositor reports a frame of a transform animation it runs that moved content under the pointer at
+ // rest, or away from it. The hover follows with the animations sampled at the frame's time.
+ void note_animated_content_moved_under_pointer(i64 frame_time_nanoseconds);
GC::Ptr<DOM::Node> target_node_for_mouse_position(CSSPixelPoint);
EventResult handle_keydown(UIEvents::KeyCode, unsigned modifiers, u32 code_point, bool repeat, bool should_insert_text, bool async_scroll_performed_default_action = false, ReadonlySpan<TextEditingCommand> editing_commands = {}, bool native_editing_binding_resolved = false);
@@ -246,7 +249,7 @@ private:
Layout::Node* layout_node(Layout::BegunRead const& read) const;
GC::Ptr<DOM::Node> dom_node() const;
};
- Optional<Target> target_for_mouse_position(CSSPixelPoint position);
+ Optional<Target> target_for_mouse_position(CSSPixelPoint position, Optional<i64> visual_animation_sample_time_nanoseconds = {});
GC::Ptr<DOM::Node> focus_candidate_for_position(Layout::BegunRead const& read, CSSPixelPoint) const;
void run_mousedown_default_actions(Layout::BegunRead const& read, DOM::Document&, CSSPixelPoint visual_viewport_position, unsigned button, unsigned modifiers, int click_count);
@@ -274,7 +277,7 @@ private:
void clear_mousedown_tracking();
void stop_updating_selection();
- void update_hover_after_scroll(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, GC::Ptr<DOM::Node> hover_target = {});
+ void update_hover_after_scroll(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, GC::Ptr<DOM::Node> hover_target = {}, Optional<i64> visual_animation_sample_time_nanoseconds = {});
EventResult dispatch_wheel_event(Layout::BegunRead const& read, Layout::Node&, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, bool is_cancelable);
// Both drop the latch when what it refers to is gone from the document, so that the event is targeted afresh.
Layout::Node* validated_latched_wheel_event_target_layout_node(Layout::BegunRead const& read, DOM::Document&);
@@ -346,6 +349,9 @@ private:
Optional<CSSPixelPoint> m_last_known_mouse_visual_viewport_position;
// Whether what is under the pointer may have moved, or changed its cursor, since the hover last followed it.
bool m_hover_may_be_stale { false };
+ // The time of the compositor's frame whose animations moved what is under the pointer, which the hover samples
+ // them at.
+ Optional<i64> m_visual_animation_sample_time_nanoseconds;
bool m_handling_outdated_input { false };
// The UI process's id of the input event being handled, or 0.
u64 m_handling_input_event_id { 0 };
diff --git a/Libraries/LibWeb/Painting/HitTestDisplayList.cpp b/Libraries/LibWeb/Painting/HitTestDisplayList.cpp
index 0f72314eda5..e2926ec1aaa 100644
--- a/Libraries/LibWeb/Painting/HitTestDisplayList.cpp
+++ b/Libraries/LibWeb/Painting/HitTestDisplayList.cpp
@@ -85,6 +85,8 @@ struct HitTestDisplayList::QueryContext {
.scroll_offsets_len = scroll_offsets.size(),
.has_chrome_metrics = query != nullptr,
.chrome_metrics = {},
+ .has_visual_animation_sample_time = query && query->visual_animation_sample_time_nanoseconds().has_value(),
+ .visual_animation_sample_time_ns = query ? query->visual_animation_sample_time_nanoseconds().value_or(0) : 0,
.contains = [](void* context_pointer, Layout::RustFFI::FfiNodeIdentity ancestor, Layout::RustFFI::FfiNodeIdentity node) -> bool {
auto& context = *static_cast<QueryContext*>(context_pointer);
if (!context.document)
diff --git a/Libraries/LibWeb/Painting/HitTestDisplayList.h b/Libraries/LibWeb/Painting/HitTestDisplayList.h
index b080f38be2b..70dc937b2bd 100644
--- a/Libraries/LibWeb/Painting/HitTestDisplayList.h
+++ b/Libraries/LibWeb/Painting/HitTestDisplayList.h
@@ -53,16 +53,19 @@ public:
Compositing::ScrollStateSnapshot const& scroll_state() const { return m_scroll_state; }
double device_pixels_per_css_pixel() const { return m_device_pixels_per_css_pixel; }
ChromeMetrics const& chrome_metrics() const { return m_chrome_metrics; }
+ // The time the query reads the compositor's animations at, as a frame of the compositor's shows them, if any.
+ Optional<i64> visual_animation_sample_time_nanoseconds() const { return m_visual_animation_sample_time_nanoseconds; }
private:
friend class DOM::Document;
- HitTestQuery(HitTestDisplayList const& list, Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::ScrollStateSnapshot const& scroll_state, double device_pixels_per_css_pixel, ChromeMetrics chrome_metrics)
+ HitTestQuery(HitTestDisplayList const& list, Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::ScrollStateSnapshot const& scroll_state, double device_pixels_per_css_pixel, ChromeMetrics chrome_metrics, Optional<i64> visual_animation_sample_time_nanoseconds)
: m_list(list)
, m_visual_context_tree(move(visual_context_tree))
, m_scroll_state(scroll_state)
, m_device_pixels_per_css_pixel(device_pixels_per_css_pixel)
, m_chrome_metrics(chrome_metrics)
+ , m_visual_animation_sample_time_nanoseconds(visual_animation_sample_time_nanoseconds)
{
}
@@ -71,6 +74,7 @@ private:
Compositing::ScrollStateSnapshot const& m_scroll_state;
double m_device_pixels_per_css_pixel { 1 };
ChromeMetrics m_chrome_metrics;
+ Optional<i64> m_visual_animation_sample_time_nanoseconds;
};
class WEB_API HitTestDisplayList : public RefCounted<HitTestDisplayList> {
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
index 0ea32e84da7..a0cb36a276e 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
@@ -142,6 +142,10 @@ impl TransformGeometry for ContainedBoxTransformGeometry<'_> {
self.contained.border_box
}
+ fn scrollable_overflow_rect(&self) -> Option<CssPixelRect> {
+ None
+ }
+
fn nearest_svg_viewport_user_rect(&self) -> Option<CssPixelRect> {
None
}
diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
index f5b495cd0e3..5edbf016431 100644
--- a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
+++ b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
@@ -831,6 +831,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
});
let clip = tree.append_clip(
ClipNodeData::rect_clip(libgfx_rust::FloatRect::new(0.0, 0.0, 9.0, 9.0)),
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rs
index 494765793f1..7fa7840590f 100644
--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs
+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs
@@ -632,6 +632,7 @@ pub unsafe extern "C" fn ladybird_web_record_image_paint_display_list(
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect::default(),
});
// Force-dark never reaches here: an image is darkened by classifying the image itself — not by inverting the
// fills that raster it.
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
index 95b5867f482..e4824e9e36c 100644
--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
@@ -898,6 +898,21 @@ fn with_hit_test_list_spatial_indexes_and_visual_context_tree<R>(
.unwrap_or(default)
}
+/// `tree` with the compositor's animations sampled at the time the query reads them at, where it reads them so, kept in
+/// `sampled`; otherwise `tree` itself.
+fn tree_as_the_query_reads_it<'tree>(
+ tree: &'tree crate::painting::visual_context::VisualContextTree,
+ callbacks: &crate::painting::host::FfiHitTestQueryCallbacks,
+ sampled: &'tree mut Option<crate::painting::visual_context::VisualContextTree>,
+) -> &'tree crate::painting::visual_context::VisualContextTree {
+ match callbacks.visual_animation_sample_time_ns() {
+ Some(sample_time_ns) if tree.has_visual_animations() => {
+ sampled.insert(tree.with_visual_animation_samples(sample_time_ns))
+ }
+ _ => tree,
+ }
+}
+
fn ffi_topmost(item: Option<crate::painting::hit_test::query::TopmostItem>) -> crate::painting::host::FfiTopmostItem {
match item {
Some(item) => crate::painting::host::FfiTopmostItem {
@@ -1006,7 +1021,11 @@ pub unsafe extern "C" fn layout_hit_test_find_topmost_item(
read,
false,
Default::default(),
- |list, tree, arena| ffi_topmost(list.find_topmost_item(arena, tree, &callbacks, point.into())),
+ |list, tree, arena| {
+ let mut sampled = None;
+ let tree = tree_as_the_query_reads_it(tree, &callbacks, &mut sampled);
+ ffi_topmost(list.find_topmost_item(arena, tree, &callbacks, point.into()))
+ },
);
}
@@ -1027,7 +1046,11 @@ pub unsafe extern "C" fn layout_hit_test_all(
read,
false,
Vec::new(),
- |list, tree, arena| list.hit_test_all(arena, tree, &callbacks, point.into()),
+ |list, tree, arena| {
+ let mut sampled = None;
+ let tree = tree_as_the_query_reads_it(tree, &callbacks, &mut sampled);
+ list.hit_test_all(arena, tree, &callbacks, point.into())
+ },
);
for index in indices {
// SAFETY: The C++ sink consumes the index synchronously.
diff --git a/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs b/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs
index 07881c22b21..31f4f2230d8 100644
--- a/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs
+++ b/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs
@@ -18,6 +18,9 @@ pub struct FfiHitTestQueryCallbacks {
pub scroll_offsets_len: usize,
pub has_chrome_metrics: bool,
pub chrome_metrics: crate::painting::ffi::FfiChromeMetrics,
+ /// Where set, the query reads the compositor's animations at this time, as a frame of the compositor's shows them.
+ pub has_visual_animation_sample_time: bool,
+ pub visual_animation_sample_time_ns: i64,
/// Private: reached only through the method below, which takes the main thread token.
contains: extern "C" fn(*mut c_void, FfiNodeIdentity, FfiNodeIdentity) -> bool,
}
@@ -41,10 +44,17 @@ impl FfiHitTestQueryCallbacks {
scroll_offsets_len: scroll_offsets.len(),
has_chrome_metrics: true,
chrome_metrics,
+ has_visual_animation_sample_time: false,
+ visual_animation_sample_time_ns: 0,
contains: no_contains,
}
}
+ pub(crate) fn visual_animation_sample_time_ns(&self) -> Option<i64> {
+ self.has_visual_animation_sample_time
+ .then_some(self.visual_animation_sample_time_ns)
+ }
+
/// Whether `node` is `ancestor` or one of its descendants in the DOM.
pub(crate) fn contains(
&self,
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs
index ab66d8bdcfa..31241104f6e 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs
@@ -1687,6 +1687,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect::default(),
}))
}
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs
index d6ffc6139d9..c5c290d190e 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs
@@ -429,6 +429,7 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(
role: TransformDataRole::CssTransform,
synthetic_plane: true,
establishes_sorting_context: inherited.sorting_context_root.is_none(),
+ bounds: libgfx_rust::FloatRect::default(),
}),
);
appended_synthetic_plane = true;
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
index 30053a765d8..88be6248912 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
@@ -44,6 +44,7 @@ pub(crate) fn compute_svg_viewport_transform_data(
role: TransformDataRole::SvgViewportTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect::default(),
}
}
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rs
index 30bc14e8feb..67b20534c21 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rs
@@ -422,6 +422,7 @@ mod node_dump_tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
})
}
@@ -444,6 +445,7 @@ mod node_dump_tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}),
VISUAL_VIEWPORT_NODE_INDEX,
);
@@ -456,6 +458,7 @@ mod node_dump_tests {
role: TransformDataRole::SvgViewportTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}),
VISUAL_VIEWPORT_NODE_INDEX,
);
@@ -672,6 +675,7 @@ mod section_dump_tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
});
let scroll_node = tree.append_spatial(
SpatialData::Scroll(ScrollData {
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs
index a402be8f679..90d79afdfff 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs
@@ -781,6 +781,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
})
}
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
index 10c729f254e..addfad2e6b2 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
@@ -47,12 +47,14 @@ pub(crate) fn visual_viewport_transform_data(inputs: &FfiVisualContextTreeInputs
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect::default(),
}
}
pub(crate) trait TransformGeometry {
fn content_box(&self) -> CssPixelRect;
fn border_box(&self) -> CssPixelRect;
+ fn scrollable_overflow_rect(&self) -> Option<CssPixelRect>;
fn nearest_svg_viewport_user_rect(&self) -> Option<CssPixelRect>;
fn containing_block_box(&self, coord_box: u16) -> CssPixelRect;
fn svg_additional_element_transform(&self) -> Option<AffineTransform>;
@@ -72,6 +74,10 @@ impl<Arena: PaintRead> TransformGeometry for CommittedTransformGeometry<'_, Aren
paintable_geometry::absolute_border_box_rect(self.arena, self.node)
}
+ fn scrollable_overflow_rect(&self) -> Option<CssPixelRect> {
+ paintable_geometry::scrollable_overflow_rect(self.arena, self.node)
+ }
+
fn nearest_svg_viewport_user_rect(&self) -> Option<CssPixelRect> {
crate::painting::svg_viewport::nearest_svg_viewport_user_rect(self.arena, self.node).map(|rect| {
CssPixelRect::new(
@@ -301,6 +307,11 @@ pub(crate) fn compute_transform_against(
};
let matrix = scale_matrix_for_device_pixels(matrix, scale);
let is_invertible = matrix.is_invertible();
+ let mut bounds = geometry.border_box();
+ bounds.unite(reference_box);
+ if let Some(scrollable_overflow_rect) = geometry.scrollable_overflow_rect() {
+ bounds.unite(scrollable_overflow_rect);
+ }
Some((
TransformData {
matrix,
@@ -310,6 +321,12 @@ pub(crate) fn compute_transform_against(
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: libgfx_rust::FloatRect {
+ x: bounds.x.to_float() * scale,
+ y: bounds.y.to_float() * scale,
+ width: bounds.width.to_float() * scale,
+ height: bounds.height.to_float() * scale,
+ },
},
is_invertible,
))
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/reconcile.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/reconcile.rs
index 1fe361fc4c7..7005aaf52a0 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/reconcile.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/reconcile.rs
@@ -295,6 +295,7 @@ mod tests {
role: TransformDataRole::CssTransform,
synthetic_plane: false,
establishes_sorting_context: false,
+ bounds: FloatRect::default(),
}
}
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 0b70f257bc4..918e8fdf201 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -635,6 +635,11 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
return;
}
+ if (event.type == Web::MouseEvent::Type::MouseMove)
+ context->note_pointer_position(Gfx::FloatPoint { static_cast<float>(event.position.x().value()), static_cast<float>(event.position.y().value()) });
+ else if (first_is_one_of(event.type, Web::MouseEvent::Type::MouseLeave, Web::MouseEvent::Type::MouseCancel))
+ context->note_pointer_position({});
+
if (event.type == Web::MouseEvent::Type::MouseDown)
dispatch_scroll_fling_step(context_id, *context, context->end_scroll_fling(), MonotonicTime::now());
@@ -814,6 +819,7 @@ ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_
if (pointer.context_under_pointer == nested_context_id)
return;
if (auto* context_left = context_still_nested_in(context_id, pointer.context_under_pointer)) {
+ context_left->note_pointer_position({});
if (auto frame_to_present = context_left->clear_scrollbar_hover(); frame_to_present.has_value())
schedule_present_frame(*pointer.context_under_pointer, *context_left, *frame_to_present);
}
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index ba8d88d1974..1aa9ce78b8f 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -66,6 +66,7 @@ public:
virtual void pointer_moved(Web::CompositorContextId, Web::DevicePixelPoint, u32 /* buttons */, bool /* scrolled_since_frame */, u64 /* input_event_id */) { }
virtual void pointer_left(Web::CompositorContextId, u64 /* input_event_id */) { }
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) = 0;
+ virtual void animated_content_moved_under_pointer(Web::CompositorContextId, i64 /* frame_time_nanoseconds */) { }
virtual void overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const&) { }
virtual void create_video_edge(Media::VideoSinkHandle) = 0;
virtual void release_video_edge(Media::VideoSinkHandle) = 0;
diff --git a/Services/Compositor/CompositorWebContentClient.ipc b/Services/Compositor/CompositorWebContentClient.ipc
index 1989ad84c1f..1d13509cad2 100644
--- a/Services/Compositor/CompositorWebContentClient.ipc
+++ b/Services/Compositor/CompositorWebContentClient.ipc
@@ -11,6 +11,9 @@ endpoint CompositorWebContentClient
request_rendering_update() =|
rendering_opportunity(Web::CompositorContextId context_id, i64 frame_time_nanoseconds, double frame_interval_milliseconds) =|
async_scroll_updates(Web::CompositorContextId context_id, Compositing::PendingAsyncScrollUpdates updates) =|
+ // A frame of a transform animation the compositor runs moved content under the pointer at rest, or away from it,
+ // as of the frame's time.
+ animated_content_moved_under_pointer(Web::CompositorContextId context_id, i64 frame_time_nanoseconds) =|
overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> visibilities) =|
did_complete_screenshot(Compositing::ScreenshotRequestId request_id) =|
did_fail_screenshot(Compositing::ScreenshotRequestId request_id) =|
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index 774e34bc116..da619cf8755 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -154,6 +154,11 @@ void ConnectionFromWebContent::async_scroll_updates(Web::CompositorContextId con
async_async_scroll_updates(context_id, updates);
}
+void ConnectionFromWebContent::animated_content_moved_under_pointer(Web::CompositorContextId context_id, i64 frame_time_nanoseconds)
+{
+ async_animated_content_moved_under_pointer(context_id, frame_time_nanoseconds);
+}
+
void ConnectionFromWebContent::overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const& visibilities)
{
async_overlay_scrollbar_visibilities_changed(visibilities);
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index 885655fd787..506b67eb36d 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -103,6 +103,7 @@ private:
virtual void pointer_moved(Web::CompositorContextId, Web::DevicePixelPoint, u32 buttons, bool scrolled_since_frame, u64 input_event_id) override;
virtual void pointer_left(Web::CompositorContextId, u64 input_event_id) override;
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) override;
+ virtual void animated_content_moved_under_pointer(Web::CompositorContextId, i64 frame_time_nanoseconds) override;
virtual void overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const&) override;
virtual void create_video_edge(Media::VideoSinkHandle) override;
virtual void release_video_edge(Media::VideoSinkHandle) override;
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index f59b1795f13..d3c5adec889 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -458,9 +458,18 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve
ContextState::ContextUpdateResult ContextState::handle_mouse_event_from_containing_context(Web::MouseEvent const& event, Gfx::FloatPoint position)
{
+ if (event.type == Web::MouseEvent::Type::MouseMove)
+ note_pointer_position(position);
+ else if (first_is_one_of(event.type, Web::MouseEvent::Type::MouseLeave, Web::MouseEvent::Type::MouseCancel))
+ note_pointer_position({});
return handle_mouse_event_at(event, position);
}
+void ContextState::note_pointer_position(Optional<Gfx::FloatPoint> position)
+{
+ m_pointer_position = position;
+}
+
// The compositor presents how scrollbars expand, outside of what damage tracking sees.
Optional<PendingFrame> ContextState::frame_repainting_scrollbars() const
{
@@ -2578,7 +2587,15 @@ bool ContextState::visual_animations_need_frame()
bool ContextState::advance_visual_animations(MonotonicTime now)
{
- return m_scene.advance_visual_animations(now);
+ auto animations_are_active = m_scene.advance_visual_animations(now);
+ // The main thread hovers what is under the pointer at rest again as a transform animation moves content under it,
+ // with the animation sampled at the frame's time, and once more as the content moves away.
+ auto animated_content_is_under_pointer = animations_are_active && m_pointer_position.has_value()
+ && m_scene.visual_context_tree_for_compositing().running_transform_animation_covers_point(now.nanoseconds(), *m_pointer_position, m_scroll_state_snapshot);
+ if (animated_content_is_under_pointer || m_animated_content_was_under_pointer)
+ m_web_content_client.animated_content_moved_under_pointer(m_context_id, now.nanoseconds());
+ m_animated_content_was_under_pointer = animated_content_is_under_pointer;
+ return animations_are_active;
}
}
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index f5e592ae1e7..c53f958887a 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -314,6 +314,9 @@ public:
Compositing::FirstWheelStepRouteForTesting route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Compositing::NestedContextRegions);
bool advance_visual_animations(MonotonicTime now);
bool visual_animations_need_frame();
+ // Where the pointer is in this context's device pixels, as the mouse event the context takes or hands on says, or
+ // nowhere, as the pointer leaves it.
+ void note_pointer_position(Optional<Gfx::FloatPoint>);
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates();
bool has_pending_async_scroll_updates() const;
@@ -511,6 +514,8 @@ private:
bool m_scrollbar_track_press_jumps { false };
RefPtr<Core::Timer> m_scrollbar_paging_timer;
PointerInNestedContexts m_pointer_in_nested_contexts;
+ Optional<Gfx::FloatPoint> m_pointer_position;
+ bool m_animated_content_was_under_pointer { false };
ScrollFlingController m_scroll_fling_controller;
Optional<Web::MouseEvent> m_last_reported_scroll_momentum_step;
bool m_reported_scroll_momentum_was_interrupted { false };
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-under-a-compositor-animation.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-under-a-compositor-animation.txt
new file mode 100644
index 00000000000..b044ea55968
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-under-a-compositor-animation.txt
@@ -0,0 +1,4 @@
+at rest: Arrow, :hover false, events none
+as the animation started: Arrow, :hover false, events none
+at a frame 2s in: Hand, :hover true, events mouseover
+at a frame 9s in: Arrow, :hover false, events mouseover mouseout
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-under-a-compositor-animation.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-under-a-compositor-animation.html
new file mode 100644
index 00000000000..0d6a310c4ef
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-under-a-compositor-animation.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ #target { cursor: pointer; position: absolute; left: 150px; top: 0; width: 1000px; height: 100px; }
+</style>
+<div id="target"></div>
+<script>
+ // The compositor runs a transform animation itself, which moves a box across the pointer at rest between the
+ // frames the main thread presents, and reports each frame of it that moves content under the pointer. The hover
+ // follows with the animation sampled at the frame's time, and shows the cursor of what is under the pointer then.
+ // The output is printed at the end, so that no text of it lies under the pointer meanwhile.
+ asyncTest(async done => {
+ await whileLaneHovers(async frameTime => {
+ internals.mouseMove(50, 50);
+ let time = frameTime;
+ const lines = [];
+ const events = [];
+ target.addEventListener("mouseover", () => events.push("mouseover"));
+ target.addEventListener("mouseout", () => events.push("mouseout"));
+ const state = what => `${what}: ${internals.currentCursor()}, :hover ${target.matches(":hover")}, events ${events.join(" ") || "none"}`;
+ const step = async change => {
+ change();
+ time += 16;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ lines.push(state("at rest"));
+ // Moves 150px a second: under the pointer from 1s to 7s in.
+ let animation;
+ await step(() => animation = target.animate([{ transform: "translateX(0)" }, { transform: "translateX(-1500px)" }], { duration: 10000 }));
+ while (animation.pending)
+ await step(() => {});
+ lines.push(state("as the animation started"));
+ const frame = async (at, what) => {
+ internals.noteAnimatedContentMovedUnderPointer(at);
+ await nextTask();
+ lines.push(state(what));
+ // The restyle of a hover asks for a rendering update, which comes at the frame's time.
+ time = at;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ await frame(time + 2000, "at a frame 2s in");
+ await frame(time + 9000, "at a frame 9s in");
+ println(lines.join("\n"));
+ });
+ done();
+ });
+</script>