Sfoglia il codice sorgente

LibWeb: Use strong pointers and null checks in handle_keyup()

Andreas Kling 3 anni fa
parent
commit
dcb409a112
1 ha cambiato i file con 12 aggiunte e 6 eliminazioni
  1. 12 6
      Userland/Libraries/LibWeb/Page/EventHandler.cpp

+ 12 - 6
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)