Commit 7fa9f412 authored by Nick Burris's avatar Nick Burris Committed by Commit Bot

Add accessibility call to scroll to text

Screen readers read from the top of the page on a scroll to text
navigation, instead of the targeted text. This patch adds an AX call
that is made when navigating to an anchor, as is done with element
fragment anchors.

Confirmed this works with TalkBack on Android.

Bug: 1044644
Change-Id: If5c905b083189efd7276f64abc4a547f81f6b054
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015132Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Nick Burris <nburris@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734668}
parent c50704ec
......@@ -1135,5 +1135,31 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
}
}
IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
TextFragmentAnchor) {
EXPECT_TRUE(NavigateToURL(shell(), GURL(url::kAboutBlankURL)));
AccessibilityNotificationWaiter anchor_waiter(
shell()->web_contents(), ui::kAXModeComplete,
ax::mojom::Event::kScrolledToAnchor);
GURL url(
"data:text/html,"
"<p>Some text</p>"
"<p id='target' style='position: absolute; top: 1000px'>Anchor text</p>"
"#:~:text=Anchor%20text");
EXPECT_TRUE(NavigateToURL(shell(), url));
anchor_waiter.WaitForNotification();
WaitForAccessibilityTreeToContainNodeWithName(shell()->web_contents(),
"Anchor text");
const BrowserAccessibility* root = GetManager()->GetRoot();
ASSERT_EQ(2u, root->PlatformChildCount());
const BrowserAccessibility* target = root->PlatformGetChild(1);
ASSERT_EQ(1u, target->PlatformChildCount());
const BrowserAccessibility* text = target->PlatformGetChild(0);
EXPECT_EQ(text->GetId(), anchor_waiter.event_target_id());
}
#endif
} // namespace content
......@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/page/scrolling/text_fragment_anchor.h"
#include "third_party/blink/public/platform/web_scroll_into_view_params.h"
#include "third_party/blink/renderer/core/accessibility/ax_object_cache.h"
#include "third_party/blink/renderer/core/display_lock/display_lock_utilities.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
......@@ -258,6 +259,10 @@ void TextFragmentAnchor::DidFindMatch(const EphemeralRangeInFlatTree& range) {
ScrollAlignment::kAlignCenterAlways,
kProgrammaticScroll));
did_scroll_into_view_ = true;
if (AXObjectCache* cache = frame_->GetDocument()->ExistingAXObjectCache())
cache->HandleScrolledToAnchor(&node);
metrics_->DidScroll();
// We scrolled the text into view if the main document scrolled or the text
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment