Added automation peer for Expander control (#20475)
* Added `ExpanderAutomationPeer` for `Expander` control * Use Group/"group" on UIA and NSAccessibilityDisclosureTriangleRole on AX --------- Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
This commit is contained in:
@@ -126,6 +126,7 @@
|
||||
case AutomationHeaderItem: return NSAccessibilityButtonRole;
|
||||
case AutomationTable: return NSAccessibilityTableRole;
|
||||
case AutomationTitleBar: return NSAccessibilityGroupRole;
|
||||
case AutomationExpander: return NSAccessibilityDisclosureTriangleRole;
|
||||
// Treat unknown roles as generic group container items. Returning
|
||||
// NSAccessibilityUnknownRole is also possible but makes the screen
|
||||
// reader focus on the item instead of passing focus to child items.
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Avalonia.Automation.Peers
|
||||
Table,
|
||||
TitleBar,
|
||||
Separator,
|
||||
Expander,
|
||||
}
|
||||
|
||||
public enum AutomationLandmarkType
|
||||
@@ -536,6 +537,7 @@ namespace Avalonia.Automation.Peers
|
||||
AutomationControlType.SplitButton => "split button",
|
||||
AutomationControlType.HeaderItem => "header item",
|
||||
AutomationControlType.TitleBar => "title bar",
|
||||
AutomationControlType.Expander => "group",
|
||||
AutomationControlType.None => (GetLandmarkType()?.ToString() ?? controlType.ToString()).ToLowerInvariant(),
|
||||
_ => controlType.ToString().ToLowerInvariant(),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using Avalonia.Automation;
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Automation.Provider;
|
||||
|
||||
namespace Avalonia.Controls.Automation.Peers
|
||||
{
|
||||
public class ExpanderAutomationPeer : ControlAutomationPeer,
|
||||
IExpandCollapseProvider
|
||||
{
|
||||
public ExpanderAutomationPeer(Control owner)
|
||||
: base(owner)
|
||||
{
|
||||
owner.PropertyChanged += OwnerPropertyChanged;
|
||||
}
|
||||
|
||||
public new Expander Owner => (Expander)base.Owner;
|
||||
|
||||
public ExpandCollapseState ExpandCollapseState => ToState(Owner.IsExpanded);
|
||||
public bool ShowsMenu => false;
|
||||
public void Collapse() => Owner.IsExpanded = false;
|
||||
public void Expand() => Owner.IsExpanded = true;
|
||||
|
||||
protected override AutomationControlType GetAutomationControlTypeCore()
|
||||
{
|
||||
return AutomationControlType.Expander;
|
||||
}
|
||||
|
||||
private void OwnerPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == Expander.IsExpandedProperty)
|
||||
{
|
||||
RaisePropertyChangedEvent(
|
||||
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
|
||||
ToState((bool)e.OldValue!),
|
||||
ToState((bool)e.NewValue!));
|
||||
}
|
||||
}
|
||||
|
||||
private static ExpandCollapseState ToState(bool value)
|
||||
{
|
||||
return value ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
|
||||
}
|
||||
|
||||
protected override bool IsContentElementCore() => true;
|
||||
protected override bool IsControlElementCore() => true;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Controls.Automation.Peers;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
@@ -274,6 +276,11 @@ namespace Avalonia.Controls
|
||||
}
|
||||
}
|
||||
|
||||
protected override AutomationPeer OnCreateAutomationPeer()
|
||||
{
|
||||
return new ExpanderAutomationPeer(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the visual state of the control by applying latest PseudoClasses.
|
||||
/// </summary>
|
||||
|
||||
@@ -652,6 +652,7 @@ enum AvnAutomationControlType
|
||||
AutomationTable,
|
||||
AutomationTitleBar,
|
||||
AutomationSeparator,
|
||||
AutomationExpander,
|
||||
}
|
||||
|
||||
enum AvnLandmarkType
|
||||
|
||||
@@ -357,6 +357,7 @@ namespace Avalonia.Win32.Automation
|
||||
AutomationControlType.Table => UiaControlTypeId.Table,
|
||||
AutomationControlType.TitleBar => UiaControlTypeId.TitleBar,
|
||||
AutomationControlType.Separator => UiaControlTypeId.Separator,
|
||||
AutomationControlType.Expander => UiaControlTypeId.Group,
|
||||
_ => UiaControlTypeId.Custom,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user