Commit 0ab7bd09 authored by Nektarios Paisios's avatar Nektarios Paisios Committed by Commit Bot

Introduces a workaround for handling ignored children when computing IA2 hypertext offsets

Accessibility selection returns tree positions that are adjusted taking into account ignored children.
However, some ignored children are now included in the accessibility tree, and ax selection doesn't account for those.
This is just a workaround to avoid crashes and unblock users from using GSuite
until a re-write of the selection calculations in IA2 hypertext is undertaken using AXPosition.
R=aleventhal@chromium.org

Change-Id: I94287b344d0f8a6a0459ca0f769b9921a332d033
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715752Reviewed-by: default avatarAaron Leventhal <aleventhal@chromium.org>
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680570}
parent a98c4e43
......@@ -1129,7 +1129,7 @@ void AXPlatformNodeBase::UpdateComputedHypertext() {
return;
}
int child_count = delegate_->GetChildCount();
int child_count = GetChildCount();
if (!child_count) {
if (IsRichTextField()) {
......@@ -1148,7 +1148,7 @@ void AXPlatformNodeBase::UpdateComputedHypertext() {
// child object it points to.
base::string16 hypertext;
for (int i = 0; i < child_count; ++i) {
const auto* child = FromNativeViewAccessible(delegate_->ChildAtIndex(i));
const auto* child = FromNativeViewAccessible(ChildAtIndex(i));
DCHECK(child);
// Similar to Firefox, we don't expose text-only objects in IA2 hypertext.
......@@ -1289,11 +1289,10 @@ int32_t AXPlatformNodeBase::GetHypertextOffsetFromChild(
int32_t hypertext_offset = 0;
int32_t index_in_parent = child->GetDelegate()->GetIndexInParent();
DCHECK_GE(index_in_parent, 0);
DCHECK_LT(index_in_parent,
static_cast<int32_t>(GetDelegate()->GetChildCount()));
DCHECK_LT(index_in_parent, static_cast<int32_t>(GetChildCount()));
for (uint32_t i = 0; i < static_cast<uint32_t>(index_in_parent); ++i) {
auto* sibling = static_cast<AXPlatformNodeBase*>(
FromNativeViewAccessible(GetDelegate()->ChildAtIndex(i)));
FromNativeViewAccessible(ChildAtIndex(i)));
DCHECK(sibling);
if (sibling->IsTextOnlyObject()) {
hypertext_offset += (int32_t)sibling->GetHypertext().size();
......@@ -1357,11 +1356,11 @@ int AXPlatformNodeBase::GetHypertextOffsetFromEndpoint(
// Adjust the |endpoint_offset| because the selection endpoint is a tree
// position, i.e. it represents a child index and not a text offset.
if (endpoint_offset == endpoint_object->GetDelegate()->GetChildCount()) {
if (endpoint_offset >= endpoint_object->GetChildCount()) {
return static_cast<int>(endpoint_object->GetHypertext().size());
} else {
auto* child = static_cast<AXPlatformNodeBase*>(FromNativeViewAccessible(
endpoint_object->GetDelegate()->ChildAtIndex(endpoint_offset)));
endpoint_object->ChildAtIndex(endpoint_offset)));
DCHECK(child);
return endpoint_object->GetHypertextOffsetFromChild(child);
}
......
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