Search below providers that end hit testing early

Mouse review and touch exploration ask AT-SPI for the object at a point.
Some providers stop at a container: Chromium at tables, so cells were never
reached, and GTK notebooks report a page tab as only its label, so a page
such as the Thunar file view was never reached either.

When the provider returns nothing deeper, ask the children directly for the
smallest one containing the point, then search up to three levels below,
bounded at 512 children per object and 1024 objects in all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ChaseandClaude Opus 5.5 authored and Storm Dragon committed 2026-11-24 19:09:45 -05:00
1 parent a34d7e70c8
commit 418b72329e
1 file changed
+92 -4
+92 -4
View File
@@ -99,6 +99,86 @@ func nativeAccessibleAtPoint(source *C.AtspiAccessible, x, y int) *C.AtspiAccess
return child
}
// maxPointChildren bounds the fallback scan of one object's children.
const maxPointChildren = 512
// nativeChildContainingPoint finds the smallest child containing the point by
// asking each child. Some providers, Chromium tables among them, stop their
// own hit test at a container, so the child under the point is never reached.
func nativeChildContainingPoint(ctx context.Context, source *C.AtspiAccessible, x, y int) *C.AtspiAccessible {
count := min(int(C.atspi_accessible_get_child_count(source, nil)), maxPointChildren)
sourceID := nativeObjectID(source)
var best *C.AtspiAccessible
bestArea := int64(1 << 62)
for i := 0; i < count && ctx.Err() == nil; i++ {
child := C.atspi_accessible_get_child_at_index(source, C.gint(i), nil)
if child == nil {
continue
}
if nativeObjectID(child) != sourceID && nativeContainsPoint(child, x, y) {
if area := nativePointArea(child); best == nil || area < bestArea {
if best != nil {
C.g_object_unref(C.gpointer(best))
}
best, bestArea = child, area
continue
}
}
C.g_object_unref(C.gpointer(child))
}
return best
}
// maxPointSearchDepth and maxPointSearchNodes bound the descendant search.
const (
maxPointSearchDepth = 3
maxPointSearchNodes = 1024
)
// nativeDescendantContainingPoint searches a few levels below source for the
// smallest object containing the point. GTK notebooks report a page tab's
// extents as only its label, so the page under the finger is a grandchild of
// the tab list that no direct child contains.
func nativeDescendantContainingPoint(ctx context.Context, source *C.AtspiAccessible, x, y int) *C.AtspiAccessible {
type entry struct {
node *C.AtspiAccessible
depth int
}
sourceID := nativeObjectID(source)
queue := []entry{{(*C.AtspiAccessible)(C.g_object_ref(C.gpointer(source))), 0}}
visited := 0
var best *C.AtspiAccessible
bestArea := int64(1 << 62)
for len(queue) > 0 && visited < maxPointSearchNodes && ctx.Err() == nil {
current := queue[0]
queue = queue[1:]
if current.depth < maxPointSearchDepth {
count := min(int(C.atspi_accessible_get_child_count(current.node, nil)), maxPointChildren)
for i := 0; i < count && visited < maxPointSearchNodes && ctx.Err() == nil; i++ {
child := C.atspi_accessible_get_child_at_index(current.node, C.gint(i), nil)
if child == nil {
continue
}
visited++
if nativeObjectID(child) != sourceID && nativeContainsPoint(child, x, y) {
if area := nativePointArea(child); best == nil || area < bestArea {
if best != nil {
C.g_object_unref(C.gpointer(best))
}
best, bestArea = (*C.AtspiAccessible)(C.g_object_ref(C.gpointer(child))), area
}
}
queue = append(queue, entry{child, current.depth + 1})
}
}
C.g_object_unref(C.gpointer(current.node))
}
for _, rest := range queue {
C.g_object_unref(C.gpointer(rest.node))
}
return best
}
func nativePointText(ctx context.Context, source, window *C.AtspiAccessible, x, y int) (word, line string, lineStart, nativeOffset int) {
if C.atspi_accessible_get_role(source, nil) == C.ATSPI_ROLE_PASSWORD_TEXT {
return "", "", -1, -1
@@ -216,11 +296,19 @@ func (adapter *Adapter) nativeReviewAtPoint(ctx context.Context, x, y, pid int)
defer func() { C.g_object_unref(C.gpointer(current)) }()
for depth := 0; depth < 24 && ctx.Err() == nil; depth++ {
child := nativeAccessibleAtPoint(current, x, y)
if child == nil {
break
}
if nativeObjectID(child) == nativeObjectID(current) || !nativeContainsPoint(child, x, y) {
if child != nil && (nativeObjectID(child) == nativeObjectID(current) || !nativeContainsPoint(child, x, y)) {
C.g_object_unref(C.gpointer(child))
child = nil
}
if child == nil {
// The provider's hit test ended here. Ask the children directly
// before settling on a container such as a table or list.
child = nativeChildContainingPoint(ctx, current, x, y)
}
if child == nil {
child = nativeDescendantContainingPoint(ctx, current, x, y)
}
if child == nil {
break
}
C.g_object_unref(C.gpointer(current))