From e60586aeea1cdeeb8afc6e70825b0160b714c758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Fri, 29 Mar 2024 23:32:18 +0100 Subject: [PATCH 1/5] Add basic support for automation for DataGrid and DataGridRow --- .../Peers/DataGridAutomationPeer.cs | 18 +++++++++++++++++ .../Peers/DataGridRowAutomationPeer.cs | 20 +++++++++++++++++++ src/Avalonia.Controls.DataGrid/DataGrid.cs | 7 +++++++ src/Avalonia.Controls.DataGrid/DataGridRow.cs | 6 ++++++ 4 files changed, 51 insertions(+) create mode 100644 src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridAutomationPeer.cs create mode 100644 src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridRowAutomationPeer.cs diff --git a/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridAutomationPeer.cs b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridAutomationPeer.cs new file mode 100644 index 00000000000..5d181d85673 --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridAutomationPeer.cs @@ -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; + } +} diff --git a/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridRowAutomationPeer.cs b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridRowAutomationPeer.cs new file mode 100644 index 00000000000..4e137a4e747 --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridRowAutomationPeer.cs @@ -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; + } +} diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index ad7f905c648..c3f428450b0 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/src/Avalonia.Controls.DataGrid/DataGrid.cs @@ -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; @@ -800,6 +802,11 @@ public DataGrid() UpdatePseudoClasses(); } + protected override AutomationPeer OnCreateAutomationPeer() + { + return new DataGridAutomationPeer(this); + } + private void SetValueNoCallback(AvaloniaProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) { _areHandlersSuspended = true; diff --git a/src/Avalonia.Controls.DataGrid/DataGridRow.cs b/src/Avalonia.Controls.DataGrid/DataGridRow.cs index 48d6ca7f445..5a312e8b7c3 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRow.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridRow.cs @@ -15,6 +15,7 @@ using Avalonia.VisualTree; using System; using System.Diagnostics; +using Avalonia.Automation.Peers; using Avalonia.Reactive; namespace Avalonia.Controls @@ -150,6 +151,11 @@ public DataGridRow() Cells.CellRemoved += DataGridCellCollection_CellRemoved; } + protected override AutomationPeer OnCreateAutomationPeer() + { + return new DataGridRowAutomationPeer(this); + } + private void SetValueNoCallback(AvaloniaProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) { _areHandlersSuspended = true; From c24e7bf91f7111df6601bea22f57b6823e48ff56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Sat, 30 Mar 2024 00:33:55 +0100 Subject: [PATCH 2/5] Add DataGridCellAutomationPeer --- .../Peers/DataGridCellAutomationPeer.cs | 22 +++++++++++++++++++ .../DataGridCell.cs | 7 ++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridCellAutomationPeer.cs diff --git a/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridCellAutomationPeer.cs b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridCellAutomationPeer.cs new file mode 100644 index 00000000000..f1301be70dd --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridCellAutomationPeer.cs @@ -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; + } + + protected override bool IsContentElementCore() => true; + + protected override bool IsControlElementCore() => true; +} diff --git a/src/Avalonia.Controls.DataGrid/DataGridCell.cs b/src/Avalonia.Controls.DataGrid/DataGridCell.cs index 2f5f2c25e07..852b85ff01b 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridCell.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridCell.cs @@ -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; @@ -123,6 +125,11 @@ private bool IsMouseOver } } + protected override AutomationPeer OnCreateAutomationPeer() + { + return new DataGridCellAutomationPeer(this); + } + /// /// Builds the visual tree for the cell control when a new template is applied. /// From a16e6bec14502cd1be099c6bd7336d3ecbe9648f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Sat, 30 Mar 2024 00:34:05 +0100 Subject: [PATCH 3/5] Add DataGridColumnHeaderAutomationPeer --- .../DataGridColumnHeaderAutomationPeer.cs | 22 +++++++++++++++++++ .../DataGridColumnHeader.cs | 7 ++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeaderAutomationPeer.cs diff --git a/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeaderAutomationPeer.cs b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeaderAutomationPeer.cs new file mode 100644 index 00000000000..bfcf00607f6 --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeaderAutomationPeer.cs @@ -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; +} diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs index 1eef700a45f..579c4d04ad1 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs @@ -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; @@ -87,6 +89,11 @@ public DataGridColumnHeader() PointerExited += DataGridColumnHeader_PointerExited; } + protected override AutomationPeer OnCreateAutomationPeer() + { + return new DataGridColumnHeaderAutomationPeer(this); + } + private void OnAreSeparatorsVisibleChanged(AvaloniaPropertyChangedEventArgs e) { if (!_areHandlersSuspended) From 24a26154fec52f3305ff368119a6ec64f416e715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Sat, 30 Mar 2024 00:34:16 +0100 Subject: [PATCH 4/5] Add DataGridColumnHeadersPresenterAutomationPeer --- ...ridColumnHeadersPresenterAutomationPeer.cs | 23 +++++++++++++++++++ .../DataGridColumnHeadersPresenter.cs | 7 ++++++ 2 files changed, 30 insertions(+) create mode 100644 src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs diff --git a/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs new file mode 100644 index 00000000000..f84951206e1 --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridColumnHeadersPresenterAutomationPeer.cs @@ -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; +} diff --git a/src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs b/src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs index fcf72385b2b..fb7b2562756 100644 --- a/src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs +++ b/src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs @@ -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 { @@ -126,6 +128,11 @@ bool IChildIndexProvider.TryGetTotalCount(out int count) return true; } + protected override AutomationPeer OnCreateAutomationPeer() + { + return new DataGridColumnHeadersPresenterAutomationPeer(this); + } + /// /// Arranges the content of the . /// From e5b5fc90c3c87ed56c95d603bdfed148881f0d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Sat, 30 Mar 2024 00:39:41 +0100 Subject: [PATCH 5/5] Add DataGridDetailsPresenterAutomationPeer --- .../DataGridDetailsPresenterAutomationPeer.cs | 14 ++++++++++++++ .../Primitives/DataGridDetailsPresenter.cs | 7 +++++++ 2 files changed, 21 insertions(+) create mode 100644 src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridDetailsPresenterAutomationPeer.cs diff --git a/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridDetailsPresenterAutomationPeer.cs b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridDetailsPresenterAutomationPeer.cs new file mode 100644 index 00000000000..58b79541c57 --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/Automation/Peers/DataGridDetailsPresenterAutomationPeer.cs @@ -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; +} diff --git a/src/Avalonia.Controls.DataGrid/Primitives/DataGridDetailsPresenter.cs b/src/Avalonia.Controls.DataGrid/Primitives/DataGridDetailsPresenter.cs index 07e7708003e..ed7169cae35 100644 --- a/src/Avalonia.Controls.DataGrid/Primitives/DataGridDetailsPresenter.cs +++ b/src/Avalonia.Controls.DataGrid/Primitives/DataGridDetailsPresenter.cs @@ -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 @@ -43,6 +45,11 @@ public DataGridDetailsPresenter() AffectsMeasure(ContentHeightProperty); } + protected override AutomationPeer OnCreateAutomationPeer() + { + return new DataGridDetailsPresenterAutomationPeer(this); + } + /// /// Arranges the content of the . ///