diff --git a/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs b/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs index a71e42f894..7534d8c83d 100644 --- a/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs +++ b/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs @@ -8,13 +8,42 @@ using Avalonia.Android.Automation; using Avalonia.Automation; using Avalonia.Automation.Peers; using Avalonia.Automation.Provider; -using Avalonia.Controls; using Java.Lang; namespace Avalonia.Android { internal class AvaloniaAccessHelper : ExploreByTouchHelper { + private static readonly HashSet s_containerTypes = + new HashSet() + { + AutomationControlType.Calendar, + AutomationControlType.ComboBoxItem, + AutomationControlType.Custom, + AutomationControlType.DataGrid, + AutomationControlType.DataItem, + AutomationControlType.Document, + AutomationControlType.Expander, + AutomationControlType.Group, + AutomationControlType.List, + AutomationControlType.ListItem, + AutomationControlType.Menu, + AutomationControlType.MenuBar, + AutomationControlType.MenuItem, + AutomationControlType.None, + AutomationControlType.Pane, + AutomationControlType.ScrollViewer, + AutomationControlType.SplitButton, + AutomationControlType.Tab, + AutomationControlType.TabItem, + AutomationControlType.Table, + AutomationControlType.TitleBar, + AutomationControlType.ToolBar, + AutomationControlType.Tree, + AutomationControlType.TreeItem, + AutomationControlType.Window, + }; + private readonly Dictionary _peers; private readonly Dictionary _peerIds; @@ -109,7 +138,17 @@ namespace Avalonia.Android AutomationPeer? peer = embeddedRootProvider?.GetPeerFromPoint(p); if (peer is not null) { - GetOrCreateNodeInfoProvidersFromPeer(peer, out int virtualViewId); + int virtualViewId; + if (peer.GetParent() is AutomationPeer parent && + !s_containerTypes.Contains(parent.GetAutomationControlType())) + { + GetOrCreateNodeInfoProvidersFromPeer(parent, out virtualViewId); + } + else + { + GetOrCreateNodeInfoProvidersFromPeer(peer, out virtualViewId); + } + return virtualViewId == 0 ? InvalidId : virtualViewId; } else @@ -199,7 +238,7 @@ namespace Avalonia.Android nodeInfo.Enabled = peer.IsEnabled(); // Control focus state - bool canFocusAtAll = peer.IsContentElement() && !peer.IsOffscreen(); + bool canFocusAtAll = peer.IsControlElement() && !peer.IsOffscreen(); nodeInfo.ScreenReaderFocusable = canFocusAtAll; nodeInfo.Focusable = canFocusAtAll && peer.IsKeyboardFocusable(); diff --git a/src/Avalonia.Controls/Automation/Peers/EmbeddableControlRootAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/EmbeddableControlRootAutomationPeer.cs index f15b18b7d3..1df6edf564 100644 --- a/src/Avalonia.Controls/Automation/Peers/EmbeddableControlRootAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/EmbeddableControlRootAutomationPeer.cs @@ -33,7 +33,7 @@ namespace Avalonia.Controls.Automation.Peers public AutomationPeer? GetPeerFromPoint(Point p) { - var hit = Owner.GetVisualAt(p)?.FindAncestorOfType(); + var hit = Owner.GetVisualAt(p)?.FindAncestorOfType(includeSelf: true); if (hit is null) return null;