Commit 68f7b94b authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

Use the precomputed IndexInParent if available.

JAWS calls IndexInParent on nodes in the accessibility
tree frequently. Try to use the efficient version rather
than recomputing it.

Bug: 1008558

Change-Id: Ieadfe193b0b294eb1bdb2efbcfd118ff5e1fecc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1828066Reviewed-by: default avatarAaron Leventhal <aleventhal@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706260}
parent 05f9838f
...@@ -1811,7 +1811,23 @@ gint GetIndexInParent(AtkObject* atk_object) { ...@@ -1811,7 +1811,23 @@ gint GetIndexInParent(AtkObject* atk_object) {
if (!parent) if (!parent)
return -1; return -1;
AXPlatformNodeAuraLinux* obj = AtkObjectToAXPlatformNodeAuraLinux(atk_object);
if (!obj)
return -1;
int n_children = atk_object_get_n_accessible_children(parent); int n_children = atk_object_get_n_accessible_children(parent);
// Ask the delegate for the index in parent, and return it if it's plausible.
//
// Delegates are allowed to not implement this (AXPlatformNodeDelegateBase
// returns -1). Also, delegates may not know the correct answer if this
// node is the root of a tree that's embedded in another tree, in which
// case the delegate should return -1 and we'll compute it.
int index_in_parent = obj->GetDelegate()->GetIndexInParent();
if (index_in_parent >= 0 && index_in_parent < n_children)
return index_in_parent;
// Otherwise, search the parent's children.
for (int i = 0; i < n_children; i++) { for (int i = 0; i < n_children; i++) {
AtkObject* child = atk_object_ref_accessible_child(parent, i); AtkObject* child = atk_object_ref_accessible_child(parent, i);
g_object_unref(child); g_object_unref(child);
......
...@@ -636,6 +636,18 @@ int AXPlatformNodeWin::GetIndexInParent() { ...@@ -636,6 +636,18 @@ int AXPlatformNodeWin::GetIndexInParent() {
LONG child_count = 0; LONG child_count = 0;
if (S_OK != parent_accessible->get_accChildCount(&child_count)) if (S_OK != parent_accessible->get_accChildCount(&child_count))
return -1; return -1;
// Ask the delegate for the index in parent, and return it if it's plausible.
//
// Delegates are allowed to not implement this (AXPlatformNodeDelegateBase
// returns -1). Also, delegates may not know the correct answer if this
// node is the root of a tree that's embedded in another tree, in which
// case the delegate should return -1 and we'll compute it.
int index_in_parent = GetDelegate()->GetIndexInParent();
if (index_in_parent >= 0 && index_in_parent < child_count)
return index_in_parent;
// Otherwise, search the parent's children.
for (LONG index = 1; index <= child_count; ++index) { for (LONG index = 1; index <= child_count; ++index) {
base::win::ScopedVariant childid_index(index); base::win::ScopedVariant childid_index(index);
Microsoft::WRL::ComPtr<IDispatch> child_dispatch; Microsoft::WRL::ComPtr<IDispatch> child_dispatch;
......
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