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 #332

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 TreeDataGridAutomationPeer : ControlAutomationPeer
{
public TreeDataGridAutomationPeer(TreeDataGrid owner)
: base(owner)
{
}

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

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.DataGrid;
}
}
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 TreeDataGridCellAutomationPeer : ControlAutomationPeer
{
public TreeDataGridCellAutomationPeer(TreeDataGridCell owner)
: base(owner)
{
}

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

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

protected override bool IsContentElementCore() => true;

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 TreeDataGridColumnHeaderAutomationPeer : ContentControlAutomationPeer
{
public TreeDataGridColumnHeaderAutomationPeer(TreeDataGridColumnHeader owner)
: base(owner)
{
}

public new TreeDataGridColumnHeader Owner => (TreeDataGridColumnHeader)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 TreeDataGridColumnHeadersPresenterAutomationPeer : ControlAutomationPeer
{
public TreeDataGridColumnHeadersPresenterAutomationPeer(TreeDataGridColumnHeadersPresenter owner)
: base(owner)
{
}

public new TreeDataGridColumnHeadersPresenter Owner => (TreeDataGridColumnHeadersPresenter)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,21 @@
using Avalonia.Automation.Peers;
using Avalonia.Controls.Primitives;

namespace Avalonia.Controls.Automation.Peers;

public class TreeDataGridRowAutomationPeer : ControlAutomationPeer
{
public TreeDataGridRowAutomationPeer(TreeDataGridRow owner)
: base(owner)
{
}

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

protected override bool IsContentElementCore() => true;

protected override bool IsControlElementCore() => true;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.ComponentModel;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
Expand Down Expand Up @@ -74,6 +76,11 @@ public virtual void Unrealize()
Model = null;
}

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

protected internal void BeginEdit()
{
if (!IsEditing)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.ComponentModel;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Input;
using Avalonia.Utilities;
Expand Down Expand Up @@ -81,6 +83,11 @@ public void Unrealize()
UpdatePropertiesFromModel();
}

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

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Layout;
using Avalonia.LogicalTree;
Expand All @@ -12,6 +14,11 @@ public class TreeDataGridColumnHeadersPresenter : TreeDataGridColumnarPresenterB

protected override Orientation Orientation => Orientation.Horizontal;

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

protected override Size ArrangeOverride(Size finalSize)
{
(Items as IColumns)?.CommitActualWidths();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Text;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
Expand Down Expand Up @@ -112,6 +114,11 @@ public void Unrealize()
CellsPresenter?.Unrealize();
}

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

protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
_treeDataGrid = this.FindLogicalAncestorOfType<TreeDataGrid>();
Expand Down
7 changes: 7 additions & 0 deletions src/Avalonia.Controls.TreeDataGrid/TreeDataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Primitives;
Expand Down Expand Up @@ -310,6 +312,11 @@ public bool QueryCancelSelection()
return e.Cancel;
}

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

protected virtual TreeDataGridElementFactory CreateDefaultElementFactory() => new TreeDataGridElementFactory();

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Expand Down