Browse Source

Merge pull request #9360 from AvaloniaUI/fixes/tapped-gestures

Fixes for Tapped gestures and IPlatformSettings refactor.
pull/9400/head
Max Katz 3 years ago
committed by GitHub
parent
commit
a8d674015d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      samples/IntegrationTestApp/MainWindow.axaml
  2. 34
      samples/IntegrationTestApp/MainWindow.axaml.cs
  3. 14
      src/Android/Avalonia.Android/AndroidPlatform.cs
  4. 25
      src/Avalonia.Base/Input/Gestures.cs
  5. 6
      src/Avalonia.Base/Input/MouseDevice.cs
  6. 5
      src/Avalonia.Base/Input/PenDevice.cs
  7. 7
      src/Avalonia.Base/Input/TouchDevice.cs
  8. 30
      src/Avalonia.Base/Platform/DefaultPlatformSettings.cs
  9. 22
      src/Avalonia.Base/Platform/IPlatformSettings.cs
  10. 8
      src/Avalonia.Controls/Automation/AutomationProperties.cs
  11. 14
      src/Avalonia.Controls/Automation/Peers/AutomationPeer.cs
  12. 16
      src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
  13. 11
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowingPlatform.cs
  14. 2
      src/Avalonia.Headless/AvaloniaHeadlessPlatform.cs
  15. 10
      src/Avalonia.Headless/HeadlessPlatformStubs.cs
  16. 14
      src/Avalonia.Native/AvaloniaNativePlatform.cs
  17. 6
      src/Avalonia.Native/DoubleClickHelper.cs
  18. 17
      src/Avalonia.X11/Stubs.cs
  19. 2
      src/Avalonia.X11/X11Platform.cs
  20. 2
      src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs
  21. 9
      src/Linux/Avalonia.LinuxFramebuffer/Stubs.cs
  22. 11
      src/Web/Avalonia.Web/WindowingPlatform.cs
  23. 31
      src/Windows/Avalonia.Win32/Win32Platform.cs
  24. 17
      src/iOS/Avalonia.iOS/Platform.cs
  25. 4
      tests/Avalonia.Base.UnitTests/Input/TouchDeviceTests.cs
  26. 175
      tests/Avalonia.IntegrationTests.Appium/GestureTests.cs

17
samples/IntegrationTestApp/MainWindow.axaml

@ -69,6 +69,23 @@
</StackPanel>
</TabItem>
<TabItem Header="Gestures">
<DockPanel>
<DockPanel DockPanel.Dock="Top">
<Button Name="ResetGestures" DockPanel.Dock="Right">Reset</Button>
<TextBlock Name="LastGesture" />
</DockPanel>
<Panel>
<Border Name="GestureBorder" Background="Blue"
AutomationProperties.AccessibilityView="Content"
AutomationProperties.ControlTypeOverride="Image"/>
<Border Name="GestureBorder2" Background="Green" IsVisible="False"
AutomationProperties.AccessibilityView="Content"
AutomationProperties.ControlTypeOverride="Image"/>
</Panel>
</DockPanel>
</TabItem>
<TabItem Header="ListBox">
<DockPanel>
<StackPanel DockPanel.Dock="Bottom">

34
samples/IntegrationTestApp/MainWindow.axaml.cs

@ -4,6 +4,7 @@ using Avalonia;
using Avalonia.Automation;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.VisualTree;
@ -17,6 +18,7 @@ namespace IntegrationTestApp
{
InitializeComponent();
InitializeViewMenu();
InitializeGesturesTab();
this.AttachDevTools();
AddHandler(Button.ClickEvent, OnButtonClick);
ListBoxItems = Enumerable.Range(0, 100).Select(x => "Item " + x).ToList();
@ -120,6 +122,38 @@ namespace IntegrationTestApp
}
}
private void InitializeGesturesTab()
{
var gestureBorder = this.GetControl<Border>("GestureBorder");
var gestureBorder2 = this.GetControl<Border>("GestureBorder2");
var lastGesture = this.GetControl<TextBlock>("LastGesture");
var resetGestures = this.GetControl<Button>("ResetGestures");
gestureBorder.Tapped += (s, e) => lastGesture.Text = "Tapped";
gestureBorder.DoubleTapped += (s, e) =>
{
lastGesture.Text = "DoubleTapped";
// Testing #8733
gestureBorder.IsVisible = false;
gestureBorder2.IsVisible = true;
};
gestureBorder2.DoubleTapped += (s, e) =>
{
lastGesture.Text = "DoubleTapped2";
};
Gestures.AddRightTappedHandler(gestureBorder, (s, e) => lastGesture.Text = "RightTapped");
resetGestures.Click += (s, e) =>
{
lastGesture.Text = string.Empty;
gestureBorder.IsVisible = true;
gestureBorder2.IsVisible = false;
};
}
private void MenuClicked(object? sender, RoutedEventArgs e)
{
var clickedMenuItemTextBlock = this.Get<TextBlock>("ClickedMenuItem");

14
src/Android/Avalonia.Android/AndroidPlatform.cs

@ -26,21 +26,11 @@ namespace Avalonia
namespace Avalonia.Android
{
class AndroidPlatform : IPlatformSettings
class AndroidPlatform
{
public static readonly AndroidPlatform Instance = new AndroidPlatform();
public static AndroidPlatformOptions Options { get; private set; }
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickSize"/>
public Size TouchDoubleClickSize => new Size(4, 4);
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/>
public TimeSpan TouchDoubleClickTime => TimeSpan.FromMilliseconds(200);
public Size DoubleClickSize => TouchDoubleClickSize;
public TimeSpan DoubleClickTime => TimeSpan.FromMilliseconds(500);
internal static Compositor Compositor { get; private set; }
public static void Initialize()
@ -52,7 +42,7 @@ namespace Avalonia.Android
.Bind<ICursorFactory>().ToTransient<CursorFactory>()
.Bind<IWindowingPlatform>().ToConstant(new WindowingPlatformStub())
.Bind<IKeyboardDevice>().ToSingleton<AndroidKeyboardDevice>()
.Bind<IPlatformSettings>().ToConstant(Instance)
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<IPlatformThreadingInterface>().ToConstant(new AndroidThreadingInterface())
.Bind<IPlatformIconLoader>().ToSingleton<PlatformIconLoaderStub>()
.Bind<IRenderTimer>().ToConstant(new ChoreographerTimer())

25
src/Avalonia.Base/Input/Gestures.cs

@ -1,5 +1,6 @@
using System;
using Avalonia.Interactivity;
using Avalonia.Platform;
using Avalonia.VisualTree;
namespace Avalonia.Input
@ -42,9 +43,8 @@ namespace Avalonia.Input
RoutedEvent.Register<PointerDeltaEventArgs>(
"PointerSwipeGesture", RoutingStrategies.Bubble, typeof(Gestures));
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
private static readonly WeakReference<IInteractive> s_lastPress = new WeakReference<IInteractive>(null);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
private static readonly WeakReference<IInteractive?> s_lastPress = new WeakReference<IInteractive?>(null);
private static Point s_lastPressPoint;
static Gestures()
{
@ -94,10 +94,11 @@ namespace Avalonia.Input
var e = (PointerPressedEventArgs)ev;
var visual = (IVisual)ev.Source;
if (e.ClickCount <= 1)
if (e.ClickCount % 2 == 1)
{
s_isDoubleTapped = false;
s_lastPress.SetTarget(ev.Source);
s_lastPressPoint = e.GetPosition((IVisual)ev.Source);
}
else if (e.ClickCount % 2 == 0 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed)
{
@ -107,10 +108,6 @@ namespace Avalonia.Input
e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e));
}
}
else
{
s_isDoubleTapped = false;
}
}
}
@ -120,9 +117,17 @@ namespace Avalonia.Input
{
var e = (PointerReleasedEventArgs)ev;
if (s_lastPress.TryGetTarget(out var target) && target == e.Source)
if (s_lastPress.TryGetTarget(out var target) &&
target == e.Source &&
e.InitialPressMouseButton is MouseButton.Left or MouseButton.Right)
{
if (e.InitialPressMouseButton == MouseButton.Left || e.InitialPressMouseButton == MouseButton.Right)
var point = e.GetCurrentPoint((IVisual)target);
var settings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
var tapSize = settings?.GetTapSize(point.Pointer.Type) ?? new Size(4, 4);
var tapRect = new Rect(s_lastPressPoint, new Size())
.Inflate(new Thickness(tapSize.Width, tapSize.Height));
if (tapRect.ContainsExclusive(point.Position))
{
if (e.InitialPressMouseButton == MouseButton.Right)
{

6
src/Avalonia.Base/Input/MouseDevice.cs

@ -127,9 +127,9 @@ namespace Avalonia.Input
_pointer.Capture(source);
if (source != null)
{
var settings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
var doubleClickTime = settings?.DoubleClickTime.TotalMilliseconds ?? 500;
var doubleClickSize = settings?.DoubleClickSize ?? new Size(4, 4);
var settings = AvaloniaLocator.Current.GetRequiredService<IPlatformSettings>();
var doubleClickTime = settings.GetDoubleTapTime(PointerType.Mouse).TotalMilliseconds;
var doubleClickSize = settings.GetDoubleTapSize(PointerType.Mouse);
if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
{

5
src/Avalonia.Base/Input/PenDevice.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Avalonia.Input.Raw;
using Avalonia.Platform;
@ -77,8 +78,8 @@ namespace Avalonia.Input
{
pointer.Capture(source);
var settings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
var doubleClickTime = settings?.DoubleClickTime.TotalMilliseconds ?? 500;
var doubleClickSize = settings?.DoubleClickSize ?? new Size(4, 4);
var doubleClickTime = settings?.GetDoubleTapTime(PointerType.Pen).TotalMilliseconds ?? 500;
var doubleClickSize = settings?.GetDoubleTapSize(PointerType.Pen) ?? new Size(4, 4);
if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
{

7
src/Avalonia.Base/Input/TouchDevice.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Avalonia.Input.Raw;
using Avalonia.Platform;
@ -59,16 +60,18 @@ namespace Avalonia.Input
else
{
var settings = AvaloniaLocator.Current.GetRequiredService<IPlatformSettings>();
var doubleClickTime = settings.GetDoubleTapTime(PointerType.Touch).TotalMilliseconds;
var doubleClickSize = settings.GetDoubleTapSize(PointerType.Touch);
if (!_lastClickRect.Contains(args.Position)
|| ev.Timestamp - _lastClickTime > settings.TouchDoubleClickTime.TotalMilliseconds)
|| ev.Timestamp - _lastClickTime > doubleClickTime)
{
_clickCount = 0;
}
++_clickCount;
_lastClickTime = ev.Timestamp;
_lastClickRect = new Rect(args.Position, new Size())
.Inflate(new Thickness(settings.TouchDoubleClickSize.Width / 2, settings.TouchDoubleClickSize.Height / 2));
.Inflate(new Thickness(doubleClickSize.Width / 2, doubleClickSize.Height / 2));
}
target.RaiseEvent(new PointerPressedEventArgs(target, pointer,

30
src/Avalonia.Base/Platform/DefaultPlatformSettings.cs

@ -0,0 +1,30 @@
using System;
using Avalonia.Input;
namespace Avalonia.Platform
{
/// <summary>
/// A default implementation of <see cref="IPlatformSettings"/> for platforms which don't have
/// an OS-specific implementation.
/// </summary>
public class DefaultPlatformSettings : IPlatformSettings
{
public Size GetTapSize(PointerType type)
{
return type switch
{
PointerType.Touch => new(10, 10),
_ => new(4, 4),
};
}
public Size GetDoubleTapSize(PointerType type)
{
return type switch
{
PointerType.Touch => new(16, 16),
_ => new(4, 4),
};
}
public TimeSpan GetDoubleTapTime(PointerType type) => TimeSpan.FromMilliseconds(500);
}
}

22
src/Avalonia.Base/Platform/IPlatformSettings.cs

@ -1,4 +1,5 @@
using System;
using Avalonia.Input;
using Avalonia.Metadata;
namespace Avalonia.Platform
@ -6,18 +7,25 @@ namespace Avalonia.Platform
[Unstable]
public interface IPlatformSettings
{
Size DoubleClickSize { get; }
TimeSpan DoubleClickTime { get; }
/// <summary>
/// The size of the rectangle around the location of a pointer down that a pointer up
/// must occur within in order to register a tap gesture, in device-independent pixels.
/// </summary>
/// <param name="type">The pointer type.</param>
Size GetTapSize(PointerType type);
/// <summary>
/// Determines the size of the area within that you should click twice in order for a double click to be counted.
/// The size of the rectangle around the location of a pointer down that a pointer up
/// must occur within in order to register a double-tap gesture, in device-independent
/// pixels.
/// </summary>
Size TouchDoubleClickSize { get; }
/// <param name="type">The pointer type.</param>
Size GetDoubleTapSize(PointerType type);
/// <summary>
/// Determines the time span that what will be used to determine the double-click.
/// Gets the maximum time that may occur between the first and second click of a double-
/// tap gesture.
/// </summary>
TimeSpan TouchDoubleClickTime { get; }
TimeSpan GetDoubleTapTime(PointerType type);
}
}

8
src/Avalonia.Controls/Automation/AutomationProperties.cs

@ -9,6 +9,11 @@ namespace Avalonia.Automation
/// </summary>
public enum AccessibilityView
{
/// <summary>
/// The control's view is defined by its automation peer.
/// </summary>
Default,
/// <summary>
/// The control is included in the Raw view of the automation tree.
/// </summary>
@ -44,8 +49,7 @@ namespace Avalonia.Automation
public static readonly AttachedProperty<AccessibilityView> AccessibilityViewProperty =
AvaloniaProperty.RegisterAttached<StyledElement, AccessibilityView>(
"AccessibilityView",
typeof(AutomationProperties),
defaultValue: AccessibilityView.Content);
typeof(AutomationProperties));
/// <summary>
/// Defines the AutomationProperties.AccessKey attached property

14
src/Avalonia.Controls/Automation/Peers/AutomationPeer.cs

@ -128,13 +128,13 @@ namespace Avalonia.Automation.Peers
/// Gets a value that indicates whether the element that is associated with this automation
/// peer contains data that is presented to the user.
/// </summary>
public bool IsContentElement() => IsControlElement() && IsContentElementCore();
public bool IsContentElement() => IsContentElementOverrideCore();
/// <summary>
/// Gets a value that indicates whether the element is understood by the user as
/// interactive or as contributing to the logical structure of the control in the GUI.
/// </summary>
public bool IsControlElement() => IsControlElementCore();
public bool IsControlElement() => IsControlElementOverrideCore();
/// <summary>
/// Gets a value indicating whether the control is enabled for user interaction.
@ -247,6 +247,16 @@ namespace Avalonia.Automation.Peers
return GetAutomationControlTypeCore();
}
protected virtual bool IsContentElementOverrideCore()
{
return IsControlElement() && IsContentElementCore();
}
protected virtual bool IsControlElementOverrideCore()
{
return IsControlElementCore();
}
protected virtual object? GetProviderCore(Type providerType)
{
return providerType.IsAssignableFrom(this.GetType()) ? this : null;

16
src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs

@ -149,8 +149,8 @@ namespace Avalonia.Automation.Peers
protected override Rect GetBoundingRectangleCore() => GetBounds(Owner);
protected override string GetClassNameCore() => Owner.GetType().Name;
protected override bool HasKeyboardFocusCore() => Owner.IsFocused;
protected override bool IsContentElementCore() => AutomationProperties.GetAccessibilityView(Owner) >= AccessibilityView.Content;
protected override bool IsControlElementCore() => AutomationProperties.GetAccessibilityView(Owner) >= AccessibilityView.Control;
protected override bool IsContentElementCore() => true;
protected override bool IsControlElementCore() => true;
protected override bool IsEnabledCore() => Owner.IsEnabled;
protected override bool IsKeyboardFocusableCore() => Owner.Focusable;
protected override void SetFocusCore() => Owner.Focus();
@ -160,6 +160,18 @@ namespace Avalonia.Automation.Peers
return AutomationProperties.GetControlTypeOverride(Owner) ?? GetAutomationControlTypeCore();
}
protected override bool IsContentElementOverrideCore()
{
var view = AutomationProperties.GetAccessibilityView(Owner);
return view == AccessibilityView.Default ? IsContentElementCore() : view >= AccessibilityView.Content;
}
protected override bool IsControlElementOverrideCore()
{
var view = AutomationProperties.GetAccessibilityView(Owner);
return view == AccessibilityView.Default ? IsControlElementCore() : view >= AccessibilityView.Control;
}
private static Rect GetBounds(Control control)
{
var root = control.GetVisualRoot();

11
src/Avalonia.DesignerSupport/Remote/PreviewerWindowingPlatform.cs

@ -9,7 +9,7 @@ using Avalonia.Rendering;
namespace Avalonia.DesignerSupport.Remote
{
class PreviewerWindowingPlatform : IWindowingPlatform, IPlatformSettings
class PreviewerWindowingPlatform : IWindowingPlatform
{
static readonly IKeyboardDevice Keyboard = new KeyboardDevice();
private static IAvaloniaRemoteTransportConnection s_transport;
@ -51,7 +51,7 @@ namespace Avalonia.DesignerSupport.Remote
.Bind<IClipboard>().ToSingleton<ClipboardStub>()
.Bind<ICursorFactory>().ToSingleton<CursorFactoryStub>()
.Bind<IKeyboardDevice>().ToConstant(Keyboard)
.Bind<IPlatformSettings>().ToConstant(instance)
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<IPlatformThreadingInterface>().ToConstant(threading)
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
@ -60,12 +60,5 @@ namespace Avalonia.DesignerSupport.Remote
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>();
}
public Size DoubleClickSize { get; } = new Size(2, 2);
public TimeSpan DoubleClickTime { get; } = TimeSpan.FromMilliseconds(500);
public Size TouchDoubleClickSize => new Size(16, 16);
public TimeSpan TouchDoubleClickTime => DoubleClickTime;
}
}

2
src/Avalonia.Headless/AvaloniaHeadlessPlatform.cs

@ -63,7 +63,7 @@ namespace Avalonia.Headless
.Bind<IPlatformThreadingInterface>().ToConstant(new HeadlessPlatformThreadingInterface())
.Bind<IClipboard>().ToSingleton<HeadlessClipboardStub>()
.Bind<ICursorFactory>().ToSingleton<HeadlessCursorFactoryStub>()
.Bind<IPlatformSettings>().ToConstant(new HeadlessPlatformSettingsStub())
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<IPlatformIconLoader>().ToSingleton<HeadlessIconLoaderStub>()
.Bind<IKeyboardDevice>().ToConstant(new KeyboardDevice())
.Bind<IRenderLoop>().ToConstant(new RenderLoop())

10
src/Avalonia.Headless/HeadlessPlatformStubs.cs

@ -65,16 +65,6 @@ namespace Avalonia.Headless
}
}
class HeadlessPlatformSettingsStub : IPlatformSettings
{
public Size DoubleClickSize { get; } = new Size(2, 2);
public TimeSpan DoubleClickTime { get; } = TimeSpan.FromMilliseconds(500);
public Size TouchDoubleClickSize => new Size(16,16);
public TimeSpan TouchDoubleClickTime => DoubleClickTime;
}
class HeadlessGlyphTypefaceImpl : IGlyphTypeface
{
public FontMetrics Metrics => new FontMetrics

14
src/Avalonia.Native/AvaloniaNativePlatform.cs

@ -14,7 +14,7 @@ using MicroCom.Runtime;
namespace Avalonia.Native
{
class AvaloniaNativePlatform : IPlatformSettings, IWindowingPlatform
class AvaloniaNativePlatform : IWindowingPlatform
{
private readonly IAvaloniaNativeFactory _factory;
private AvaloniaNativePlatformOptions _options;
@ -26,16 +26,6 @@ namespace Avalonia.Native
internal static readonly KeyboardDevice KeyboardDevice = new KeyboardDevice();
[CanBeNull] internal static Compositor Compositor { get; private set; }
public Size DoubleClickSize => new Size(4, 4);
public TimeSpan DoubleClickTime => TimeSpan.FromMilliseconds(500); //TODO
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickSize"/>
public Size TouchDoubleClickSize => new Size(16, 16);
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/>
public TimeSpan TouchDoubleClickTime => DoubleClickTime;
public static AvaloniaNativePlatform Initialize(IntPtr factory, AvaloniaNativePlatformOptions options)
{
var result = new AvaloniaNativePlatform(MicroComRuntime.CreateProxyFor<IAvaloniaNativeFactory>(factory, true));
@ -113,7 +103,7 @@ namespace Avalonia.Native
.Bind<ICursorFactory>().ToConstant(new CursorFactory(_factory.CreateCursorFactory()))
.Bind<IPlatformIconLoader>().ToSingleton<IconLoader>()
.Bind<IKeyboardDevice>().ToConstant(KeyboardDevice)
.Bind<IPlatformSettings>().ToConstant(this)
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<IWindowingPlatform>().ToConstant(this)
.Bind<IClipboard>().ToConstant(new ClipboardImpl(_factory.CreateClipboard()))
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))

6
src/Avalonia.Native/DoubleClickHelper.cs

@ -1,3 +1,4 @@
using Avalonia.Input;
using Avalonia.Platform;
namespace Avalonia.Native
@ -13,7 +14,8 @@ namespace Avalonia.Native
Point p)
{
var settings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds;
var doubleClickTime = settings?.GetDoubleTapTime(PointerType.Mouse).TotalMilliseconds ?? 500;
var doubleClickSize = settings?.GetDoubleTapSize(PointerType.Mouse) ?? new Size(4, 4);
if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
{
@ -23,7 +25,7 @@ namespace Avalonia.Native
++_clickCount;
_lastClickTime = timestamp;
_lastClickRect = new Rect(p, new Size())
.Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2));
.Inflate(new Thickness(doubleClickSize.Width / 2, doubleClickSize.Height / 2));
return _clickCount == 2;
}

17
src/Avalonia.X11/Stubs.cs

@ -1,17 +0,0 @@
using System;
using Avalonia.Platform;
namespace Avalonia.X11
{
class PlatformSettingsStub : IPlatformSettings
{
public Size DoubleClickSize { get; } = new Size(2, 2);
public TimeSpan DoubleClickTime { get; } = TimeSpan.FromMilliseconds(500);
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickSize"/>
public Size TouchDoubleClickSize => new Size(16, 16);
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/>
public TimeSpan TouchDoubleClickTime => DoubleClickTime;
}
}

2
src/Avalonia.X11/X11Platform.cs

@ -80,7 +80,7 @@ namespace Avalonia.X11
.Bind<IKeyboardDevice>().ToFunc(() => KeyboardDevice)
.Bind<ICursorFactory>().ToConstant(new X11CursorFactory(Display))
.Bind<IClipboard>().ToConstant(new X11Clipboard(this))
.Bind<IPlatformSettings>().ToConstant(new PlatformSettingsStub())
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<IPlatformIconLoader>().ToConstant(new X11IconLoader())
.Bind<IMountedVolumeInfoProvider>().ToConstant(new LinuxMountedVolumeInfoProvider())
.Bind<IPlatformLifetimeEventsImpl>().ToConstant(new X11PlatformLifetimeEvents(this));

2
src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs

@ -51,7 +51,7 @@ namespace Avalonia.LinuxFramebuffer
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<ICursorFactory>().ToTransient<CursorFactoryStub>()
.Bind<IKeyboardDevice>().ToConstant(new KeyboardDevice())
.Bind<IPlatformSettings>().ToSingleton<PlatformSettings>()
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>();
Compositor = new Compositor(

9
src/Linux/Avalonia.LinuxFramebuffer/Stubs.cs

@ -14,13 +14,4 @@ namespace Avalonia.LinuxFramebuffer
public void Dispose() { }
}
}
internal class PlatformSettings : IPlatformSettings
{
public Size DoubleClickSize { get; } = new Size(4, 4);
public TimeSpan DoubleClickTime { get; } = new TimeSpan(0, 0, 0, 0, 500);
public Size TouchDoubleClickSize => new Size(16,16);
public TimeSpan TouchDoubleClickTime => DoubleClickTime;
}
}

11
src/Web/Avalonia.Web/WindowingPlatform.cs

@ -8,7 +8,7 @@ using Avalonia.Threading;
namespace Avalonia.Web
{
internal class BrowserWindowingPlatform : IWindowingPlatform, IPlatformSettings, IPlatformThreadingInterface
internal class BrowserWindowingPlatform : IWindowingPlatform, IPlatformThreadingInterface
{
private bool _signaled;
private static KeyboardDevice? s_keyboard;
@ -36,7 +36,7 @@ namespace Avalonia.Web
.Bind<IClipboard>().ToSingleton<ClipboardImpl>()
.Bind<ICursorFactory>().ToSingleton<CssCursorFactory>()
.Bind<IKeyboardDevice>().ToConstant(s_keyboard)
.Bind<IPlatformSettings>().ToConstant(instance)
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<IPlatformThreadingInterface>().ToConstant(instance)
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<IRenderTimer>().ToConstant(ManualTriggerRenderTimer.Instance)
@ -45,13 +45,6 @@ namespace Avalonia.Web
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>();
}
public Size DoubleClickSize { get; } = new Size(2, 2);
public TimeSpan DoubleClickTime { get; } = TimeSpan.FromMilliseconds(500);
public Size TouchDoubleClickSize => new Size(16, 16);
public TimeSpan TouchDoubleClickTime => DoubleClickTime;
public void RunLoop(CancellationToken cancellationToken)
{
throw new NotSupportedException();

31
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -130,17 +130,6 @@ namespace Avalonia.Win32
internal static Compositor Compositor { get; private set; }
public Size DoubleClickSize => new Size(
UnmanagedMethods.GetSystemMetrics(UnmanagedMethods.SystemMetric.SM_CXDOUBLECLK),
UnmanagedMethods.GetSystemMetrics(UnmanagedMethods.SystemMetric.SM_CYDOUBLECLK));
public TimeSpan DoubleClickTime => TimeSpan.FromMilliseconds(UnmanagedMethods.GetDoubleClickTime());
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickSize"/>
public Size TouchDoubleClickSize => new Size(16,16);
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/>
public TimeSpan TouchDoubleClickTime => DoubleClickTime;
public static void Initialize()
{
Initialize(new Win32PlatformOptions());
@ -398,5 +387,25 @@ namespace Avalonia.Win32
SetProcessDPIAware();
}
Size IPlatformSettings.GetTapSize(PointerType type)
{
return type switch
{
PointerType.Touch => new(10, 10),
_ => new(GetSystemMetrics(SystemMetric.SM_CXDRAG), GetSystemMetrics(SystemMetric.SM_CYDRAG)),
};
}
Size IPlatformSettings.GetDoubleTapSize(PointerType type)
{
return type switch
{
PointerType.Touch => new(16, 16),
_ => new(GetSystemMetrics(SystemMetric.SM_CXDOUBLECLK), GetSystemMetrics(SystemMetric.SM_CYDOUBLECLK)),
};
}
TimeSpan IPlatformSettings.GetDoubleTapTime(PointerType type) => TimeSpan.FromMilliseconds(GetDoubleClickTime());
}
}

17
src/iOS/Avalonia.iOS/Platform.cs

@ -28,32 +28,19 @@ namespace Avalonia.iOS
public static EaglFeature GlFeature;
public static DisplayLinkTimer Timer;
internal static Compositor Compositor { get; private set; }
class PlatformSettings : IPlatformSettings
{
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickSize"/>
public Size TouchDoubleClickSize => new Size(10, 10);
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/>
public TimeSpan TouchDoubleClickTime => TimeSpan.FromMilliseconds(500);
public Size DoubleClickSize => new Size(4, 4);
public TimeSpan DoubleClickTime => TouchDoubleClickTime;
}
public static void Register()
{
GlFeature ??= new EaglFeature();
Timer ??= new DisplayLinkTimer();
var keyboard = new KeyboardDevice();
AvaloniaLocator.CurrentMutable
.Bind<IPlatformOpenGlInterface>().ToConstant(GlFeature)
.Bind<ICursorFactory>().ToConstant(new CursorFactoryStub())
.Bind<IWindowingPlatform>().ToConstant(new WindowingPlatformStub())
.Bind<IClipboard>().ToConstant(new ClipboardImpl())
.Bind<IPlatformSettings>().ToConstant(new PlatformSettings())
.Bind<IPlatformSettings>().ToSingleton<DefaultPlatformSettings>()
.Bind<IPlatformIconLoader>().ToConstant(new PlatformIconLoaderStub())
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>()
.Bind<IRenderLoop>().ToSingleton<RenderLoop>()

4
tests/Avalonia.Base.UnitTests/Input/TouchDeviceTests.cs

@ -209,7 +209,9 @@ namespace Avalonia.Input.UnitTests
var unitTestApp = UnitTestApplication.Start(
new TestServices(inputManager: new InputManager()));
var iSettingsMock = new Mock<IPlatformSettings>();
iSettingsMock.Setup(x => x.TouchDoubleClickTime).Returns(doubleClickTime);
iSettingsMock.Setup(x => x.GetDoubleTapTime(It.IsAny<PointerType>())).Returns(doubleClickTime);
iSettingsMock.Setup(x => x.GetDoubleTapSize(It.IsAny<PointerType>())).Returns(new Size(16, 16));
iSettingsMock.Setup(x => x.GetTapSize(It.IsAny<PointerType>())).Returns(new Size(16, 16));
AvaloniaLocator.CurrentMutable.BindToSelf(this)
.Bind<IPlatformSettings>().ToConstant(iSettingsMock.Object);
return unitTestApp;

175
tests/Avalonia.IntegrationTests.Appium/GestureTests.cs

@ -0,0 +1,175 @@
using System;
using System.Threading;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Interactions;
using Xunit;
namespace Avalonia.IntegrationTests.Appium
{
[Collection("Default")]
public class GestureTests
{
private readonly AppiumDriver<AppiumWebElement> _session;
public GestureTests(TestAppFixture fixture)
{
_session = fixture.Session;
var tabs = _session.FindElementByAccessibilityId("MainTabs");
var tab = tabs.FindElementByName("Gestures");
tab.Click();
var clear = _session.FindElementByAccessibilityId("ResetGestures");
clear.Click();
}
[Fact]
public void Tapped_Is_Raised()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session).Click(border).Perform();
Assert.Equal("Tapped", lastGesture.Text);
}
[Fact]
public void Tapped_Is_Raised_Slow()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session).ClickAndHold(border).Perform();
Thread.Sleep(2000);
new Actions(_session).Release(border).Perform();
Assert.Equal("Tapped", lastGesture.Text);
}
[Fact]
public void Tapped_Is_Not_Raised_For_Drag()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session)
.ClickAndHold(border)
.MoveByOffset(50, 50)
.Release()
.Perform();
Assert.Equal(string.Empty, lastGesture.Text);
}
[Fact]
public void DoubleTapped_Is_Raised()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session).DoubleClick(border).Perform();
Assert.Equal("DoubleTapped", lastGesture.Text);
}
[Fact]
public void DoubleTapped_Is_Raised_2()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session).ClickAndHold(border).Release().Perform();
Thread.Sleep(100);
// DoubleTapped is raised on second pointer press, not release.
new Actions(_session).ClickAndHold(border).Perform();
try
{
Assert.Equal("DoubleTapped", lastGesture.Text);
}
finally
{
new Actions(_session).Release(border).Perform();
}
}
[Fact]
public void DoubleTapped_Is_Raised_Not_Raised_If_Too_Slow()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session).ClickAndHold(border).Release().Perform();
Thread.Sleep(2000);
new Actions(_session).ClickAndHold(border).Release().Perform();
Assert.Equal("Tapped", lastGesture.Text);
}
[Fact]
public void DoubleTapped_Is_Raised_After_Control_Changes()
{
// #8733
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session)
.MoveToElement(border)
.DoubleClick()
.DoubleClick()
.Perform();
Assert.Equal("DoubleTapped2", lastGesture.Text);
}
[Fact]
public void RightTapped_Is_Raised()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
new Actions(_session).ContextClick(border).Perform();
Assert.Equal("RightTapped", lastGesture.Text);
}
[PlatformFact(TestPlatforms.MacOS)]
public void RightTapped_Is_Raised_2()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
var device = new PointerInputDevice(PointerKind.Mouse);
var b = new ActionBuilder();
b.AddAction(device.CreatePointerMove(border, 50, 50, TimeSpan.FromMilliseconds(100)));
b.AddAction(device.CreatePointerDown(MouseButton.Right));
b.AddAction(device.CreatePointerMove(border, 2, 2, TimeSpan.FromMilliseconds(100)));
b.AddAction(device.CreatePointerUp(MouseButton.Right));
_session.PerformActions(b.ToActionSequenceList());
Assert.Equal("RightTapped", lastGesture.Text);
}
[PlatformFact(TestPlatforms.MacOS)]
public void RightTapped_Is_Not_Raised_For_Drag()
{
var border = _session.FindElementByAccessibilityId("GestureBorder");
var lastGesture = _session.FindElementByAccessibilityId("LastGesture");
var device = new PointerInputDevice(PointerKind.Mouse);
var b = new ActionBuilder();
b.AddAction(device.CreatePointerMove(border, 50, 50, TimeSpan.FromMilliseconds(100)));
b.AddAction(device.CreatePointerDown(MouseButton.Right));
b.AddAction(device.CreatePointerMove(CoordinateOrigin.Pointer, 50, 50, TimeSpan.FromMilliseconds(100)));
b.AddAction(device.CreatePointerUp(MouseButton.Right));
Assert.Equal(string.Empty, lastGesture.Text);
}
}
}
Loading…
Cancel
Save