From 0756c1b3be4c8ebdf4d60ed568de896af3624f8f Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 4 Oct 2021 23:27:33 +0200 Subject: [PATCH] Use new properties to remove some peers. Simple peers which only change the accessibility view or control type can now use the new `AutomationProperties`. --- .../Peers/CheckBoxAutomationPeer.cs | 19 --------------- .../Peers/ComboBoxItemAutomationPeer.cs | 23 ------------------- .../Peers/ContextMenuAutomationPeer.cs | 21 ----------------- .../Automation/Peers/ImageAutomationPeer.cs | 19 --------------- .../Automation/Peers/MenuAutomationPeer.cs | 21 ----------------- .../Automation/Peers/SliderAutomationPeer.cs | 19 --------------- .../Peers/TabControlAutomationPeer.cs | 19 --------------- .../Automation/Peers/TabItemAutomationPeer.cs | 17 -------------- src/Avalonia.Controls/CheckBox.cs | 5 ++-- src/Avalonia.Controls/ComboBoxItem.cs | 5 ++-- src/Avalonia.Controls/ContextMenu.cs | 8 +++---- src/Avalonia.Controls/Image.cs | 7 ++---- src/Avalonia.Controls/Menu.cs | 8 +++---- src/Avalonia.Controls/Slider.cs | 7 ++---- src/Avalonia.Controls/TabControl.cs | 7 ++---- src/Avalonia.Controls/TabItem.cs | 7 ++---- 16 files changed, 20 insertions(+), 192 deletions(-) delete mode 100644 src/Avalonia.Controls/Automation/Peers/CheckBoxAutomationPeer.cs delete mode 100644 src/Avalonia.Controls/Automation/Peers/ComboBoxItemAutomationPeer.cs delete mode 100644 src/Avalonia.Controls/Automation/Peers/ContextMenuAutomationPeer.cs delete mode 100644 src/Avalonia.Controls/Automation/Peers/ImageAutomationPeer.cs delete mode 100644 src/Avalonia.Controls/Automation/Peers/MenuAutomationPeer.cs delete mode 100644 src/Avalonia.Controls/Automation/Peers/SliderAutomationPeer.cs delete mode 100644 src/Avalonia.Controls/Automation/Peers/TabControlAutomationPeer.cs delete mode 100644 src/Avalonia.Controls/Automation/Peers/TabItemAutomationPeer.cs diff --git a/src/Avalonia.Controls/Automation/Peers/CheckBoxAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/CheckBoxAutomationPeer.cs deleted file mode 100644 index 7f4e492935..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/CheckBoxAutomationPeer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Controls; - -#nullable enable - -namespace Avalonia.Automation.Peers -{ - public class CheckBoxAutomationPeer : ToggleButtonAutomationPeer - { - public CheckBoxAutomationPeer(CheckBox owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.CheckBox; - } - } -} diff --git a/src/Avalonia.Controls/Automation/Peers/ComboBoxItemAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ComboBoxItemAutomationPeer.cs deleted file mode 100644 index 70d29dbc87..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/ComboBoxItemAutomationPeer.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using Avalonia.Automation.Provider; -using Avalonia.Controls; -using Avalonia.Controls.Primitives; -using Avalonia.Controls.Selection; - -#nullable enable - -namespace Avalonia.Automation.Peers -{ - public class ComboBoxItemAutomationPeer : ListItemAutomationPeer - { - public ComboBoxItemAutomationPeer(ComboBoxItem owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.ComboBoxItem; - } - } -} diff --git a/src/Avalonia.Controls/Automation/Peers/ContextMenuAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ContextMenuAutomationPeer.cs deleted file mode 100644 index 3230f33506..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/ContextMenuAutomationPeer.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Avalonia.Controls; - -#nullable enable - -namespace Avalonia.Automation.Peers -{ - public class ContextMenuAutomationPeer : ControlAutomationPeer - { - public ContextMenuAutomationPeer(ContextMenu owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.Menu; - } - - protected override bool IsContentElementCore() => false; - } -} diff --git a/src/Avalonia.Controls/Automation/Peers/ImageAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ImageAutomationPeer.cs deleted file mode 100644 index 4548341487..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/ImageAutomationPeer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Controls; - -#nullable enable - -namespace Avalonia.Automation.Peers -{ - public class ImageAutomationPeer : ControlAutomationPeer - { - public ImageAutomationPeer(Control owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.Image; - } - } -} diff --git a/src/Avalonia.Controls/Automation/Peers/MenuAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/MenuAutomationPeer.cs deleted file mode 100644 index e223a0864f..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/MenuAutomationPeer.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Avalonia.Controls; - -#nullable enable - -namespace Avalonia.Automation.Peers -{ - public class MenuAutomationPeer : ControlAutomationPeer - { - public MenuAutomationPeer(Menu owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.Menu; - } - - protected override bool IsContentElementCore() => false; - } -} diff --git a/src/Avalonia.Controls/Automation/Peers/SliderAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/SliderAutomationPeer.cs deleted file mode 100644 index 907e779046..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/SliderAutomationPeer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Controls; - -#nullable enable - -namespace Avalonia.Automation.Peers -{ - public class SliderAutomationPeer : RangeBaseAutomationPeer - { - public SliderAutomationPeer(Slider owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.Slider; - } - } -} diff --git a/src/Avalonia.Controls/Automation/Peers/TabControlAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/TabControlAutomationPeer.cs deleted file mode 100644 index e14e61a6e4..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/TabControlAutomationPeer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Controls; - -#nullable enable - -namespace Avalonia.Automation.Peers -{ - public class TabControlAutomationPeer : SelectingItemsControlAutomationPeer - { - public TabControlAutomationPeer(TabControl owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.Tab; - } - } -} diff --git a/src/Avalonia.Controls/Automation/Peers/TabItemAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/TabItemAutomationPeer.cs deleted file mode 100644 index dc794da915..0000000000 --- a/src/Avalonia.Controls/Automation/Peers/TabItemAutomationPeer.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Avalonia.Controls; - -namespace Avalonia.Automation.Peers -{ - public class TabItemAutomationPeer : ListItemAutomationPeer - { - public TabItemAutomationPeer(TabItem owner) - : base(owner) - { - } - - protected override AutomationControlType GetAutomationControlTypeCore() - { - return AutomationControlType.TabItem; - } - } -} diff --git a/src/Avalonia.Controls/CheckBox.cs b/src/Avalonia.Controls/CheckBox.cs index f7b0dcfdc2..238a21393f 100644 --- a/src/Avalonia.Controls/CheckBox.cs +++ b/src/Avalonia.Controls/CheckBox.cs @@ -1,3 +1,4 @@ +using Avalonia.Automation; using Avalonia.Automation.Peers; using Avalonia.Controls.Primitives; @@ -8,9 +9,9 @@ namespace Avalonia.Controls /// public class CheckBox : ToggleButton { - protected override AutomationPeer OnCreateAutomationPeer() + static CheckBox() { - return new CheckBoxAutomationPeer(this); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.CheckBox); } } } diff --git a/src/Avalonia.Controls/ComboBoxItem.cs b/src/Avalonia.Controls/ComboBoxItem.cs index 42ec6e43b9..83057d139f 100644 --- a/src/Avalonia.Controls/ComboBoxItem.cs +++ b/src/Avalonia.Controls/ComboBoxItem.cs @@ -1,5 +1,6 @@ using System; using System.Reactive.Linq; +using Avalonia.Automation; using Avalonia.Automation.Peers; namespace Avalonia.Controls @@ -15,9 +16,9 @@ namespace Avalonia.Controls .Subscribe(_ => (Parent as ComboBox)?.ItemFocused(this)); } - protected override AutomationPeer OnCreateAutomationPeer() + static ComboBoxItem() { - return new ComboBoxItemAutomationPeer(this); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.ComboBoxItem); } } } diff --git a/src/Avalonia.Controls/ContextMenu.cs b/src/Avalonia.Controls/ContextMenu.cs index 0a4b518f57..90c61aaed9 100644 --- a/src/Avalonia.Controls/ContextMenu.cs +++ b/src/Avalonia.Controls/ContextMenu.cs @@ -14,6 +14,7 @@ using Avalonia.Input.Platform; using Avalonia.Interactivity; using Avalonia.Layout; using Avalonia.Styling; +using Avalonia.Automation; #nullable enable @@ -110,6 +111,8 @@ namespace Avalonia.Controls ItemsPanelProperty.OverrideDefaultValue(DefaultPanel); PlacementModeProperty.OverrideDefaultValue(PlacementMode.Pointer); ContextMenuProperty.Changed.Subscribe(ContextMenuChanged); + AutomationProperties.AccessibilityViewProperty.OverrideDefaultValue(AccessibilityView.Control); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.Menu); } /// @@ -319,11 +322,6 @@ namespace Avalonia.Controls return new MenuItemContainerGenerator(this); } - protected override AutomationPeer OnCreateAutomationPeer() - { - return new ContextMenuAutomationPeer(this); - } - private void Open(Control control, Control placementTarget, bool requestedByPointer) { if (IsOpen) diff --git a/src/Avalonia.Controls/Image.cs b/src/Avalonia.Controls/Image.cs index aaf93cac26..3d67880638 100644 --- a/src/Avalonia.Controls/Image.cs +++ b/src/Avalonia.Controls/Image.cs @@ -1,3 +1,4 @@ +using Avalonia.Automation; using Avalonia.Automation.Peers; using Avalonia.Media; using Avalonia.Media.Imaging; @@ -34,6 +35,7 @@ namespace Avalonia.Controls { AffectsRender(SourceProperty, StretchProperty, StretchDirectionProperty); AffectsMeasure(SourceProperty, StretchProperty, StretchDirectionProperty); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.Image); } /// @@ -125,10 +127,5 @@ namespace Avalonia.Controls return new Size(); } } - - protected override AutomationPeer OnCreateAutomationPeer() - { - return new ImageAutomationPeer(this); - } } } diff --git a/src/Avalonia.Controls/Menu.cs b/src/Avalonia.Controls/Menu.cs index ed70316a53..4e71c99b02 100644 --- a/src/Avalonia.Controls/Menu.cs +++ b/src/Avalonia.Controls/Menu.cs @@ -1,3 +1,4 @@ +using Avalonia.Automation; using Avalonia.Automation.Peers; using Avalonia.Controls.Platform; using Avalonia.Controls.Primitives; @@ -38,6 +39,8 @@ namespace Avalonia.Controls static Menu() { ItemsPanelProperty.OverrideDefaultValue(typeof(Menu), DefaultPanel); + AutomationProperties.AccessibilityViewProperty.OverrideDefaultValue(AccessibilityView.Control); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.Menu); } /// @@ -92,10 +95,5 @@ namespace Avalonia.Controls inputRoot.AccessKeyHandler.MainMenu = this; } } - - protected override AutomationPeer OnCreateAutomationPeer() - { - return new MenuAutomationPeer(this); - } } } diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index 227c387ffb..dc8e27c3e2 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -9,6 +9,7 @@ using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Layout; using Avalonia.Utilities; +using Avalonia.Automation; namespace Avalonia.Controls { @@ -106,6 +107,7 @@ namespace Avalonia.Controls RoutingStrategies.Bubble); ValueProperty.OverrideMetadata(new DirectPropertyMetadata(enableDataValidation: true)); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.Slider); } /// @@ -210,11 +212,6 @@ namespace Avalonia.Controls _pointerMovedDispose = this.AddDisposableHandler(PointerMovedEvent, TrackMoved, RoutingStrategies.Tunnel); } - protected override AutomationPeer OnCreateAutomationPeer() - { - return new SliderAutomationPeer(this); - } - protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); diff --git a/src/Avalonia.Controls/TabControl.cs b/src/Avalonia.Controls/TabControl.cs index cc9dab986a..da204ffce8 100644 --- a/src/Avalonia.Controls/TabControl.cs +++ b/src/Avalonia.Controls/TabControl.cs @@ -10,6 +10,7 @@ using Avalonia.Input; using Avalonia.Layout; using Avalonia.LogicalTree; using Avalonia.VisualTree; +using Avalonia.Automation; namespace Avalonia.Controls { @@ -69,6 +70,7 @@ namespace Avalonia.Controls ItemsPanelProperty.OverrideDefaultValue(DefaultPanel); AffectsMeasure(TabStripPlacementProperty); SelectedItemProperty.Changed.AddClassHandler((x, e) => x.UpdateSelectedContent()); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.Tab); } /// @@ -231,10 +233,5 @@ namespace Avalonia.Controls } } } - - protected override AutomationPeer OnCreateAutomationPeer() - { - return new TabControlAutomationPeer(this); - } } } diff --git a/src/Avalonia.Controls/TabItem.cs b/src/Avalonia.Controls/TabItem.cs index 846010ce77..7f3df0ed8a 100644 --- a/src/Avalonia.Controls/TabItem.cs +++ b/src/Avalonia.Controls/TabItem.cs @@ -1,3 +1,4 @@ +using Avalonia.Automation; using Avalonia.Automation.Peers; using Avalonia.Controls.Metadata; using Avalonia.Controls.Mixins; @@ -32,6 +33,7 @@ namespace Avalonia.Controls PressedMixin.Attach(); FocusableProperty.OverrideDefaultValue(typeof(TabItem), true); DataContextProperty.Changed.AddClassHandler((x, e) => x.UpdateHeader(e)); + AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue(AutomationControlType.TabItem); } /// @@ -81,10 +83,5 @@ namespace Avalonia.Controls } } } - - protected override AutomationPeer OnCreateAutomationPeer() - { - return new TabItemAutomationPeer(this); - } } }