From 2eca1603255c5997011a9b6380f3b5bc3879103c Mon Sep 17 00:00:00 2001 From: David Date: Fri, 14 Apr 2023 10:56:44 -0400 Subject: [PATCH] chore: Fix CI --- .../Uno_UI_Xaml_Core/Given_InputManager.cs | 4 ++- .../Xaml/Internal/PointerCapture.Managed.cs | 19 +++++++++++++ src/Uno.UI/UI/Xaml/Internal/PointerCapture.cs | 28 ++++++++++++++----- .../UI/Xaml/Internal/PointerCapture.wasm.cs | 16 +++++++++++ src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs | 6 ++-- .../UI/Xaml/UIElement.Pointers.Android.cs | 6 ---- .../UI/Xaml/UIElement.Pointers.Managed.cs | 6 ---- src/Uno.UI/UI/Xaml/UIElement.Pointers.cs | 3 -- src/Uno.UI/UI/Xaml/UIElement.Pointers.iOS.cs | 6 ---- src/Uno.UI/UI/Xaml/UIElement.Pointers.wasm.cs | 12 -------- 10 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 src/Uno.UI/UI/Xaml/Internal/PointerCapture.Managed.cs create mode 100644 src/Uno.UI/UI/Xaml/Internal/PointerCapture.wasm.cs diff --git a/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs b/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs index 89f6973385..a7377272a9 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs @@ -1,4 +1,5 @@ -using System; +#if __SKIA__ +using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; @@ -54,3 +55,4 @@ public class Given_InputManager Assert.IsFalse(failed, "The pointer should not have been dispatched to the col2 as it has been set to visibility collapsed."); } } +#endif diff --git a/src/Uno.UI/UI/Xaml/Internal/PointerCapture.Managed.cs b/src/Uno.UI/UI/Xaml/Internal/PointerCapture.Managed.cs new file mode 100644 index 0000000000..5aa947f371 --- /dev/null +++ b/src/Uno.UI/UI/Xaml/Internal/PointerCapture.Managed.cs @@ -0,0 +1,19 @@ +#if UNO_HAS_MANAGED_POINTERS +#nullable enable + +using System; +using System.Collections.Generic; +using System.Text; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Input; + +namespace Uno.UI.Xaml.Core; +internal partial class PointerCapture +{ + partial void CaptureNative(UIElement target, Pointer pointer) + => target.XamlRoot?.VisualTree.ContentRoot.InputManager!.SetPointerCapture(pointer.UniqueId); + + partial void ReleaseNative(UIElement target, Pointer pointer) + => target.XamlRoot?.VisualTree.ContentRoot.InputManager!.ReleasePointerCapture(pointer.UniqueId); +} +#endif diff --git a/src/Uno.UI/UI/Xaml/Internal/PointerCapture.cs b/src/Uno.UI/UI/Xaml/Internal/PointerCapture.cs index a2f5ce66b3..12f0896c64 100644 --- a/src/Uno.UI/UI/Xaml/Internal/PointerCapture.cs +++ b/src/Uno.UI/UI/Xaml/Internal/PointerCapture.cs @@ -24,7 +24,7 @@ namespace Uno.UI.Xaml.Core; /// /// This is an helper class that use to manage the captures for a given pointer. /// -internal class PointerCapture +internal partial class PointerCapture { private static readonly IDictionary _actives = new Dictionary(EqualityComparer.Default); @@ -316,33 +316,47 @@ internal class PointerCapture /// See https://github.com/dotnet/runtime/issues/56309 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ReleasePointerNative() + private void CapturePointerNative() { try { - _nativeCaptureElement?.ReleasePointerNative(Pointer); + if (_nativeCaptureElement is not null) + { + CaptureNative(_nativeCaptureElement, Pointer); + } } catch (Exception e) { - this.Log().Error($"Failed to release native capture of {Pointer}", e); + this.Log().Error($"Failed to capture natively pointer {Pointer}.", e); } } + // Implement this to get pointer capture out of the bounds of the app + [MethodImpl(MethodImplOptions.AggressiveInlining)] + partial void CaptureNative(UIElement target, Pointer pointer); + /// /// This method contains or is called by a try/catch containing method and /// can be significantly slower than other methods as a result on WebAssembly. /// See https://github.com/dotnet/runtime/issues/56309 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CapturePointerNative() + private void ReleasePointerNative() { try { - _nativeCaptureElement?.CapturePointerNative(Pointer); + if (_nativeCaptureElement is not null) + { + ReleaseNative(_nativeCaptureElement, Pointer); + } } catch (Exception e) { - this.Log().Error($"Failed to capture natively pointer {Pointer}.", e); + this.Log().Error($"Failed to release native capture of {Pointer}", e); } } + + // Implement this to get pointer capture out of the bounds of the app + [MethodImpl(MethodImplOptions.AggressiveInlining)] + partial void ReleaseNative(UIElement target, Pointer pointer); } diff --git a/src/Uno.UI/UI/Xaml/Internal/PointerCapture.wasm.cs b/src/Uno.UI/UI/Xaml/Internal/PointerCapture.wasm.cs new file mode 100644 index 0000000000..0230fa5fad --- /dev/null +++ b/src/Uno.UI/UI/Xaml/Internal/PointerCapture.wasm.cs @@ -0,0 +1,16 @@ +#nullable enable + +using System; +using System.Linq; +using Windows.UI.Xaml; + +namespace Uno.UI.Xaml.Core; + +internal partial class PointerCapture +{ + partial void CapturePointerNative(UIElement target, Pointer pointer) + => WindowManagerInterop.SetPointerCapture(target.HtmlId, pointer.PointerId); + + partial void ReleasePointerNative(UIElement target, Pointer pointer) + => WindowManagerInterop.ReleasePointerCapture(target.HtmlId, pointer.PointerId); +} diff --git a/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs b/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs index f4be5e677d..0d4f2afc67 100644 --- a/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs +++ b/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs @@ -622,7 +622,7 @@ namespace Windows.UI.Xaml.Media } } -#region Helpers + #region Helpers private static Func, IEnumerable> Except(UIElement element) => children => children.Except(element); @@ -678,9 +678,9 @@ namespace Windows.UI.Xaml.Media internal static IEnumerable GetManagedVisualChildren(_View view) => view.GetChildren().OfType(); #endif -#endregion + #endregion -#region HitTest tracing + #region HitTest tracing #if TRACE_HIT_TESTING [ThreadStatic] private static StringBuilder? _trace; diff --git a/src/Uno.UI/UI/Xaml/UIElement.Pointers.Android.cs b/src/Uno.UI/UI/Xaml/UIElement.Pointers.Android.cs index b260a0c1c4..d09ad8f88e 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.Pointers.Android.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.Pointers.Android.cs @@ -237,12 +237,6 @@ namespace Windows.UI.Xaml }; } - #region Capture - // No needs to explicitly capture pointers on Android, they are implicitly captured - // partial void CapturePointerNative(Pointer pointer); - // partial void ReleasePointerNative(Pointer pointer); - #endregion - partial void OnIsHitTestVisibleChangedPartial(bool oldValue, bool newValue) { base.SetNativeIsHitTestVisible(newValue); diff --git a/src/Uno.UI/UI/Xaml/UIElement.Pointers.Managed.cs b/src/Uno.UI/UI/Xaml/UIElement.Pointers.Managed.cs index b1eeec12c6..f5ad1b4315 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.Pointers.Managed.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.Pointers.Managed.cs @@ -103,12 +103,6 @@ namespace Windows.UI.Xaml } #endregion - - internal partial void CapturePointerNative(Pointer pointer) - => XamlRoot?.VisualTree.ContentRoot.InputManager!.SetPointerCapture(pointer.UniqueId); - - internal partial void ReleasePointerNative(Pointer pointer) - => XamlRoot?.VisualTree.ContentRoot.InputManager!.ReleasePointerCapture(pointer.UniqueId); } } #endif diff --git a/src/Uno.UI/UI/Xaml/UIElement.Pointers.cs b/src/Uno.UI/UI/Xaml/UIElement.Pointers.cs index cd0f176d88..064fd0b7d7 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.Pointers.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.Pointers.cs @@ -1441,9 +1441,6 @@ namespace Windows.UI.Xaml } #endregion - internal partial void CapturePointerNative(Pointer pointer); - internal partial void ReleasePointerNative(Pointer pointer); - private bool ValidateAndUpdateCapture(PointerRoutedEventArgs args) => ValidateAndUpdateCapture(args, IsOver(args.Pointer)); diff --git a/src/Uno.UI/UI/Xaml/UIElement.Pointers.iOS.cs b/src/Uno.UI/UI/Xaml/UIElement.Pointers.iOS.cs index ab7e88c6f2..d5c884a5ec 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.Pointers.iOS.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.Pointers.iOS.cs @@ -441,11 +441,5 @@ namespace Windows.UI.Xaml } } #endregion - - #region Capture - // Pointer capture is not needed on iOS, otherwise we could use ExclusiveTouch = true; - // partial void CapturePointerNative(Pointer pointer); - // partial void ReleasePointerNative(Pointer pointer); - #endregion } } diff --git a/src/Uno.UI/UI/Xaml/UIElement.Pointers.wasm.cs b/src/Uno.UI/UI/Xaml/UIElement.Pointers.wasm.cs index fcca3909dd..9d808cdc38 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.Pointers.wasm.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.Pointers.wasm.cs @@ -340,18 +340,6 @@ public partial class UIElement : DependencyObject } } - #region Capture - partial void CapturePointerNative(Pointer pointer) - { - WindowManagerInterop.SetPointerCapture(HtmlId, pointer.PointerId); - } - - partial void ReleasePointerNative(Pointer pointer) - { - WindowManagerInterop.ReleasePointerCapture(HtmlId, pointer.PointerId); - } - #endregion - #region HitTestVisibility internal void UpdateHitTest() { -- GitLab