Truly independent web browser
LibWeb: Show the cursor from the lane where it may present no frame
Zaggy1024ab53afc298c8
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex cdcbba5fe27..1a5b1139858 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -1406,7 +1406,12 @@ void EventHandler::update_hover_at(CSSPixelPoint visual_viewport_position, GC::Pif (m_last_known_mouse_visual_viewport_position.has_value())screen_position = m_last_known_mouse_screen_position + (visual_viewport_position - *m_last_known_mouse_visual_viewport_position);record_last_known_mouse_position(visual_viewport_position, screen_position, m_last_known_mouse_buttons, m_last_known_mouse_modifiers);- update_hover_after_scroll(visual_viewport_position, screen_position, UIEvents::MouseButton::None, m_last_known_mouse_buttons, m_last_known_mouse_modifiers, hover_target);+ // A hit test of the host's own finds what the screen shows where it samples the compositor's animations at the+ // frame time the compositor reported last. The hover the pointer rests on clears the time as it reads it.+ Optional<i64> visual_animation_sample_time_nanoseconds;+ if (!hover_target)+ visual_animation_sample_time_nanoseconds = m_visual_animation_sample_time_nanoseconds;+ update_hover_after_scroll(visual_viewport_position, screen_position, UIEvents::MouseButton::None, m_last_known_mouse_buttons, m_last_known_mouse_modifiers, hover_target, visual_animation_sample_time_nanoseconds);}// AD-HOC: The hover and the cursor follow what is under the pointer while it rests. A frame may move what is there,diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex fcb5084a91e..8c1f214cb7d 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -1379,6 +1379,22 @@ impl Lane {Some(ticked)}+ /// Shows the cursor of what is under `pointer` in the frame the screen shows at `frame_time_nanoseconds`, on the+ /// lane's fork, as a tick that may present nothing would (see [`Lane::show_cursor_only`]). Answers the move it+ /// leaves to the host, or none where the lane has no fork to hit test on.+ fn show_cursor_on_fork(&mut self, frame_time_nanoseconds: i64, pointer: PendingPointer) -> Option<LaneMove> {+ let (mut fork, state_moved_on) = match std::mem::take(&mut self.state) {+ LaneState::Forked { fork, state_moved_on } => (fork, state_moved_on),+ state => {+ self.state = state;+ return None;+ }+ };+ let left_to_host = self.show_cursor_only(&mut fork, pointer, frame_time_nanoseconds);+ self.state = LaneState::Forked { fork, state_moved_on };+ Some(left_to_host)+ }+fn tick(&mut self,state: &mut RenderState,@@ -1395,6 +1411,12 @@ impl Lane {presented: false,sampled: false,};+ // A parked hover, or a frame left to the host, hovers nothing: the cursor follows the pointer all the same.+ if let Some(pointer) = pointer+ && (hovers.is_none() || self.frame_left_to_host)+ {+ ticked.hover_move = Some(self.show_cursor_only(state, pointer, frame_time_nanoseconds));+ }if self.frame_left_to_host || (!samples_animations && hovers.is_none() && !transitions) {return ticked;}diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rsindex 9dbff4edb68..ffb65b56400 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs@@ -565,6 +565,35 @@ impl Lane {}}+ /// Shows the cursor of what is under `pointer` in the frame the screen shows at `frame_time_nanoseconds`, where the+ /// lane may present nothing, and leaves the move to the host, which hovers what is under the pointer itself.+ pub(super) fn show_cursor_only(+ &mut self,+ state: &mut RenderState,+ pointer: PendingPointer,+ frame_time_nanoseconds: i64,+ ) -> super::LaneMove {+ let left_to_host = super::LaneMove {+ input_event_id: pointer.input_event_id,+ target: None,+ handed: false,+ };+ let Some(plan) = self.plan.hover.take() else {+ return left_to_host;+ };+ let placed = pointer.buttons == 0 && !(pointer.scrolled_since_frame && self.scroll_offsets.is_empty());+ if placed+ && let Some(position) = pointer.position+ && let Ok(HoverTarget::Element(hit)) = self.hit_test(state, &plan, position, frame_time_nanoseconds)+ && let Some(page_cursor) = &plan.page_cursor+ && let Some(cursor) = cursor_for_hit(state, hit)+ {+ page_cursor.request(cursor);+ }+ self.plan.hover = Some(plan);+ left_to_host+ }+/// Hovers the element under `pointer`, in the frame as the screen shows it at `frame_time_nanoseconds`, and answers/// whether that moved anything to lay out and present.pub(super) fn hover(@@ -603,9 +632,10 @@ impl Lane {}hovered};- // The cursor shows what the pointer is over once the element the hover is on is the one under it, as the host- // shows it as it handles the move. A move the host hovers leaves the cursor to it too.- if matches!(hovered, Ok(()) | Err(HoverDeclined::Same))+ // The cursor shows what the pointer is over in the frame on screen, whether the hover moves or the host hovers+ // the move: the host shows the cursor of what it finds there as it handles the move. A move handed to an iframe+ // shows the cursor its lane finds.+ if !matches!(hovered, Err(HoverDeclined::Handed(_)))&& let Some(page_cursor) = &plan.page_cursor&& let Some(hit) = cursor_hit&& let Some(cursor) = cursor_for_hit(state, hit)diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rsindex 6dfeaf1af0a..f231162f861 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs@@ -441,10 +441,53 @@ impl LaneSlot {}}+ /// Shows the cursor of what is under the move that waits for a tick, if one waits, in the frame the screen shows,+ /// as a tick that presents nothing: the host hovers the move once it takes the lanes in.+ fn show_cursor_where_a_move_waits(&mut self) {+ let Some(pointer) = self.ticks.pointer_state().take() else {+ return;+ };+ self.show_cursor_for(pointer);+ }++ fn show_cursor_for(&mut self, pointer: PendingPointer) {+ let frame_time_nanoseconds = self.ticks.latest.load(Ordering::Acquire);+ let document = self.ticks.document;+ let nested = self.nested;+ let (hovered, nested) = match self.lanes.current() {+ // A lane that needs no render state hovers its read-only frame as it always does, which presents nothing.+ Some(lane) if !lane.needs_render_state() => {+ lane.hovered.go_on_from_nested(nested);+ let hovered = lane.hover_read_only(pointer, frame_time_nanoseconds);+ (Some(hovered), lane.hovered.nested())+ }+ // A lane without a fork, which the host's write let go of as the update took the lane in, hit tests the+ // state the host writes: what the frame the update presents next shows, which the cursor follows ahead of it.+ Some(lane) => {+ let hovered = lane+ .show_cursor_on_fork(frame_time_nanoseconds, pointer)+ .unwrap_or_else(|| {+ owner::with_state(document, None, |state| {+ lane.show_cursor_only(state, pointer, frame_time_nanoseconds)+ })+ });+ (Some(hovered), nested)+ }+ None => (None, nested),+ };+ self.nested = nested;+ self.last_move = Some(hovered.unwrap_or(LaneMove {+ input_event_id: pointer.input_event_id,+ target: None,+ handed: false,+ }));+ }+fn tick(&mut self) {self.take_in_scroll_offsets();// A recording of the host's own adds to the resource storage the lane presents with: a move waits for it.if self.ticks.is_held() {+ self.show_cursor_where_a_move_waits();return;}// A rendering update took in what the lanes did, and the frame it presents shows that, at the time it took it@@ -457,6 +500,7 @@ impl LaneSlot {super::hover::log_time());}+ self.show_cursor_where_a_move_waits();return;}let samples_animations = !self.ticks.animations_held.load(Ordering::Relaxed);@@ -485,6 +529,9 @@ impl LaneSlot {lane.parked = true;lane.hovered.park();}+ if let Some(pointer) = pointer {+ self.show_cursor_for(pointer);+ }return;}self.run_tick(pointer, samples_animations);diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-a-lane-that-animates.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-a-lane-that-animates.txtnew file mode 100644index 00000000000..c03466c9a88--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-a-lane-that-animates.txt@@ -0,0 +1,5 @@+frame scheduler while held: in-flight+cursor beside the held frame: Crosshair+box matches :hover beside the held frame: false, presented height undefined+box matches :hover once the frame landed: true+cursor once the frame landed: Crosshairdiff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-it.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-it.txtnew file mode 100644index 00000000000..6bfbda0aeee--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-it.txt@@ -0,0 +1,5 @@+frame scheduler while held: in-flight+cursor beside the held frame: Hand+box matches :hover beside the held frame: false, presented width undefined+box matches :hover once the frame landed: true+cursor once the frame landed: Handdiff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-a-lane-that-animates.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-a-lane-that-animates.htmlnew file mode 100644index 00000000000..61dfb429acd--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-a-lane-that-animates.html@@ -0,0 +1,36 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ body { margin: 0; }+ #stage { position: relative; width: 400px; height: 150px; }+ #box { position: absolute; width: 100px; height: 60px; top: 20px; left: 100px; cursor: cell; }+ #box:hover { height: 80px; }+ #spinner { position: absolute; left: 300px; top: 100px; width: 20px; height: 20px; animation: grow 10s linear infinite; }+ @keyframes grow { to { width: 40px; } }+</style>+<div id="stage"><div id="box"></div><div id="spinner"></div></div>+<script>+ // As above, for a lane that samples a layout animation beside the tasks, which hit tests the frame on its fork of+ // the render state: the cursor follows a move while the update's frame is held, and the move waits for the host.+ asyncTest(async done => {+ // The lane follows the pointer, which the compositor told it of, beside the box.+ await whileLaneHovers(frameTime => {+ internals.injectHoverPointer(350, 50, frameTime + 16);+ });+ const result = await whileRecordingInFlight(() => {+ stage.style.marginTop = "5px";+ }, async schedulerState => {+ internals.injectHoverPointer(150, 50, performance.now());+ return { schedulerState, cursor: internals.currentCursor(), hovered: box.matches(":hover"), height: internals.presentedBorderBox(box)?.height };+ });+ println(`frame scheduler while held: ${result.schedulerState}`);+ println(`cursor beside the held frame: ${result.cursor}`);+ println(`box matches :hover beside the held frame: ${result.hovered}, presented height ${result.height}`);+ await twoFramesLanded();+ await nextTask();+ println(`box matches :hover once the frame landed: ${box.matches(":hover")}`);+ println(`cursor once the frame landed: ${internals.currentCursor()}`);+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-it.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-it.htmlnew file mode 100644index 00000000000..95be39063c8--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-the-cursor-while-an-update-holds-it.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ body { margin: 0; }+ #box { width: 100px; height: 100px; cursor: pointer; }+ #box:hover { width: 150px; }+ #filler { height: 100px; }+</style>+<div id="filler"></div>+<div id="box"></div>+<script>+ // A rendering update that took the lanes in, whose frame is still in flight, holds the lane from presenting: the+ // frame the update presents would go back from anything the lane showed since. The cursor is not in a frame, so a+ // move beside the held frame shows the cursor of what it is over in the frame on screen all the same, and the move+ // itself waits for the host, which hovers it once the frame lands.+ asyncTest(async done => {+ // The lane follows the pointer, which the compositor told it of, beside the box.+ await whileLaneHovers(frameTime => {+ internals.injectHoverPointer(50, 50, frameTime + 16);+ });+ const result = await whileRecordingInFlight(() => {+ filler.style.height = "120px";+ }, async schedulerState => {+ internals.injectHoverPointer(50, 150, performance.now());+ return { schedulerState, cursor: internals.currentCursor(), hovered: box.matches(":hover"), width: internals.presentedBorderBox(box)?.width };+ });+ println(`frame scheduler while held: ${result.schedulerState}`);+ println(`cursor beside the held frame: ${result.cursor}`);+ println(`box matches :hover beside the held frame: ${result.hovered}, presented width ${result.width}`);+ await twoFramesLanded();+ await nextTask();+ println(`box matches :hover once the frame landed: ${box.matches(":hover")}`);+ println(`cursor once the frame landed: ${internals.currentCursor()}`);+ done();+ });+</script>