Skip to content

Truly independent web browser

LibWeb: Update the pointer target when it may change while unmoved

Zaggy1024b770df87822a
diff --git a/Libraries/LibWeb/CSS/StyleInvalidation.cpp b/Libraries/LibWeb/CSS/StyleInvalidation.cpp
index 1b95712b38c..daf67674430 100644
--- a/Libraries/LibWeb/CSS/StyleInvalidation.cpp
+++ b/Libraries/LibWeb/CSS/StyleInvalidation.cpp
@@ -32,6 +32,7 @@ RequiredInvalidationAfterStyleChange decode_style_invalidation(u32 packed)
result.repaint_propagated_text_decorations = packed & to_underlying(RepaintTextDecorations);
result.non_inherited_property_inheritance_sources_changed = packed & to_underlying(NonInheritedInheritanceSource);
result.affects_hit_testing = packed & to_underlying(AffectsHitTesting);
+ result.cursor_changed = packed & to_underlying(CursorChanged);
result.repaint_highlights = packed & to_underlying(RepaintHighlights);
result.white_space_collapse_changed = packed & to_underlying(WhiteSpaceCollapseChanged);
return result;
diff --git a/Libraries/LibWeb/CSS/StyleInvalidation.h b/Libraries/LibWeb/CSS/StyleInvalidation.h
index 9c445dd8ce5..6c52136e1f5 100644
--- a/Libraries/LibWeb/CSS/StyleInvalidation.h
+++ b/Libraries/LibWeb/CSS/StyleInvalidation.h
@@ -93,6 +93,7 @@ struct RequiredInvalidationAfterStyleChange {
// space text among them may gain or lose its box.
bool white_space_collapse_changed : 1 { false };
bool affects_hit_testing : 1 { false };
+ bool cursor_changed : 1 { false };
// A non-inherited property changed without any other invalidation, which happens when a running
// animation covers the property. Descendants that explicitly inherit non-inherited properties
// still observe the change.
@@ -116,6 +117,7 @@ struct RequiredInvalidationAfterStyleChange {
repaint_highlights |= other.repaint_highlights;
white_space_collapse_changed |= other.white_space_collapse_changed;
affects_hit_testing |= other.affects_hit_testing;
+ cursor_changed |= other.cursor_changed;
non_inherited_property_inheritance_sources_changed |= other.non_inherited_property_inheritance_sources_changed;
}
diff --git a/Libraries/LibWeb/CSS/UpdateStyle.cpp b/Libraries/LibWeb/CSS/UpdateStyle.cpp
index 7f6092d6580..0625561ecea 100644
--- a/Libraries/LibWeb/CSS/UpdateStyle.cpp
+++ b/Libraries/LibWeb/CSS/UpdateStyle.cpp
@@ -163,6 +163,8 @@ static void apply_element_style_invalidation_after_style_change(Layout::BegunRea
static void apply_document_style_invalidation_after_style_change(DOM::Document& document, RequiredInvalidationAfterStyleChange const& invalidation)
{
+ if (invalidation.cursor_changed)
+ document.set_cursor_may_be_stale();
if (!invalidation.needs_repaint())
return;
if (invalidation.invalidates_hit_test_display_list())
diff --git a/Libraries/LibWeb/Compositor/NavigablePresenter.h b/Libraries/LibWeb/Compositor/NavigablePresenter.h
index 38e22aa3311..fd0bd4a212f 100644
--- a/Libraries/LibWeb/Compositor/NavigablePresenter.h
+++ b/Libraries/LibWeb/Compositor/NavigablePresenter.h
@@ -59,6 +59,8 @@ struct SealedPresentation {
Optional<Compositing::AccumulatedVisualContextTree> visual_context_tree;
// Whether the document's tree changed since the compositor took one.
bool sends_visual_context_tree { false };
+ // Whether the document's scroll offsets changed since the frame before.
+ bool scroll_state_changed { false };
// The scroll state, which seeds the offsets of the boxes new to the compositor.
Compositing::ScrollStateSnapshot scroll_state_snapshot;
// The scrolls the navigable asked for since the frame before, which the compositor applies once it has the frame's
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 7d37442d6af..70c1b82f340 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -11676,17 +11676,30 @@ RefPtr<Compositing::DisplayList> Document::finish_display_list_recording(Layout:
return display_list;
}
-void Document::adopt_published_recording(Optional<Layout::BegunRead const&> hit_test_list_read, Painting::DisplayListRecording const& recording, NonnullRefPtr<Compositing::DisplayList> display_list, Function<Compositing::DisplayListResourceSet()> const& referenced_resources)
+Painting::HitTestListAdoption Document::adopt_published_recording(Optional<Layout::BegunRead const&> hit_test_list_read, Painting::DisplayListRecording const& recording, NonnullRefPtr<Compositing::DisplayList> display_list, Function<Compositing::DisplayListResourceSet()> const& referenced_resources)
{
auto& document_paint_state = paint_state();
bool const recording_returned_the_paint_command_cache_source = display_list == document_paint_state.display_list_used_as_paint_command_cache_source();
- if (!hit_test_list_read.has_value())
+ auto adoption = Painting::HitTestListAdoption::Kept;
+ if (!hit_test_list_read.has_value()) {
m_hit_test_display_list = nullptr;
- else if (!recording_returned_the_paint_command_cache_source || !m_hit_test_display_list || !m_hit_test_display_list->is_current())
+ adoption = Painting::HitTestListAdoption::Dropped;
+ } else if (!recording_returned_the_paint_command_cache_source || !m_hit_test_display_list || !m_hit_test_display_list->is_current()) {
m_hit_test_display_list = Painting::HitTestDisplayList::create_from_rust_recording(*hit_test_list_read, recording.visual_context_tree.structural_epoch(), layout_node_arena(), *m_chrome_widget_registry);
+ adoption = Painting::HitTestListAdoption::TookNew;
+ }
if (recording.cache_mode == Painting::PaintCommandCacheMode::ReadWrite && !recording_returned_the_paint_command_cache_source)
document_paint_state.set_display_list_used_as_paint_command_cache_source(display_list, referenced_resources());
+ return adoption;
+}
+
+bool Document::hit_test_display_list_is_current(Layout::BegunRead const& read)
+{
+ update_paint_and_hit_testing_properties_if_needed();
+ if (!has_committed_viewport_box())
+ return false;
+ return m_hit_test_display_list && m_hit_test_display_list->is_current() && m_hit_test_display_list->visual_context_tree_structural_epoch() == paint_state().visual_context_tree_structural_epoch_without_update(read);
}
void Document::set_caret_hit_test_debug_rect(Optional<CSSPixelRect> rect)
@@ -11719,20 +11732,15 @@ Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunR
(void)record_display_list(read, paint_config, throwaway_resource_storage_for_hit_test_only_recording, Painting::PaintCommandCacheMode::ReadOnly);
};
- // The paint properties were prepared above, and a query reads them as they were left there: preparing them again
- // for every item a query converts would find nothing to do, but still ask the render state to do it.
- auto hit_test_display_list_is_current = [&] {
- return m_hit_test_display_list && m_hit_test_display_list->is_current() && m_hit_test_display_list->visual_context_tree_structural_epoch() == paint_state().visual_context_tree_structural_epoch_without_update(read);
- };
// The recording in flight replaces the hit-test list once it lands, so a list that is not current waits for it
// first.
- if (!hit_test_display_list_is_current()) {
+ if (!hit_test_display_list_is_current(read)) {
if (auto navigable = this->navigable())
navigable->take_recording_in_flight_in(HTML::LocalNavigable::TakeIn::Wait);
}
- if (!hit_test_display_list_is_current()) {
+ if (!hit_test_display_list_is_current(read)) {
rebuild_hit_test_display_list();
- if (!hit_test_display_list_is_current())
+ if (!hit_test_display_list_is_current(read))
return {};
}
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index cddaf9f5e0c..a18fc4d8236 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -640,6 +640,8 @@ public:
m_effects_needing_animated_style_update.clear();
m_effects_needing_animated_style_update_after_current_update.clear();
}
+ void set_cursor_may_be_stale() { m_cursor_may_be_stale = true; }
+ [[nodiscard]] bool take_cursor_may_be_stale() { return exchange(m_cursor_may_be_stale, false); }
[[nodiscard]] bool is_running_update_layout() const;
// The selection changed, or lost its range, so the selection states of the boxes it paints through are stale. They
@@ -1599,7 +1601,9 @@ public:
RefPtr<Compositing::DisplayList> finish_display_list_recording(Layout::BegunRead const& read, Painting::DisplayListRecording const&, Compositing::DisplayListResourceStorage&, Painting::HitTestListStands = Painting::HitTestListStands::Yes);
// Takes in `display_list`, which `recording` published: the paint command cache source, and the hit-test list it made,
// read in `hit_test_list_read`, where that still stands for the document's boxes. Where none does, nothing is read.
- void adopt_published_recording(Optional<Layout::BegunRead const&> hit_test_list_read, Painting::DisplayListRecording const&, NonnullRefPtr<Compositing::DisplayList>, Function<Compositing::DisplayListResourceSet()> const& referenced_resources);
+ 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);
Optional<Painting::CaretPosition> caret_position_from_point(Layout::BegunRead const& read, CSSPixelPoint);
@@ -2128,6 +2132,7 @@ private:
bool m_is_decoded_svg { false };
bool m_needs_animated_style_update { false };
+ bool m_cursor_may_be_stale { false };
bool m_reads_layout_as_it_flew { false };
GC::WeakHashSet<Animations::KeyframeEffect> m_effects_needing_animated_style_update;
GC::WeakHashSet<Animations::KeyframeEffect> m_effects_needing_animated_style_update_after_current_update;
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 774a9f8cc13..1f7dcaf68e6 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -670,6 +670,7 @@ class DOMRectReadOnly;
namespace Web::HTML {
enum class CheckIfUnloadingIsCanceledResult;
+enum class HoverUpdatePoint : u8;
class AnimationFrameCallbackDriver;
class AudioTrack;
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index fa4464310f7..9f0695839dc 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -851,6 +851,9 @@ Vector<GC::Root<DOM::Document>> EventLoop::take_clock_lanes_and_input_events_in(
else
owed.navigable->event_handler().handle_mouseleave();
}
+ // AD-HOC: A hover left stale between the tasks, as the style or layout it reads was pending, follows now. The
+ // update brings the style and layout up to date next, so the hover may bring them up to date first.
+ update_hovers_that_may_be_stale(HoverUpdatePoint::RenderingUpdateBegins);
// What the lanes reported has been taken in: the style node ids that left their nodes since name nothing of theirs.
// A document with no lanes has none that report any.
for (auto& document : documents_in_this_event_loop_matching([](auto const&) { return true; })) {
@@ -1296,8 +1299,8 @@ void EventLoop::update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM:
auto now = relative_frame_timestamp_for(*document);
document->run_the_update_intersection_observations_steps(now);
- // AD-HOC: The cursor shows the style the update applied to what the pointer is over.
- document->navigable()->event_handler().update_cursor_after_rendering_update();
+ // AD-HOC: The hover and the cursor follow a style the update applied to what the pointer is over.
+ document->navigable()->event_handler().update_hover_after_rendering_update();
}
// AD-HOC: Whether a video sink is ticked depends on whether the element would be painted, which is only known once
@@ -1571,6 +1574,25 @@ bool EventLoop::let_layout_of_rendering_update_fly()
return true;
}
+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; }))
+ return;
+ m_navigables_with_hover_that_may_be_stale.append(navigable);
+}
+
+void EventLoop::update_hovers_that_may_be_stale(HoverUpdatePoint hover_update_point)
+{
+ // What the hover dispatches may note a hover as stale again, which waits for the next point.
+ auto navigables = move(m_navigables_with_hover_that_may_be_stale);
+ for (auto& navigable : navigables) {
+ if (navigable->has_been_destroyed())
+ continue;
+ if (navigable->event_handler().update_hover_where_the_pointer_rests(hover_update_point))
+ note_hover_may_be_stale(*navigable);
+ }
+}
+
void EventLoop::take_finished_frames_in()
{
// A rendering update whose style update, then layout, has landed goes on; the tasks before that run beside it,
@@ -1584,6 +1606,8 @@ void EventLoop::take_finished_frames_in()
// A frame that was taken in leaves the list as it is, which moves only the entries after it.
for (size_t index = m_navigables_with_frames_in_flight.size(); index-- > 0;)
(void)m_navigables_with_frames_in_flight[index]->take_recording_in_flight_in(LocalNavigable::TakeIn::IfFinished);
+ // The frames taken in are the ones the hover waits for.
+ update_hovers_that_may_be_stale(HoverUpdatePoint::BetweenTasks);
// NB: This runs between tasks, so no end of a task takes what the style drains above queued, such as the reaction
// to a promise an animation resolved, and no task may follow for a long time.
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index 4092221cd53..cc9cec9bbab 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -29,6 +29,13 @@ enum class FfiFlightBlocker : uint8_t;
namespace Web::HTML {
+// Where the event loop follows the pointer at rest: between two tasks, or as a rendering update begins, which brings
+// the style and layout up to date itself.
+enum class HoverUpdatePoint : u8 {
+ BetweenTasks,
+ RenderingUpdateBegins,
+};
+
// What the render clock's lanes do with a document's running animations.
enum class ClockAnimations : u8 {
// Leaves them alone: the event loop is idle, and its rendering updates run them.
@@ -190,6 +197,9 @@ public:
void ensure_frame_completion_registered();
// Whether a frame flies beside the event loop, which has not taken it in yet.
bool has_frame_in_flight() const;
+ // Notes that the hover of `navigable` may be stale, which the event loop updates between two tasks, or as the next
+ // rendering update begins.
+ void note_hover_may_be_stale(LocalNavigable&);
// Whether a rendering update has let its frame fly and has not run its steps from its style and layout on yet.
bool has_rendering_update_in_flight() const { return m_rendering_update_in_flight; }
// Whether the layout of the rendering update in flight runs, or ran, beside the event loop.
@@ -241,6 +251,7 @@ private:
void note_script_ran_beside_rendering_update_in_flight();
// 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 let_layout_of_rendering_update_fly();
void note_clock_lanes(ClockAnimations);
@@ -298,6 +309,8 @@ private:
// The navigables whose committed frame flies beside the event loop, which has not taken it in yet.
Vector<GC::Ref<LocalNavigable>> m_navigables_with_frames_in_flight;
+ // The navigables whose hover may be stale: what is under their pointer at rest may have moved, or changed its cursor.
+ Vector<GC::Root<LocalNavigable>> m_navigables_with_hover_that_may_be_stale;
// The navigables whose active document a rendering update left a plan for the lane of its frame, which the event
// loop tells whether it runs a task.
Vector<GC::Ref<LocalNavigable>> m_navigables_with_clock_lanes;
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index f658991b63d..221e63ac923 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -86,6 +86,7 @@
#include <LibWeb/Layout/NodeArena.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Loader/GeneratedPagesLoader.h>
+#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
@@ -5259,6 +5260,11 @@ void LocalNavigable::note_scroll_sequence_moved(Web::AsyncScrollNodeStableID sta
}
}
+bool LocalNavigable::has_user_scroll_gesture() const
+{
+ return any_of(m_scroll_sequences, [](auto const& sequence) { return sequence.user_gesture.has_value(); });
+}
+
LocalNavigable::UserScrollGesture* LocalNavigable::user_scroll_gesture_for(Web::AsyncScrollNodeStableID stable_node_id)
{
auto* sequence = scroll_sequence_for(stable_node_id);
@@ -5977,11 +5983,13 @@ void LocalNavigable::adopt_pending_async_scroll_offsets(Compositing::AsyncScroll
}
}
- if (adopted_any_scroll_offset)
- schedule_hover_update_after_async_scroll();
-
- for (auto const& applied_scroll_request : async_scroll_updates.applied_scroll_requests)
+ bool moved_a_box_by_request = false;
+ for (auto const& applied_scroll_request : async_scroll_updates.applied_scroll_requests) {
+ moved_a_box_by_request |= applied_scroll_request.moved_the_box;
finish_instant_scrolls_answered_by(applied_scroll_request);
+ }
+ if (adopted_any_scroll_offset || moved_a_box_by_request)
+ schedule_hover_update_after_async_scroll();
for (auto operation_id : async_scroll_updates.completed_operation_ids)
resolve_async_scroll_operation(operation_id);
@@ -6048,7 +6056,7 @@ void LocalNavigable::update_hover_after_async_scroll_stops()
{
if (has_been_destroyed())
return;
- event_handler().update_hover_after_scroll();
+ event_handler().update_hover_at_last_known_mouse_position();
}
void LocalNavigable::cancel_hover_update_after_async_scroll()
@@ -7064,6 +7072,7 @@ Compositor::SealedPresentation LocalNavigable::seal_presentation(DOM::Document&
.paint_config = paint_config,
.visual_context_tree = move(visual_context_tree),
.sends_visual_context_tree = sends_visual_context_tree,
+ .scroll_state_changed = paint_state.take_scroll_state_change(),
.scroll_state_snapshot = move(scroll_state_snapshot),
.scroll_requests = take_unsent_scroll_requests(),
.keyboard_scroll_state = move(keyboard_scroll_state),
@@ -7083,6 +7092,8 @@ void LocalNavigable::unseal_presentation(DOM::Document& document, Compositor::Se
{
if (sealed.sends_visual_context_tree && document.has_paint_state())
document.paint_state().did_update_visual_context_values();
+ if (sealed.scroll_state_changed && document.has_paint_state())
+ document.paint_state().did_change_scroll_state();
give_back_unsent_scroll_requests(move(sealed.scroll_requests));
}
@@ -7126,20 +7137,38 @@ void LocalNavigable::finish_recording_in_flight(RecordingInFlight& in_flight, La
// A frame the render owner found no box to record of presents nothing.
if (landing == Layout::RustFFI::FfiRecordingLanding::NothingRecorded) {
unseal_presentation(document, *sealed);
+ if (!has_been_destroyed() && active_document().ptr() == document.ptr())
+ event_handler().note_frame_landed(Web::EventHandler::FramePlacement::Unchanged);
return;
}
- if (landing == Layout::RustFFI::FfiRecordingLanding::PresentedUnrecorded)
- return;
-
Layout::ForcedReadScope read { *document };
// What the recording made goes to a document this navigable still presents, which still has the boxes it recorded.
if (has_been_destroyed() || !has_compositor_context() || active_document().ptr() != document.ptr() || !document->has_committed_viewport_box())
return;
- // What the recording made stands as the compositor's frame. One that landed after the host wrote the document's rows
- // leaves no hit-test list, as the boxes it names may be gone.
- auto const hit_test_list_stands = landing == Layout::RustFFI::FfiRecordingLanding::LandedBehindRows ? Painting::HitTestListStands::No : Painting::HitTestListStands::Yes;
- Painting::take_recording_trace_if_pending(read, *document);
- document->adopt_published_recording(Painting::hit_test_list_read(read, hit_test_list_stands), *in_flight.recording, sealed->published->display_list, [&] { return sealed->published->referenced_resources; });
+ // A frame presented without a recording keeps the hit-test list.
+ auto hit_test_list_adoption = Painting::HitTestListAdoption::Kept;
+ if (landing != Layout::RustFFI::FfiRecordingLanding::PresentedUnrecorded) {
+ // What the recording made stands as the compositor's frame. One that landed after the host wrote the document's
+ // rows leaves no hit-test list, as the boxes it names may be gone.
+ auto const hit_test_list_stands = landing == Layout::RustFFI::FfiRecordingLanding::LandedBehindRows ? Painting::HitTestListStands::No : Painting::HitTestListStands::Yes;
+ Painting::take_recording_trace_if_pending(read, *document);
+ hit_test_list_adoption = document->adopt_published_recording(Painting::hit_test_list_read(read, hit_test_list_stands), *in_flight.recording, sealed->published->display_list, [&] { return sealed->published->referenced_resources; });
+ }
+ // A frame that kept its hit-test items, and sent no visual context tree, placed them as the frame before it did,
+ // unless it scrolled them. The hover waits for a scroll of the user's to stop instead (see
+ // schedule_hover_update_after_async_scroll).
+ auto const frame_placement = [&] {
+ if (hit_test_list_adoption == Painting::HitTestListAdoption::TookNew)
+ return Web::EventHandler::FramePlacement::Changed;
+ if (hit_test_list_adoption != Painting::HitTestListAdoption::Kept)
+ return Web::EventHandler::FramePlacement::Unchanged;
+ if (sealed->sends_visual_context_tree)
+ return Web::EventHandler::FramePlacement::Changed;
+ if (sealed->scroll_state_changed && !has_user_scroll_gesture())
+ return Web::EventHandler::FramePlacement::Changed;
+ return Web::EventHandler::FramePlacement::Unchanged;
+ }();
+ event_handler().note_frame_landed(frame_placement);
}
void LocalNavigable::record_rendering_invalidation()
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 25b5258ec99..c19546c0e63 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -576,6 +576,8 @@ private:
ScrollSequence* begin_scroll_sequence(Web::AsyncScrollNodeStableID);
void note_scroll_sequence_moved(Web::AsyncScrollNodeStableID);
UserScrollGesture* user_scroll_gesture_for(Web::AsyncScrollNodeStableID);
+ // Whether the user scrolls a box of this navigable: a gesture of theirs goes on.
+ bool has_user_scroll_gesture() const;
bool has_scroll_in_progress(ScrollSequence const&, MonotonicTime now) const;
void note_scroll_sequences_may_have_completed();
void end_completed_scroll_sequences();
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index d983657ad55..6bd1ff2185b 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -36,6 +36,7 @@
#include <LibWeb/HTML/CloseWatcherManager.h>
#include <LibWeb/HTML/DataTransfer.h>
#include <LibWeb/HTML/DragDataStore.h>
+#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/Focus.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
@@ -672,7 +673,6 @@ EventResult EventHandler::handle_mousemove(CSSPixelPoint visual_viewport_positio
if (found_parent_element) {
update_cursor(read, target_layout_node, *node, chrome_widget, hit_text_fragment);
- m_cursor_resolved_before_hover = true;
clear_cursor.disarm();
auto coordinates = compute_mouse_event_coordinates(visual_viewport_position, viewport_position, *layout_node);
@@ -1384,7 +1384,7 @@ void EventHandler::update_nested_navigable_under_pointer(GC::Ptr<HTML::LocalNavi
(void)previous->event_handler().handle_mouseleave();
}
-void EventHandler::update_hover_after_scroll()
+void EventHandler::update_hover_at_last_known_mouse_position()
{
if (!m_last_known_mouse_visual_viewport_position.has_value())
return;
@@ -1409,32 +1409,78 @@ void EventHandler::update_hover_at(CSSPixelPoint visual_viewport_position, GC::P
update_hover_after_scroll(visual_viewport_position, screen_position, UIEvents::MouseButton::None, m_last_known_mouse_buttons, m_last_known_mouse_modifiers, hover_target);
}
-// AD-HOC: A move resolves the cursor before it hovers what is under the pointer, which the style of the hover (a :hover
-// rule, or a style a handler of the move's events set) then gives a cursor of its own. Blink resolves the
-// cursor again on a timer once a style change moved a box's cursor. Here the rendering update after the move
-// resolves it again, once.
-void EventHandler::update_cursor_after_rendering_update()
+// AD-HOC: The hover and the cursor follow what is under the pointer while it rests. A frame may move what is there,
+// and a style a rendering update applies may change the `cursor` of what is there. Blink, WebKit and Gecko
+// hover again after a layout, and Blink resolves the cursor again once a style change moved a box's cursor.
+// The event loop follows the pointer once a frame shows the change, between two tasks or as the next rendering
+// update begins, where it reads the frame's hit-test list.
+void EventHandler::update_hover_after_rendering_update()
{
- if (!exchange(m_cursor_resolved_before_hover, false))
- return;
- if (!m_last_known_mouse_visual_viewport_position.has_value() || should_ignore_device_input_event())
- return;
auto document = m_navigable->active_document();
- if (!document || !document->is_fully_active() || !has_committed_root_box())
+ if (document && document->take_cursor_may_be_stale())
+ note_hover_may_be_stale();
+}
+
+void EventHandler::note_frame_landed(FramePlacement frame_placement)
+{
+ if (frame_placement == FramePlacement::Changed)
+ note_hover_may_be_stale();
+}
+
+void EventHandler::note_hover_may_be_stale()
+{
+ // The next move hovers where the pointer is, where none has said yet.
+ if (!m_last_known_mouse_visual_viewport_position.has_value())
return;
+ m_hover_may_be_stale = true;
+ HTML::main_thread_event_loop().note_hover_may_be_stale(*m_navigable);
+}
+
+bool EventHandler::update_hover_where_the_pointer_rests(HTML::HoverUpdatePoint hover_update_point)
+{
+ if (!m_hover_may_be_stale)
+ return false;
+ auto document = m_navigable->active_document();
+ if (!document || !m_last_known_mouse_visual_viewport_position.has_value()) {
+ m_hover_may_be_stale = false;
+ return false;
+ }
+ // A style or layout the host owes, and a hit-test list that is not current, each come with a frame: the hover
+ // follows once it landed. A rendering update brings the style and layout up to date as it begins, which the hover
+ // may do ahead of it.
+ if (document->layout_is_known_stale()) {
+ return true;
+ }
Layout::ForcedReadScope read { *document };
+ if (hover_update_point == HTML::HoverUpdatePoint::BetweenTasks && (document->style_computer().style_engine().has_pending_transaction(read) || !document->layout_is_up_to_date())) {
+ return true;
+ }
+ // A layout the host does not know is stale may still be. The update lays the document out, or lets its style
+ // update fly.
+ if (hover_update_point == HTML::HoverUpdatePoint::RenderingUpdateBegins) {
+ document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseMove);
+ if (document->layout_is_known_stale())
+ return true;
+ }
+ if (hover_update_point == HTML::HoverUpdatePoint::BetweenTasks && !document->hit_test_display_list_is_current(read)) {
+ return true;
+ }
+ m_hover_may_be_stale = false;
+ 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);
- if (!target.has_value())
- return;
- auto node = target->dom_node();
- auto* target_layout_node = target->layout_node(read);
- // A nested navigable's own event handler shows the cursor over its content.
- if (!node || !target_layout_node || Painting::is_navigable_container_viewport_paintable(*target_layout_node))
- return;
- Layout::Node* layout_node = nullptr;
- if (!parent_element_for_event_dispatch(*target_layout_node, node, layout_node))
- return;
- update_cursor(read, target_layout_node, *node, target->chrome_widget, target->is_text_fragment);
+ 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)) {
+ Layout::Node* layout_node = nullptr;
+ if (parent_element_for_event_dispatch(*target_layout_node, node, layout_node))
+ update_cursor(read, target_layout_node, *node, target->chrome_widget, target->is_text_fragment);
+ return false;
+ }
+ update_hover_at_last_known_mouse_position();
+ 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)
@@ -1536,7 +1582,6 @@ void EventHandler::update_hover_after_scroll(CSSPixelPoint visual_viewport_posit
return;
update_cursor(read, target_layout_node, *node, chrome_widget, hit_text_fragment);
- m_cursor_resolved_before_hover = true;
auto coordinates = compute_mouse_event_coordinates(visual_viewport_position, viewport_position, *layout_node);
track_the_effective_position_of_the_legacy_mouse_pointer(node, DOM::HoverEventData {
@@ -5682,6 +5727,13 @@ 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_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.
+ if (auto document = m_navigable->active_document()) {
+ if (auto* arena = document->layout_node_arena_if_created())
+ Layout::RustFFI::document_host_forget_pointer_for_testing(arena->host());
+ }
m_wheel_event_target_latch.clear();
m_navigable->page().clear_context_menu_request();
}
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index c2dbd5e6b0d..22866b49eb4 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -90,10 +90,21 @@ public:
#if defined(AK_OS_MACOS)
bool select_word_for_dictionary_lookup(CSSPixelPoint visual_viewport_position);
#endif
- void update_hover_after_scroll();
+ void update_hover_at_last_known_mouse_position();
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_cursor_after_rendering_update();
+ void update_hover_after_rendering_update();
+ // Whether a frame that landed may have moved what is under the pointer: it has other hit-test items than the frame
+ // before it, or it places the items it kept through other visual contexts.
+ enum class FramePlacement {
+ Unchanged,
+ Changed,
+ };
+ // Call once a frame landed, or presented nothing.
+ void note_frame_landed(FramePlacement);
+ // 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);
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);
@@ -303,6 +314,7 @@ private:
void update_nested_navigable_under_pointer(GC::Ptr<HTML::LocalNavigable>);
void update_cursor(Layout::BegunRead const& read, Layout::Node const*, GC::Ptr<DOM::Node> host_element, RefPtr<Painting::ChromeWidget>, bool hit_text_fragment = false);
+ void note_hover_may_be_stale();
void record_last_known_mouse_position(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned buttons, unsigned modifiers);
EventResult cancel_drag_and_drop_event(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
@@ -332,8 +344,8 @@ private:
Optional<CSSPixelPoint> m_mousemove_previous_screen_position;
Optional<CSSPixelPoint> m_last_known_mouse_visual_viewport_position;
- // Whether a move resolved the cursor before it hovered what is under the pointer, since the last rendering update.
- bool m_cursor_resolved_before_hover { false };
+ // 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 };
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/DisplayListRecording.h b/Libraries/LibWeb/Painting/DisplayListRecording.h
index 197ecf7d110..1f21fc96839 100644
--- a/Libraries/LibWeb/Painting/DisplayListRecording.h
+++ b/Libraries/LibWeb/Painting/DisplayListRecording.h
@@ -23,6 +23,13 @@ enum class HitTestListStands {
Yes,
};
+// What a document did with the hit-test list a recording made as it took the recording in.
+enum class HitTestListAdoption : u8 {
+ Dropped,
+ Kept,
+ TookNew,
+};
+
// The read a recording's hit-test list is made in, `read`, where the list stands, and none otherwise.
inline Optional<Layout::BegunRead const&> hit_test_list_read(Layout::BegunRead const& read, HitTestListStands stands)
{
diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.cpp b/Libraries/LibWeb/Painting/DocumentPaintState.cpp
index 90fae02e476..62bd23acb7d 100644
--- a/Libraries/LibWeb/Painting/DocumentPaintState.cpp
+++ b/Libraries/LibWeb/Painting/DocumentPaintState.cpp
@@ -139,8 +139,12 @@ void DocumentPaintState::refresh_scroll_state(Layout::BegunRead const& read, DOM
// The render state hands over a new snapshot only where something invalidated the one kept.
Layout::RustFFI::render_state_refresh_scroll_state(
m_layout_node_arena->host(), &read, document.page().client().device_pixels_per_css_pixel(),
- &m_scroll_state_snapshot, [](void* sink, Gfx::FloatPoint const* offsets, size_t count) {
- static_cast<Compositing::ScrollStateSnapshot*>(sink)->assign_device_offsets({ offsets, count });
+ this, [](void* sink, Gfx::FloatPoint const* offsets, size_t count) {
+ auto& paint_state = *static_cast<DocumentPaintState*>(sink);
+ ReadonlySpan<Gfx::FloatPoint> device_offsets { offsets, count };
+ if (paint_state.m_scroll_state_snapshot.device_offsets() != device_offsets)
+ paint_state.m_scroll_state_changed = true;
+ paint_state.m_scroll_state_snapshot.assign_device_offsets(device_offsets);
});
}
diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.h b/Libraries/LibWeb/Painting/DocumentPaintState.h
index 14ab1cf94f2..9bf967208ba 100644
--- a/Libraries/LibWeb/Painting/DocumentPaintState.h
+++ b/Libraries/LibWeb/Painting/DocumentPaintState.h
@@ -51,6 +51,9 @@ public:
void republish_visual_animations(Layout::BegunRead const& read, DOM::Document&);
bool visual_context_tree_needs_compositor_update() const { return m_visual_context_tree_needs_compositor_update; }
void did_update_visual_context_tree_in_compositor() { m_visual_context_tree_needs_compositor_update = false; }
+ // Whether the scroll offsets changed since a frame last took the change.
+ bool take_scroll_state_change() { return exchange(m_scroll_state_changed, false); }
+ void did_change_scroll_state() { m_scroll_state_changed = true; }
bool has_visual_context_tree(Layout::BegunRead const& read) const;
u64 accumulated_visual_context_tree_build_count() const { return m_accumulated_visual_context_tree_build_count; }
u64 accumulated_visual_context_tree_incremental_update_count() const { return m_accumulated_visual_context_tree_incremental_update_count; }
@@ -100,6 +103,7 @@ private:
u64 m_accumulated_visual_context_tree_build_count { 0 };
u64 m_accumulated_visual_context_tree_incremental_update_count { 0 };
bool m_visual_context_tree_needs_compositor_update { false };
+ bool m_scroll_state_changed { false };
};
}
diff --git a/Libraries/LibWeb/Painting/Forward.h b/Libraries/LibWeb/Painting/Forward.h
index 6df7467e74d..d4942ebb069 100644
--- a/Libraries/LibWeb/Painting/Forward.h
+++ b/Libraries/LibWeb/Painting/Forward.h
@@ -17,6 +17,7 @@ class HitTestQuery;
enum class CaretLineDirection : u8;
enum class CaretLineEdge : u8;
enum class CaretPositionMode : u8;
+enum class HitTestListAdoption : u8;
struct CaretPosition;
struct DisplayListRecording;
struct HitTestResult;
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
index 8e8bd947bca..94e1cc333d1 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
@@ -88,6 +88,7 @@ pub enum FfiStyleInvalidationField {
/// The white space of the element's text children collapses where it did not, or the other way round, so the white
/// space text among them may gain or lose its box.
WhiteSpaceCollapseChanged = 1 << 25,
+ CursorChanged = 1 << 26,
}
/// The `InvalidationLevel` of a style move at which its box is painted again, the one at which it lays out again, and
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
index c8040e39aa8..2fd56a3bdf2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
@@ -102,6 +102,7 @@ struct StyleInvalidation {
affects_hit_testing: bool,
repaint_highlights: bool,
white_space_collapse_changed: bool,
+ cursor_changed: bool,
}
impl StyleInvalidation {
@@ -153,6 +154,7 @@ impl StyleInvalidation {
self.affects_hit_testing |= other.affects_hit_testing;
self.repaint_highlights |= other.repaint_highlights;
self.white_space_collapse_changed |= other.white_space_collapse_changed;
+ self.cursor_changed |= other.cursor_changed;
}
/// Whether the damage stays in the box of its element: no layout tree, stacking context, visual context, scroll
@@ -188,6 +190,7 @@ impl StyleInvalidation {
affects_hit_testing: has(FfiStyleInvalidationField::AffectsHitTesting),
repaint_highlights: has(FfiStyleInvalidationField::RepaintHighlights),
white_space_collapse_changed: has(FfiStyleInvalidationField::WhiteSpaceCollapseChanged),
+ cursor_changed: has(FfiStyleInvalidationField::CursorChanged),
}
}
@@ -209,6 +212,7 @@ impl StyleInvalidation {
packed |= u32::from(self.repaint_highlights) * FfiStyleInvalidationField::RepaintHighlights as u32;
packed |=
u32::from(self.white_space_collapse_changed) * FfiStyleInvalidationField::WhiteSpaceCollapseChanged as u32;
+ packed |= u32::from(self.cursor_changed) * FfiStyleInvalidationField::CursorChanged as u32;
packed
}
}
@@ -599,6 +603,7 @@ fn property_invalidation(property: u16, old: ComputedValuesView<'_>, new: Comput
let mut result = StyleInvalidation {
affects_hit_testing: property_metadata::property_affects_hit_testing(property),
+ cursor_changed: property == property_id::CURSOR,
..StyleInvalidation::default()
};
if matches!(property, property_id::CONTAINER_NAME | property_id::CONTAINER_TYPE) {
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rs
index f4b05edadd8..1f95d233fad 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs
@@ -1837,6 +1837,13 @@ pub extern "C" fn document_host_take_clock_lanes_in(host: &DocumentHost, update:
host.take_clock_lanes_in(update, outer_input_event)
}
+/// Forgets where the compositor said the pointer of `host`'s document went: the lanes of the next document hear of no
+/// move before one of its own. For a test, whose documents follow each other with the pointer where the last left it.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_forget_pointer_for_testing(host: &DocumentHost) {
+ host.clock_ticks().pointer_state().forget();
+}
+
/// Takes in what the lanes of `host`'s document did, as a task between two rendering updates handles a press, and
/// answers as [`document_host_take_clock_lanes_in`] does. No frame of the host's follows yet, so the lanes tick on.
/// `outer_input_event` is as there.
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.txt
index 89fb5b5f2cb..fcdb2b46859 100644
--- a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.txt
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.txt
@@ -1,2 +1,3 @@
mousemove targets: inner
-#inner matches :hover: true
+#inner matches :hover: false
+#cover matches :hover: true
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.txt
index 87c6ecab2ab..121734760d0 100644
--- a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.txt
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.txt
@@ -2,4 +2,4 @@ cursor over the parent: Crosshair
left read in the task: 150
cursor inside the iframe: Hand
mousemove targets: second
-#second matches :hover: true
+#second matches :hover: false
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.txt
index 9936402fecd..8ceea9332e4 100644
--- a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.txt
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.txt
@@ -2,4 +2,4 @@ cursor over the parent: Hand
left read in the task: 150
cursor inside the iframe: Arrow
mousemove targets: second
-#second matches :hover: true
+#second matches :hover: false
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-after-a-layout-change.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-after-a-layout-change.txt
new file mode 100644
index 00000000000..0b83eb4a2c2
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-after-a-layout-change.txt
@@ -0,0 +1,3 @@
+beside the target: hovered=false cursor=Arrow events=none
+the target laid out under the pointer: hovered=true cursor=Hand events=mouseout html, mouseover target
+the target laid out away again: hovered=false cursor=Arrow events=mouseout target, mouseover html
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-an-image-cursor-after-a-style-change.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-an-image-cursor-after-a-style-change.txt
new file mode 100644
index 00000000000..f2538d97c17
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-an-image-cursor-after-a-style-change.txt
@@ -0,0 +1,2 @@
+cursor over the target: Hand
+cursor once the frame with the style landed: Image
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-scroll.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-scroll.txt
new file mode 100644
index 00000000000..f4b13b99ceb
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-scroll.txt
@@ -0,0 +1,3 @@
+at rest: Arrow
+the help row scrolled under the pointer: Help
+the plain row scrolled back under the pointer: Arrow
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-transform.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-transform.txt
new file mode 100644
index 00000000000..8634aa984c3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-transform.txt
@@ -0,0 +1,4 @@
+at rest: Arrow
+the target transformed under the pointer: Hand
+the target transformed further, still under the pointer: Hand
+the target transformed away: Arrow
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-style-change.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-style-change.txt
new file mode 100644
index 00000000000..ca202e5669c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-updates-the-cursor-after-a-style-change.txt
@@ -0,0 +1,3 @@
+cursor over the target: Hand
+cursor once the frame with the style landed: Hidden
+cursor once the frame with the next style landed: Help
diff --git a/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-ancestor-style-change.txt b/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-ancestor-style-change.txt
new file mode 100644
index 00000000000..484bdefc1bb
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-ancestor-style-change.txt
@@ -0,0 +1,2 @@
+initial cursor: Hand
+cursor after ancestor style change: Hidden
diff --git a/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-element-moves-under-mouse.txt b/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-element-moves-under-mouse.txt
new file mode 100644
index 00000000000..c667bf5503e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-element-moves-under-mouse.txt
@@ -0,0 +1,2 @@
+initial cursor: Arrow
+cursor after element moves under mouse: Hand
diff --git a/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-style-change.txt b/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-style-change.txt
new file mode 100644
index 00000000000..9ce073e18b7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/hit_testing/cursor-updates-after-style-change.txt
@@ -0,0 +1,2 @@
+initial cursor: Hand
+cursor after style change: Hidden
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/frame-in-flight.js b/Tests/LibWeb/Text/input/HTML/frame-in-flight/frame-in-flight.js
index 5a24a836180..5d11b602f48 100644
--- a/Tests/LibWeb/Text/input/HTML/frame-in-flight/frame-in-flight.js
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/frame-in-flight.js
@@ -91,6 +91,13 @@ async function whileLaneAnimates(animate, during) {
}
}
+// Resolves in the first task after the rendering update a test injected has ended with nothing of it in flight, and the
+// lane of its frame, not that of an earlier frame, has come together from it.
+async function untilLaneSettled() {
+ do await nextTask();
+ while (internals.frameSchedulerState() !== "idle" || internals.clockLaneIsComing(document));
+}
+
// Resolves once the srcdoc document of `iframe` has loaded, which it may have before the page's DOMContentLoaded, as the
// test begins.
function srcdocLoaded(iframe) {
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.html
index 4b969273964..41d88f6b210 100644
--- a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.html
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-mouse-move-handed-to-an-iframe-goes-to-it-after-the-task-moved-boxes.html
@@ -12,7 +12,8 @@
// Beside a task that moves an element over a same-process iframe, the lane of the document hands a move over the
// iframe, as the screen shows it, to the iframe's lane, which hovers it. The rendering update after the task
// handles the mouse event of that move, which goes to the iframe's element under the pointer, as the screen showed
- // it, not to the element the task moved there.
+ // it, not to the element the task moved there. The pointer then rests on the element the task moved under it,
+ // which the update hovers.
asyncTest(async done => {
const iframe = document.querySelector("iframe");
await srcdocLoaded(iframe);
@@ -26,9 +27,12 @@
internals.injectHoverPointer(80, 50, frameTime + 16, id);
iframe.contentWindow.internals.injectClockTick(frameTime + 32);
}, [document, iframe.contentDocument]);
- await twoFrames();
+ // The hover follows the frame that moved the element under the pointer, between two tasks once it landed.
+ await twoFramesLanded();
+ await nextTask();
println(`mousemove targets: ${targets.join(", ")}`);
println(`#inner matches :hover: ${inner.matches(":hover")}`);
+ println(`#cover matches :hover: ${cover.matches(":hover")}`);
done();
});
</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-moves-the-cursor.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-moves-the-cursor.html
index 1bd596d07a0..dbcc04c6290 100644
--- a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-moves-the-cursor.html
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-moves-the-cursor.html
@@ -40,6 +40,7 @@
for (const y of rows) {
internals.mouseMove(10, y);
await twoFrames();
+ internals.synchronizeCompositor();
mainThreadCursors.push(internals.currentCursor());
}
println(`main thread cursors: ${mainThreadCursors.join(", ")}`);
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.html
index d8b660478c7..e71a760e67a 100644
--- a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.html
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-predefined-cursors-without-hover-style-work.html
@@ -31,7 +31,8 @@
iframe.contentWindow.internals.injectClockTick(frameTime + 48);
println(`cursor inside the iframe: ${internals.currentCursor()}`);
}, [document, innerDocument]);
- await twoFrames();
+ // The hover follows the frame with the moved box once it landed.
+ await twoFramesLanded();
println(`mousemove targets: ${targets.join(", ")}`);
println(`#second matches :hover: ${second.matches(":hover")}`);
done();
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.html
index bbc815b4d27..8f41cc176da 100644
--- a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.html
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-preserves-the-hit-target-without-hover-style-work.html
@@ -30,7 +30,8 @@
iframe.contentWindow.internals.injectClockTick(frameTime + 48);
println(`cursor inside the iframe: ${internals.currentCursor()}`);
}, [document, innerDocument]);
- await twoFrames();
+ // The hover follows the frame with the moved box once it landed.
+ await twoFramesLanded();
println(`mousemove targets: ${targets.join(", ")}`);
println(`#second matches :hover: ${second.matches(":hover")}`);
done();
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-after-a-layout-change.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-after-a-layout-change.html
new file mode 100644
index 00000000000..e3f3adbdc30
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-after-a-layout-change.html
@@ -0,0 +1,40 @@
+<!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: 100px; height: 100px; }
+ #target:hover { background: green; }
+</style>
+<div id="target"></div>
+<script>
+ // A layout a rendering update runs moves a box under the pointer at rest, and away again. The hover follows once
+ // the update's frame landed: the box is hovered while it is under the pointer, the boundary events fire as they
+ // would for a move, and the cursor is the box's while it is there.
+ asyncTest(async done => {
+ const events = [];
+ for (const type of ["mouseover", "mouseout"])
+ document.addEventListener(type, event => events.push(`${type} ${event.target.id || event.target.localName}`), { capture: true });
+ await whileLaneHovers(async frameTime => {
+ internals.mouseMove(50, 50);
+ let time = frameTime;
+ const step = async change => {
+ change();
+ time += 16;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ events.length = 0;
+ const report = label => println(`${label}: hovered=${target.matches(":hover")} cursor=${internals.currentCursor()} events=${events.join(", ") || "none"}`);
+ report("beside the target");
+ events.length = 0;
+ await step(() => target.style.left = "0px");
+ report("the target laid out under the pointer");
+ events.length = 0;
+ await step(() => target.style.left = "150px");
+ report("the target laid out away again");
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-an-image-cursor-after-a-style-change.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-an-image-cursor-after-a-style-change.html
new file mode 100644
index 00000000000..10b8765db2e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-an-image-cursor-after-a-style-change.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ #target { cursor: pointer; width: 100px; height: 100px; }
+</style>
+<div id="target"></div>
+<script>
+ // A style a rendering update applies gives what is under the pointer at rest an image cursor. The hover follows
+ // once the update's frame landed, and shows the image. The output is printed at the end, so that no text of it lies
+ // under the pointer meanwhile.
+ asyncTest(async done => {
+ const image = new Image();
+ image.src = "../../../../Assets/120.png";
+ await image.decode();
+ await whileLaneHovers(async frameTime => {
+ internals.mouseMove(50, 50);
+ let time = frameTime;
+ const lines = [];
+ const step = async change => {
+ change();
+ time += 16;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ lines.push(`cursor over the target: ${internals.currentCursor()}`);
+ await step(() => target.style.cursor = "url(../../../../Assets/120.png), auto");
+ lines.push(`cursor once the frame with the style landed: ${internals.currentCursor()}`);
+ println(lines.join("\n"));
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-scroll.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-scroll.html
new file mode 100644
index 00000000000..9806d72afcf
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-scroll.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ #scroller { width: 100px; height: 100px; overflow: hidden; }
+ #scroller div { height: 100px; }
+ #help { cursor: help; }
+</style>
+<div id="scroller"><div id="plain"></div><div id="help"></div></div>
+<script>
+ // Script scrolls a box under the pointer at rest, which keeps the frame's hit-test items: the frame places them at
+ // other scroll offsets. The hover follows once the frame landed, and shows the cursor of what the scroll put under
+ // the pointer. 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 step = async change => {
+ change();
+ time += 16;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ lines.push(`at rest: ${internals.currentCursor()}`);
+ await step(() => scroller.scrollTop = 100);
+ lines.push(`the help row scrolled under the pointer: ${internals.currentCursor()}`);
+ await step(() => scroller.scrollTop = 0);
+ lines.push(`the plain row scrolled back under the pointer: ${internals.currentCursor()}`);
+ println(lines.join("\n"));
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-transform.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-transform.html
new file mode 100644
index 00000000000..5b8eabf766a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-script-transform.html
@@ -0,0 +1,37 @@
+<!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: 100px; height: 100px; }
+</style>
+<div id="target"></div>
+<script>
+ // Script transforms a box under the pointer at rest, and away again, which keeps the frame's hit-test items: the
+ // frame places them through other visual contexts. The hover follows once the frame landed, 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 step = async change => {
+ change();
+ time += 16;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ lines.push(`at rest: ${internals.currentCursor()}`);
+ await step(() => target.style.transform = "translateX(-150px)");
+ lines.push(`the target transformed under the pointer: ${internals.currentCursor()}`);
+ await step(() => target.style.transform = "translateX(-120px)");
+ lines.push(`the target transformed further, still under the pointer: ${internals.currentCursor()}`);
+ await step(() => target.style.transform = "translateX(-300px)");
+ lines.push(`the target transformed away: ${internals.currentCursor()}`);
+ println(lines.join("\n"));
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-style-change.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-style-change.html
new file mode 100644
index 00000000000..3e5d36c1089
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-updates-the-cursor-after-a-style-change.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ #target { cursor: pointer; width: 100px; height: 100px; }
+</style>
+<div id="target"></div>
+<script>
+ // A style a rendering update applies changes the `cursor` of what is under the pointer at rest. The hover follows
+ // once the update's frame landed, and shows the cursor the style gives. 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 step = async change => {
+ change();
+ time += 16;
+ internals.injectRenderingOpportunity(time);
+ await untilLaneSettled();
+ await nextTask();
+ };
+ lines.push(`cursor over the target: ${internals.currentCursor()}`);
+ await step(() => target.style.cursor = "none");
+ lines.push(`cursor once the frame with the style landed: ${internals.currentCursor()}`);
+ await step(() => target.style.cursor = "help");
+ lines.push(`cursor once the frame with the next style landed: ${internals.currentCursor()}`);
+ println(lines.join("\n"));
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-ancestor-style-change.html b/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-ancestor-style-change.html
new file mode 100644
index 00000000000..3bdd224b6dc
--- /dev/null
+++ b/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-ancestor-style-change.html
@@ -0,0 +1,39 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ }
+
+ #player {
+ cursor: pointer;
+ height: 200px;
+ width: 200px;
+ }
+
+ #controls {
+ height: 100px;
+ width: 100px;
+ }
+</style>
+<div id="player"><div id="controls"></div></div>
+<script>
+ function nextRenderingUpdate() {
+ return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ }
+
+ // A player hides its cursor through the style of a container, which what is under the pointer inherits.
+ asyncTest(async done => {
+ internals.mouseMove(50, 50);
+ await nextRenderingUpdate();
+ println(`initial cursor: ${internals.currentCursor()}`);
+
+ player.style.cursor = "none";
+ await nextRenderingUpdate();
+ internals.synchronizeCompositor();
+ // The hover follows the frame between two tasks.
+ await new Promise(resolve => setTimeout(resolve, 0));
+ println(`cursor after ancestor style change: ${internals.currentCursor()}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-element-moves-under-mouse.html b/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-element-moves-under-mouse.html
new file mode 100644
index 00000000000..e1480974b5c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-element-moves-under-mouse.html
@@ -0,0 +1,37 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ }
+
+ #target {
+ cursor: pointer;
+ height: 100px;
+ left: 150px;
+ position: absolute;
+ top: 0;
+ width: 100px;
+ }
+</style>
+<div id="target"></div>
+<script>
+ function nextRenderingUpdate() {
+ return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ }
+
+ // The element moves a rendering update after the move settled.
+ asyncTest(async done => {
+ internals.mouseMove(50, 50);
+ await nextRenderingUpdate();
+ println(`initial cursor: ${internals.currentCursor()}`);
+
+ target.style.left = "0";
+ await nextRenderingUpdate();
+ internals.synchronizeCompositor();
+ // The hover follows the frame between two tasks.
+ await new Promise(resolve => setTimeout(resolve, 0));
+ println(`cursor after element moves under mouse: ${internals.currentCursor()}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-style-change.html b/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-style-change.html
new file mode 100644
index 00000000000..631ca5eef58
--- /dev/null
+++ b/Tests/LibWeb/Text/input/hit_testing/cursor-updates-after-style-change.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ }
+
+ #target {
+ cursor: pointer;
+ height: 100px;
+ width: 100px;
+ }
+</style>
+<div id="target"></div>
+<script>
+ function nextRenderingUpdate() {
+ return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ }
+
+ // The style changes a rendering update after the move settled, as a player hiding its controls does.
+ asyncTest(async done => {
+ internals.mouseMove(50, 50);
+ await nextRenderingUpdate();
+ println(`initial cursor: ${internals.currentCursor()}`);
+
+ target.style.cursor = "none";
+ await nextRenderingUpdate();
+ internals.synchronizeCompositor();
+ // The hover follows the frame between two tasks.
+ await new Promise(resolve => setTimeout(resolve, 0));
+ println(`cursor after style change: ${internals.currentCursor()}`);
+ done();
+ });
+</script>