Skip to content

Commit

Permalink
fix Automation.HelpText on windows (#17030)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ahopper and Gillibald authored Sep 18, 2024
1 parent 49fb9ff commit 85fff4a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ public static class AutomationElementIdentifiers
/// 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 changes: 6 additions & 0 deletions src/Avalonia.Controls/Automation/Peers/AutomationPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public abstract class AutomationPeer
/// 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"/>.
Expand Down Expand Up @@ -250,6 +255,7 @@ protected virtual string GetLocalizedControlTypeCore()
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();
Expand Down
10 changes: 10 additions & 0 deletions src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ protected override IReadOnlyList<AutomationPeer> GetOrCreateChildrenCore()

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public abstract class UnrealizedElementAutomationPeer : AutomationPeer
protected override void SetFocusCore() { }
protected override bool ShowContextMenuCore() => false;
protected internal override bool TrySetParent(AutomationPeer? parent) => false;

}
}
2 changes: 2 additions & 0 deletions src/Windows/Avalonia.Win32/Automation/AutomationNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal partial class AutomationNode : MarshalByRefObject,
{ 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 },
Expand Down Expand Up @@ -122,6 +123,7 @@ public virtual IRawElementProviderFragmentRoot? FragmentRoot
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,
Expand Down

0 comments on commit 85fff4a

Please sign in to comment.