Browse Source

fix Automation.HelpText on windows (#17030)

* fix Automation.HelpText on windows

* change breaking abstract to virtual

* only fall back to tooltip if string

* remove duplicate override

---------

Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
pull/17101/head
ahopper 2 years ago
committed by GitHub
parent
commit
85fff4a232
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      src/Avalonia.Controls/Automation/AutomationElementIdentifiers.cs
  2. 6
      src/Avalonia.Controls/Automation/Peers/AutomationPeer.cs
  3. 10
      src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
  4. 1
      src/Avalonia.Controls/Automation/Peers/InteropAutomationPeer.cs
  5. 1
      src/Avalonia.Controls/Automation/Peers/UnrealizedElementAutomationPeer.cs
  6. 2
      src/Windows/Avalonia.Win32/Automation/AutomationNode.cs

6
src/Avalonia.Controls/Automation/AutomationElementIdentifiers.cs

@ -24,5 +24,11 @@ namespace Avalonia.Automation
/// by the <see cref="AutomationPeer.GetName"/> method.
/// </summary>
public static AutomationProperty NameProperty { get; } = new AutomationProperty();
/// <summary>
/// Identifies the helpText automation property. The class name property value is returned
/// by the <see cref="AutomationPeer.GetHelpText"/> method.
/// </summary>
public static AutomationProperty HelpTextProperty { get; } = new AutomationProperty();
}
}

6
src/Avalonia.Controls/Automation/Peers/AutomationPeer.cs

@ -112,6 +112,11 @@ namespace Avalonia.Automation.Peers
/// Gets text that describes the element that is associated with this automation peer.
/// </summary>
public string GetName() => GetNameCore() ?? string.Empty;
/// <summary>
/// Gets text that provides help for the element that is associated with this automation peer.
/// </summary>
public string GetHelpText() => GetHelpTextCore() ?? string.Empty;
/// <summary>
/// Gets the <see cref="AutomationPeer"/> that is the parent of this <see cref="AutomationPeer"/>.
@ -250,6 +255,7 @@ namespace Avalonia.Automation.Peers
protected abstract string GetClassNameCore();
protected abstract AutomationPeer? GetLabeledByCore();
protected abstract string? GetNameCore();
protected virtual string? GetHelpTextCore() => null;
protected abstract AutomationPeer? GetParentCore();
protected abstract bool HasKeyboardFocusCore();
protected abstract bool IsContentElementCore();

10
src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs

@ -116,7 +116,17 @@ namespace Avalonia.Automation.Peers
return result;
}
protected override string? GetHelpTextCore()
{
var result = AutomationProperties.GetHelpText(Owner);
if (string.IsNullOrWhiteSpace(result))
{
result = ToolTip.GetTip(Owner) as string;
}
return result;
}
protected override AutomationPeer? GetParentCore()
{
EnsureConnected();

1
src/Avalonia.Controls/Automation/Peers/InteropAutomationPeer.cs

@ -28,6 +28,7 @@ internal class InteropAutomationPeer : AutomationPeer
protected override string GetClassNameCore() => throw new NotImplementedException();
protected override AutomationPeer? GetLabeledByCore() => throw new NotImplementedException();
protected override string? GetNameCore() => throw new NotImplementedException();
protected override string? GetHelpTextCore() => throw new NotImplementedException();
protected override IReadOnlyList<AutomationPeer> GetOrCreateChildrenCore() => throw new NotImplementedException();
protected override AutomationPeer? GetParentCore() => _parent;
protected override bool HasKeyboardFocusCore() => throw new NotImplementedException();

1
src/Avalonia.Controls/Automation/Peers/UnrealizedElementAutomationPeer.cs

@ -20,5 +20,6 @@ namespace Avalonia.Automation.Peers
protected override void SetFocusCore() { }
protected override bool ShowContextMenuCore() => false;
protected internal override bool TrySetParent(AutomationPeer? parent) => false;
}
}

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

@ -28,6 +28,7 @@ namespace Avalonia.Win32.Automation
{ AutomationElementIdentifiers.BoundingRectangleProperty, UiaPropertyId.BoundingRectangle },
{ AutomationElementIdentifiers.ClassNameProperty, UiaPropertyId.ClassName },
{ AutomationElementIdentifiers.NameProperty, UiaPropertyId.Name },
{ AutomationElementIdentifiers.HelpTextProperty, UiaPropertyId.HelpText },
{ ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, UiaPropertyId.ExpandCollapseExpandCollapseState },
{ RangeValuePatternIdentifiers.IsReadOnlyProperty, UiaPropertyId.RangeValueIsReadOnly},
{ RangeValuePatternIdentifiers.MaximumProperty, UiaPropertyId.RangeValueMaximum },
@ -122,6 +123,7 @@ namespace Avalonia.Win32.Automation
UiaPropertyId.IsOffscreen => InvokeSync(() => Peer.IsOffscreen()),
UiaPropertyId.LocalizedControlType => InvokeSync(() => Peer.GetLocalizedControlType()),
UiaPropertyId.Name => InvokeSync(() => Peer.GetName()),
UiaPropertyId.HelpText => InvokeSync(() => Peer.GetHelpText()),
UiaPropertyId.ProcessId => Process.GetCurrentProcess().Id,
UiaPropertyId.RuntimeId => _runtimeId,
_ => null,

Loading…
Cancel
Save