diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp
index 8260b9ded304..714fbf42f707 100644
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -4486,7 +4486,7 @@ void Element::RegUnRegAccessKey(bool aDoReg) {
}
// We have an access key, so get the ESM from the pres context.
- if (nsPresContext* presContext = GetPresContext(eForUncomposedDoc)) {
+ if (nsPresContext* presContext = GetPresContext(eForComposedDoc)) {
EventStateManager* esm = presContext->EventStateManager();
// Register or unregister as appropriate.
diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp
index 67689bc856a8..6e023d7f167c 100644
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -438,8 +438,11 @@ nsresult nsGenericHTMLElement::BindToTree(BindContext& aContext,
nsresult rv = nsGenericHTMLElementBase::BindToTree(aContext, aParent);
NS_ENSURE_SUCCESS(rv, rv);
- if (IsInUncomposedDoc()) {
+ if (IsInComposedDoc()) {
RegUnRegAccessKey(true);
+ }
+
+ if (IsInUncomposedDoc()) {
if (HasName() && CanHaveName(NodeInfo()->NameAtom())) {
aContext.OwnerDoc().AddToNameTable(
this, GetParsedAttr(nsGkAtoms::name)->GetAtomValue());
@@ -477,7 +480,7 @@ nsresult nsGenericHTMLElement::BindToTree(BindContext& aContext,
}
void nsGenericHTMLElement::UnbindFromTree(bool aNullParent) {
- if (IsInUncomposedDoc()) {
+ if (IsInComposedDoc()) {
RegUnRegAccessKey(false);
}
@@ -2407,7 +2410,7 @@ bool nsGenericHTMLElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
bool nsGenericHTMLElement::PerformAccesskey(bool aKeyCausesActivation,
bool aIsTrustedEvent) {
- nsPresContext* presContext = GetPresContext(eForUncomposedDoc);
+ nsPresContext* presContext = GetPresContext(eForComposedDoc);
if (!presContext) {
return false;
}
diff --git a/dom/tests/mochitest/webcomponents/chrome.ini b/dom/tests/mochitest/webcomponents/chrome.ini
index ab0b6d09c215..05cb82bf9343 100644
--- a/dom/tests/mochitest/webcomponents/chrome.ini
+++ b/dom/tests/mochitest/webcomponents/chrome.ini
@@ -14,3 +14,4 @@ support-files =
test_upgrade_page.html
upgrade_tests.js
[test_xul_custom_element.xhtml]
+[test_xul_shadowdom_accesskey.xhtml]
diff --git a/dom/tests/mochitest/webcomponents/test_xul_shadowdom_accesskey.xhtml b/dom/tests/mochitest/webcomponents/test_xul_shadowdom_accesskey.xhtml
new file mode 100644
index 000000000000..79fb16727602
--- /dev/null
+++ b/dom/tests/mochitest/webcomponents/test_xul_shadowdom_accesskey.xhtml
@@ -0,0 +1,60 @@
+
+
+
+
+