Bug 1703171: Support a11y exposure of accessKey for elements in shadow DOM. r=morgan

Previously, when determining the modifier, the code used the uncomposed document, which will be null for an element inside shadow DOM.

Differential Revision: https://phabricator.services.mozilla.com/D111033
This commit is contained in:
James Teh 2021-04-08 22:58:34 +00:00
parent 950a63fea5
commit cc19c08fbf
2 changed files with 18 additions and 1 deletions

View File

@ -250,7 +250,7 @@ KeyBinding LocalAccessible::AccessKey() const {
}
// Determine the access modifier used in this context.
dom::Document* document = mContent->GetUncomposedDoc();
dom::Document* document = mContent->GetComposedDoc();
if (!document) return KeyBinding();
nsCOMPtr<nsIDocShellTreeItem> treeItem(document->GetDocShell());

View File

@ -59,6 +59,12 @@
is(input.accessKey, (MAC ? "⌃⌥i" : "Alt+Shift+i"),
"Wrong accessKey on input");
// Test accessKey on HTML element inside shadow DOM.
let shadowButton = getAccessible(
document.getElementById("buttonShadow").shadowRoot.firstElementChild);
is(shadowButton.accessKey, (MAC ? "⌃⌥t" : "Alt+Shift+t"),
"Wrong accessKey on shadow button");
gQueue = new eventQueue();
gQueue.push(new openMenu("menu", "menuitem"));
gQueue.invoke(); // Will call SimpleTest.finish();
@ -87,6 +93,17 @@
<label control="input" accesskey="i">input</label>
<html:input id="input"/>
<html:div id="buttonShadow"/>
<script>
<![CDATA[
let host = document.getElementById("buttonShadow");
let shadow = host.attachShadow({mode: "open"});
let button = document.createElement("button");
button.setAttribute("accesskey", "t");
shadow.append(button);
]]>
</script>
<keyset>
<key key="l" modifiers="control" id="key1"/>
</keyset>