diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 6ce8fabf2c6b..c79518df1fee 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -1102,28 +1102,31 @@ bool EventStateManager::LookForAccessKeyAndExecute( shouldActivate = false; } - while (shouldActivate && ++count <= length) { - Element* el = mAccessKeys[(start + count) % length]; + // XXXedgar, Bug 1700646, maybe we could use other data structure to + // make searching target with same accesskey easier, and current setup + // could not ensure we cycle the target with tree order. + int32_t j = 0; + while (shouldActivate && ++j < length) { + Element* el = mAccessKeys[(start + count + j) % length]; if (IsAccessKeyTarget(el, accessKey)) { shouldActivate = false; } } - bool focusChanged = - element->PerformAccesskey(shouldActivate, aIsTrustedEvent); - if (focusChanged && aIsTrustedEvent) { - // If this is a child process, inform the parent that we want the - // focus, but pass false since we don't want to change the window - // order. - nsIDocShell* docShell = mPresContext->GetDocShell(); - nsCOMPtr child = - docShell ? docShell->GetBrowserChild() : nullptr; - if (child) { - child->SendRequestFocus(false, CallerType::System); + if (element->PerformAccesskey(shouldActivate, aIsTrustedEvent)) { + if (aIsTrustedEvent) { + // If this is a child process, inform the parent that we want the + // focus, but pass false since we don't want to change the window + // order. + nsIDocShell* docShell = mPresContext->GetDocShell(); + nsCOMPtr child = + docShell ? docShell->GetBrowserChild() : nullptr; + if (child) { + child->SendRequestFocus(false, CallerType::System); + } } + return true; } - - return true; } } } diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 529e10ff06dd..b5c926853fc3 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -2418,11 +2418,8 @@ bool nsGenericHTMLElement::PerformAccesskey(bool aKeyCausesActivation, fm->SetFocus(this, nsIFocusManager::FLAG_BYKEY); // Return true if the element became the current focus within its window. - // - // FIXME(emilio): Shouldn't this check `window->GetFocusedElement() == this` - // based on the above comment? nsPIDOMWindowOuter* window = OwnerDoc()->GetWindow(); - focused = window && window->GetFocusedElement(); + focused = window && window->GetFocusedElement() == this; } if (aKeyCausesActivation) { diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 62016a69c46f..b0390f13c23f 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -543,7 +543,7 @@ bool nsXULElement::PerformAccesskey(bool aKeyCausesActivation, // Return true if the element became focused. nsPIDOMWindowOuter* window = OwnerDoc()->GetWindow(); - focused = (window && window->GetFocusedElement()); + focused = (window && window->GetFocusedElement() == elementToFocus); } } } diff --git a/dom/xul/test/test_accesskey.xhtml b/dom/xul/test/test_accesskey.xhtml index 7307fb4f7b06..c71fcf78a06c 100644 --- a/dom/xul/test/test_accesskey.xhtml +++ b/dom/xul/test/test_accesskey.xhtml @@ -12,7 +12,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1699284 - + +