Skip to content

Commit

Permalink
chore: make previous changes adjustable in FeatureConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Nov 7, 2024
1 parent 38bab0f commit 3eb75b1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/SamplesApp/SamplesApp.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ static void ConfigureFeatureFlags()
#if HAS_UNO
Uno.UI.FeatureConfiguration.TextBox.UseOverlayOnSkia = false;
Uno.UI.FeatureConfiguration.ToolTip.UseToolTips = true;
Uno.UI.FeatureConfiguration.DependencyProperty.ValidatePropertyOwnerOnReadWrite = true;

Uno.UI.FeatureConfiguration.Font.DefaultTextFontFamily = "ms-appx:///Uno.Fonts.OpenSans/Fonts/OpenSans.ttf";
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UI.RuntimeTests/MUX/Helpers/EventTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.UI.Xaml;
using UIExecutor = MUXControlsTestApp.Utilities.RunOnUIThread;
using MUXControlsTestApp.Utilities;
using Uno.UI;

namespace Microsoft/* UWP don't rename */.UI.Xaml.Tests.Common
{
Expand Down Expand Up @@ -153,7 +154,7 @@ public static EventTester<UIElement, TEventArgs> FromRoutedEvent(UIElement sende
return new RoutedEventTester<TEventArgs>(sender, eventName, action);
}

public TimeSpan DefaultTimeout = EventTesterConfig.Timeout;
public TimeSpan DefaultTimeout = FeatureConfiguration.DebugOptions.WaitIndefinitelyInEventTester ? TimeSpan.FromMilliseconds(-1) : EventTesterConfig.Timeout;

Check warning on line 157 in src/Uno.UI.RuntimeTests/MUX/Helpers/EventTester.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI.RuntimeTests/MUX/Helpers/EventTester.cs#L157

Make 'DefaultTimeout' private.

Check notice on line 157 in src/Uno.UI.RuntimeTests/MUX/Helpers/EventTester.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI.RuntimeTests/MUX/Helpers/EventTester.cs#L157

Make this field 'private' and encapsulate it in a 'public' property.

private TSender Sender
{
Expand Down
23 changes: 23 additions & 0 deletions src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,29 @@ public static class DependencyProperty
/// of having an undefined behavior and/or race conditions.
/// </summary>
public static bool DisableThreadingCheck { get; set; }

/// <summary>
/// Enables checks that make sure that <see cref="DependencyObjectStore.GetValue" /> and
/// <see cref="DependencyObjectStore.SetValue" /> are only called on the owner of the property being
/// set/got.
/// </summary>
public static bool ValidatePropertyOwnerOnReadWrite { get; set; } =
#if DEBUG
true;
#else
global::System.Diagnostics.Debugger.IsAttached;
#endif
}

/// <summary>
/// This is for internal use to facilitate turning on/off certain logic that makes it easier/harder
/// to debug.
/// </summary>
internal static class DebugOptions
{
public static bool PreventKeyboardStateTrackerFromResettingOnWindowActivationChange { get; set; }

public static bool WaitIndefinitelyInEventTester { get; set; }
}
}
}
31 changes: 16 additions & 15 deletions src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,24 +790,25 @@ private void WritePropertyEventTrace(int eventId, DependencyProperty property, D
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ValidatePropertyOwner(DependencyProperty property)
{
#if DEBUG
var isFrameworkElement = _originalObjectType.Is(typeof(FrameworkElement));
var isMixinFrameworkElement = _originalObjectRef.Target is IFrameworkElement && !isFrameworkElement;
if (FeatureConfiguration.DependencyProperty.ValidatePropertyOwnerOnReadWrite)
{
var isFrameworkElement = _originalObjectType.Is(typeof(FrameworkElement));
var isMixinFrameworkElement = _originalObjectRef.Target is IFrameworkElement && !isFrameworkElement;

if (
!_originalObjectType.Is(property.OwnerType)
&& !property.IsAttached
if (
!_originalObjectType.Is(property.OwnerType)
&& !property.IsAttached

// Don't fail validation for properties that are located on non-FrameworkElement types
// e.g. ScrollContentPresenter, for which using the Name property should not fail.
&& !isMixinFrameworkElement
)
{
throw new InvalidOperationException(
$"The Dependency Property [{property.Name}] is owned by [{property.OwnerType}] and cannot be used on [{_originalObjectType}]"
);
// Don't fail validation for properties that are located on non-FrameworkElement types
// e.g. ScrollContentPresenter, for which using the Name property should not fail.
&& !isMixinFrameworkElement
)
{
throw new InvalidOperationException(
$"The Dependency Property [{property.Name}] is owned by [{property.OwnerType}] and cannot be used on [{_originalObjectType}]"
);
}
}
#endif
}

public long RegisterPropertyChangedCallback(DependencyProperty property, DependencyPropertyChangedCallback callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ private void OnActivationStateChanged(CoreWindowActivationState state)
CoreWindow?.OnActivated(coreWindowActivatedEventArgs);
Activated?.Invoke(Window, activatedEventArgs);
SystemThemeHelper.RefreshSystemTheme();
KeyboardStateTracker.Reset();
if (!FeatureConfiguration.DebugOptions.PreventKeyboardStateTrackerFromResettingOnWindowActivationChange)
{
KeyboardStateTracker.Reset();
}
}

public bool Close()
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/Buffers/DefaultArrayPoolBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal Bucket(int bufferLength, int numberOfBuffers, int poolId)
#if DEBUG // thread tracking adds non-trivial overheads to Enter/Exit
true
#else
false
global::System.Diagnostics.Debugger.IsAttached
#endif
);
_buffers = new T[numberOfBuffers][];
Expand Down

0 comments on commit 3eb75b1

Please sign in to comment.