From 7c1d359790933a33096dee9b3cce776fa85e3097 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 17 Apr 2026 11:18:13 +0100 Subject: [PATCH] LibWeb: Clean-up more input state after running each test The clean-up in 71c457c36e33c68ce3ef24d49ab8ae56e731bef7 turns out to not be enough for all cases. So be more thorough and clear up anything that could affect the next test. In particular this fixes flakiness in `Text/input/select-text.html` but hopefully it solves the issue for good! --- Libraries/LibWeb/Internals/Internals.cpp | 4 ++-- Libraries/LibWeb/Page/DragAndDropEventHandler.h | 4 ++-- Libraries/LibWeb/Page/EventHandler.cpp | 13 +++++++++++++ Libraries/LibWeb/Page/EventHandler.h | 2 ++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp index 195138b535..fe2f809538 100644 --- a/Libraries/LibWeb/Internals/Internals.cpp +++ b/Libraries/LibWeb/Internals/Internals.cpp @@ -574,8 +574,8 @@ void Internals::perform_per_test_cleanup() gamepad->disconnect(); m_gamepads.clear(); - // Clear any mouse-down state - page().top_level_traversable()->event_handler().clear_mousedown_tracking(); + // Clear any input state + page().top_level_traversable()->event_handler().clear_per_test_input_state({}); } void Internals::set_highlighted_node(GC::Ptr node) diff --git a/Libraries/LibWeb/Page/DragAndDropEventHandler.h b/Libraries/LibWeb/Page/DragAndDropEventHandler.h index 0c2d515379..4de413ab93 100644 --- a/Libraries/LibWeb/Page/DragAndDropEventHandler.h +++ b/Libraries/LibWeb/Page/DragAndDropEventHandler.h @@ -27,6 +27,8 @@ public: EventResult handle_drag_leave(JS::Realm&, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers); EventResult handle_drop(JS::Realm&, CSSPixelPoint screen_position, CSSPixelPoint page_offset, CSSPixelPoint client_offset, CSSPixelPoint offset, unsigned button, unsigned buttons, unsigned modifiers); + void reset(); + private: enum class Cancelled { No, @@ -49,8 +51,6 @@ private: bool allow_text_drop(GC::Ref) const; - void reset(); - RefPtr m_drag_data_store; // https://html.spec.whatwg.org/multipage/dnd.html#source-node diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index fcd2fd4e53..9934c8175c 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -980,6 +980,19 @@ void EventHandler::stop_updating_selection() m_auto_scroll_handler = nullptr; } +void EventHandler::clear_per_test_input_state(Badge) +{ + clear_mousedown_tracking(); + stop_updating_selection(); + m_middle_button_scroll_handler = nullptr; + m_prevent_mouse_event = false; + m_hovered_chrome_widget = nullptr; + m_captured_chrome_widget = nullptr; + m_effective_legacy_mouse_pointer_position = nullptr; + m_drag_and_drop_event_handler->reset(); + m_mousemove_previous_screen_position.clear(); +} + EventResult EventHandler::handle_mouseup(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers) { auto middle_button_autoscrolled = m_middle_button_scroll_handler && m_middle_button_scroll_handler->mouse_has_moved_beyond_dead_zone(); diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h index 681951f681..5463092f20 100644 --- a/Libraries/LibWeb/Page/EventHandler.h +++ b/Libraries/LibWeb/Page/EventHandler.h @@ -77,6 +77,8 @@ public: return {}; } + void clear_per_test_input_state(Badge); + private: EventResult focus_next_element(); EventResult focus_previous_element();