forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update delegatesFocus to match recent spec changes
https://bugs.webkit.org/show_bug.cgi?id=232564 Reviewed by Darin Adler. Implemented the new behavior of focusDelegates and added the support for autofocus focus delegation. Also fixed a bug that an element with autofocus content attribute inside a shadow tree gets focus. See whatwg/html#7079 * LayoutTests/fast/shadow-dom/autofocus-in-shadow-tree-autofocus-host-expected.txt: Added. * LayoutTests/fast/shadow-dom/autofocus-in-shadow-tree-autofocus-host.html: Added. * LayoutTests/fast/shadow-dom/autofocus-in-shadow-tree-expected.txt: Added. * LayoutTests/fast/shadow-dom/autofocus-in-shadow-tree.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/selectors/focus-visible-020.html: Merge the test fix posted in web-platform-tests/wpt#35257. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/focus/focus-autofocus-expected.txt: Rebaselined. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/focus/focus-method-delegatesFocus-expected.txt: Ditto. * Source/WebCore/dom/Element.cpp: (WebCore::shouldAutofocus): Fixed the bug that this wasn't ignoring elements inside shadow trees. Autofocus attribute yields autofocus candidates if the relevant element is **inserted** into a document, not connected to it. See https://html.spec.whatwg.org/multipage/interaction.html#the-autofocus-attribute (WebCore::autoFocusDelegate): Added. This implements autofocus delegation mechanism for shadow root/host. (WebCore::focusDelegateFromShadowHost): Renamed from findFirstProgramaticallyFocusableElementInComposedTree and made it recursively traverse shadow trees instead of the composed/flat tree. (WebCore::Element::focus): Canonical link: https://commits.webkit.org/252901@main
- Loading branch information
Showing
8 changed files
with
82 additions
and
18 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
LayoutTests/fast/shadow-dom/autofocus-in-shadow-tree-autofocus-host-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
PASS an element with autofocus content attribute in a shadow tree whereby shadow host also has autofocus should automatically get focus | ||
|
20 changes: 20 additions & 0 deletions
20
LayoutTests/fast/shadow-dom/autofocus-in-shadow-tree-autofocus-host.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<div id="host" tabindex="0" autofocus></div> | ||
<script> | ||
|
||
const shadowRoot = host.attachShadow({mode: 'closed', delegatesFocus: true}); | ||
shadowRoot.innerHTML = `<input type="text" id="target"><input type="text" id="target" autofocus>`; | ||
|
||
promise_test(async () => { | ||
await new Promise((resolve) => { requestAnimationFrame(() => setTimeout(resolve, 0)); }); | ||
assert_equals(document.activeElement, host); | ||
assert_equals(shadowRoot.activeElement, shadowRoot.lastChild); | ||
}, 'an element with autofocus content attribute in a shadow tree whereby shadow host also has autofocus should automatically get focus'); | ||
|
||
</script> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
LayoutTests/fast/shadow-dom/autofocus-in-shadow-tree-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
PASS an element with autofocus content attribute in a shadow tree should not automatically get focus | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<div id="host" tabindex="0"></div> | ||
<script> | ||
|
||
const shadowRoot = host.attachShadow({mode: 'closed', delegatesFocus: true}); | ||
shadowRoot.innerHTML = `<input type="text" id="target" autofocus>`; | ||
|
||
promise_test(async () => { | ||
await new Promise(requestAnimationFrame); | ||
assert_equals(document.activeElement, document.body); | ||
assert_equals(shadowRoot.activeElement, null); | ||
}, 'an element with autofocus content attribute in a shadow tree should not automatically get focus'); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 5 additions & 8 deletions
13
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/focus/focus-autofocus-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
|
||
FAIL The second input should be focused since it has autofocus assert_equals: expected Element node <div tabindex="0" autofocus="true"></div> but got Element node <div tabindex="0"></div> | ||
FAIL Focus should not be delegated to the autofocus element because the inner host doesn't have delegates focus assert_equals: expected Element node <body> | ||
<script> | ||
function createShadowDOMTree() { | ||
... but got Element node <div id="host"></div> | ||
FAIL Focus should be delegated to the autofocus element when the inner host has delegates focus assert_equals: expected Element node <div tabindex="0" autofocus="true"></div> but got Element node <div tabindex="0"></div> | ||
FAIL Focus should not be delegated to the slotted elements assert_equals: expected Element node <div id="host"><div tabindex="0" autofocus="true"></div><... but got Element node <div tabindex="0" autofocus="true"></div> | ||
FAIL Focus should be delegated to the nested div which has autofocus based on the tree order assert_equals: expected Element node <div tabindex="0" autofocus="true"></div> but got Element node <div tabindex="0"><div tabindex="0"><div tabindex="0" aut... | ||
PASS The second input should be focused since it has autofocus | ||
PASS Focus should not be delegated to the autofocus element because the inner host doesn't have delegates focus | ||
PASS Focus should be delegated to the autofocus element when the inner host has delegates focus | ||
PASS Focus should not be delegated to the slotted elements | ||
PASS Focus should be delegated to the nested div which has autofocus based on the tree order | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters