Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CefGlue.Avalonia/AvaloniaBrowserProcessHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System;
using System.Reactive.Linq;
using Avalonia.ReactiveUI;
using ReactiveUI.Avalonia;
using Xilium.CefGlue.Common.Handlers;

namespace Xilium.CefGlue.Avalonia
Expand Down
4 changes: 2 additions & 2 deletions CefGlue.Avalonia/CefGlue.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

<ItemGroup>
<PackageReference PrivateAssets="all" Include="Avalonia" />
<PackageReference Include="Avalonia.ReactiveUI" />
<PackageReference Include="System.Reactive.Linq" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" />
<PackageReference Include="ReactiveUI.Avalonia" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 11 additions & 9 deletions CefGlue.Avalonia/InputExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using Avalonia;
using Avalonia.Input;
using Avalonia.VisualTree;
Expand Down Expand Up @@ -200,21 +200,23 @@ public static CefDragData GetDragData(this DragEventArgs e)
{
var dragData = CefDragData.Create();

// Files
if (e.Data.Contains(DataFormats.FileNames))
// Avalonia 12 uses DataTransfer.TryGetFiles for asynchronous strongly-typed file extraction
var files = e.DataTransfer.TryGetFiles();
if (files != null)
{
var files = (string[])e.Data.GetFileNames();
foreach (var filePath in files)
foreach (var file in files)
{
var displayName = Path.GetFileName(filePath);
var filePath = file.Path.LocalPath;
var displayName = file.Name;
dragData.AddFile(filePath.Replace("\\", "/"), displayName);
}
}

// Text
if (e.Data.Contains(DataFormats.Text))
// Avalonia 12 Using DataTransfer.TryGetText for Strongly-Typed Text Extraction
var text = e.DataTransfer.TryGetText();
if (!string.IsNullOrWhiteSpace(text))
{
dragData.SetFragmentText(e.Data.GetText());
dragData.SetFragmentText(text);
}

return dragData;
Expand Down
4 changes: 2 additions & 2 deletions CefGlue.Avalonia/Platform/AvaloniaControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void OnLayoutUpdated(object sender, EventArgs e)
SizeChanged?.Invoke(new CefSize((int)_control.Bounds.Width, (int)_control.Bounds.Height));
}

private void OnGotFocus(object sender, GotFocusEventArgs e)
private void OnGotFocus(object sender, FocusChangedEventArgs e)
{
GotFocus?.Invoke();
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public void OpenContextMenu(IEnumerable<MenuEntry> menuEntries, int x, int y, Ce

menu.PlacementAnchor = PopupAnchor.TopLeft;
menu.PlacementGravity = PopupGravity.BottomRight;
menu.PlacementMode = PlacementMode.AnchorAndGravity;
menu.Placement = PlacementMode.AnchorAndGravity;
menu.PlacementRect = new Rect(x, y, 1, 1);
menu.Open(_control);
},
Expand Down
28 changes: 20 additions & 8 deletions CefGlue.Avalonia/Platform/AvaloniaOffScreenControlHost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Collections;
Expand Down Expand Up @@ -173,7 +173,7 @@ private void OnPointerMoved(object sender, PointerEventArgs e)
MouseMoved?.Invoke(e.AsCefMouseEvent(MousePositionReferential));
}

private void OnLostFocus(object sender, RoutedEventArgs e)
private void OnLostFocus(object sender, FocusChangedEventArgs e)
{
LostFocus?.Invoke();
}
Expand All @@ -190,13 +190,16 @@ private void OnDetachedFromVisualTree(object sender, VisualTreeAttachmentEventAr
private void OnAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e)
{
VisibilityChanged?.Invoke(true);
if (e.Root is Window newWindow)
if (e.RootVisual is Window newWindow)
{
_windowStateChangedObservable = newWindow.GetPropertyChangedObservable(Window.WindowStateProperty).Subscribe(OnHostWindowStateChanged);
}
if (e.Root.RenderScaling != RenderSurface.DeviceScaleFactor)

// In Avalonia 12, safely read the current window's scaling factor through TopLevel
var topLevel = TopLevel.GetTopLevel(_control);
if (topLevel != null && topLevel.RenderScaling != RenderSurface.DeviceScaleFactor)
{
RenderSurface.DeviceScaleFactor = (float)e.Root.RenderScaling;
RenderSurface.DeviceScaleFactor = (float)topLevel.RenderScaling;
ScreenInfoChanged?.Invoke(RenderSurface.DeviceScaleFactor);
}
}
Expand Down Expand Up @@ -268,10 +271,19 @@ public async Task<CefDragOperationsMask> StartDrag(CefDragData dragData, CefDrag
var lastPointerEvent = this._lastPointerEvent; // story a copy, since this might be other thread
if (lastPointerEvent != null)
{
var dataObject = new DataObject();
dataObject.Set(DataFormats.Text, dragData.FragmentText);
// Replace the deprecated DataObject with the officially recommended DataTransfer
var dataObject = new DataTransfer();
if (!string.IsNullOrEmpty(dragData.FragmentText))
{
var item = new DataTransferItem();
item.SetText(dragData.FragmentText);
dataObject.Add(item);
}

// Use asynchronous DoDragDropAsync to trigger the OS's native drag-and-drop action
var result = await Dispatcher.UIThread.InvokeAsync(() =>
DragDrop.DoDragDropAsync(lastPointerEvent, dataObject, allowedOps.AsDragDropEffects()));

var result = await Dispatcher.UIThread.InvokeAsync(() => DragDrop.DoDragDrop(lastPointerEvent, dataObject, allowedOps.AsDragDropEffects()));
this._lastPointerEvent = null;
_previousCursor = null;
_currentDragCursor = null;
Expand Down
3 changes: 2 additions & 1 deletion CefGlue.Avalonia/Platform/AvaloniaPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void Open()
{
Dispatcher.UIThread.Post(() =>
{
_popup.Show(_popup.PlacementTarget.GetVisualRoot() as Window);
// Use TopLevel.GetTopLevel to dynamically get ownership of the current rendering root window
_popup.Show(TopLevel.GetTopLevel(_popup.PlacementTarget) as Window);
});
}

Expand Down
2 changes: 1 addition & 1 deletion CefGlue.Avalonia/Platform/ExtendedAvaloniaPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ExtendedAvaloniaPopup : Window
public ExtendedAvaloniaPopup()
{
CanResize = false;
SystemDecorations = SystemDecorations.None;
WindowDecorations = WindowDecorations.None;
Focusable = false;
Topmost = true;
ShowActivated = false;
Expand Down
3 changes: 2 additions & 1 deletion CefGlue.Demo.Avalonia/CefGlue.Demo.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Themes.Simple" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" />
<PackageReference Include="Dotnet.Bundle" />
<PackageReference Include="Avalonia.Diagnostics" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CefGlue.Tests/Events/EventsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void OnBrowserLoadError(object sender, LoadErrorEventArgs e)
taskCompletionSource.SetResult(true);
}
Browser.LoadError += OnBrowserLoadError;
Browser.Address = "http://0.0.0.0"; // navigate to an invalid url
Browser.Address = "http://invalidurl"; // navigate to an invalid url
await taskCompletionSource.Task;
}

Expand Down
3 changes: 2 additions & 1 deletion CefGlue.Tests/Javascript/JavascriptEvaluationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public async Task DateTimeReturn()
{
var expected = DateTime.Parse("2022-12-20T15:50:21.817Z");
var result = await EvaluateJavascript<DateTime>($"return new Date('{expected.ToString("o", CultureInfo.InvariantCulture)}');");
Assert.AreEqual(expected, result);
// Align to UTC before comparison to eliminate local Ticks deviation
Assert.AreEqual(expected.ToUniversalTime(), result.ToUniversalTime());
}

[Test]
Expand Down
8 changes: 4 additions & 4 deletions CefGlue.Tests/Javascript/NativeObjectInteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public async Task MethodParamsArePassed()
Assert.AreEqual(4, result.Length);
Assert.AreEqual(Arg1, result[0]);
Assert.AreEqual(Arg2, result[1]);
Assert.AreEqual(DateTime.Parse(Date), result[2]);
Assert.AreEqual(DateTime.Parse(Date).ToUniversalTime(), ((DateTime)result[2]).ToUniversalTime());
Assert.AreEqual(true, result[3]);
}

Expand Down Expand Up @@ -297,7 +297,7 @@ public async Task MethodWithObjectParamIsPassed()
var arg = (Person) result[0];
Assert.AreEqual("cef", arg.Name);
Assert.AreEqual(10, arg.Age);
Assert.AreEqual(DateTime.Parse(Date), arg.BirthDate);
Assert.AreEqual(DateTime.Parse(Date).ToUniversalTime(), arg.BirthDate.ToUniversalTime());
}

[Test]
Expand Down Expand Up @@ -407,7 +407,7 @@ public async Task NativeObjectMethodDateTimeResultIsReturned()
var result = await nativeObject.ResultTask;

// Assert
Assert.AreEqual(nativeObject.MethodWithDateTimeReturn(), result);
Assert.AreEqual(nativeObject.MethodWithDateTimeReturn().ToUniversalTime(), ((DateTime)result).ToUniversalTime());
}

[Test]
Expand All @@ -420,7 +420,7 @@ public async Task NativeObjectMethodObjectResultIsReturned()
var expected = nativeObject.MethodWithObjectReturn();
Assert.AreEqual(expected.Name, result.Name);
Assert.AreEqual(expected.Age, result.Age);
Assert.AreEqual(expected.BirthDate, result.BirthDate);
Assert.AreEqual(expected.BirthDate.ToUniversalTime(), result.BirthDate.ToUniversalTime());
Assert.AreEqual(expected.Photo, result.Photo);
}

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DotnetVersion>net8.0</DotnetVersion>
<LangVersion>latest</LangVersion>
<CefRedistVersion>120.1.8</CefRedistVersion>
<AvaloniaVersion>11.0.9</AvaloniaVersion>
<AvaloniaVersion>12.1.0</AvaloniaVersion>
<CefRedistOSXVersion>120.1.8</CefRedistOSXVersion>
<CefRedistLinuxVersion>120.1.8</CefRedistLinuxVersion>
<Platforms>x64;ARM64</Platforms>
Expand Down
78 changes: 36 additions & 42 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemDefinitionGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemDefinitionGroup>
<!--
Disable transitive package references
https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets
https://github.com/dotnet/sdk/issues/11803
-->
<PackageReference>
<PrivateAssets>$(PrivateAssets);compile</PrivateAssets>
</PackageReference>
</ItemDefinitionGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Themes.Simple" Version="$(AvaloniaVersion)" />

<PackageVersion Include="Dotnet.Bundle" Version="0.9.13" />
<PackageVersion Include="System.Reactive.Linq" Version="6.0.0-preview.9" />
<PackageVersion Include="System.Text.Json" Version="6.0.1" />
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />

<PackageVersion Include="chromiumembeddedframework.runtime" Version="$(CefRedistVersion)" />
<PackageVersion Include="chromiumembeddedframework.runtime.win-x64" Version="$(CefRedistVersion)" />
<PackageVersion Include="chromiumembeddedframework.runtime.win-arm64" Version="$(CefRedistVersion)" />

<PackageVersion Include="cef.redist.linux64" Version="$(CefRedistLinuxVersion)" />
<PackageVersion Include="cef.redist.linuxarm64" Version="$(CefRedistLinuxVersion)" />

<PackageVersion Include="cef.redist.osx64" Version="$(CefRedistOSXVersion)" />
<PackageVersion Include="cef.redist.osx.arm64" Version="$(CefRedistOSXVersion)" />

<PackageVersion Include="nunit" Version="3.12.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageVersion Include="Moq" Version="4.10.1" />
<PackageVersion Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(DefineConstants), '(^|;)HAS_NLOG($|;)'))">
<PackageVersion Include="NLog" Version="4.6.2" />
</ItemGroup>
</Project>
<PackageReference>
<PrivateAssets>$(PrivateAssets);compile</PrivateAssets>
</PackageReference>
</ItemDefinitionGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Themes.Simple" Version="$(AvaloniaVersion)" />
<PackageVersion Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3" />
<PackageVersion Include="Dotnet.Bundle" Version="0.9.13" />
<PackageVersion Include="ReactiveUI.Avalonia" Version="12.0.3" />
<PackageVersion Include="System.Reactive" Version="7.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.6" />
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />
<PackageVersion Include="chromiumembeddedframework.runtime" Version="$(CefRedistVersion)" />
<PackageVersion Include="chromiumembeddedframework.runtime.win-x64" Version="$(CefRedistVersion)" />
<PackageVersion Include="chromiumembeddedframework.runtime.win-arm64" Version="$(CefRedistVersion)" />
<PackageVersion Include="cef.redist.linux64" Version="$(CefRedistLinuxVersion)" />
<PackageVersion Include="cef.redist.linuxarm64" Version="$(CefRedistLinuxVersion)" />
<PackageVersion Include="cef.redist.osx64" Version="$(CefRedistOSXVersion)" />
<PackageVersion Include="cef.redist.osx.arm64" Version="$(CefRedistOSXVersion)" />
<PackageVersion Include="nunit" Version="3.12.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageVersion Include="Moq" Version="4.10.1" />
<PackageVersion Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="8.0.29" />
</ItemGroup>
<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(DefineConstants), '(^|;)HAS_NLOG($|;)'))">
<PackageVersion Include="NLog" Version="4.6.2" />
</ItemGroup>
</Project>
Loading