Browse Source
Merge pull request #10915 from AvaloniaUI/fixes/stable-popup-pointerposition-with-touch
[stable] Fix popup pointer position with touch
backport-11096
Max Katz
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
26 additions and
6 deletions
-
src/Avalonia.Controls/Primitives/PopupPositioning/IPopupPositioner.cs
-
src/Avalonia.Controls/TopLevel.cs
-
src/Avalonia.Input/ILastPointerPosition.cs
-
src/Avalonia.Input/MouseDevice.cs
-
src/Avalonia.Input/TouchDevice.cs
|
|
|
@ -45,6 +45,7 @@ Copyright © 2019 Nikita Tsukanov |
|
|
|
*/ |
|
|
|
|
|
|
|
using System; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
|
|
|
|
namespace Avalonia.Controls.Primitives.PopupPositioning |
|
|
|
@ -446,13 +447,16 @@ namespace Avalonia.Controls.Primitives.PopupPositioning |
|
|
|
PopupAnchor anchor, PopupGravity gravity, |
|
|
|
PopupPositionerConstraintAdjustment constraintAdjustment, Rect? rect) |
|
|
|
{ |
|
|
|
// We need a better way for tracking the last pointer position
|
|
|
|
var pointer = topLevel.PointToClient(topLevel.PlatformImpl.MouseDevice.Position); |
|
|
|
|
|
|
|
|
|
|
|
positionerParameters.Offset = offset; |
|
|
|
positionerParameters.ConstraintAdjustment = constraintAdjustment; |
|
|
|
if (placement == PlacementMode.Pointer) |
|
|
|
{ |
|
|
|
// We need a better way for tracking the last pointer position
|
|
|
|
var pointer = topLevel.PointToClient( |
|
|
|
(topLevel as ILastPointerPosition)?.LastPointerPosition ?? |
|
|
|
topLevel.PlatformImpl.MouseDevice.Position); |
|
|
|
|
|
|
|
positionerParameters.AnchorRectangle = new Rect(pointer, new Size(1, 1)); |
|
|
|
positionerParameters.Anchor = PopupAnchor.TopLeft; |
|
|
|
positionerParameters.Gravity = PopupGravity.BottomRight; |
|
|
|
|
|
|
|
@ -36,7 +36,8 @@ namespace Avalonia.Controls |
|
|
|
IStyleHost, |
|
|
|
ILogicalRoot, |
|
|
|
ITextInputMethodRoot, |
|
|
|
IWeakEventSubscriber<ResourcesChangedEventArgs> |
|
|
|
IWeakEventSubscriber<ResourcesChangedEventArgs>, |
|
|
|
ILastPointerPosition |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="ClientSize"/> property.
|
|
|
|
@ -92,6 +93,7 @@ namespace Avalonia.Controls |
|
|
|
private WindowTransparencyLevel _actualTransparencyLevel; |
|
|
|
private ILayoutManager _layoutManager; |
|
|
|
private Border _transparencyFallbackBorder; |
|
|
|
private PixelPoint? _lastPointerPosition; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes static members of the <see cref="TopLevel"/> class.
|
|
|
|
@ -315,6 +317,8 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
IRenderTarget IRenderRoot.CreateRenderTarget() => CreateRenderTarget(); |
|
|
|
|
|
|
|
PixelPoint? ILastPointerPosition.LastPointerPosition => _lastPointerPosition; |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
protected virtual IRenderTarget CreateRenderTarget() |
|
|
|
{ |
|
|
|
@ -340,7 +344,9 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
return PlatformImpl?.PointToScreen(p) ?? default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ILastPointerPosition.SetLastPointerPosition(PixelPoint point) => _lastPointerPosition = point; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the layout manager for this <see cref="TopLevel" />.
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
@ -0,0 +1,8 @@ |
|
|
|
namespace Avalonia.Input |
|
|
|
{ |
|
|
|
public interface ILastPointerPosition |
|
|
|
{ |
|
|
|
PixelPoint? LastPointerPosition { get; } |
|
|
|
void SetLastPointerPosition(PixelPoint point); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -150,6 +150,8 @@ namespace Avalonia.Input |
|
|
|
if (e.Type == RawPointerEventType.NonClientLeftButtonDown) return; |
|
|
|
|
|
|
|
_position = e.Root.PointToScreen(e.Position); |
|
|
|
(e.Root as ILastPointerPosition)?.SetLastPointerPosition(_position.Value); |
|
|
|
|
|
|
|
var props = CreateProperties(e); |
|
|
|
var keyModifiers = KeyModifiersUtils.ConvertToKey(e.InputModifiers); |
|
|
|
switch (e.Type) |
|
|
|
|
|
|
|
@ -110,7 +110,7 @@ namespace Avalonia.Input |
|
|
|
GetKeyModifiers(args.InputModifiers), args.IntermediatePoints)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
(ev.Root as ILastPointerPosition)?.SetLastPointerPosition(ev.Root.PointToScreen(args.Position)); |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|