1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:27:35 +00:00

LibWeb: Implement EventHandler::focus_previous_element()

This implements EventHandler::focus_previous_element() so we can cycle
backwards through focusable elements on a web page with Shift+Tab.
This commit is contained in:
Kenneth Myhra 2022-02-08 21:23:43 +01:00 committed by Linus Groh
parent 3f9fc0f690
commit bf7f6a9e98
2 changed files with 26 additions and 2 deletions

View file

@ -413,8 +413,22 @@ bool EventHandler::focus_next_element()
bool EventHandler::focus_previous_element()
{
// FIXME: Implement Shift-Tab cycling backwards through focusable elements!
return false;
if (!m_browsing_context.active_document())
return false;
auto* element = m_browsing_context.active_document()->focused_element();
if (!element) {
element = m_browsing_context.active_document()->last_child_of_type<DOM::Element>();
if (element && element->is_focusable()) {
m_browsing_context.active_document()->set_focused_element(element);
return true;
}
}
for (element = element->previous_element_in_pre_order(); element && !element->is_focusable(); element = element->previous_element_in_pre_order())
;
m_browsing_context.active_document()->set_focused_element(element);
return element;
}
constexpr bool should_ignore_keydown_event(u32 code_point)