mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:07:44 +00:00
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
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.
|
// FIXME: This isn't entirely right.
|
||||||
if (is<DOM::Element>(*entry))
|
if (is<DOM::Element>(*entry))
|
||||||
entry->document().set_focused_element(&static_cast<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;
|
JS::GCPtr<DOM::EventTarget> focus_event_target;
|
||||||
if (is<DOM::Element>(*entry)) {
|
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.
|
// 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) {
|
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 {
|
} else {
|
||||||
// FIXME: Otherwise, apply any relevant platform-specific conventions for removing system focus from
|
// 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
|
// topDocument's browsing context, and run the focus update steps with old chain, an empty list, and null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue