Skip to content

Commit

Permalink
feat: Custom dispatch pointer events on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
David authored and dr1rrb committed Mar 10, 2021
1 parent a9dd550 commit 2b00bcd
Show file tree
Hide file tree
Showing 12 changed files with 740 additions and 881 deletions.
1,020 changes: 637 additions & 383 deletions src/Uno.UI/Controls/Window.macOS.cs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ static Application()
{
ApiInformation.RegisterAssembly(typeof(Application).Assembly);
ApiInformation.RegisterAssembly(typeof(Windows.Storage.ApplicationData).Assembly);

InitializePartialStatic();
}

static partial void InitializePartialStatic();

[Preserve]
public static class TraceProvider
{
Expand Down
7 changes: 7 additions & 0 deletions src/Uno.UI/UI/Xaml/Application.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Extensions.Logging;
using Selector = ObjCRuntime.Selector;
using Windows.System.Profile;
using Windows.UI.Core;
using Uno.Foundation.Extensibility;
using Uno.Helpers;
#if HAS_UNO_WINUI
using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;
Expand All @@ -33,6 +35,11 @@ public partial class Application : NSApplicationDelegate

private NSUrl[] _launchUrls = null;

static partial void InitializePartialStatic()
{
ApiExtensibility.Register(typeof(Windows.UI.Core.ICoreWindowExtension), o => new CoreWindowExtension());
}

public Application()
{
Current = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if UNO_HAS_MANAGED_POINTERS
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -49,3 +50,4 @@ private Pointer GetPointer(PointerEventArgs args)
isInRange: args.CurrentPoint.Properties.IsInRange);
}
}
#endif
8 changes: 4 additions & 4 deletions src/Uno.UI/UI/Xaml/Input/PointerRoutedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
namespace Windows.UI.Xaml.Input
{
public sealed partial class PointerRoutedEventArgs : RoutedEventArgs, ICancellableRoutedEventArgs, CoreWindow.IPointerEventArgs, IDragEventSource
{
#if __IOS__ || __MACOS__ || __ANDROID__ || __WASM__
internal const bool PlatformSupportsNativeBubbling = true;
#else
{
#if UNO_HAS_MANAGED_POINTERS
internal const bool PlatformSupportsNativeBubbling = false;
#else
internal const bool PlatformSupportsNativeBubbling = true;
#endif

public PointerRoutedEventArgs()
Expand Down
217 changes: 0 additions & 217 deletions src/Uno.UI/UI/Xaml/Input/PointerRoutedEventArgs.macOS.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
#if UNO_HAS_MANAGED_POINTERS
#nullable enable

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -33,13 +34,13 @@ private class PointerManager

public PointerManager()
{
Window.Current.CoreWindow.PointerMoved += CoreWindow_PointerMoved;
Window.Current.CoreWindow.PointerEntered += CoreWindow_PointerEntered;
Window.Current.CoreWindow.PointerExited += CoreWindow_PointerExited;
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
Window.Current.CoreWindow.PointerReleased += CoreWindow_PointerReleased;
Window.Current.CoreWindow.PointerWheelChanged += CoreWindow_PointerWheelChanged;
Window.Current.CoreWindow.PointerCancelled += CoreWindow_PointerCancelled;
Windows.UI.Xaml.Window.Current.CoreWindow.PointerMoved += CoreWindow_PointerMoved;
Windows.UI.Xaml.Window.Current.CoreWindow.PointerEntered += CoreWindow_PointerEntered;
Windows.UI.Xaml.Window.Current.CoreWindow.PointerExited += CoreWindow_PointerExited;
Windows.UI.Xaml.Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
Windows.UI.Xaml.Window.Current.CoreWindow.PointerReleased += CoreWindow_PointerReleased;
Windows.UI.Xaml.Window.Current.CoreWindow.PointerWheelChanged += CoreWindow_PointerWheelChanged;
Windows.UI.Xaml.Window.Current.CoreWindow.PointerCancelled += CoreWindow_PointerCancelled;
}

private void CoreWindow_PointerWheelChanged(CoreWindow sender, PointerEventArgs args)
Expand All @@ -48,8 +49,8 @@ private void CoreWindow_PointerWheelChanged(CoreWindow sender, PointerEventArgs

// Even if impossible for the Release, we are fallbacking on the RootElement for safety
// This is how UWP behaves: when out of the bounds of the Window, the root element is use.
// Note that is another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Window.Current.Content;
// Note that if another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Windows.UI.Xaml.Window.Current.Content;

if (originalSource is null)
{
Expand Down Expand Up @@ -104,8 +105,8 @@ private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)

// Even if impossible for the Pressed, we are fallbacking on the RootElement for safety
// This is how UWP behaves: when out of the bounds of the Window, the root element is use.
// Note that is another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Window.Current.Content;
// Note that if another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Windows.UI.Xaml.Window.Current.Content;

if (originalSource is null)
{
Expand Down Expand Up @@ -134,8 +135,8 @@ private void CoreWindow_PointerReleased(CoreWindow sender, PointerEventArgs args

// Even if impossible for the Release, we are fallbacking on the RootElement for safety
// This is how UWP behaves: when out of the bounds of the Window, the root element is use.
// Note that is another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Window.Current.Content;
// Note that if another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Windows.UI.Xaml.Window.Current.Content;

if (originalSource is null)
{
Expand Down Expand Up @@ -184,8 +185,8 @@ private void CoreWindow_PointerMoved(CoreWindow sender, PointerEventArgs args)
var (originalSource, staleBranch) = VisualTreeHelper.HitTest(args.CurrentPoint.Position, isStale: _isOver);

// This is how UWP behaves: when out of the bounds of the Window, the root element is use.
// Note that is another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Window.Current.Content;
// Note that if another app covers your app, then the OriginalSource on UWP is still the element of your app at the pointer's location.
originalSource ??= Windows.UI.Xaml.Window.Current.Content;

if (originalSource is null)
{
Expand Down Expand Up @@ -371,7 +372,11 @@ private static object CoerceHitTestVisibility(DependencyObject dependencyObject,
}

// If we're not locally hit-test visible, visible, or enabled, we should be collapsed. Our children will be collapsed as well.
if (!element.IsLoaded || !element.IsHitTestVisible || element.Visibility != Visibility.Visible || !element.IsEnabledOverride())
if (
#if !__MACOS__
!element.IsLoaded ||
#endif
!element.IsHitTestVisible || element.Visibility != Visibility.Visible || !element.IsEnabledOverride())
{
return HitTestability.Collapsed;
}
Expand All @@ -398,3 +403,4 @@ private static void OnHitTestVisibilityChanged(DependencyObject dependencyObject
=> CoreWindow.GetForCurrentThread()!.ReleasePointerCapture();
}
}
#endif
Loading

0 comments on commit 2b00bcd

Please sign in to comment.