LibWeb: Focus the document element when unfocusing an element

Otherwise, the currently focused element remains focused.
This commit is contained in:
Timothy Flynn 2023-12-03 09:12:12 -05:00 committed by Andreas Kling
parent 3c0c300039
commit 48240a6fc3
Notes: sideshowbarker 2024-07-17 05:18:58 +09:00
3 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,2 @@
focus
blur

View file

@ -0,0 +1,18 @@
<input id=input type=text>
<script src="include.js"></script>
<script>
test(() => {
let input = document.getElementById("input");
input.addEventListener("focus", () => {
println("focus");
});
input.addEventListener("blur", () => {
println("blur");
});
input.focus();
input.blur();
})
</script>

View file

@ -91,6 +91,8 @@ static void run_focus_update_steps(Vector<JS::Handle<DOM::Node>> old_chain, Vect
// FIXME: This isn't entirely right.
if (is<DOM::Element>(*entry))
entry->document().set_focused_element(&static_cast<DOM::Element&>(*entry));
else if (is<DOM::Document>(*entry))
entry->document().set_focused_element(static_cast<DOM::Document&>(*entry).document_element());
JS::GCPtr<DOM::EventTarget> focus_event_target;
if (is<DOM::Element>(*entry)) {
@ -268,7 +270,7 @@ void run_unfocusing_steps(DOM::Node* old_focus_target)
// 8. If topDocument's node navigable has system focus, then run the focusing steps for topDocument's viewport.
if (top_document->navigable()->traversable_navigable()->system_visibility_state() == HTML::VisibilityState::Visible) {
// FIXME: run the focusing steps for topDocument's viewport (??)
run_focusing_steps(top_document);
} else {
// FIXME: Otherwise, apply any relevant platform-specific conventions for removing system focus from
// topDocument's browsing context, and run the focus update steps with old chain, an empty list, and null