Browse Source

ItemStatus and ItemType UIA properties (#20669)

* ItemStatus and ItemType UIA properties

* ItemStatus property change notification

---------

Co-authored-by: Jan Kučera <miloush@users.noreply.github.com>
release/latest
Jan Kučera 1 month ago
committed by Julien Lebosquain
parent
commit
b6f2b4c7e9
No known key found for this signature in database GPG Key ID: 1833CAD10ACC46FD
  1. 6
      src/Avalonia.Controls/Automation/AutomationElementIdentifiers.cs
  2. 37
      src/Avalonia.Controls/Automation/Peers/AutomationPeer.cs
  3. 9
      src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
  4. 3
      src/Windows/Avalonia.Win32.Automation/AutomationNode.cs

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

@ -31,6 +31,12 @@ namespace Avalonia.Automation
/// </summary>
public static AutomationProperty HelpTextProperty { get; } = new AutomationProperty();
/// <summary>
/// Identifies the itemStatus automation property. The class name property value is returned
/// by the <see cref="AutomationPeer.GetItemStatus"/> method.
/// </summary>
public static AutomationProperty ItemStatusProperty { get; } = new AutomationProperty();
/// <summary>
/// Identifies the landmark type automation property. The class name property value is returned
/// by the <see cref="AutomationPeer.GetLandmarkType"/> method.

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

@ -319,6 +319,41 @@ namespace Avalonia.Automation.Peers
/// </remarks>
public int GetHeadingLevel() => GetHeadingLevelCore();
/// <summary>
/// Gets the item type that is associated with this automation peer.
/// </summary>
/// <remarks>
/// <list type="table">
/// <item>
/// <term>Windows</term>
/// <description><c>UIA_ItemTypePropertyId</c></description>
/// </item>
/// <item>
/// <term>macOS</term>
/// <description>No mapping.</description>
/// </item>
/// </list>
/// </remarks>
public string? GetItemType() => GetItemTypeCore();
/// <summary>
/// Gets the item status that is associated with this automation peer.
/// </summary>
/// <remarks>
/// <list type="table">
/// <item>
/// <term>Windows</term>
/// <description><c>UIA_ItemStatusPropertyId</c></description>
/// </item>
/// <item>
/// <term>macOS</term>
/// <description>No mapping.</description>
/// </item>
/// </list>
/// </remarks>
public string? GetItemStatus() => GetItemStatusCore();
/// <summary>
/// Gets the <see cref="AutomationPeer"/> that is the parent of this <see cref="AutomationPeer"/>.
/// </summary>
@ -562,6 +597,8 @@ namespace Avalonia.Automation.Peers
protected virtual string? GetHelpTextCore() => null;
protected virtual AutomationLandmarkType? GetLandmarkTypeCore() => null;
protected virtual int GetHeadingLevelCore() => 0;
protected virtual string? GetItemTypeCore() => null;
protected virtual string? GetItemStatusCore() => null;
protected abstract AutomationPeer? GetParentCore();
protected abstract bool HasKeyboardFocusCore();
protected abstract bool IsContentElementCore();

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

@ -192,6 +192,8 @@ namespace Avalonia.Automation.Peers
protected override string? GetAutomationIdCore() => AutomationProperties.GetAutomationId(Owner) ?? Owner.Name;
protected override Rect GetBoundingRectangleCore() => GetBounds(Owner);
protected override string GetClassNameCore() => Owner.GetType().Name;
protected override string? GetItemStatusCore() => AutomationProperties.GetItemStatus(Owner);
protected override string? GetItemTypeCore() => AutomationProperties.GetItemType(Owner);
protected override bool HasKeyboardFocusCore() => Owner.IsFocused;
protected override bool IsContentElementCore() => true;
protected override bool IsControlElementCore() => true;
@ -274,6 +276,13 @@ namespace Avalonia.Automation.Peers
{
InvalidateParent();
}
else if (e.Property == AutomationProperties.ItemStatusProperty)
{
RaisePropertyChangedEvent(
AutomationElementIdentifiers.ItemStatusProperty,
e.OldValue,
e.NewValue);
}
}

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

@ -39,6 +39,7 @@ namespace Avalonia.Win32.Automation
{ AutomationElementIdentifiers.HelpTextProperty, UiaPropertyId.HelpText },
{ AutomationElementIdentifiers.LandmarkTypeProperty, UiaPropertyId.LandmarkType },
{ AutomationElementIdentifiers.HeadingLevelProperty, UiaPropertyId.HeadingLevel },
{ AutomationElementIdentifiers.ItemStatusProperty, UiaPropertyId.ItemStatus },
{ ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, UiaPropertyId.ExpandCollapseExpandCollapseState },
{ RangeValuePatternIdentifiers.IsReadOnlyProperty, UiaPropertyId.RangeValueIsReadOnly},
{ RangeValuePatternIdentifiers.MaximumProperty, UiaPropertyId.RangeValueMaximum },
@ -135,6 +136,8 @@ namespace Avalonia.Win32.Automation
UiaPropertyId.IsEnabled => InvokeSync(() => Peer.IsEnabled()),
UiaPropertyId.IsKeyboardFocusable => InvokeSync(() => Peer.IsKeyboardFocusable()),
UiaPropertyId.IsOffscreen => InvokeSync(() => Peer.IsOffscreen()),
UiaPropertyId.ItemType => InvokeSync(() => Peer.GetItemType()),
UiaPropertyId.ItemStatus => InvokeSync(() => Peer.GetItemStatus()),
UiaPropertyId.LocalizedControlType => InvokeSync(() => Peer.GetLocalizedControlType()),
UiaPropertyId.Name => InvokeSync(() => Peer.GetName()),
UiaPropertyId.HelpText => InvokeSync(() => Peer.GetHelpText()),

Loading…
Cancel
Save