Bug 1926198: Use GetAccessibleOrContainer in nsAccessibilityService::NotifyOfAnchorJumpTo. r=morgan

The target might be an element for which we don't create an Accessible; e.g. a <b> element.
Previously, we wouldn't fire an event in NotifyOfAnchorJumpTo and would instead defer the event until the next document focus.
However, the document might already have focus, in which case we won't fire this event when the user expects it (if ever).
Instead, use GetAccessibleOrContainer, which is also consistent with the deferred anchor jump code in FocusManager.
This means we will fire the event on the correct container Accessible immediately.

Differential Revision: https://phabricator.services.mozilla.com/D226437
This commit is contained in:
James Teh 2024-10-29 01:54:00 +00:00
parent 5b88f50ed1
commit ff7475fdea
2 changed files with 7 additions and 3 deletions

View File

@ -568,8 +568,12 @@ void nsAccessibilityService::NotifyOfAnchorJumpTo(nsIContent* aTargetNode) {
const Accessible* focusedAcc = FocusedAccessible();
if (focusedAcc &&
(focusedAcc == document || focusedAcc->IsNonInteractive())) {
LocalAccessible* targetAcc = document->GetAccessible(aTargetNode);
if (targetAcc) {
LocalAccessible* targetAcc =
document->GetAccessibleOrContainer(aTargetNode);
// If targetAcc is the document, this isn't useful. It's possible we just
// haven't built the initial tree yet. Regardless, we don't want to fire an
// event for the document here.
if (targetAcc && !targetAcc->IsDoc()) {
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SCROLLING_START,
targetAcc);
document->SetAnchorJump(nullptr);

View File

@ -12,7 +12,7 @@ const boldAttrs = { "font-weight": "700" };
const fragmentAttrs = { mark: "true" };
const snippet = `
<p id="first">The first phrase.</p>
<p id="second">The second <b>phrase.</b></p>
<p id="second">The <i>second <b>phrase.</b></i></p>
`;
/**