From b9998dd4839b27516d2006c3633ec302c72495c5 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 15 Jul 2022 15:56:59 +0200 Subject: [PATCH] Don't use TransformedBounds for automation. --- .../Automation/Peers/ControlAutomationPeer.cs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs index 28cb3e34b2..a93d3fa7dd 100644 --- a/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs @@ -146,7 +146,7 @@ namespace Avalonia.Automation.Peers protected override string? GetAccessKeyCore() => AutomationProperties.GetAccessKey(Owner); protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Custom; protected override string? GetAutomationIdCore() => AutomationProperties.GetAutomationId(Owner) ?? Owner.Name; - protected override Rect GetBoundingRectangleCore() => GetBounds(Owner.TransformedBounds); + protected override Rect GetBoundingRectangleCore() => GetBounds(Owner); protected override string GetClassNameCore() => Owner.GetType().Name; protected override bool HasKeyboardFocusCore() => Owner.IsFocused; protected override bool IsContentElementCore() => AutomationProperties.GetAccessibilityView(Owner) >= AccessibilityView.Content; @@ -160,9 +160,19 @@ namespace Avalonia.Automation.Peers return AutomationProperties.GetControlTypeOverride(Owner) ?? GetAutomationControlTypeCore(); } - private static Rect GetBounds(TransformedBounds? bounds) + private static Rect GetBounds(Control control) { - return bounds?.Bounds.TransformToAABB(bounds!.Value.Transform) ?? default; + var root = control.GetVisualRoot(); + + if (root is null) + return default; + + var transform = control.TransformToVisual(root); + + if (!transform.HasValue) + return default; + + return new Rect(control.Bounds.Size).TransformToAABB(transform.Value); } private void Initialize() @@ -182,12 +192,14 @@ namespace Avalonia.Automation.Peers if (parent is Control c) (GetOrCreate(c) as ControlAutomationPeer)?.InvalidateChildren(); } - else if (e.Property == Visual.TransformedBoundsProperty) + else if (e.Property == Visual.BoundsProperty || + e.Property == Visual.RenderTransformProperty || + e.Property == Visual.RenderTransformOriginProperty) { RaisePropertyChangedEvent( AutomationElementIdentifiers.BoundingRectangleProperty, - GetBounds((TransformedBounds?)e.OldValue), - GetBounds((TransformedBounds?)e.NewValue)); + null, + GetBounds(Owner)); } else if (e.Property == Visual.VisualParentProperty) {