summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-10-12 14:38:31 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-12 14:39:09 +0200
commitdcb409a1120425cab9ec2b124014fafa81b586c3 (patch)
treebbb56942b5de44646b4b202eaf805c38728e9141
parent865162b1c3a0d94b3cfa165e7f4e33f647cbb749 (diff)
downloadserenity-dcb409a1120425cab9ec2b124014fafa81b586c3.zip
LibWeb: Use strong pointers and null checks in handle_keyup()
-rw-r--r--Userland/Libraries/LibWeb/Page/EventHandler.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
index 8541269565..6fc36d603c 100644
--- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
@@ -478,13 +478,19 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
bool EventHandler::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
{
+ RefPtr<DOM::Document> document = m_frame.active_document();
+ if (!document)
+ return false;
+
auto event = UIEvents::KeyboardEvent::create_from_platform_event(UIEvents::EventNames::keyup, key, modifiers, code_point);
- if (m_frame.active_document()->focused_element())
- return m_frame.active_document()->focused_element()->dispatch_event(move(event));
- else if (m_frame.active_document()->body())
- return m_frame.active_document()->body()->dispatch_event(move(event));
- else
- return m_frame.active_document()->root().dispatch_event(move(event));
+
+ if (RefPtr<DOM::Element> focused_element = document->focused_element())
+ return document->focused_element()->dispatch_event(move(event));
+
+ if (RefPtr<HTML::HTMLElement> body = document->body())
+ return body->dispatch_event(move(event));
+
+ return document->root().dispatch_event(move(event));
}
void EventHandler::set_mouse_event_tracking_layout_node(Layout::Node* layout_node)