Browse Source
* Make resizing work again * Fix various DOM events on multithreading * Refactor WASM input to work with multithreading * Minor improvements for drag n drop * Use Microsoft.NET.Sdk.WebAssembly in control catalog browser * Shortcut resolved exports * Fix DomHelper.GetCurrentDocumentVisibility not working * Fix embed sample * Remove ManualTriggerRenderTimer * Use pre-saved globalThis instance to make sure that JSImport interop works on a correct threading context * Implement managed dispatcher for browser with event grouping * Fix InputHelper.GetCoalescedEvents usage * Nits after reviewpull/15936/head
committed by
GitHub
30 changed files with 619 additions and 539 deletions
@ -1,36 +1,20 @@ |
|||
using System; |
|||
using Avalonia.Browser.Interop; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
using Avalonia.Threading; |
|||
|
|||
namespace Avalonia.Browser; |
|||
|
|||
internal class BrowserActivatableLifetime : IActivatableLifetime |
|||
internal class BrowserActivatableLifetime : ActivatableLifetimeBase |
|||
{ |
|||
public BrowserActivatableLifetime() |
|||
public void OnVisibilityStateChanged(string visibilityState) |
|||
{ |
|||
bool? initiallyVisible = InputHelper.SubscribeVisibilityChange(visible => |
|||
var visible = visibilityState == "visible"; |
|||
if (visible) |
|||
{ |
|||
initiallyVisible = null; |
|||
(visible ? Activated : Deactivated)?.Invoke(this, new ActivatedEventArgs(ActivationKind.Background)); |
|||
}); |
|||
|
|||
// Trigger Activated as an initial state, if web page is visible, and wasn't hidden during initialization.
|
|||
if (initiallyVisible == true) |
|||
OnActivated(ActivationKind.Background); |
|||
} |
|||
else |
|||
{ |
|||
_ = Dispatcher.UIThread.InvokeAsync(() => |
|||
{ |
|||
if (initiallyVisible == true) |
|||
{ |
|||
Activated?.Invoke(this, new ActivatedEventArgs(ActivationKind.Background)); |
|||
} |
|||
}, DispatcherPriority.Background); |
|||
OnDeactivated(ActivationKind.Background); |
|||
} |
|||
} |
|||
|
|||
public event EventHandler<ActivatedEventArgs>? Activated; |
|||
public event EventHandler<ActivatedEventArgs>? Deactivated; |
|||
|
|||
public bool TryLeaveBackground() => false; |
|||
public bool TryEnterBackground() => false; |
|||
} |
|||
|
|||
@ -1,24 +1,19 @@ |
|||
using System; |
|||
using Avalonia.Browser.Interop; |
|||
using Avalonia.Interactivity; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Browser |
|||
namespace Avalonia.Browser; |
|||
|
|||
internal class BrowserSystemNavigationManagerImpl : ISystemNavigationManagerImpl |
|||
{ |
|||
internal class BrowserSystemNavigationManagerImpl : ISystemNavigationManagerImpl |
|||
{ |
|||
public event EventHandler<RoutedEventArgs>? BackRequested; |
|||
public event EventHandler<RoutedEventArgs>? BackRequested; |
|||
|
|||
public BrowserSystemNavigationManagerImpl() |
|||
{ |
|||
NavigationHelper.AddBackHandler(() => |
|||
{ |
|||
var routedEventArgs = new RoutedEventArgs(); |
|||
public bool OnBackRequested() |
|||
{ |
|||
var routedEventArgs = new RoutedEventArgs(); |
|||
|
|||
BackRequested?.Invoke(this, routedEventArgs); |
|||
BackRequested?.Invoke(this, routedEventArgs); |
|||
|
|||
return routedEventArgs.Handled; |
|||
}); |
|||
} |
|||
return routedEventArgs.Handled; |
|||
} |
|||
} |
|||
|
|||
@ -1,36 +1,53 @@ |
|||
using System; |
|||
using System.Runtime.InteropServices.JavaScript; |
|||
using System.Runtime.InteropServices.JavaScript; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Browser.Interop; |
|||
|
|||
internal static partial class DomHelper |
|||
{ |
|||
[JSImport("globalThis.document.getElementById")] |
|||
internal static partial JSObject? GetElementById(string id); |
|||
[JSImport("AvaloniaDOM.getGlobalThis", AvaloniaModule.MainModuleName)] |
|||
internal static partial JSObject GetGlobalThis(); |
|||
|
|||
[JSImport("AvaloniaDOM.getFirstElementById", AvaloniaModule.MainModuleName)] |
|||
internal static partial JSObject? GetElementById(string id, JSObject parent); |
|||
|
|||
[JSImport("AvaloniaDOM.getFirstElementByClassName", AvaloniaModule.MainModuleName)] |
|||
internal static partial JSObject? GetElementsByClassName(string className, JSObject? parent); |
|||
internal static partial JSObject? GetElementsByClassName(string className, JSObject parent); |
|||
|
|||
[JSImport("AvaloniaDOM.createAvaloniaHost", AvaloniaModule.MainModuleName)] |
|||
public static partial JSObject CreateAvaloniaHost(JSObject element); |
|||
|
|||
[JSImport("AvaloniaDOM.isFullscreen", AvaloniaModule.MainModuleName)] |
|||
public static partial bool IsFullscreen(); |
|||
public static partial bool IsFullscreen(JSObject globalThis); |
|||
|
|||
[JSImport("AvaloniaDOM.setFullscreen", AvaloniaModule.MainModuleName)] |
|||
public static partial JSObject SetFullscreen(bool isFullscreen); |
|||
public static partial Task SetFullscreen(JSObject globalThis, bool isFullscreen); |
|||
|
|||
[JSImport("AvaloniaDOM.getSafeAreaPadding", AvaloniaModule.MainModuleName)] |
|||
public static partial double[] GetSafeAreaPadding(); |
|||
public static partial double[] GetSafeAreaPadding(JSObject globalThis); |
|||
|
|||
[JSImport("AvaloniaDOM.initSafeAreaPadding", AvaloniaModule.MainModuleName)] |
|||
public static partial void InitSafeAreaPadding(); |
|||
[JSImport("AvaloniaDOM.getDarkMode", AvaloniaModule.MainModuleName)] |
|||
public static partial int[] GetDarkMode(JSObject globalThis); |
|||
|
|||
[JSImport("AvaloniaDOM.addClass", AvaloniaModule.MainModuleName)] |
|||
public static partial void AddCssClass(JSObject element, string className); |
|||
|
|||
[JSImport("AvaloniaDOM.observeDarkMode", AvaloniaModule.MainModuleName)] |
|||
public static partial JSObject ObserveDarkMode( |
|||
[JSMarshalAs<JSType.Function<JSType.Boolean, JSType.Boolean>>] |
|||
Action<bool, bool> observer); |
|||
[JSImport("AvaloniaDOM.initGlobalDomEvents", AvaloniaModule.MainModuleName)] |
|||
public static partial void InitGlobalDomEvents(JSObject globalThis); |
|||
|
|||
[JSExport] |
|||
public static Task DarkModeChanged(bool isDarkMode, bool isHighContrast) |
|||
{ |
|||
(AvaloniaLocator.Current.GetService<IPlatformSettings>() as BrowserPlatformSettings)?.OnValuesChanged(isDarkMode, isHighContrast); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
[JSExport] |
|||
public static Task DocumentVisibilityChanged(string visibilityState) |
|||
{ |
|||
(AvaloniaLocator.Current.GetService<IActivatableLifetime>() as BrowserActivatableLifetime)?.OnVisibilityStateChanged(visibilityState); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +0,0 @@ |
|||
using System; |
|||
using System.Diagnostics; |
|||
using Avalonia.Rendering; |
|||
|
|||
namespace Avalonia.Browser |
|||
{ |
|||
internal class ManualTriggerRenderTimer : IRenderTimer |
|||
{ |
|||
private static readonly Stopwatch s_sw = Stopwatch.StartNew(); |
|||
|
|||
public static ManualTriggerRenderTimer Instance { get; } = new(); |
|||
|
|||
public void RaiseTick() => Tick?.Invoke(s_sw.Elapsed); |
|||
|
|||
public event Action<TimeSpan>? Tick; |
|||
public bool RunsInBackground => false; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue