LibWeb: Dispatch keydown/keyup events on the appropriate target

This commit is contained in:
Idan Horowitz 2021-10-01 20:22:29 +03:00 committed by Andreas Kling
parent 43482dfde3
commit c5b924b1e6
Notes: sideshowbarker 2024-07-18 03:13:44 +09:00

View File

@ -456,15 +456,23 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
}
auto event = UIEvents::KeyboardEvent::create_from_platform_event(UIEvents::EventNames::keydown, key, modifiers, code_point);
// FIXME: Figure out the right event target.
return m_frame.active_document()->window().dispatch_event(move(event));
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));
}
bool EventHandler::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
{
auto event = UIEvents::KeyboardEvent::create_from_platform_event(UIEvents::EventNames::keyup, key, modifiers, code_point);
// FIXME: Figure out the right event target.
return m_frame.active_document()->window().dispatch_event(move(event));
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));
}
void EventHandler::set_mouse_event_tracking_layout_node(Layout::Node* layout_node)