Browse Source

Merge pull request #8232 from AvaloniaUI/feature/window-integration-tests

Feature/window integration tests
pull/8415/head
Steven Kirk 4 years ago
committed by Steven Kirk
parent
commit
af05fce02e
  1. 6
      src/Avalonia.Controls/TopLevel.cs
  2. 48
      src/Avalonia.Controls/Window.cs
  3. 12
      src/Avalonia.Controls/WindowBase.cs
  4. 27
      tests/Avalonia.Controls.UnitTests/WindowTests.cs

6
src/Avalonia.Controls/TopLevel.cs

@ -465,7 +465,11 @@ namespace Avalonia.Controls
/// Raises the <see cref="Opened"/> event.
/// </summary>
/// <param name="e">The event args.</param>
protected virtual void OnOpened(EventArgs e) => Opened?.Invoke(this, e);
protected virtual void OnOpened(EventArgs e)
{
FrameSize = PlatformImpl?.FrameSize;
Opened?.Invoke(this, e);
}
/// <summary>
/// Raises the <see cref="Closed"/> event.

48
src/Avalonia.Controls/Window.cs

@ -872,10 +872,10 @@ namespace Avalonia.Controls
var scaling = owner?.DesktopScaling ?? PlatformImpl?.DesktopScaling ?? 1;
// TODO: We really need non-client size here.
var rect = new PixelRect(
PixelPoint.Origin,
PixelSize.FromSize(ClientSize, scaling));
// Use frame size, falling back to client size if the platform can't give it to us.
var rect = FrameSize.HasValue ?
new PixelRect(PixelSize.FromSize(FrameSize.Value, scaling)) :
new PixelRect(PixelSize.FromSize(ClientSize, scaling));
if (startupLocation == WindowStartupLocation.CenterScreen)
{
@ -992,28 +992,28 @@ namespace Avalonia.Controls
/// <inheritdoc/>
protected sealed override void HandleResized(Size clientSize, PlatformResizeReason reason)
{
if (ClientSize == clientSize)
return;
var sizeToContent = SizeToContent;
// If auto-sizing is enabled, and the resize came from a user resize (or the reason was
// unspecified) then turn off auto-resizing for any window dimension that is not equal
// to the requested size.
if (sizeToContent != SizeToContent.Manual &&
CanResize &&
reason == PlatformResizeReason.Unspecified ||
reason == PlatformResizeReason.User)
if (ClientSize != clientSize || double.IsNaN(Width) || double.IsNaN(Height))
{
if (clientSize.Width != ClientSize.Width)
sizeToContent &= ~SizeToContent.Width;
if (clientSize.Height != ClientSize.Height)
sizeToContent &= ~SizeToContent.Height;
SizeToContent = sizeToContent;
}
var sizeToContent = SizeToContent;
// If auto-sizing is enabled, and the resize came from a user resize (or the reason was
// unspecified) then turn off auto-resizing for any window dimension that is not equal
// to the requested size.
if (sizeToContent != SizeToContent.Manual &&
CanResize &&
reason == PlatformResizeReason.Unspecified ||
reason == PlatformResizeReason.User)
{
if (clientSize.Width != ClientSize.Width)
sizeToContent &= ~SizeToContent.Width;
if (clientSize.Height != ClientSize.Height)
sizeToContent &= ~SizeToContent.Height;
SizeToContent = sizeToContent;
}
Width = clientSize.Width;
Height = clientSize.Height;
Width = clientSize.Width;
Height = clientSize.Height;
}
base.HandleResized(clientSize, reason);
}

12
src/Avalonia.Controls/WindowBase.cs

@ -217,10 +217,14 @@ namespace Avalonia.Controls
/// <param name="reason">The reason for the resize.</param>
protected override void HandleResized(Size clientSize, PlatformResizeReason reason)
{
ClientSize = clientSize;
FrameSize = PlatformImpl.FrameSize;
LayoutManager.ExecuteLayoutPass();
Renderer?.Resized(clientSize);
FrameSize = PlatformImpl?.FrameSize;
if (ClientSize != clientSize)
{
ClientSize = clientSize;
LayoutManager.ExecuteLayoutPass();
Renderer?.Resized(clientSize);
}
}
/// <summary>

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

@ -695,6 +695,31 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void Width_Height_Should_Not_Be_NaN_After_Show_With_SizeToContent_Manual()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var child = new Canvas
{
Width = 400,
Height = 800,
};
var target = new Window()
{
SizeToContent = SizeToContent.Manual,
Content = child
};
Show(target);
// Values come from MockWindowingPlatform defaults.
Assert.Equal(800, target.Width);
Assert.Equal(600, target.Height);
}
}
[Fact]
public void Width_Height_Should_Not_Be_NaN_After_Show_With_SizeToContent_WidthAndHeight()
{
@ -712,6 +737,8 @@ namespace Avalonia.Controls.UnitTests
Content = child
};
target.GetObservable(Window.WidthProperty).Subscribe(x => { });
Show(target);
Assert.Equal(400, target.Width);

Loading…
Cancel
Save