Browse Source

Add pointer properties to hold event args, fixup some docs.

pull/9652/head
Emmanuel Hansen 4 years ago
parent
commit
6791a2bca1
  1. 18
      src/Avalonia.Base/Input/Gestures.cs
  2. 33
      src/Avalonia.Base/Input/HoldingRoutedEventArgs.cs
  3. 3
      src/Avalonia.Base/Input/InputElement.cs
  4. 4
      src/Avalonia.Controls/Control.cs

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

@ -13,13 +13,6 @@ namespace Avalonia.Input
private static bool s_isHolding; private static bool s_isHolding;
private static CancellationTokenSource? s_holdCancellationToken; private static CancellationTokenSource? s_holdCancellationToken;
/* /// <summary>
/// Defines the <see cref="IsHoldWithMouseEnabled"/> property.
/// </summary>
public static readonly AttachedProperty<bool> IsHoldWithMouseEnabledProperty =
AvaloniaProperty.RegisterAttached<Gestures, Interactive, bool>(
"IsHoldWithMouseEnabled");*/
public static readonly RoutedEvent<TappedEventArgs> TappedEvent = RoutedEvent.Register<TappedEventArgs>( public static readonly RoutedEvent<TappedEventArgs> TappedEvent = RoutedEvent.Register<TappedEventArgs>(
"Tapped", "Tapped",
RoutingStrategies.Bubble, RoutingStrategies.Bubble,
@ -71,6 +64,9 @@ namespace Avalonia.Input
RoutedEvent.Register<PullGestureEventArgs>( RoutedEvent.Register<PullGestureEventArgs>(
"PullGesture", RoutingStrategies.Bubble, typeof(Gestures)); "PullGesture", RoutingStrategies.Bubble, typeof(Gestures));
/// <summary>
/// Occurs when a user performs a press and hold gesture (with a single touch, mouse, or pen/stylus contact).
/// </summary>
public static readonly RoutedEvent<HoldingRoutedEventArgs> HoldingEvent = public static readonly RoutedEvent<HoldingRoutedEventArgs> HoldingEvent =
RoutedEvent.Register<HoldingRoutedEventArgs>( RoutedEvent.Register<HoldingRoutedEventArgs>(
"Holding", RoutingStrategies.Bubble, typeof(Gestures)); "Holding", RoutingStrategies.Bubble, typeof(Gestures));
@ -132,7 +128,7 @@ namespace Avalonia.Input
{ {
if(s_isHolding && ev.Source is Interactive i) if(s_isHolding && ev.Source is Interactive i)
{ {
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled)); i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastPointer.Type));
} }
s_holdCancellationToken?.Cancel(); s_holdCancellationToken?.Cancel();
s_holdCancellationToken?.Dispose(); s_holdCancellationToken?.Dispose();
@ -157,7 +153,7 @@ namespace Avalonia.Input
if (!token.IsCancellationRequested && e.Source is InputElement i && i.IsHoldingEnabled && ( e.Pointer.Type != PointerType.Mouse || i.IsHoldWithMouseEnabled)) if (!token.IsCancellationRequested && e.Source is InputElement i && i.IsHoldingEnabled && ( e.Pointer.Type != PointerType.Mouse || i.IsHoldWithMouseEnabled))
{ {
s_isHolding = true; s_isHolding = true;
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started)); i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started, s_lastPressPoint, s_lastPointer.Type));
} }
}, TimeSpan.FromMilliseconds(300)); }, TimeSpan.FromMilliseconds(300));
} }
@ -196,7 +192,7 @@ namespace Avalonia.Input
if(s_isHolding) if(s_isHolding)
{ {
s_isHolding = false; s_isHolding = false;
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Completed)); i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Completed, s_lastPressPoint, s_lastPointer!.Type));
} }
else if (e.InitialPressMouseButton == MouseButton.Right) else if (e.InitialPressMouseButton == MouseButton.Right)
{ {
@ -241,7 +237,7 @@ namespace Avalonia.Input
if (s_isHolding && ev.Source is Interactive i) if (s_isHolding && ev.Source is Interactive i)
{ {
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled)); i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastPointer!.Type));
} }
} }

33
src/Avalonia.Base/Input/HoldingRoutedEventArgs.cs

@ -5,18 +5,47 @@ namespace Avalonia.Input
{ {
public class HoldingRoutedEventArgs : RoutedEventArgs public class HoldingRoutedEventArgs : RoutedEventArgs
{ {
/// <summary>
/// Gets the state of the <see cref="Gestures.HoldingEvent"/> event.
/// </summary>
public HoldingState HoldingState { get; } public HoldingState HoldingState { get; }
public HoldingRoutedEventArgs(HoldingState holdingState) : base(Gestures.HoldingEvent) /// <summary>
/// Gets the location of the touch, mouse, or pen/stylus contact.
/// </summary>
public Point Position { get; }
/// <summary>
/// Gets the pointer type of the input source.
/// </summary>
public PointerType PointerType { get; }
/// <summary>
/// Initializes a new instance of the <see cref="HoldingRoutedEventArgs"/> class.
/// </summary>
public HoldingRoutedEventArgs(HoldingState holdingState, Point position, PointerType pointerType) : base(Gestures.HoldingEvent)
{ {
HoldingState = holdingState; HoldingState = holdingState;
Position = position;
PointerType = pointerType;
} }
} }
public enum HoldingState public enum HoldingState
{ {
/// <summary>
/// A single contact has been detected and a time threshold is crossed without the contact being lifted, another contact detected, or another gesture started.
/// </summary>
Started, Started,
/// <summary>
/// The single contact is lifted.
/// </summary>
Completed, Completed,
/// <summary>
/// An additional contact is detected or a subsequent gesture (such as a slide) is detected.
/// </summary>
Cancelled, Cancelled,
} }
} }

3
src/Avalonia.Base/Input/InputElement.cs

@ -426,8 +426,7 @@ namespace Avalonia.Input
} }
/// <summary> /// <summary>
/// Gets or sets a value that determines whether the Holding event can originate /// Enables or disables support for the press and hold gesture through the left button on a mouse.
/// from that element.
/// </summary> /// </summary>
public bool IsHoldWithMouseEnabled public bool IsHoldWithMouseEnabled
{ {

4
src/Avalonia.Controls/Control.cs

@ -375,9 +375,9 @@ namespace Avalonia.Controls
private void OnHoldEvent(object? sender, HoldingRoutedEventArgs e) private void OnHoldEvent(object? sender, HoldingRoutedEventArgs e)
{ {
if(e.HoldingState == HoldingState.Completed) if(e.HoldingState == HoldingState.Started)
{ {
// Trigger ContentRequest when hold is complete // Trigger ContentRequest when hold has started
RaiseEvent(new ContextRequestedEventArgs()); RaiseEvent(new ContextRequestedEventArgs());
} }
} }

Loading…
Cancel
Save