From 02e30f80f5c2293e115ef8b0679e4ddd8537d166 Mon Sep 17 00:00:00 2001 From: Sergey Mikolaitis Date: Wed, 8 Sep 2021 20:53:05 +0300 Subject: [PATCH 1/4] [OSX] Add Swipe, Rotate and Magnify PitchToZoom trackpad gestures as native mouse events, because they can be triggered from magic mouse AFAIK and creation of new TrackpadDevice is too big task for me now --- native/Avalonia.Native/src/OSX/window.mm | 31 ++++++++++++++++++++++++ src/Avalonia.Native/avn.idl | 5 +++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/native/Avalonia.Native/src/OSX/window.mm b/native/Avalonia.Native/src/OSX/window.mm index 14fe60ab0b..b1e923c434 100644 --- a/native/Avalonia.Native/src/OSX/window.mm +++ b/native/Avalonia.Native/src/OSX/window.mm @@ -1625,6 +1625,19 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent return; } } + else if (type == Magnify) + { + delta.X = delta.Y = [event magnification]; + } + else if (type == Rotate) + { + delta.X = delta.Y = [event rotation]; + } + else if (type == Swipe) + { + delta.X = [event deltaX]; + delta.Y = [event deltaY]; + } auto timestamp = [event timestamp] * 1000; auto modifiers = [self getModifiers:[event modifierFlags]]; @@ -1749,6 +1762,24 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent [super scrollWheel:event]; } +- (void)magnifyWithEvent:(NSEvent *)event +{ + [self mouseEvent:event withType:Magnify]; + [super magnifyWithEvent:event]; +} + +- (void)rotateWithEvent:(NSEvent *)event +{ + [self mouseEvent:event withType:Rotate]; + [super rotateWithEvent:event]; +} + +- (void)swipeWithEvent:(NSEvent *)event +{ + [self mouseEvent:event withType:Swipe]; + [super swipeWithEvent:event]; +} + - (void)mouseEntered:(NSEvent *)event { _isMouseOver = true; diff --git a/src/Avalonia.Native/avn.idl b/src/Avalonia.Native/avn.idl index 70d85dacdd..05fcdc71a5 100644 --- a/src/Avalonia.Native/avn.idl +++ b/src/Avalonia.Native/avn.idl @@ -295,7 +295,10 @@ enum AvnRawMouseEventType TouchBegin, TouchUpdate, TouchEnd, - TouchCancel + TouchCancel, + Magnify, + Rotate, + Swipe, } enum AvnRawKeyEventType From 33c22a952f13b7217cce887c1f4dfd739f98cce4 Mon Sep 17 00:00:00 2001 From: Sergey Mikolaitis Date: Wed, 8 Sep 2021 21:51:50 +0300 Subject: [PATCH 2/4] [OSX] Add PointerMagnifyGesture, PointerRotateGesture, PointerSwipeGesture events --- src/Avalonia.Input/InputElement.cs | 83 ++++++++++++++++++- src/Avalonia.Input/MouseDevice.cs | 72 ++++++++++++++++ .../PointerMagnifyGestureEventArgs.cs | 19 +++++ .../PointerRotateGestureEventArgs.cs | 19 +++++ .../PointerSwipeGestureEventArgs.cs | 19 +++++ src/Avalonia.Input/Raw/RawPointerEventArgs.cs | 5 +- .../Raw/RawPointerGestureEventArgs.cs | 19 +++++ src/Avalonia.Native/WindowImplBase.cs | 21 ++++- 8 files changed, 253 insertions(+), 4 deletions(-) create mode 100644 src/Avalonia.Input/PointerMagnifyGestureEventArgs.cs create mode 100644 src/Avalonia.Input/PointerRotateGestureEventArgs.cs create mode 100644 src/Avalonia.Input/PointerSwipeGestureEventArgs.cs create mode 100644 src/Avalonia.Input/Raw/RawPointerGestureEventArgs.cs diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 63080e74e4..93434af4a1 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -186,6 +186,30 @@ namespace Avalonia.Input RoutedEvent.Register( "PointerWheelChanged", RoutingStrategies.Tunnel | RoutingStrategies.Bubble); + + /// + /// Defines the event. + /// + public static readonly RoutedEvent PointerMagnifyGestureEvent = + RoutedEvent.Register( + "PointerMagnifyGesture", + RoutingStrategies.Tunnel | RoutingStrategies.Bubble); + + /// + /// Defines the event. + /// + public static readonly RoutedEvent PointerRotateGestureEvent = + RoutedEvent.Register( + "PointerRotateGesture", + RoutingStrategies.Tunnel | RoutingStrategies.Bubble); + + /// + /// Defines the event. + /// + public static readonly RoutedEvent PointerSwipeGestureEvent = + RoutedEvent.Register( + "PointerSwipeGesture", + RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// /// Defines the event. @@ -223,6 +247,9 @@ namespace Avalonia.Input PointerReleasedEvent.AddClassHandler((x, e) => x.OnPointerReleased(e)); PointerCaptureLostEvent.AddClassHandler((x, e) => x.OnPointerCaptureLost(e)); PointerWheelChangedEvent.AddClassHandler((x, e) => x.OnPointerWheelChanged(e)); + PointerMagnifyGestureEvent.AddClassHandler((x, e) => x.OnPointerMagnifyGesture(e)); + PointerRotateGestureEvent.AddClassHandler((x, e) => x.OnPointerRotateGesture(e)); + PointerSwipeGestureEvent.AddClassHandler((x, e) => x.OnPointerSwipeGesture(e)); } public InputElement() @@ -349,13 +376,43 @@ namespace Avalonia.Input } /// - /// Occurs when the mouse wheen is scrolled over the control. + /// Occurs when the mouse is scrolled over the control. /// public event EventHandler PointerWheelChanged { add { AddHandler(PointerWheelChangedEvent, value); } remove { RemoveHandler(PointerWheelChangedEvent, value); } } + + /// + /// Occurs when the user uses magnify (Pitch to Zoom) gesture on a trackpad and pointer is over the control. + /// Works only on macOS. + /// + public event EventHandler PointerMagnifyGesture + { + add { AddHandler(PointerMagnifyGestureEvent, value); } + remove { RemoveHandler(PointerMagnifyGestureEvent, value); } + } + + /// + /// Occurs when the user uses rotate gesture on a trackpad and pointer is over the control. + /// Works only on macOS. + /// + public event EventHandler PointerRotateGesture + { + add { AddHandler(PointerRotateGestureEvent, value); } + remove { RemoveHandler(PointerRotateGestureEvent, value); } + } + + /// + /// Occurs when the user uses swipe gesture on a trackpad and pointer is over the control. + /// Works only on macOS. + /// + public event EventHandler PointerSwipeGesture + { + add { AddHandler(PointerSwipeGestureEvent, value); } + remove { RemoveHandler(PointerSwipeGestureEvent, value); } + } /// /// Occurs when a tap gesture occurs on the control. @@ -617,6 +674,30 @@ namespace Avalonia.Input protected virtual void OnPointerWheelChanged(PointerWheelEventArgs e) { } + + /// + /// Called before the trackpad event occurs. + /// + /// The event args. + protected virtual void OnPointerMagnifyGesture(PointerMagnifyGestureEventArgs e) + { + } + + /// + /// Called before the trackpad event occurs. + /// + /// The event args. + protected virtual void OnPointerRotateGesture(PointerRotateGestureEventArgs e) + { + } + + /// + /// Called before the trackpad event occurs. + /// + /// The event args. + protected virtual void OnPointerSwipeGesture(PointerSwipeGestureEventArgs e) + { + } protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs index cfa3690daf..745c0caafd 100644 --- a/src/Avalonia.Input/MouseDevice.cs +++ b/src/Avalonia.Input/MouseDevice.cs @@ -178,6 +178,15 @@ namespace Avalonia.Input case RawPointerEventType.Wheel: e.Handled = MouseWheel(mouse, e.Timestamp, e.Root, e.Position, props, ((RawMouseWheelEventArgs)e).Delta, keyModifiers); break; + case RawPointerEventType.Magnify: + e.Handled = GestureMagnify(mouse, e.Timestamp, e.Root, e.Position, props, ((RawPointerGestureEventArgs)e).Delta, keyModifiers); + break; + case RawPointerEventType.Rotate: + e.Handled = GestureRotate(mouse, e.Timestamp, e.Root, e.Position, props, ((RawPointerGestureEventArgs)e).Delta, keyModifiers); + break; + case RawPointerEventType.Swipe: + e.Handled = GestureSwipe(mouse, e.Timestamp, e.Root, e.Position, props, ((RawPointerGestureEventArgs)e).Delta, keyModifiers); + break; } } @@ -331,6 +340,69 @@ namespace Avalonia.Input return false; } + + private bool GestureMagnify(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, + PointerPointProperties props, + Vector delta, KeyModifiers inputModifiers) + { + device = device ?? throw new ArgumentNullException(nameof(device)); + root = root ?? throw new ArgumentNullException(nameof(root)); + + var hit = HitTest(root, p); + + if (hit != null) + { + var source = GetSource(hit); + var e = new PointerMagnifyGestureEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); + + source?.RaiseEvent(e); + return e.Handled; + } + + return false; + } + + private bool GestureRotate(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, + PointerPointProperties props, + Vector delta, KeyModifiers inputModifiers) + { + device = device ?? throw new ArgumentNullException(nameof(device)); + root = root ?? throw new ArgumentNullException(nameof(root)); + + var hit = HitTest(root, p); + + if (hit != null) + { + var source = GetSource(hit); + var e = new PointerRotateGestureEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); + + source?.RaiseEvent(e); + return e.Handled; + } + + return false; + } + + private bool GestureSwipe(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, + PointerPointProperties props, + Vector delta, KeyModifiers inputModifiers) + { + device = device ?? throw new ArgumentNullException(nameof(device)); + root = root ?? throw new ArgumentNullException(nameof(root)); + + var hit = HitTest(root, p); + + if (hit != null) + { + var source = GetSource(hit); + var e = new PointerSwipeGestureEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta); + + source?.RaiseEvent(e); + return e.Handled; + } + + return false; + } private IInteractive GetSource(IVisual hit) { diff --git a/src/Avalonia.Input/PointerMagnifyGestureEventArgs.cs b/src/Avalonia.Input/PointerMagnifyGestureEventArgs.cs new file mode 100644 index 0000000000..828307c5a7 --- /dev/null +++ b/src/Avalonia.Input/PointerMagnifyGestureEventArgs.cs @@ -0,0 +1,19 @@ +using Avalonia.Interactivity; +using Avalonia.VisualTree; + +namespace Avalonia.Input +{ + public class PointerMagnifyGestureEventArgs : PointerEventArgs + { + public double Delta { get; set; } + + public PointerMagnifyGestureEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, + Point rootVisualPosition, ulong timestamp, + PointerPointProperties properties, KeyModifiers modifiers, double delta) + : base(InputElement.PointerMagnifyGestureEvent, source, pointer, rootVisual, rootVisualPosition, + timestamp, properties, modifiers) + { + Delta = delta; + } + } +} diff --git a/src/Avalonia.Input/PointerRotateGestureEventArgs.cs b/src/Avalonia.Input/PointerRotateGestureEventArgs.cs new file mode 100644 index 0000000000..4bf1ffaaaa --- /dev/null +++ b/src/Avalonia.Input/PointerRotateGestureEventArgs.cs @@ -0,0 +1,19 @@ +using Avalonia.Interactivity; +using Avalonia.VisualTree; + +namespace Avalonia.Input +{ + public class PointerRotateGestureEventArgs : PointerEventArgs + { + public double Delta { get; set; } + + public PointerRotateGestureEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, + Point rootVisualPosition, ulong timestamp, + PointerPointProperties properties, KeyModifiers modifiers, double delta) + : base(InputElement.PointerRotateGestureEvent, source, pointer, rootVisual, rootVisualPosition, + timestamp, properties, modifiers) + { + Delta = delta; + } + } +} diff --git a/src/Avalonia.Input/PointerSwipeGestureEventArgs.cs b/src/Avalonia.Input/PointerSwipeGestureEventArgs.cs new file mode 100644 index 0000000000..c4994c8504 --- /dev/null +++ b/src/Avalonia.Input/PointerSwipeGestureEventArgs.cs @@ -0,0 +1,19 @@ +using Avalonia.Interactivity; +using Avalonia.VisualTree; + +namespace Avalonia.Input +{ + public class PointerSwipeGestureEventArgs : PointerEventArgs + { + public Vector Delta { get; set; } + + public PointerSwipeGestureEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, + Point rootVisualPosition, ulong timestamp, + PointerPointProperties properties, KeyModifiers modifiers, Vector delta) + : base(InputElement.PointerSwipeGestureEvent, source, pointer, rootVisual, rootVisualPosition, + timestamp, properties, modifiers) + { + Delta = delta; + } + } +} diff --git a/src/Avalonia.Input/Raw/RawPointerEventArgs.cs b/src/Avalonia.Input/Raw/RawPointerEventArgs.cs index 62a1dd5d84..d6406121c7 100644 --- a/src/Avalonia.Input/Raw/RawPointerEventArgs.cs +++ b/src/Avalonia.Input/Raw/RawPointerEventArgs.cs @@ -21,7 +21,10 @@ namespace Avalonia.Input.Raw TouchBegin, TouchUpdate, TouchEnd, - TouchCancel + TouchCancel, + Magnify, + Rotate, + Swipe } /// diff --git a/src/Avalonia.Input/Raw/RawPointerGestureEventArgs.cs b/src/Avalonia.Input/Raw/RawPointerGestureEventArgs.cs new file mode 100644 index 0000000000..5a6dbda9a7 --- /dev/null +++ b/src/Avalonia.Input/Raw/RawPointerGestureEventArgs.cs @@ -0,0 +1,19 @@ +namespace Avalonia.Input.Raw +{ + public class RawPointerGestureEventArgs : RawPointerEventArgs + { + public RawPointerGestureEventArgs( + IInputDevice device, + ulong timestamp, + IInputRoot root, + RawPointerEventType gestureType, + Point position, + Vector delta, RawInputModifiers inputModifiers) + : base(device, timestamp, root, gestureType, position, inputModifiers) + { + Delta = delta; + } + + public Vector Delta { get; private set; } + } +} diff --git a/src/Avalonia.Native/WindowImplBase.cs b/src/Avalonia.Native/WindowImplBase.cs index 4a3baa2788..f1c42efb7f 100644 --- a/src/Avalonia.Native/WindowImplBase.cs +++ b/src/Avalonia.Native/WindowImplBase.cs @@ -306,11 +306,28 @@ namespace Avalonia.Native switch (type) { case AvnRawMouseEventType.Wheel: - Input?.Invoke(new RawMouseWheelEventArgs(_mouse, timeStamp, _inputRoot, point.ToAvaloniaPoint(), new Vector(delta.X, delta.Y), (RawInputModifiers)modifiers)); + Input?.Invoke(new RawMouseWheelEventArgs(_mouse, timeStamp, _inputRoot, + point.ToAvaloniaPoint(), new Vector(delta.X, delta.Y), (RawInputModifiers)modifiers)); + break; + + case AvnRawMouseEventType.Magnify: + Input?.Invoke(new RawPointerGestureEventArgs(_mouse, timeStamp, _inputRoot, RawPointerEventType.Magnify, + point.ToAvaloniaPoint(), new Vector(delta.X, delta.Y), (RawInputModifiers)modifiers)); + break; + + case AvnRawMouseEventType.Rotate: + Input?.Invoke(new RawPointerGestureEventArgs(_mouse, timeStamp, _inputRoot, RawPointerEventType.Rotate, + point.ToAvaloniaPoint(), new Vector(delta.X, delta.Y), (RawInputModifiers)modifiers)); + break; + + case AvnRawMouseEventType.Swipe: + Input?.Invoke(new RawPointerGestureEventArgs(_mouse, timeStamp, _inputRoot, RawPointerEventType.Swipe, + point.ToAvaloniaPoint(), new Vector(delta.X, delta.Y), (RawInputModifiers)modifiers)); break; default: - var e = new RawPointerEventArgs(_mouse, timeStamp, _inputRoot, (RawPointerEventType)type, point.ToAvaloniaPoint(), (RawInputModifiers)modifiers); + var e = new RawPointerEventArgs(_mouse, timeStamp, _inputRoot, (RawPointerEventType)type, + point.ToAvaloniaPoint(), (RawInputModifiers)modifiers); if(!ChromeHitTest(e)) { From 17ec020239ca4b737c60195b0e039ea98f7b7ca1 Mon Sep 17 00:00:00 2001 From: Sergey Mikolaitis Date: Sat, 27 Nov 2021 16:51:04 +0300 Subject: [PATCH 3/4] [OSX] Trackpad Gestures - code refactoring --- src/Avalonia.Input/Gestures.cs | 12 +++ src/Avalonia.Input/InputElement.cs | 85 ++++++------------- src/Avalonia.Input/MouseDevice.cs | 6 +- ...PointerTouchPadGestureMagnifyEventArgs.cs} | 6 +- ... PointerTouchPadGestureRotateEventArgs.cs} | 6 +- ...> PointerTouchPadGestureSwipeEventArgs.cs} | 6 +- 6 files changed, 50 insertions(+), 71 deletions(-) rename src/Avalonia.Input/{PointerRotateGestureEventArgs.cs => PointerTouchPadGestureMagnifyEventArgs.cs} (55%) rename src/Avalonia.Input/{PointerMagnifyGestureEventArgs.cs => PointerTouchPadGestureRotateEventArgs.cs} (55%) rename src/Avalonia.Input/{PointerSwipeGestureEventArgs.cs => PointerTouchPadGestureSwipeEventArgs.cs} (55%) diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index 639b4ef117..f218bcb9ce 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -28,6 +28,18 @@ namespace Avalonia.Input public static readonly RoutedEvent ScrollGestureEndedEvent = RoutedEvent.Register( "ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures)); + + public static readonly RoutedEvent PointerTouchPadGestureMagnifyEvent = + RoutedEvent.Register( + "PointerMagnifyGesture", RoutingStrategies.Bubble, typeof(Gestures)); + + public static readonly RoutedEvent PointerTouchPadGestureRotateEvent = + RoutedEvent.Register( + "PointerRotateGesture", RoutingStrategies.Bubble, typeof(Gestures)); + + public static readonly RoutedEvent PointerTouchPadGestureSwipeEvent = + RoutedEvent.Register( + "PointerSwipeGesture", RoutingStrategies.Bubble, typeof(Gestures)); #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. private static readonly WeakReference s_lastPress = new WeakReference(null); diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 88a5b0e971..af135e3e9f 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -186,40 +186,34 @@ namespace Avalonia.Input RoutedEvent.Register( "PointerWheelChanged", RoutingStrategies.Tunnel | RoutingStrategies.Bubble); - + /// - /// Defines the event. + /// Defines the event. /// - public static readonly RoutedEvent PointerMagnifyGestureEvent = - RoutedEvent.Register( - "PointerMagnifyGesture", - RoutingStrategies.Tunnel | RoutingStrategies.Bubble); - + public static readonly RoutedEvent TappedEvent = Gestures.TappedEvent; + /// - /// Defines the event. + /// Defines the event. /// - public static readonly RoutedEvent PointerRotateGestureEvent = - RoutedEvent.Register( - "PointerRotateGesture", - RoutingStrategies.Tunnel | RoutingStrategies.Bubble); + public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; /// - /// Defines the event. + /// Defines the event. /// - public static readonly RoutedEvent PointerSwipeGestureEvent = - RoutedEvent.Register( - "PointerSwipeGesture", - RoutingStrategies.Tunnel | RoutingStrategies.Bubble); - + public static readonly RoutedEvent PointerTouchPadGestureMagnifyEvent + = Gestures.PointerTouchPadGestureMagnifyEvent; + /// - /// Defines the event. + /// Defines the event. /// - public static readonly RoutedEvent TappedEvent = Gestures.TappedEvent; - + public static readonly RoutedEvent PointerTouchPadGestureRotateEvent + = Gestures.PointerTouchPadGestureRotateEvent; + /// - /// Defines the event. + /// Defines the event. /// - public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; + public static readonly RoutedEvent PointerTouchPadGestureSwipeEvent + = Gestures.PointerTouchPadGestureSwipeEvent; private bool _isEffectivelyEnabled = true; private bool _isFocused; @@ -247,9 +241,6 @@ namespace Avalonia.Input PointerReleasedEvent.AddClassHandler((x, e) => x.OnPointerReleased(e)); PointerCaptureLostEvent.AddClassHandler((x, e) => x.OnPointerCaptureLost(e)); PointerWheelChangedEvent.AddClassHandler((x, e) => x.OnPointerWheelChanged(e)); - PointerMagnifyGestureEvent.AddClassHandler((x, e) => x.OnPointerMagnifyGesture(e)); - PointerRotateGestureEvent.AddClassHandler((x, e) => x.OnPointerRotateGesture(e)); - PointerSwipeGestureEvent.AddClassHandler((x, e) => x.OnPointerSwipeGesture(e)); } public InputElement() @@ -388,30 +379,30 @@ namespace Avalonia.Input /// Occurs when the user uses magnify (Pitch to Zoom) gesture on a trackpad and pointer is over the control. /// Works only on macOS. /// - public event EventHandler PointerMagnifyGesture + public event EventHandler PointerTouchPadGestureMagnify { - add { AddHandler(PointerMagnifyGestureEvent, value); } - remove { RemoveHandler(PointerMagnifyGestureEvent, value); } + add { AddHandler(PointerTouchPadGestureMagnifyEvent, value); } + remove { RemoveHandler(PointerTouchPadGestureMagnifyEvent, value); } } /// /// Occurs when the user uses rotate gesture on a trackpad and pointer is over the control. /// Works only on macOS. /// - public event EventHandler PointerRotateGesture + public event EventHandler PointerTouchPadGestureRotate { - add { AddHandler(PointerRotateGestureEvent, value); } - remove { RemoveHandler(PointerRotateGestureEvent, value); } + add { AddHandler(PointerTouchPadGestureRotateEvent, value); } + remove { RemoveHandler(PointerTouchPadGestureRotateEvent, value); } } /// /// Occurs when the user uses swipe gesture on a trackpad and pointer is over the control. /// Works only on macOS. /// - public event EventHandler PointerSwipeGesture + public event EventHandler PointerTouchPadGestureSwipe { - add { AddHandler(PointerSwipeGestureEvent, value); } - remove { RemoveHandler(PointerSwipeGestureEvent, value); } + add { AddHandler(PointerTouchPadGestureSwipeEvent, value); } + remove { RemoveHandler(PointerTouchPadGestureSwipeEvent, value); } } /// @@ -674,30 +665,6 @@ namespace Avalonia.Input protected virtual void OnPointerWheelChanged(PointerWheelEventArgs e) { } - - /// - /// Called before the trackpad event occurs. - /// - /// The event args. - protected virtual void OnPointerMagnifyGesture(PointerMagnifyGestureEventArgs e) - { - } - - /// - /// Called before the trackpad event occurs. - /// - /// The event args. - protected virtual void OnPointerRotateGesture(PointerRotateGestureEventArgs e) - { - } - - /// - /// Called before the trackpad event occurs. - /// - /// The event args. - protected virtual void OnPointerSwipeGesture(PointerSwipeGestureEventArgs e) - { - } protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs index c919242c78..7197397e99 100644 --- a/src/Avalonia.Input/MouseDevice.cs +++ b/src/Avalonia.Input/MouseDevice.cs @@ -355,7 +355,7 @@ namespace Avalonia.Input if (hit != null) { var source = GetSource(hit); - var e = new PointerMagnifyGestureEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); + var e = new PointerTouchPadGestureMagnifyEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); source?.RaiseEvent(e); return e.Handled; @@ -376,7 +376,7 @@ namespace Avalonia.Input if (hit != null) { var source = GetSource(hit); - var e = new PointerRotateGestureEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); + var e = new PointerTouchPadGestureRotateEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); source?.RaiseEvent(e); return e.Handled; @@ -397,7 +397,7 @@ namespace Avalonia.Input if (hit != null) { var source = GetSource(hit); - var e = new PointerSwipeGestureEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta); + var e = new PointerTouchPadGestureSwipeEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta); source?.RaiseEvent(e); return e.Handled; diff --git a/src/Avalonia.Input/PointerRotateGestureEventArgs.cs b/src/Avalonia.Input/PointerTouchPadGestureMagnifyEventArgs.cs similarity index 55% rename from src/Avalonia.Input/PointerRotateGestureEventArgs.cs rename to src/Avalonia.Input/PointerTouchPadGestureMagnifyEventArgs.cs index 4bf1ffaaaa..d55d23d2c8 100644 --- a/src/Avalonia.Input/PointerRotateGestureEventArgs.cs +++ b/src/Avalonia.Input/PointerTouchPadGestureMagnifyEventArgs.cs @@ -3,14 +3,14 @@ using Avalonia.VisualTree; namespace Avalonia.Input { - public class PointerRotateGestureEventArgs : PointerEventArgs + public class PointerTouchPadGestureMagnifyEventArgs : PointerEventArgs { public double Delta { get; set; } - public PointerRotateGestureEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, + public PointerTouchPadGestureMagnifyEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, Point rootVisualPosition, ulong timestamp, PointerPointProperties properties, KeyModifiers modifiers, double delta) - : base(InputElement.PointerRotateGestureEvent, source, pointer, rootVisual, rootVisualPosition, + : base(InputElement.PointerTouchPadGestureMagnifyEvent, source, pointer, rootVisual, rootVisualPosition, timestamp, properties, modifiers) { Delta = delta; diff --git a/src/Avalonia.Input/PointerMagnifyGestureEventArgs.cs b/src/Avalonia.Input/PointerTouchPadGestureRotateEventArgs.cs similarity index 55% rename from src/Avalonia.Input/PointerMagnifyGestureEventArgs.cs rename to src/Avalonia.Input/PointerTouchPadGestureRotateEventArgs.cs index 828307c5a7..8563cf6609 100644 --- a/src/Avalonia.Input/PointerMagnifyGestureEventArgs.cs +++ b/src/Avalonia.Input/PointerTouchPadGestureRotateEventArgs.cs @@ -3,14 +3,14 @@ using Avalonia.VisualTree; namespace Avalonia.Input { - public class PointerMagnifyGestureEventArgs : PointerEventArgs + public class PointerTouchPadGestureRotateEventArgs : PointerEventArgs { public double Delta { get; set; } - public PointerMagnifyGestureEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, + public PointerTouchPadGestureRotateEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, Point rootVisualPosition, ulong timestamp, PointerPointProperties properties, KeyModifiers modifiers, double delta) - : base(InputElement.PointerMagnifyGestureEvent, source, pointer, rootVisual, rootVisualPosition, + : base(InputElement.PointerTouchPadGestureRotateEvent, source, pointer, rootVisual, rootVisualPosition, timestamp, properties, modifiers) { Delta = delta; diff --git a/src/Avalonia.Input/PointerSwipeGestureEventArgs.cs b/src/Avalonia.Input/PointerTouchPadGestureSwipeEventArgs.cs similarity index 55% rename from src/Avalonia.Input/PointerSwipeGestureEventArgs.cs rename to src/Avalonia.Input/PointerTouchPadGestureSwipeEventArgs.cs index c4994c8504..1d9c0d6189 100644 --- a/src/Avalonia.Input/PointerSwipeGestureEventArgs.cs +++ b/src/Avalonia.Input/PointerTouchPadGestureSwipeEventArgs.cs @@ -3,14 +3,14 @@ using Avalonia.VisualTree; namespace Avalonia.Input { - public class PointerSwipeGestureEventArgs : PointerEventArgs + public class PointerTouchPadGestureSwipeEventArgs : PointerEventArgs { public Vector Delta { get; set; } - public PointerSwipeGestureEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, + public PointerTouchPadGestureSwipeEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, Point rootVisualPosition, ulong timestamp, PointerPointProperties properties, KeyModifiers modifiers, Vector delta) - : base(InputElement.PointerSwipeGestureEvent, source, pointer, rootVisual, rootVisualPosition, + : base(InputElement.PointerTouchPadGestureSwipeEvent, source, pointer, rootVisual, rootVisualPosition, timestamp, properties, modifiers) { Delta = delta; From 90c846007aad2a414a33bdf47208bd68ab081a1f Mon Sep 17 00:00:00 2001 From: Sergey Mikolaytis Date: Sat, 22 Jan 2022 14:18:34 +0300 Subject: [PATCH 4/4] Requested Changes --- src/Avalonia.Input/Gestures.cs | 12 ++--- src/Avalonia.Input/InputElement.cs | 48 ------------------- src/Avalonia.Input/MouseDevice.cs | 18 +++---- src/Avalonia.Input/PointerDeltaEventArgs.cs | 19 ++++++++ .../PointerTouchPadGestureMagnifyEventArgs.cs | 19 -------- .../PointerTouchPadGestureRotateEventArgs.cs | 19 -------- .../PointerTouchPadGestureSwipeEventArgs.cs | 19 -------- 7 files changed, 34 insertions(+), 120 deletions(-) create mode 100644 src/Avalonia.Input/PointerDeltaEventArgs.cs delete mode 100644 src/Avalonia.Input/PointerTouchPadGestureMagnifyEventArgs.cs delete mode 100644 src/Avalonia.Input/PointerTouchPadGestureRotateEventArgs.cs delete mode 100644 src/Avalonia.Input/PointerTouchPadGestureSwipeEventArgs.cs diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index 6e7b74911d..86e6e96a71 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -30,16 +30,16 @@ namespace Avalonia.Input RoutedEvent.Register( "ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent PointerTouchPadGestureMagnifyEvent = - RoutedEvent.Register( + public static readonly RoutedEvent PointerTouchPadGestureMagnifyEvent = + RoutedEvent.Register( "PointerMagnifyGesture", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent PointerTouchPadGestureRotateEvent = - RoutedEvent.Register( + public static readonly RoutedEvent PointerTouchPadGestureRotateEvent = + RoutedEvent.Register( "PointerRotateGesture", RoutingStrategies.Bubble, typeof(Gestures)); - public static readonly RoutedEvent PointerTouchPadGestureSwipeEvent = - RoutedEvent.Register( + public static readonly RoutedEvent PointerTouchPadGestureSwipeEvent = + RoutedEvent.Register( "PointerSwipeGesture", RoutingStrategies.Bubble, typeof(Gestures)); #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 6ac3a98b70..5aa1f1ff44 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -197,24 +197,6 @@ namespace Avalonia.Input /// public static readonly RoutedEvent DoubleTappedEvent = Gestures.DoubleTappedEvent; - /// - /// Defines the event. - /// - public static readonly RoutedEvent PointerTouchPadGestureMagnifyEvent - = Gestures.PointerTouchPadGestureMagnifyEvent; - - /// - /// Defines the event. - /// - public static readonly RoutedEvent PointerTouchPadGestureRotateEvent - = Gestures.PointerTouchPadGestureRotateEvent; - - /// - /// Defines the event. - /// - public static readonly RoutedEvent PointerTouchPadGestureSwipeEvent - = Gestures.PointerTouchPadGestureSwipeEvent; - private bool _isEffectivelyEnabled = true; private bool _isFocused; private bool _isKeyboardFocusWithin; @@ -375,36 +357,6 @@ namespace Avalonia.Input remove { RemoveHandler(PointerWheelChangedEvent, value); } } - /// - /// Occurs when the user uses magnify (Pitch to Zoom) gesture on a trackpad and pointer is over the control. - /// Works only on macOS. - /// - public event EventHandler PointerTouchPadGestureMagnify - { - add { AddHandler(PointerTouchPadGestureMagnifyEvent, value); } - remove { RemoveHandler(PointerTouchPadGestureMagnifyEvent, value); } - } - - /// - /// Occurs when the user uses rotate gesture on a trackpad and pointer is over the control. - /// Works only on macOS. - /// - public event EventHandler PointerTouchPadGestureRotate - { - add { AddHandler(PointerTouchPadGestureRotateEvent, value); } - remove { RemoveHandler(PointerTouchPadGestureRotateEvent, value); } - } - - /// - /// Occurs when the user uses swipe gesture on a trackpad and pointer is over the control. - /// Works only on macOS. - /// - public event EventHandler PointerTouchPadGestureSwipe - { - add { AddHandler(PointerTouchPadGestureSwipeEvent, value); } - remove { RemoveHandler(PointerTouchPadGestureSwipeEvent, value); } - } - /// /// Occurs when a tap gesture occurs on the control. /// diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs index e856488b43..087a806f77 100644 --- a/src/Avalonia.Input/MouseDevice.cs +++ b/src/Avalonia.Input/MouseDevice.cs @@ -345,8 +345,7 @@ namespace Avalonia.Input } private bool GestureMagnify(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, - PointerPointProperties props, - Vector delta, KeyModifiers inputModifiers) + PointerPointProperties props, Vector delta, KeyModifiers inputModifiers) { device = device ?? throw new ArgumentNullException(nameof(device)); root = root ?? throw new ArgumentNullException(nameof(root)); @@ -356,7 +355,8 @@ namespace Avalonia.Input if (hit != null) { var source = GetSource(hit); - var e = new PointerTouchPadGestureMagnifyEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); + var e = new PointerDeltaEventArgs(Gestures.PointerTouchPadGestureMagnifyEvent, source, + _pointer, root, p, timestamp, props, inputModifiers, delta); source?.RaiseEvent(e); return e.Handled; @@ -366,8 +366,7 @@ namespace Avalonia.Input } private bool GestureRotate(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, - PointerPointProperties props, - Vector delta, KeyModifiers inputModifiers) + PointerPointProperties props, Vector delta, KeyModifiers inputModifiers) { device = device ?? throw new ArgumentNullException(nameof(device)); root = root ?? throw new ArgumentNullException(nameof(root)); @@ -377,7 +376,8 @@ namespace Avalonia.Input if (hit != null) { var source = GetSource(hit); - var e = new PointerTouchPadGestureRotateEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta.X); + var e = new PointerDeltaEventArgs(Gestures.PointerTouchPadGestureRotateEvent, source, + _pointer, root, p, timestamp, props, inputModifiers, delta); source?.RaiseEvent(e); return e.Handled; @@ -387,8 +387,7 @@ namespace Avalonia.Input } private bool GestureSwipe(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, - PointerPointProperties props, - Vector delta, KeyModifiers inputModifiers) + PointerPointProperties props, Vector delta, KeyModifiers inputModifiers) { device = device ?? throw new ArgumentNullException(nameof(device)); root = root ?? throw new ArgumentNullException(nameof(root)); @@ -398,7 +397,8 @@ namespace Avalonia.Input if (hit != null) { var source = GetSource(hit); - var e = new PointerTouchPadGestureSwipeEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta); + var e = new PointerDeltaEventArgs(Gestures.PointerTouchPadGestureSwipeEvent, source, + _pointer, root, p, timestamp, props, inputModifiers, delta); source?.RaiseEvent(e); return e.Handled; diff --git a/src/Avalonia.Input/PointerDeltaEventArgs.cs b/src/Avalonia.Input/PointerDeltaEventArgs.cs new file mode 100644 index 0000000000..b3085a038d --- /dev/null +++ b/src/Avalonia.Input/PointerDeltaEventArgs.cs @@ -0,0 +1,19 @@ +using Avalonia.Interactivity; +using Avalonia.VisualTree; + +namespace Avalonia.Input +{ + public class PointerDeltaEventArgs : PointerEventArgs + { + public Vector Delta { get; set; } + + public PointerDeltaEventArgs(RoutedEvent routedEvent, IInteractive? source, + IPointer pointer, IVisual rootVisual, Point rootVisualPosition, ulong timestamp, + PointerPointProperties properties, KeyModifiers modifiers, Vector delta) + : base(routedEvent, source, pointer, rootVisual, rootVisualPosition, + timestamp, properties, modifiers) + { + Delta = delta; + } + } +} diff --git a/src/Avalonia.Input/PointerTouchPadGestureMagnifyEventArgs.cs b/src/Avalonia.Input/PointerTouchPadGestureMagnifyEventArgs.cs deleted file mode 100644 index d55d23d2c8..0000000000 --- a/src/Avalonia.Input/PointerTouchPadGestureMagnifyEventArgs.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Interactivity; -using Avalonia.VisualTree; - -namespace Avalonia.Input -{ - public class PointerTouchPadGestureMagnifyEventArgs : PointerEventArgs - { - public double Delta { get; set; } - - public PointerTouchPadGestureMagnifyEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, - Point rootVisualPosition, ulong timestamp, - PointerPointProperties properties, KeyModifiers modifiers, double delta) - : base(InputElement.PointerTouchPadGestureMagnifyEvent, source, pointer, rootVisual, rootVisualPosition, - timestamp, properties, modifiers) - { - Delta = delta; - } - } -} diff --git a/src/Avalonia.Input/PointerTouchPadGestureRotateEventArgs.cs b/src/Avalonia.Input/PointerTouchPadGestureRotateEventArgs.cs deleted file mode 100644 index 8563cf6609..0000000000 --- a/src/Avalonia.Input/PointerTouchPadGestureRotateEventArgs.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Interactivity; -using Avalonia.VisualTree; - -namespace Avalonia.Input -{ - public class PointerTouchPadGestureRotateEventArgs : PointerEventArgs - { - public double Delta { get; set; } - - public PointerTouchPadGestureRotateEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, - Point rootVisualPosition, ulong timestamp, - PointerPointProperties properties, KeyModifiers modifiers, double delta) - : base(InputElement.PointerTouchPadGestureRotateEvent, source, pointer, rootVisual, rootVisualPosition, - timestamp, properties, modifiers) - { - Delta = delta; - } - } -} diff --git a/src/Avalonia.Input/PointerTouchPadGestureSwipeEventArgs.cs b/src/Avalonia.Input/PointerTouchPadGestureSwipeEventArgs.cs deleted file mode 100644 index 1d9c0d6189..0000000000 --- a/src/Avalonia.Input/PointerTouchPadGestureSwipeEventArgs.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Interactivity; -using Avalonia.VisualTree; - -namespace Avalonia.Input -{ - public class PointerTouchPadGestureSwipeEventArgs : PointerEventArgs - { - public Vector Delta { get; set; } - - public PointerTouchPadGestureSwipeEventArgs(IInteractive source, IPointer pointer, IVisual rootVisual, - Point rootVisualPosition, ulong timestamp, - PointerPointProperties properties, KeyModifiers modifiers, Vector delta) - : base(InputElement.PointerTouchPadGestureSwipeEvent, source, pointer, rootVisual, rootVisualPosition, - timestamp, properties, modifiers) - { - Delta = delta; - } - } -}