From 7804d75fbb938be06ff6ee9921597f270ae5e8a0 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sat, 31 Aug 2024 10:37:34 +0300 Subject: [PATCH] fix: Make GetMetadata aware of IsTabStop default value --- .../Given_DependencyProperty.cs | 25 +++++++++++++++++++ .../UI/Xaml/Controls/Control/Control.cs | 2 -- .../Xaml/Controls/UserControl/UserControl.cs | 2 -- src/Uno.UI/UI/Xaml/DependencyProperty.cs | 14 +++++++++++ src/Uno.UI/UI/Xaml/UIElement.cs | 7 ------ 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_DependencyProperty.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_DependencyProperty.cs index 4cdf87d9d378..4e1adda9f293 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_DependencyProperty.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_DependencyProperty.cs @@ -64,4 +64,29 @@ public void When_CreateDefaultValueCallback() Assert.AreEqual(2, myButton.P); Assert.AreEqual(3, myButton.P); } + + private partial class CustomFE : FrameworkElement { } + private partial class CustomControl : Control { } + private partial class CustomUserControl : UserControl { } + + [TestMethod] + public void When_IsTabStop() + { + var customControl = new CustomControl(); + Assert.IsTrue(customControl.IsTabStop); + + var userControl = new UserControl(); + Assert.IsFalse(userControl.IsTabStop); + + var customUserControl = new CustomUserControl(); + Assert.IsFalse(customUserControl.IsTabStop); + + Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(UIElement)).DefaultValue); + Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(FrameworkElement)).DefaultValue); + Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(CustomFE)).DefaultValue); + Assert.IsTrue((bool)Control.IsTabStopProperty.GetMetadata(typeof(Control)).DefaultValue); + Assert.IsTrue((bool)Control.IsTabStopProperty.GetMetadata(typeof(CustomControl)).DefaultValue); + Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(UserControl)).DefaultValue); + Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(CustomUserControl)).DefaultValue); + } } diff --git a/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs b/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs index 2f6700f6043f..e406a9c56e4d 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs @@ -52,8 +52,6 @@ private void InitializeControl() // TODO: Should use DefaultStyleKeyProperty DP protected object DefaultStyleKey { get; set; } - private protected override bool IsTabStopDefaultValue => true; - protected override bool IsSimpleLayout => true; internal override bool IsEnabledOverride() => IsEnabled && base.IsEnabledOverride(); diff --git a/src/Uno.UI/UI/Xaml/Controls/UserControl/UserControl.cs b/src/Uno.UI/UI/Xaml/Controls/UserControl/UserControl.cs index d9d80edb67f4..16115a53a482 100644 --- a/src/Uno.UI/UI/Xaml/Controls/UserControl/UserControl.cs +++ b/src/Uno.UI/UI/Xaml/Controls/UserControl/UserControl.cs @@ -12,7 +12,5 @@ public UserControl() // This mimics UWP private protected override Type GetDefaultStyleKey() => null; - - private protected override bool IsTabStopDefaultValue => false; } } diff --git a/src/Uno.UI/UI/Xaml/DependencyProperty.cs b/src/Uno.UI/UI/Xaml/DependencyProperty.cs index 439c6a03b357..8e25fb90a830 100644 --- a/src/Uno.UI/UI/Xaml/DependencyProperty.cs +++ b/src/Uno.UI/UI/Xaml/DependencyProperty.cs @@ -537,6 +537,20 @@ internal object GetDefaultValue(DependencyObject referenceObject, Type forType) return secondaryBrush; } + if (this == UIElement.IsTabStopProperty) + { + if (forType.IsAssignableTo(typeof(UserControl))) + { + return Boxes.BooleanBoxes.BoxedFalse; + } + else if (forType.IsAssignableTo(typeof(Control))) + { + return Boxes.BooleanBoxes.BoxedTrue; + } + + return Boxes.BooleanBoxes.BoxedFalse; + } + if (this == Shape.StretchProperty) { if (forType == typeof(Rectangle) || forType == typeof(Ellipse)) diff --git a/src/Uno.UI/UI/Xaml/UIElement.cs b/src/Uno.UI/UI/Xaml/UIElement.cs index 2753f624f8d1..0791e0218a94 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.cs @@ -200,8 +200,6 @@ private protected static bool GetIsEventOverrideImplemented(Type type, string na && method.DeclaringType != typeof(Control); } - private protected virtual bool IsTabStopDefaultValue => false; - /// /// Provide an instance-specific default value for the specified property /// @@ -215,11 +213,6 @@ internal virtual bool GetDefaultValue2(DependencyProperty property, out object d defaultValue = new KeyboardAcceleratorCollection(this); return true; } - else if (property == IsTabStopProperty) - { - defaultValue = Uno.UI.Helpers.Boxes.Box(IsTabStopDefaultValue); - return true; - } defaultValue = null; return false;