From 9df00d0677e0ea736ed7a493418f3b4a4f0ca827 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 3 Oct 2023 15:35:07 +0200 Subject: [PATCH] LibWeb: Exit event handlers if active document is not fully active Fixes https://github.com/SerenityOS/serenity/issues/21304 --- .../Libraries/LibWeb/Page/EventHandler.cpp | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 647727db6c..f93c78b214 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -146,8 +146,12 @@ Painting::PaintableBox const* EventHandler::paint_root() const bool EventHandler::handle_mousewheel(CSSPixelPoint position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned int modifiers, int wheel_delta_x, int wheel_delta_y) { - if (m_browsing_context->active_document()) - m_browsing_context->active_document()->update_layout(); + if (!m_browsing_context->active_document()) + return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; + + m_browsing_context->active_document()->update_layout(); if (!paint_root()) return false; @@ -205,8 +209,12 @@ bool EventHandler::handle_mousewheel(CSSPixelPoint position, CSSPixelPoint scree bool EventHandler::handle_mouseup(CSSPixelPoint position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers) { - if (m_browsing_context->active_document()) - m_browsing_context->active_document()->update_layout(); + if (!m_browsing_context->active_document()) + return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; + + m_browsing_context->active_document()->update_layout(); if (!paint_root()) return false; @@ -321,8 +329,12 @@ after_node_use: bool EventHandler::handle_mousedown(CSSPixelPoint position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers) { - if (m_browsing_context->active_document()) - m_browsing_context->active_document()->update_layout(); + if (!m_browsing_context->active_document()) + return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; + + m_browsing_context->active_document()->update_layout(); if (!paint_root()) return false; @@ -413,8 +425,12 @@ bool EventHandler::handle_mousedown(CSSPixelPoint position, CSSPixelPoint screen bool EventHandler::handle_mousemove(CSSPixelPoint position, CSSPixelPoint screen_position, unsigned buttons, unsigned modifiers) { - if (m_browsing_context->active_document()) - m_browsing_context->active_document()->update_layout(); + if (!m_browsing_context->active_document()) + return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; + + m_browsing_context->active_document()->update_layout(); if (!paint_root()) return false; @@ -533,8 +549,12 @@ bool EventHandler::handle_mousemove(CSSPixelPoint position, CSSPixelPoint screen bool EventHandler::handle_doubleclick(CSSPixelPoint position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers) { - if (m_browsing_context->active_document()) - m_browsing_context->active_document()->update_layout(); + if (!m_browsing_context->active_document()) + return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; + + m_browsing_context->active_document()->update_layout(); if (!paint_root()) return false; @@ -628,6 +648,9 @@ bool EventHandler::focus_next_element() { if (!m_browsing_context->active_document()) return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; + auto* element = m_browsing_context->active_document()->focused_element(); if (!element) { element = m_browsing_context->active_document()->first_child_of_type(); @@ -648,6 +671,9 @@ bool EventHandler::focus_previous_element() { if (!m_browsing_context->active_document()) return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; + auto* element = m_browsing_context->active_document()->focused_element(); if (!element) { element = m_browsing_context->active_document()->last_child_of_type(); @@ -676,6 +702,8 @@ bool EventHandler::fire_keyboard_event(FlyString const& event_name, HTML::Browsi JS::GCPtr document = browsing_context.active_document(); if (!document) return false; + if (!document->is_fully_active()) + return false; if (JS::GCPtr focused_element = document->focused_element()) { if (is(*focused_element)) { @@ -701,6 +729,8 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin { if (!m_browsing_context->active_document()) return false; + if (!m_browsing_context->active_document()->is_fully_active()) + return false; JS::NonnullGCPtr document = *m_browsing_context->active_document(); if (!document->layout_node())