LibWeb: Focus the document element when unfocusing an element
Otherwise, the currently focused element remains focused.
This commit is contained in:
parent
3c0c300039
commit
48240a6fc3
Notes:
sideshowbarker
2024-07-17 05:18:58 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/48240a6fc3 Pull-request: https://github.com/SerenityOS/serenity/pull/22150 Reviewed-by: https://github.com/awesomekling ✅
3 changed files with 23 additions and 1 deletions
2
Tests/LibWeb/Text/expected/input-blur.txt
Normal file
2
Tests/LibWeb/Text/expected/input-blur.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
focus
|
||||
blur
|
18
Tests/LibWeb/Text/input/input-blur.html
Normal file
18
Tests/LibWeb/Text/input/input-blur.html
Normal 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>
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue