Skip to content

Commit

Permalink
fix: Make GetMetadata aware of IsTabStop default value
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Aug 31, 2024
1 parent 8122799 commit 7804d75
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 0 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/UserControl/UserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ public UserControl()

// This mimics UWP
private protected override Type GetDefaultStyleKey() => null;

private protected override bool IsTabStopDefaultValue => false;
}
}
14 changes: 14 additions & 0 deletions src/Uno.UI/UI/Xaml/DependencyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 0 additions & 7 deletions src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ private protected static bool GetIsEventOverrideImplemented(Type type, string na
&& method.DeclaringType != typeof(Control);
}

private protected virtual bool IsTabStopDefaultValue => false;

/// <summary>
/// Provide an instance-specific default value for the specified property
/// </summary>
Expand All @@ -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;
Expand Down

0 comments on commit 7804d75

Please sign in to comment.