Browse Source

Do not use visual children enumerator in TopLevelHost (#21048)

* Add failing test for ExtendClientAreaToDecorationsHint in AttachedToVisualTree

* Do not use visual children enumerator in TopLevelHost
pull/21051/head
Julien Lebosquain 7 months ago
committed by GitHub
parent
commit
0842236630
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      src/Avalonia.Controls/TopLevelHost.cs
  2. 29
      tests/Avalonia.Controls.UnitTests/WindowTests.cs

18
src/Avalonia.Controls/TopLevelHost.cs

@ -51,11 +51,14 @@ internal partial class TopLevelHost : Control
var hasInset = inset != default;
var desiredSize = default(Size);
foreach (var child in VisualChildren)
var children = VisualChildren;
var childrenCount = children.Count;
for (var i = 0; i < childrenCount; i++)
{
if (child is Layoutable l)
if (children[i] is Layoutable l)
{
if (hasInset && ReferenceEquals(child, _topLevel))
if (hasInset && ReferenceEquals(l, _topLevel))
{
// In forced mode, measure the TopLevel with reduced size
var contentSize = new Size(
@ -89,11 +92,14 @@ internal partial class TopLevelHost : Control
var inset = _decorationInset;
var hasInset = inset != default;
foreach (var child in VisualChildren)
var children = VisualChildren;
var childrenCount = children.Count;
for (var i = 0; i < childrenCount; i++)
{
if (child is Layoutable l)
if (children[i] is Layoutable l)
{
if (hasInset && ReferenceEquals(child, _topLevel))
if (hasInset && ReferenceEquals(l, _topLevel))
{
// In forced mode, arrange the TopLevel within the inset area
var contentSize = new Size(

29
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -710,6 +710,35 @@ namespace Avalonia.Controls.UnitTests
Assert.False(visualRoot.HasMirrorTransform);
}
[Fact]
public void Extending_Client_Area_To_Decorations_When_Attached_To_Visual_Tree_Works()
{
var extended = false;
var windowImpl = MockWindowingPlatform.CreateWindowMock();
windowImpl.Setup(w => w.NeedsManagedDecorations).Returns(() => extended);
windowImpl.Setup(w => w.RequestedDrawnDecorations).Returns(PlatformRequestedDrawnDecoration.TitleBar);
using var app = UnitTestApplication.Start(TestServices.StyledWindow.With(
windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object)));
var border = new Border();
var window = new Window
{
Content = border
};
border.AttachedToVisualTree +=
(_, _) =>
{
extended = true;
windowImpl.Object.ExtendClientAreaToDecorationsChanged?.Invoke(true);
};
window.Show();
}
public class SizingTests : ScopedTestBase
{
[Fact]

Loading…
Cancel
Save