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

Add basic support for automation for DataGrid and DataGridRow #15174

Merged
merged 5 commits into from
Mar 30, 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
@@ -0,0 +1,18 @@
using Avalonia.Automation.Peers;

namespace Avalonia.Controls.Automation.Peers;

public class DataGridAutomationPeer : ControlAutomationPeer
{
public DataGridAutomationPeer(DataGrid owner)
: base(owner)
{
}

public new DataGrid Owner => (DataGrid)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.DataGrid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Avalonia.Automation.Peers;

namespace Avalonia.Controls.Automation.Peers;

public class DataGridCellAutomationPeer : ContentControlAutomationPeer
{
public DataGridCellAutomationPeer(DataGridCell owner)
: base(owner)
{
}

public new DataGridCell Owner => (DataGridCell)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Custom;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@maxkatz6 maxkatz6 Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I guess it's not as necessary for starters, since basic text works either way.

}

protected override bool IsContentElementCore() => true;

protected override bool IsControlElementCore() => true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Avalonia.Automation.Peers;

namespace Avalonia.Controls.Automation.Peers;

public class DataGridColumnHeaderAutomationPeer : ContentControlAutomationPeer
{
public DataGridColumnHeaderAutomationPeer(DataGridColumnHeader owner)
: base(owner)
{
}

public new DataGridColumnHeader Owner => (DataGridColumnHeader)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.HeaderItem;
}

protected override bool IsContentElementCore() => false;

protected override bool IsControlElementCore() => true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Avalonia.Automation.Peers;
using Avalonia.Controls.Primitives;

namespace Avalonia.Controls.Automation.Peers;

public class DataGridColumnHeadersPresenterAutomationPeer : ControlAutomationPeer
{
public DataGridColumnHeadersPresenterAutomationPeer(DataGridColumnHeadersPresenter owner)
: base(owner)
{
}

public new DataGridColumnHeadersPresenter Owner => (DataGridColumnHeadersPresenter)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Header;
}

protected override bool IsContentElementCore() => false;

protected override bool IsControlElementCore() => true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Avalonia.Automation.Peers;
using Avalonia.Controls.Primitives;

namespace Avalonia.Controls.Automation.Peers;

public class DataGridDetailsPresenterAutomationPeer : ControlAutomationPeer
{
public DataGridDetailsPresenterAutomationPeer(DataGridDetailsPresenter owner)
: base(owner)
{
}

public new DataGridDetailsPresenter Owner => (DataGridDetailsPresenter)base.Owner;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Avalonia.Controls;

namespace Avalonia.Automation.Peers
{
public class DataGridRowAutomationPeer : ControlAutomationPeer
{
public DataGridRowAutomationPeer(DataGridRow owner)
: base(owner)
{
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.DataItem;
}

protected override bool IsContentElementCore() => true;
protected override bool IsControlElementCore() => true;
}
}
7 changes: 7 additions & 0 deletions src/Avalonia.Controls.DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using System.Linq;
using Avalonia.Input.Platform;
using System.ComponentModel.DataAnnotations;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Utils;
using Avalonia.Layout;
using Avalonia.Controls.Metadata;
Expand Down Expand Up @@ -800,6 +802,11 @@ public DataGrid()
UpdatePseudoClasses();
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new DataGridAutomationPeer(this);
}

private void SetValueNoCallback<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
_areHandlersSuspended = true;
Expand Down
7 changes: 7 additions & 0 deletions src/Avalonia.Controls.DataGrid/DataGridCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
Expand Down Expand Up @@ -123,6 +125,11 @@ private bool IsMouseOver
}
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new DataGridCellAutomationPeer(this);
}

/// <summary>
/// Builds the visual tree for the cell control when a new template is applied.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using Avalonia.Automation.Peers;
using Avalonia.Collections;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Utils;
Expand Down Expand Up @@ -87,6 +89,11 @@ public DataGridColumnHeader()
PointerExited += DataGridColumnHeader_PointerExited;
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new DataGridColumnHeaderAutomationPeer(this);
}

private void OnAreSeparatorsVisibleChanged(AvaloniaPropertyChangedEventArgs e)
{
if (!_areHandlersSuspended)
Expand Down
6 changes: 6 additions & 0 deletions src/Avalonia.Controls.DataGrid/DataGridRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Avalonia.VisualTree;
using System;
using System.Diagnostics;
using Avalonia.Automation.Peers;
using Avalonia.Reactive;

namespace Avalonia.Controls
Expand Down Expand Up @@ -150,6 +151,11 @@ public DataGridRow()
Cells.CellRemoved += DataGridCellCollection_CellRemoved;
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new DataGridRowAutomationPeer(this);
}

private void SetValueNoCallback<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
_areHandlersSuspended = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;

namespace Avalonia.Controls.Primitives
{
Expand Down Expand Up @@ -126,6 +128,11 @@ bool IChildIndexProvider.TryGetTotalCount(out int count)
return true;
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new DataGridColumnHeadersPresenterAutomationPeer(this);
}

/// <summary>
/// Arranges the content of the <see cref="T:Avalonia.Controls.Primitives.DataGridColumnHeadersPresenter" />.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Media;

namespace Avalonia.Controls.Primitives
Expand Down Expand Up @@ -43,6 +45,11 @@ public DataGridDetailsPresenter()
AffectsMeasure<DataGridDetailsPresenter>(ContentHeightProperty);
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new DataGridDetailsPresenterAutomationPeer(this);
}

/// <summary>
/// Arranges the content of the <see cref="T:Avalonia.Controls.Primitives.DataGridDetailsPresenter" />.
/// </summary>
Expand Down
Loading