script: Fully implement DocumentOrShadowRoot#activeElement (#43861)

`DocumentOrShadowRoot#activeElement` should return retargeted results.
What that means is that if the DOM anchor of the `Document`'s focused
focusable area is within a shadow root, `Document#activeElement` should
return the shadow host. This change implements that behavior, properly
returning the `activeElement` from both `Document` and `ShadowRoot`.

Testing: This causes a decent number of WPT tests and subtests to start
passing. One subtest starts to fail, because it uses the `autofocus`
attribute
which we do not yet support.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson
2026-04-02 13:12:30 +02:00
committed by GitHub
parent 9a43d43c32
commit 33f74feffd
27 changed files with 68 additions and 165 deletions

View File

@@ -95,7 +95,7 @@ impl Node {
.and_then(Element::shadow_root)
.is_some_and(|shadow_root| shadow_root.DelegatesFocus())
{
if let Some(focused_element) = self.owner_document().get_focused_element() {
if let Some(focused_element) = self.owner_document().focused_element() {
// > Step 2. If focus target is a shadow-including inclusive ancestor of
// > focusedElement, then return focusedElement.
if self