From b7f971d87d5bc15f1f084769313f4fa904319372 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 8 Aug 2019 13:55:54 +0300 Subject: [PATCH] Updated mobile/interop backends --- .../Helpers/AndroidKeyboardEventsHelper.cs | 8 ++--- .../Helpers/AndroidTouchEventsHelper.cs | 6 ++-- .../Wpf/WpfTopLevelImpl.cs | 32 +++++++++++-------- .../Specific/KeyboardEventsHelper.cs | 2 +- src/iOS/Avalonia.iOS/TopLevelImpl.cs | 10 +++--- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs b/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs index c7b01413a9..1179ce9235 100644 --- a/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs +++ b/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs @@ -72,12 +72,12 @@ namespace Avalonia.Android.Platform.Specific.Helpers return false; } - private static InputModifiers GetModifierKeys(KeyEvent e) + private static RawInputModifiers GetModifierKeys(KeyEvent e) { - var rv = InputModifiers.None; + var rv = RawInputModifiers.None; - if (e.IsCtrlPressed) rv |= InputModifiers.Control; - if (e.IsShiftPressed) rv |= InputModifiers.Shift; + if (e.IsCtrlPressed) rv |= RawInputModifiers.Control; + if (e.IsShiftPressed) rv |= RawInputModifiers.Shift; return rv; } diff --git a/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidTouchEventsHelper.cs b/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidTouchEventsHelper.cs index 463d499aad..0bfbb1c2df 100644 --- a/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidTouchEventsHelper.cs +++ b/src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidTouchEventsHelper.cs @@ -78,12 +78,12 @@ namespace Avalonia.Android.Platform.Specific.Helpers if (mouseEventType == RawPointerEventType.LeftButtonDown) { var me = new RawPointerEventArgs(mouseDevice, (uint)eventTime.Ticks, inputRoot, - RawPointerEventType.Move, _point, InputModifiers.None); + RawPointerEventType.Move, _point, RawInputModifiers.None); _view.Input(me); } var mouseEvent = new RawPointerEventArgs(mouseDevice, (uint)eventTime.Ticks, inputRoot, - mouseEventType.Value, _point, InputModifiers.LeftMouseButton); + mouseEventType.Value, _point, RawInputModifiers.LeftMouseButton); _view.Input(mouseEvent); if (e.Action == MotionEventActions.Move && mouseDevice.Captured == null) @@ -102,7 +102,7 @@ namespace Avalonia.Android.Platform.Specific.Helpers (uint)eventTime.Ticks, inputRoot, _point, - new Vector(vectorX * correction / ps, vectorY * correction / ps), InputModifiers.LeftMouseButton); + new Vector(vectorX * correction / ps, vectorY * correction / ps), RawInputModifiers.LeftMouseButton); _view.Input(mouseWheelEvent); } _lastTouchMovePoint = _point; diff --git a/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs b/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs index f698266610..71c398481b 100644 --- a/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs +++ b/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs @@ -142,27 +142,33 @@ namespace Avalonia.Win32.Interop.Wpf protected override void OnLostFocus(RoutedEventArgs e) => LostFocus?.Invoke(); - InputModifiers GetModifiers() + RawInputModifiers GetModifiers(MouseEventArgs e) { var state = Keyboard.Modifiers; - var rv = default(InputModifiers); + var rv = default(RawInputModifiers); if (state.HasFlag(ModifierKeys.Windows)) - rv |= InputModifiers.Windows; + rv |= RawInputModifiers.Meta; if (state.HasFlag(ModifierKeys.Alt)) - rv |= InputModifiers.Alt; + rv |= RawInputModifiers.Alt; if (state.HasFlag(ModifierKeys.Control)) - rv |= InputModifiers.Control; + rv |= RawInputModifiers.Control; if (state.HasFlag(ModifierKeys.Shift)) - rv |= InputModifiers.Shift; - //TODO: mouse modifiers - - + rv |= RawInputModifiers.Shift; + if (e != null) + { + if (e.LeftButton == MouseButtonState.Pressed) + rv |= RawInputModifiers.LeftMouseButton; + if (e.RightButton == MouseButtonState.Pressed) + rv |= RawInputModifiers.RightMouseButton; + if (e.MiddleButton == MouseButtonState.Pressed) + rv |= RawInputModifiers.MiddleMouseButton; + } return rv; } void MouseEvent(RawPointerEventType type, MouseEventArgs e) => _ttl.Input?.Invoke(new RawPointerEventArgs(_mouse, (uint)e.Timestamp, _inputRoot, type, - e.GetPosition(this).ToAvaloniaPoint(), GetModifiers())); + e.GetPosition(this).ToAvaloniaPoint(), GetModifiers(e))); protected override void OnMouseDown(MouseButtonEventArgs e) { @@ -201,19 +207,19 @@ namespace Avalonia.Win32.Interop.Wpf protected override void OnMouseWheel(MouseWheelEventArgs e) => _ttl.Input?.Invoke(new RawMouseWheelEventArgs(_mouse, (uint) e.Timestamp, _inputRoot, - e.GetPosition(this).ToAvaloniaPoint(), new Vector(0, e.Delta), GetModifiers())); + e.GetPosition(this).ToAvaloniaPoint(), new Vector(0, e.Delta), GetModifiers(e))); protected override void OnMouseLeave(MouseEventArgs e) => MouseEvent(RawPointerEventType.LeaveWindow, e); protected override void OnKeyDown(KeyEventArgs e) => _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint) e.Timestamp, RawKeyEventType.KeyDown, (Key) e.Key, - GetModifiers())); + GetModifiers(null))); protected override void OnKeyUp(KeyEventArgs e) => _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint)e.Timestamp, RawKeyEventType.KeyUp, (Key)e.Key, - GetModifiers())); + GetModifiers(null))); protected override void OnTextInput(TextCompositionEventArgs e) => _ttl.Input?.Invoke(new RawTextInputEventArgs(_keyboard, (uint) e.Timestamp, e.Text)); diff --git a/src/iOS/Avalonia.iOS/Specific/KeyboardEventsHelper.cs b/src/iOS/Avalonia.iOS/Specific/KeyboardEventsHelper.cs index be32d12315..cdf244d330 100644 --- a/src/iOS/Avalonia.iOS/Specific/KeyboardEventsHelper.cs +++ b/src/iOS/Avalonia.iOS/Specific/KeyboardEventsHelper.cs @@ -76,7 +76,7 @@ namespace Avalonia.iOS.Specific private void HandleKey(Key key, RawKeyEventType type) { - var rawKeyEvent = new RawKeyEventArgs(KeyboardDevice.Instance, (uint)DateTime.Now.Ticks, type, key, InputModifiers.None); + var rawKeyEvent = new RawKeyEventArgs(KeyboardDevice.Instance, (uint)DateTime.Now.Ticks, type, key, RawInputModifiers.None); _view.Input(rawKeyEvent); } diff --git a/src/iOS/Avalonia.iOS/TopLevelImpl.cs b/src/iOS/Avalonia.iOS/TopLevelImpl.cs index d5f456409f..a5342b227f 100644 --- a/src/iOS/Avalonia.iOS/TopLevelImpl.cs +++ b/src/iOS/Avalonia.iOS/TopLevelImpl.cs @@ -92,7 +92,7 @@ namespace Avalonia.iOS _inputRoot, RawPointerEventType.LeftButtonUp, location, - InputModifiers.None)); + RawInputModifiers.None)); } } @@ -105,10 +105,10 @@ namespace Avalonia.iOS var location = touch.LocationInView(this).ToAvalonia(); _touchLastPoint = location; Input?.Invoke(new RawPointerEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp, _inputRoot, - RawPointerEventType.Move, location, InputModifiers.None)); + RawPointerEventType.Move, location, RawInputModifiers.None)); Input?.Invoke(new RawPointerEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp, _inputRoot, - RawPointerEventType.LeftButtonDown, location, InputModifiers.None)); + RawPointerEventType.LeftButtonDown, location, RawInputModifiers.None)); } } @@ -120,14 +120,14 @@ namespace Avalonia.iOS var location = touch.LocationInView(this).ToAvalonia(); if (iOSPlatform.MouseDevice.Captured != null) Input?.Invoke(new RawPointerEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp, _inputRoot, - RawPointerEventType.Move, location, InputModifiers.LeftMouseButton)); + RawPointerEventType.Move, location, RawInputModifiers.LeftMouseButton)); else { //magic number based on test - correction of 0.02 is working perfect double correction = 0.02; Input?.Invoke(new RawMouseWheelEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp, - _inputRoot, location, (location - _touchLastPoint) * correction, InputModifiers.LeftMouseButton)); + _inputRoot, location, (location - _touchLastPoint) * correction, RawInputModifiers.LeftMouseButton)); } _touchLastPoint = location; }