Commit f8f28226 authored by Martin Robinson's avatar Martin Robinson Committed by Commit Bot

atk_text_set_caret_offset should scroll to the target node

Orca expects that this API also scroll to the target node onto the
screen. Eventually Orca will be able to use the AtkComponent scrolling
API, but that isn't widely available yet, so we implement this fallback
behavior.

Bug: 950530
Change-Id: Id769d32849221591dfdb9ab6e96c07c8fb0e6b4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1576561
Commit-Queue: Martin Robinson <mrobinson@igalia.com>
Reviewed-by: default avatarJoanmarie Diggs <jdiggs@igalia.com>
Cr-Commit-Position: refs/heads/master@{#652898}
parent 3a8f8d2d
...@@ -568,6 +568,8 @@ IN_PROC_BROWSER_TEST_F(AccessibilityAuraLinuxBrowserTest, TestScrollTo) { ...@@ -568,6 +568,8 @@ IN_PROC_BROWSER_TEST_F(AccessibilityAuraLinuxBrowserTest, TestScrollTo) {
<div style="height: 5000px;"></div> <div style="height: 5000px;"></div>
<img src="" alt="Target2"> <img src="" alt="Target2">
<div style="height: 5000px;"></div> <div style="height: 5000px;"></div>
<span>Target 3</span>
<div style="height: 5000px;"></div>
</body> </body>
</html>)HTML"); </html>)HTML");
...@@ -581,10 +583,11 @@ IN_PROC_BROWSER_TEST_F(AccessibilityAuraLinuxBrowserTest, TestScrollTo) { ...@@ -581,10 +583,11 @@ IN_PROC_BROWSER_TEST_F(AccessibilityAuraLinuxBrowserTest, TestScrollTo) {
&doc_height, ATK_XY_SCREEN); &doc_height, ATK_XY_SCREEN);
// The document should only have two children, both with a role of GRAPHIC. // The document should only have two children, both with a role of GRAPHIC.
ASSERT_EQ(2, atk_object_get_n_accessible_children(document)); ASSERT_EQ(3, atk_object_get_n_accessible_children(document));
AtkObject* target = atk_object_ref_accessible_child(document, 0); AtkObject* target = atk_object_ref_accessible_child(document, 0);
AtkObject* target2 = atk_object_ref_accessible_child(document, 1); AtkObject* target2 = atk_object_ref_accessible_child(document, 1);
AtkObject* target3 = atk_object_ref_accessible_child(document, 2);
ASSERT_TRUE(ATK_IS_COMPONENT(target)); ASSERT_TRUE(ATK_IS_COMPONENT(target));
ASSERT_TRUE(ATK_IS_COMPONENT(target2)); ASSERT_TRUE(ATK_IS_COMPONENT(target2));
...@@ -624,8 +627,24 @@ IN_PROC_BROWSER_TEST_F(AccessibilityAuraLinuxBrowserTest, TestScrollTo) { ...@@ -624,8 +627,24 @@ IN_PROC_BROWSER_TEST_F(AccessibilityAuraLinuxBrowserTest, TestScrollTo) {
EXPECT_GT(y + height / 2, doc_y + 0.4 * doc_height); EXPECT_GT(y + height / 2, doc_y + 0.4 * doc_height);
EXPECT_LT(y + height / 2, doc_y + 0.6 * doc_height); EXPECT_LT(y + height / 2, doc_y + 0.6 * doc_height);
// Orca expects atk_text_set_caret_offset to operate like scroll to the
// target node like atk_component_scroll_to, so we test that here.
ASSERT_TRUE(ATK_IS_TEXT(target3));
AccessibilityNotificationWaiter waiter3(
shell()->web_contents(), ui::kAXModeComplete,
ax::mojom::Event::kScrollPositionChanged);
atk_text_set_caret_offset(ATK_TEXT(target3), 0);
waiter3.WaitForNotification();
// Same as above, make sure it's roughly centered.
atk_component_get_extents(ATK_COMPONENT(target3), &x, &y, &width, &height,
ATK_XY_SCREEN);
EXPECT_GT(y + height / 2, doc_y + 0.4 * doc_height);
EXPECT_LT(y + height / 2, doc_y + 0.6 * doc_height);
g_object_unref(target); g_object_unref(target);
g_object_unref(target2); g_object_unref(target2);
g_object_unref(target3);
} }
#endif // defined(ATK_230) #endif // defined(ATK_230)
......
...@@ -1120,7 +1120,13 @@ gboolean SetCaretOffset(AtkText* atk_text, gint offset) { ...@@ -1120,7 +1120,13 @@ gboolean SetCaretOffset(AtkText* atk_text, gint offset) {
AtkObjectToAXPlatformNodeAuraLinux(ATK_OBJECT(atk_text)); AtkObjectToAXPlatformNodeAuraLinux(ATK_OBJECT(atk_text));
if (!obj) if (!obj)
return FALSE; return FALSE;
return obj->SetCaretOffset(offset); if (!obj->SetCaretOffset(offset))
return FALSE;
// Orca expects atk_text_set_caret_offset to scroll to the target element.
obj->ScrollToNode(AXPlatformNodeBase::ScrollType::Anywhere);
return TRUE;
} }
int GetNSelections(AtkText* atk_text) { int GetNSelections(AtkText* atk_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