Skip to content

Commit b6f2b4c

Browse files
miloushMrJul
authored andcommitted
ItemStatus and ItemType UIA properties (AvaloniaUI#20669)
* ItemStatus and ItemType UIA properties * ItemStatus property change notification --------- Co-authored-by: Jan Kučera <miloush@users.noreply.github.com>
1 parent 2856c84 commit b6f2b4c

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/Avalonia.Controls/Automation/AutomationElementIdentifiers.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public static class AutomationElementIdentifiers
3131
/// </summary>
3232
public static AutomationProperty HelpTextProperty { get; } = new AutomationProperty();
3333

34+
/// <summary>
35+
/// Identifies the itemStatus automation property. The class name property value is returned
36+
/// by the <see cref="AutomationPeer.GetItemStatus"/> method.
37+
/// </summary>
38+
public static AutomationProperty ItemStatusProperty { get; } = new AutomationProperty();
39+
3440
/// <summary>
3541
/// Identifies the landmark type automation property. The class name property value is returned
3642
/// by the <see cref="AutomationPeer.GetLandmarkType"/> method.

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,41 @@ public abstract class AutomationPeer
319319
/// </remarks>
320320
public int GetHeadingLevel() => GetHeadingLevelCore();
321321

322+
323+
/// <summary>
324+
/// Gets the item type that is associated with this automation peer.
325+
/// </summary>
326+
/// <remarks>
327+
/// <list type="table">
328+
/// <item>
329+
/// <term>Windows</term>
330+
/// <description><c>UIA_ItemTypePropertyId</c></description>
331+
/// </item>
332+
/// <item>
333+
/// <term>macOS</term>
334+
/// <description>No mapping.</description>
335+
/// </item>
336+
/// </list>
337+
/// </remarks>
338+
public string? GetItemType() => GetItemTypeCore();
339+
340+
/// <summary>
341+
/// Gets the item status that is associated with this automation peer.
342+
/// </summary>
343+
/// <remarks>
344+
/// <list type="table">
345+
/// <item>
346+
/// <term>Windows</term>
347+
/// <description><c>UIA_ItemStatusPropertyId</c></description>
348+
/// </item>
349+
/// <item>
350+
/// <term>macOS</term>
351+
/// <description>No mapping.</description>
352+
/// </item>
353+
/// </list>
354+
/// </remarks>
355+
public string? GetItemStatus() => GetItemStatusCore();
356+
322357
/// <summary>
323358
/// Gets the <see cref="AutomationPeer"/> that is the parent of this <see cref="AutomationPeer"/>.
324359
/// </summary>
@@ -562,6 +597,8 @@ protected virtual string GetLocalizedControlTypeCore()
562597
protected virtual string? GetHelpTextCore() => null;
563598
protected virtual AutomationLandmarkType? GetLandmarkTypeCore() => null;
564599
protected virtual int GetHeadingLevelCore() => 0;
600+
protected virtual string? GetItemTypeCore() => null;
601+
protected virtual string? GetItemStatusCore() => null;
565602
protected abstract AutomationPeer? GetParentCore();
566603
protected abstract bool HasKeyboardFocusCore();
567604
protected abstract bool IsContentElementCore();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ protected internal override bool TrySetParent(AutomationPeer? parent)
192192
protected override string? GetAutomationIdCore() => AutomationProperties.GetAutomationId(Owner) ?? Owner.Name;
193193
protected override Rect GetBoundingRectangleCore() => GetBounds(Owner);
194194
protected override string GetClassNameCore() => Owner.GetType().Name;
195+
protected override string? GetItemStatusCore() => AutomationProperties.GetItemStatus(Owner);
196+
protected override string? GetItemTypeCore() => AutomationProperties.GetItemType(Owner);
195197
protected override bool HasKeyboardFocusCore() => Owner.IsFocused;
196198
protected override bool IsContentElementCore() => true;
197199
protected override bool IsControlElementCore() => true;
@@ -274,6 +276,13 @@ private void OwnerPropertyChanged(object? sender, AvaloniaPropertyChangedEventAr
274276
{
275277
InvalidateParent();
276278
}
279+
else if (e.Property == AutomationProperties.ItemStatusProperty)
280+
{
281+
RaisePropertyChangedEvent(
282+
AutomationElementIdentifiers.ItemStatusProperty,
283+
e.OldValue,
284+
e.NewValue);
285+
}
277286
}
278287

279288

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal partial class AutomationNode : MarshalByRefObject,
3939
{ AutomationElementIdentifiers.HelpTextProperty, UiaPropertyId.HelpText },
4040
{ AutomationElementIdentifiers.LandmarkTypeProperty, UiaPropertyId.LandmarkType },
4141
{ AutomationElementIdentifiers.HeadingLevelProperty, UiaPropertyId.HeadingLevel },
42+
{ AutomationElementIdentifiers.ItemStatusProperty, UiaPropertyId.ItemStatus },
4243
{ ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, UiaPropertyId.ExpandCollapseExpandCollapseState },
4344
{ RangeValuePatternIdentifiers.IsReadOnlyProperty, UiaPropertyId.RangeValueIsReadOnly},
4445
{ RangeValuePatternIdentifiers.MaximumProperty, UiaPropertyId.RangeValueMaximum },
@@ -135,6 +136,8 @@ public virtual Rect GetBoundingRectangle()
135136
UiaPropertyId.IsEnabled => InvokeSync(() => Peer.IsEnabled()),
136137
UiaPropertyId.IsKeyboardFocusable => InvokeSync(() => Peer.IsKeyboardFocusable()),
137138
UiaPropertyId.IsOffscreen => InvokeSync(() => Peer.IsOffscreen()),
139+
UiaPropertyId.ItemType => InvokeSync(() => Peer.GetItemType()),
140+
UiaPropertyId.ItemStatus => InvokeSync(() => Peer.GetItemStatus()),
138141
UiaPropertyId.LocalizedControlType => InvokeSync(() => Peer.GetLocalizedControlType()),
139142
UiaPropertyId.Name => InvokeSync(() => Peer.GetName()),
140143
UiaPropertyId.HelpText => InvokeSync(() => Peer.GetHelpText()),

0 commit comments

Comments
 (0)