Skip to content

Truly independent web browser

LibWeb+WebContent: Let go of a held scroll key when focus is lost

Zaggy10240c94141fb16e
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 209f38f78af..c9e62997570 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -2379,10 +2379,8 @@ EventResult EventHandler::handle_keyup(UIEvents::KeyCode key, u32 modifiers, u32
if (repeat)
return EventResult::Dropped;
- if (m_held_scroll_key == key) {
- m_held_scroll_key.clear();
- m_scroll_key_gesture_hold = nullptr;
- }
+ if (m_held_scroll_key == key)
+ release_held_scroll_key();
return fire_keyboard_event(UIEvents::EventNames::keyup, m_navigable, key, modifiers, code_point, false);
}
@@ -5552,10 +5550,17 @@ bool EventHandler::has_committed_root_box() const
return document && document->has_committed_viewport_box();
}
+void EventHandler::release_held_scroll_key()
+{
+ m_held_scroll_key.clear();
+ m_scroll_key_gesture_hold = nullptr;
+}
+
void EventHandler::clear_per_test_input_state(Badge<Internals::Internals>)
{
clear_mousedown_tracking();
stop_updating_selection();
+ release_held_scroll_key();
m_middle_button_scroll_handler = nullptr;
m_mouse_pointer.prevent_mouse_event = false;
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index 799e05b15c7..9de65eab5e3 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -145,6 +145,9 @@ public:
return {};
}
+ // For a held key whose release will not reach the page, as when the window loses focus.
+ void release_held_scroll_key();
+
void clear_per_test_input_state(Badge<Internals::Internals>);
private:
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 9780dc3fe16..1a7566e8941 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -208,6 +208,8 @@ void PageClient::set_has_focus(bool has_focus)
// The focus ring, the text caret, and selection highlight colors all depend on the window focus state, so
// nothing painted before the change can be reused; repaint every document the page hosts.
for (auto const& navigable : page().hosted_navigables()) {
+ if (!has_focus)
+ navigable->event_handler().release_held_scroll_key();
auto document = navigable->active_document();
if (!document)
continue;