LibWeb: Return EventResult in EventHandler::focus_next/previous_element

No functional changes.
This commit is contained in:
Jelle Raaijmakers 2025-06-13 13:06:32 +02:00 committed by Alexander Kalenik
commit e4586abc18
Notes: github-actions[bot] 2025-06-13 15:40:38 +00:00
2 changed files with 17 additions and 19 deletions

View file

@ -989,24 +989,24 @@ EventResult EventHandler::handle_drag_and_drop_event(DragEvent::Type type, CSSPi
VERIFY_NOT_REACHED();
}
bool EventHandler::focus_next_element()
EventResult EventHandler::focus_next_element()
{
if (!m_navigable->active_document())
return false;
return EventResult::Dropped;
if (!m_navigable->active_document()->is_fully_active())
return false;
return EventResult::Dropped;
auto set_focus_to_first_focusable_element = [&]() {
auto set_focus_to_first_focusable_element = [&] {
auto* element = m_navigable->active_document()->first_child_of_type<DOM::Element>();
for (; element; element = element->next_element_in_pre_order()) {
if (element->is_focusable()) {
m_navigable->active_document()->set_focused_element(element);
return true;
return EventResult::Handled;
}
}
return false;
return EventResult::Dropped;
};
auto* element = m_navigable->active_document()->focused_element();
@ -1020,28 +1020,28 @@ bool EventHandler::focus_next_element()
return set_focus_to_first_focusable_element();
m_navigable->active_document()->set_focused_element(element);
return true;
return EventResult::Handled;
}
bool EventHandler::focus_previous_element()
EventResult EventHandler::focus_previous_element()
{
if (!m_navigable->active_document())
return false;
return EventResult::Dropped;
if (!m_navigable->active_document()->is_fully_active())
return false;
return EventResult::Dropped;
auto set_focus_to_last_focusable_element = [&]() {
auto set_focus_to_last_focusable_element = [&] {
// FIXME: This often returns the HTML element itself, which has no previous sibling.
auto* element = m_navigable->active_document()->last_child_of_type<DOM::Element>();
for (; element; element = element->previous_element_in_pre_order()) {
if (element->is_focusable()) {
m_navigable->active_document()->set_focused_element(element);
return true;
return EventResult::Handled;
}
}
return false;
return EventResult::Dropped;
};
auto* element = m_navigable->active_document()->focused_element();
@ -1055,7 +1055,7 @@ bool EventHandler::focus_previous_element()
return set_focus_to_last_focusable_element();
m_navigable->active_document()->set_focused_element(element);
return true;
return EventResult::Handled;
}
constexpr bool should_ignore_keydown_event(u32 code_point, u32 modifiers)
@ -1177,9 +1177,7 @@ EventResult EventHandler::handle_keydown(UIEvents::KeyCode key, u32 modifiers, u
if (!(modifiers & UIEvents::KeyModifier::Mod_Ctrl)) {
if (key == UIEvents::KeyCode::Key_Tab) {
if (modifiers & UIEvents::KeyModifier::Mod_Shift)
return focus_previous_element() ? EventResult::Handled : EventResult::Dropped;
return focus_next_element() ? EventResult::Handled : EventResult::Dropped;
return modifiers & UIEvents::KeyModifier::Mod_Shift ? focus_previous_element() : focus_next_element();
}
}