Browse Source

Create root automation nodes like others.

ui-automation-test
Steven Kirk 5 years ago
parent
commit
8ffbbfb7fb
  1. 16
      src/Windows/Avalonia.Win32/Automation/AutomationNode.cs
  2. 14
      src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs
  3. 1
      src/Windows/Avalonia.Win32/WindowImpl.cs

16
src/Windows/Avalonia.Win32/Automation/AutomationNode.cs

@ -160,11 +160,6 @@ namespace Avalonia.Win32.Automation
return null; return null;
} }
if (Peer.GetType().Name == "PopupAutomationPeer")
{
System.Diagnostics.Debug.WriteLine("Popup automation node navigate " + direction);
}
return InvokeSync(() => return InvokeSync(() =>
{ {
return direction switch return direction switch
@ -183,11 +178,11 @@ namespace Avalonia.Win32.Automation
public static AutomationNode? GetOrCreate(AutomationPeer? peer) public static AutomationNode? GetOrCreate(AutomationPeer? peer)
{ {
if (peer is null) return peer is null ? null : s_nodes.GetValue(peer, Create);
return null;
return s_nodes.GetValue(peer, x => new AutomationNode(x));
} }
public static void Release(AutomationPeer peer) => s_nodes.Remove(peer);
IRawElementProviderSimple[]? IRawElementProviderFragment.GetEmbeddedFragmentRoots() => null; IRawElementProviderSimple[]? IRawElementProviderFragment.GetEmbeddedFragmentRoots() => null;
void IRawElementProviderSimple2.ShowContextMenu() => InvokeSync(() => Peer.ShowContextMenu()); void IRawElementProviderSimple2.ShowContextMenu() => InvokeSync(() => Peer.ShowContextMenu());
void IInvokeProvider.Invoke() => InvokeSync((AAP.IInvokeProvider x) => x.Invoke()); void IInvokeProvider.Invoke() => InvokeSync((AAP.IInvokeProvider x) => x.Invoke());
@ -294,6 +289,11 @@ namespace Avalonia.Win32.Automation
return peer is object ? GetOrCreate(peer) : null; return peer is object ? GetOrCreate(peer) : null;
} }
private static AutomationNode Create(AutomationPeer peer)
{
return peer is AAP.IRootProvider ? new RootAutomationNode(peer) : new AutomationNode(peer);
}
private static UiaControlTypeId ToUiaControlType(AutomationControlType role) private static UiaControlTypeId ToUiaControlType(AutomationControlType role)
{ {
return role switch return role switch

14
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

@ -79,8 +79,7 @@ namespace Avalonia.Win32
case WindowsMessage.WM_DESTROY: case WindowsMessage.WM_DESTROY:
{ {
if (_automationNode is object) UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, IntPtr.Zero, IntPtr.Zero, null);
UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, IntPtr.Zero, IntPtr.Zero, null);
//Window doesn't exist anymore //Window doesn't exist anymore
_hwnd = IntPtr.Zero; _hwnd = IntPtr.Zero;
@ -484,14 +483,9 @@ namespace Avalonia.Win32
case WindowsMessage.WM_GETOBJECT: case WindowsMessage.WM_GETOBJECT:
if ((long)lParam == UiaRootObjectId) if ((long)lParam == UiaRootObjectId)
{ {
if (_automationNode is null) var peer = ControlAutomationPeer.CreatePeerForElement((Control)_owner);
{ var node = AutomationNode.GetOrCreate(peer);
var peer = ControlAutomationPeer.CreatePeerForElement((Control)_owner); return UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, wParam, lParam, node);
_automationNode = new RootAutomationNode(peer);
}
var r = UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, wParam, lParam, _automationNode);
return r;
} }
break; break;
} }

1
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -87,7 +87,6 @@ namespace Avalonia.Win32
private POINT _maxTrackSize; private POINT _maxTrackSize;
private WindowImpl _parent; private WindowImpl _parent;
private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default;
private AutomationNode _automationNode;
private bool _isCloseRequested; private bool _isCloseRequested;
private bool _shown; private bool _shown;
private bool _hiddenWindowIsParent; private bool _hiddenWindowIsParent;

Loading…
Cancel
Save