Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Automation.HelpText on windows #17030

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading