|
|
|
@ -7,6 +7,7 @@ using Avalonia.Controls.Primitives; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Input.Raw; |
|
|
|
using Avalonia.Input.TextInput; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Layout; |
|
|
|
using Avalonia.Logging; |
|
|
|
using Avalonia.LogicalTree; |
|
|
|
@ -17,6 +18,8 @@ using Avalonia.Rendering; |
|
|
|
using Avalonia.Styling; |
|
|
|
using Avalonia.Utilities; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Avalonia.Input.Platform; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
@ -76,6 +79,12 @@ namespace Avalonia.Controls |
|
|
|
public static readonly StyledProperty<IBrush> TransparencyBackgroundFallbackProperty = |
|
|
|
AvaloniaProperty.Register<TopLevel, IBrush>(nameof(TransparencyBackgroundFallback), Brushes.White); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="BackRequested"/> event.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly RoutedEvent<RoutedEventArgs> BackRequestedEvent = |
|
|
|
RoutedEvent.Register<TopLevel, RoutedEventArgs>(nameof(BackRequested), RoutingStrategies.Bubble); |
|
|
|
|
|
|
|
private static readonly WeakEvent<IResourceHost, ResourcesChangedEventArgs> |
|
|
|
ResourcesChangedWeakEvent = WeakEvent.Register<IResourceHost, ResourcesChangedEventArgs>( |
|
|
|
(s, h) => s.ResourcesChanged += h, |
|
|
|
@ -89,6 +98,7 @@ namespace Avalonia.Controls |
|
|
|
private readonly IGlobalStyles? _globalStyles; |
|
|
|
private readonly PointerOverPreProcessor? _pointerOverPreProcessor; |
|
|
|
private readonly IDisposable? _pointerOverPreProcessorSubscription; |
|
|
|
private readonly IDisposable? _backGestureSubscription; |
|
|
|
private Size _clientSize; |
|
|
|
private Size? _frameSize; |
|
|
|
private WindowTransparencyLevel _actualTransparencyLevel; |
|
|
|
@ -205,6 +215,48 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
_pointerOverPreProcessor = new PointerOverPreProcessor(this); |
|
|
|
_pointerOverPreProcessorSubscription = _inputManager?.PreProcess.Subscribe(_pointerOverPreProcessor); |
|
|
|
|
|
|
|
if(impl is ITopLevelWithSystemNavigationManager topLevelWithSystemNavigation) |
|
|
|
{ |
|
|
|
topLevelWithSystemNavigation.SystemNavigationManager.BackRequested += (s, e) => |
|
|
|
{ |
|
|
|
e.RoutedEvent = BackRequestedEvent; |
|
|
|
RaiseEvent(e); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
_backGestureSubscription = _inputManager?.PreProcess.Subscribe(e => |
|
|
|
{ |
|
|
|
bool backRequested = false; |
|
|
|
|
|
|
|
if (e is RawKeyEventArgs rawKeyEventArgs && rawKeyEventArgs.Type == RawKeyEventType.KeyDown) |
|
|
|
{ |
|
|
|
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>()?.Back; |
|
|
|
|
|
|
|
if (keymap != null) |
|
|
|
{ |
|
|
|
var keyEvent = new KeyEventArgs() |
|
|
|
{ |
|
|
|
KeyModifiers = (KeyModifiers)rawKeyEventArgs.Modifiers, |
|
|
|
Key = rawKeyEventArgs.Key |
|
|
|
}; |
|
|
|
|
|
|
|
backRequested = keymap.Any( key => key.Matches(keyEvent)); |
|
|
|
} |
|
|
|
} |
|
|
|
else if(e is RawPointerEventArgs pointerEventArgs) |
|
|
|
{ |
|
|
|
backRequested = pointerEventArgs.Type == RawPointerEventType.XButton1Down; |
|
|
|
} |
|
|
|
|
|
|
|
if (backRequested) |
|
|
|
{ |
|
|
|
var backRequestedEventArgs = new RoutedEventArgs(BackRequestedEvent); |
|
|
|
RaiseEvent(backRequestedEventArgs); |
|
|
|
|
|
|
|
e.Handled = backRequestedEventArgs.Handled; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -263,6 +315,15 @@ namespace Avalonia.Controls |
|
|
|
set => SetValue(TransparencyBackgroundFallbackProperty, value); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when physical Back Button is pressed or a back navigation has been requested.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<RoutedEvent> BackRequested |
|
|
|
{ |
|
|
|
add { AddHandler(BackRequestedEvent, value); } |
|
|
|
remove { RemoveHandler(BackRequestedEvent, value); } |
|
|
|
} |
|
|
|
|
|
|
|
public ILayoutManager LayoutManager |
|
|
|
{ |
|
|
|
get |
|
|
|
@ -382,6 +443,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
_pointerOverPreProcessor?.OnCompleted(); |
|
|
|
_pointerOverPreProcessorSubscription?.Dispose(); |
|
|
|
_backGestureSubscription?.Dispose(); |
|
|
|
|
|
|
|
PlatformImpl = null; |
|
|
|
|
|
|
|
|