Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 2a93792734affd5f05cf3ac27009fcac80a3934d
https://github.com/WebKit/WebKit/commit/2a93792734affd5f05cf3ac27009fcac80a3934d
Author: Ahmad Saleem <[email protected]>
Date: 2026-04-17 (Fri, 17 Apr 2026)
Changed paths:
M
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-focusing-different-site-iframe-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-focusing-same-site-iframe-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-immediately-focusing-different-site-iframe-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-immediately-focusing-same-site-iframe-expected.txt
R
LayoutTests/platform/glib/imported/w3c/web-platform-tests/focus/activeelement-after-focusing-different-site-iframe-expected.txt
M Source/WebCore/page/FocusController.cpp
Log Message:
-----------
Element.blur() on iframe should reset document.activeElement to body
https://bugs.webkit.org/show_bug.cgi?id=312086
rdar://174591529
Reviewed by Ryosuke Niwa.
This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.
When calling blur() on a focused iframe element, document.activeElement
should revert to the document body. Instead, it incorrectly remained as
the iframe element.
The bug was in FocusController::setFocusedElement(). When called with
nullptr to clear focus, it used focusedLocalFrame() to find the "old"
document. But after iframe.focus(), the focused frame is the iframe's
content frame, not the parent frame containing the iframe element. This
caused two problems:
1. An early return when both old and new focused elements were nullptr
(the content frame's document had no focused element either), so
nothing was cleared at all.
2. Even past the early return, the wrong document (inner, not parent)
would have its focused element cleared.
The fix ensures that when clearing focus, we always clear the focused
element in the old (focused frame's) document, and additionally clear
it in the new focused frame's document when it differs. This handles
the iframe blur case — where the new focused frame (parent) differs
from the old focused frame (iframe's content frame) — while still
correctly clearing focus for elements like PDF annotation dropdowns
in the inner document.
*
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-focusing-different-site-iframe-expected.txt:
Progression
*
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-focusing-same-site-iframe-expected.txt:
Ditto
*
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-immediately-focusing-different-site-iframe-expected.txt:
Ditto
*
LayoutTests/imported/w3c/web-platform-tests/focus/activeelement-after-immediately-focusing-same-site-iframe-expected.txt:
Ditto
*
LayoutTests/platform/glib/imported/w3c/web-platform-tests/focus/activeelement-after-focusing-different-site-iframe-expected.txt:
Removed.
* Source/WebCore/page/FocusController.cpp:
(WebCore::FocusController::setFocusedElement):
Canonical link: https://commits.webkit.org/311452@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications