Browse Source

Merge branch 'master' into transitioninstance

pull/3198/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
df486e1816
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 76
      CODE_OF_CONDUCT.md
  2. 1
      build/Base.props
  3. 1
      build/BuildTargets.targets
  4. 4
      native/Avalonia.Native/src/OSX/window.mm
  5. 2
      packages/Avalonia/AvaloniaBuildTasks.targets
  6. 8
      readme.md
  7. 12
      src/Avalonia.Base/ValueStore.cs
  8. 4
      src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs
  9. 3
      src/Avalonia.Build.Tasks/Program.cs
  10. 4
      src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs
  11. 5
      src/Avalonia.Controls/AppBuilderBase.cs
  12. 9
      src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs
  13. 2
      src/Avalonia.Controls/AutoCompleteBox.cs
  14. 13
      src/Avalonia.Controls/ColumnDefinition.cs
  15. 54
      src/Avalonia.Controls/DefinitionBase.cs
  16. 1
      src/Avalonia.Controls/DesktopApplicationExtensions.cs
  17. 23
      src/Avalonia.Controls/Grid.cs
  18. 8
      src/Avalonia.Controls/ItemsControl.cs
  19. 3
      src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
  20. 6
      src/Avalonia.Controls/Platform/InProcessDragSource.cs
  21. 2
      src/Avalonia.Controls/Primitives/PopupRoot.cs
  22. 4
      src/Avalonia.Controls/Primitives/Thumb.cs
  23. 2
      src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs
  24. 13
      src/Avalonia.Controls/RowDefinition.cs
  25. 18
      src/Avalonia.Input/DragDropDevice.cs
  26. 102
      src/Avalonia.Input/KeyboardDevice.cs
  27. 6
      src/Avalonia.Input/Raw/RawDragEvent.cs
  28. 9
      src/Avalonia.Input/Raw/RawInputEventArgs.cs
  29. 3
      src/Avalonia.Input/Raw/RawKeyEventArgs.cs
  30. 8
      src/Avalonia.Input/Raw/RawPointerEventArgs.cs
  31. 11
      src/Avalonia.Input/Raw/RawTextInputEventArgs.cs
  32. 4
      src/Avalonia.Native/WindowImplBase.cs
  33. 7
      src/Avalonia.Themes.Default/Accents/BaseDark.xaml
  34. 16
      src/Avalonia.Themes.Default/Accents/BaseLight.xaml
  35. 8
      src/Avalonia.Themes.Default/ContextMenu.xaml
  36. 29
      src/Avalonia.Themes.Default/MenuItem.xaml
  37. 6
      src/Avalonia.Themes.Default/RepeatButton.xaml
  38. 264
      src/Avalonia.Themes.Default/ScrollBar.xaml
  39. 1
      src/Avalonia.Themes.Default/ScrollViewer.xaml
  40. 19
      src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
  41. 12
      src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs
  42. 4
      src/Avalonia.X11/X11Window.cs
  43. 6
      src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs
  44. 2
      src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github
  45. 6
      src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs
  46. 9
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  47. 4
      src/Windows/Avalonia.Win32/OleDropTarget.cs
  48. 26
      src/Windows/Avalonia.Win32/ScreenImpl.cs
  49. 4
      src/Windows/Avalonia.Win32/WindowImpl.cs
  50. 12
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Validation.cs
  51. 18
      tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs
  52. 286
      tests/Avalonia.Controls.UnitTests/GridTests.cs
  53. 28
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
  54. 1
      tests/Avalonia.Controls.UnitTests/TopLevelTests.cs
  55. 90
      tests/Avalonia.Input.UnitTests/KeyboardDeviceTests.cs
  56. 6
      tests/Avalonia.ReactiveUI.UnitTests/AutoSuspendHelperTest.cs
  57. 12
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/DeferredDrawingContextImplTests.cs
  58. 52
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs
  59. 21
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/VisualNodeTests.cs

76
CODE_OF_CONDUCT.md

@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at steven@avaloniaui.net. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

1
build/Base.props

@ -1,5 +1,6 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" /> <PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

1
build/BuildTargets.targets

@ -2,6 +2,7 @@
<PropertyGroup> <PropertyGroup>
<AvaloniaBuildTasksLocation>$(MSBuildThisFileDirectory)\..\src\Avalonia.Build.Tasks\bin\$(Configuration)\netstandard2.0\Avalonia.Build.Tasks.dll</AvaloniaBuildTasksLocation> <AvaloniaBuildTasksLocation>$(MSBuildThisFileDirectory)\..\src\Avalonia.Build.Tasks\bin\$(Configuration)\netstandard2.0\Avalonia.Build.Tasks.dll</AvaloniaBuildTasksLocation>
<AvaloniaUseExternalMSBuild>true</AvaloniaUseExternalMSBuild> <AvaloniaUseExternalMSBuild>true</AvaloniaUseExternalMSBuild>
<AvaloniaXamlIlVerifyIl>true</AvaloniaXamlIlVerifyIl>
</PropertyGroup> </PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)\..\packages\Avalonia\AvaloniaBuildTasks.props"/> <Import Project="$(MSBuildThisFileDirectory)\..\packages\Avalonia\AvaloniaBuildTasks.props"/>
<Import Project="$(MSBuildThisFileDirectory)\..\packages\Avalonia\AvaloniaBuildTasks.targets"/> <Import Project="$(MSBuildThisFileDirectory)\..\packages\Avalonia\AvaloniaBuildTasks.targets"/>

4
native/Avalonia.Native/src/OSX/window.mm

@ -855,8 +855,8 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
if(type == Wheel) if(type == Wheel)
{ {
delta.X = [event scrollingDeltaX] / 5; delta.X = [event scrollingDeltaX] / 50;
delta.Y = [event scrollingDeltaY] / 5; delta.Y = [event scrollingDeltaY] / 50;
if(delta.X == 0 && delta.Y == 0) if(delta.X == 0 && delta.Y == 0)
{ {

2
packages/Avalonia/AvaloniaBuildTasks.targets

@ -53,6 +53,7 @@
<PropertyGroup> <PropertyGroup>
<AvaloniaXamlReferencesTemporaryFilePath Condition="'$(AvaloniaXamlReferencesTemporaryFilePath)' == ''">$(IntermediateOutputPath)/Avalonia/references</AvaloniaXamlReferencesTemporaryFilePath> <AvaloniaXamlReferencesTemporaryFilePath Condition="'$(AvaloniaXamlReferencesTemporaryFilePath)' == ''">$(IntermediateOutputPath)/Avalonia/references</AvaloniaXamlReferencesTemporaryFilePath>
<AvaloniaXamlOriginalCopyFilePath Condition="'$(AvaloniaXamlOriginalCopyFilePath)' == ''">$(IntermediateOutputPath)/Avalonia/original.dll</AvaloniaXamlOriginalCopyFilePath> <AvaloniaXamlOriginalCopyFilePath Condition="'$(AvaloniaXamlOriginalCopyFilePath)' == ''">$(IntermediateOutputPath)/Avalonia/original.dll</AvaloniaXamlOriginalCopyFilePath>
<AvaloniaXamlIlVerifyIl Condition="'$(AvaloniaXamlIlVerifyIl)' == ''">false</AvaloniaXamlIlVerifyIl>
</PropertyGroup> </PropertyGroup>
<WriteLinesToFile <WriteLinesToFile
Condition="'$(_AvaloniaForceInternalMSBuild)' != 'true'" Condition="'$(_AvaloniaForceInternalMSBuild)' != 'true'"
@ -65,6 +66,7 @@
ReferencesFilePath="$(AvaloniaXamlReferencesTemporaryFilePath)" ReferencesFilePath="$(AvaloniaXamlReferencesTemporaryFilePath)"
OriginalCopyPath="$(AvaloniaXamlOriginalCopyFilePath)" OriginalCopyPath="$(AvaloniaXamlOriginalCopyFilePath)"
ProjectDirectory="$(MSBuildProjectDirectory)" ProjectDirectory="$(MSBuildProjectDirectory)"
VerifyIl="$(AvaloniaXamlIlVerifyIl)"
/> />
<Exec <Exec
Condition="'$(_AvaloniaUseExternalMSBuild)' == 'true'" Condition="'$(_AvaloniaUseExternalMSBuild)' == 'true'"

8
readme.md

@ -8,9 +8,9 @@
## About ## About
**Avalonia** is a WPF/UWP-inspired cross-platform XAML-based UI framework providing a flexible styling system and supporting a wide range of Operating Systems such as Windows (.NET Framework, .NET Core), Linux (via Xorg), MacOS and with experimental support for Android and iOS. **Avalonia** is a WPF/UWP-inspired cross-platform XAML-based UI framework providing a flexible styling system and supporting a wide range of Operating Systems such as Windows (.NET Framework, .NET Core), Linux (via Xorg), macOS and with experimental support for Android and iOS.
**Avalonia** is ready for **General-Purpose Desktop App Development**. However there may be some bugs and breaking changes as we continue along into this project's development. To see the status for some of our features, please see our [Roadmap here](https://github.com/AvaloniaUI/Avalonia/issues/2239). **Avalonia** is ready for **General-Purpose Desktop App Development**. However, there may be some bugs and breaking changes as we continue along into this project's development. To see the status of some of our features, please see our [Roadmap here](https://github.com/AvaloniaUI/Avalonia/issues/2239).
| Control catalog | Desktop platforms | Mobile platforms | | Control catalog | Desktop platforms | Mobile platforms |
|---|---|---| |---|---|---|
@ -20,11 +20,11 @@
Avalonia [Visual Studio Extension](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaforVisualStudio) contains project and control templates that will help you get started. After installing it, open "New Project" dialog in Visual Studio, choose "Avalonia" in "Visual C#" section, select "Avalonia .NET Core Application" and press OK (<a href="http://avaloniaui.net/docs/quickstart/images/new-project-dialog.png">screenshot</a>). Now you can write code and markup that will work on multiple platforms! Avalonia [Visual Studio Extension](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaforVisualStudio) contains project and control templates that will help you get started. After installing it, open "New Project" dialog in Visual Studio, choose "Avalonia" in "Visual C#" section, select "Avalonia .NET Core Application" and press OK (<a href="http://avaloniaui.net/docs/quickstart/images/new-project-dialog.png">screenshot</a>). Now you can write code and markup that will work on multiple platforms!
For those without Visual Studio, starter guide for .NET Core CLI can be found [here](http://avaloniaui.net/docs/quickstart/create-new-project#net-core). For those without Visual Studio, a starter guide for .NET Core CLI can be found [here](http://avaloniaui.net/docs/quickstart/create-new-project#net-core).
Avalonia is delivered via <b>NuGet</b> package manager. You can find the packages here: ([stable(ish)](https://www.nuget.org/packages/Avalonia/), [nightly](https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed)) Avalonia is delivered via <b>NuGet</b> package manager. You can find the packages here: ([stable(ish)](https://www.nuget.org/packages/Avalonia/), [nightly](https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed))
Use these commands in Package Manager console to install Avalonia manually: Use these commands in the Package Manager console to install Avalonia manually:
``` ```
Install-Package Avalonia Install-Package Avalonia
Install-Package Avalonia.Desktop Install-Package Avalonia.Desktop

12
src/Avalonia.Base/ValueStore.cs

@ -57,7 +57,8 @@ namespace Avalonia
{ {
if (priority == (int)BindingPriority.LocalValue) if (priority == (int)BindingPriority.LocalValue)
{ {
_propertyValues.SetValue(property, Validate(property, value)); Validate(property, ref value);
_propertyValues.SetValue(property, value);
Changed(property, priority, v, value); Changed(property, priority, v, value);
return; return;
} }
@ -78,7 +79,8 @@ namespace Avalonia
if (priority == (int)BindingPriority.LocalValue) if (priority == (int)BindingPriority.LocalValue)
{ {
_propertyValues.AddValue(property, Validate(property, value)); Validate(property, ref value);
_propertyValues.AddValue(property, value);
Changed(property, priority, AvaloniaProperty.UnsetValue, value); Changed(property, priority, AvaloniaProperty.UnsetValue, value);
return; return;
} }
@ -166,16 +168,14 @@ namespace Avalonia
validate2); validate2);
} }
private object Validate(AvaloniaProperty property, object value) private void Validate(AvaloniaProperty property, ref object value)
{ {
var validate = ((IStyledPropertyAccessor)property).GetValidationFunc(_owner.GetType()); var validate = ((IStyledPropertyAccessor)property).GetValidationFunc(_owner.GetType());
if (validate != null && value != AvaloniaProperty.UnsetValue) if (validate != null && value != AvaloniaProperty.UnsetValue)
{ {
return validate(_owner, value); value = validate(_owner, value);
} }
return value;
} }
private DeferredSetter<T> GetDeferredSetter<T>(AvaloniaProperty property) private DeferredSetter<T> GetDeferredSetter<T>(AvaloniaProperty property)

4
src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs

@ -34,7 +34,7 @@ namespace Avalonia.Build.Tasks
var res = XamlCompilerTaskExecutor.Compile(BuildEngine, input, var res = XamlCompilerTaskExecutor.Compile(BuildEngine, input,
File.ReadAllLines(ReferencesFilePath).Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(), File.ReadAllLines(ReferencesFilePath).Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(),
ProjectDirectory, OutputPath); ProjectDirectory, OutputPath, VerifyIl);
if (!res.Success) if (!res.Success)
return false; return false;
if (!res.WrittenFile) if (!res.WrittenFile)
@ -66,6 +66,8 @@ namespace Avalonia.Build.Tasks
public string ProjectDirectory { get; set; } public string ProjectDirectory { get; set; }
public string OutputPath { get; set; } public string OutputPath { get; set; }
public bool VerifyIl { get; set; }
public IBuildEngine BuildEngine { get; set; } public IBuildEngine BuildEngine { get; set; }
public ITaskHost HostObject { get; set; } public ITaskHost HostObject { get; set; }

3
src/Avalonia.Build.Tasks/Program.cs

@ -28,7 +28,8 @@ namespace Avalonia.Build.Tasks
ReferencesFilePath = args[1], ReferencesFilePath = args[1],
OutputPath = args[2], OutputPath = args[2],
BuildEngine = new ConsoleBuildEngine(), BuildEngine = new ConsoleBuildEngine(),
ProjectDirectory = Directory.GetCurrentDirectory() ProjectDirectory = Directory.GetCurrentDirectory(),
VerifyIl = true
}.Execute() ? }.Execute() ?
0 : 0 :
2; 2;

4
src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs

@ -40,7 +40,7 @@ namespace Avalonia.Build.Tasks
} }
public static CompileResult Compile(IBuildEngine engine, string input, string[] references, string projectDirectory, public static CompileResult Compile(IBuildEngine engine, string input, string[] references, string projectDirectory,
string output) string output, bool verifyIl)
{ {
var typeSystem = new CecilTypeSystem(references.Concat(new[] {input}), input); var typeSystem = new CecilTypeSystem(references.Concat(new[] {input}), input);
var asm = typeSystem.TargetAssemblyDefinition; var asm = typeSystem.TargetAssemblyDefinition;
@ -65,7 +65,7 @@ namespace Avalonia.Build.Tasks
var contextClass = XamlIlContextDefinition.GenerateContextClass(typeSystem.CreateTypeBuilder(contextDef), typeSystem, var contextClass = XamlIlContextDefinition.GenerateContextClass(typeSystem.CreateTypeBuilder(contextDef), typeSystem,
xamlLanguage); xamlLanguage);
var compiler = new AvaloniaXamlIlCompiler(compilerConfig, contextClass); var compiler = new AvaloniaXamlIlCompiler(compilerConfig, contextClass) { EnableIlVerification = verifyIl };
var editorBrowsableAttribute = typeSystem var editorBrowsableAttribute = typeSystem
.GetTypeReference(typeSystem.FindType("System.ComponentModel.EditorBrowsableAttribute")) .GetTypeReference(typeSystem.FindType("System.ComponentModel.EditorBrowsableAttribute"))

5
src/Avalonia.Controls/AppBuilderBase.cs

@ -125,9 +125,8 @@ namespace Avalonia.Controls
}); });
// Copy-pasted because we can't call extension methods due to generic constraints // Copy-pasted because we can't call extension methods due to generic constraints
var lifetime = new ClassicDesktopStyleApplicationLifetime(Instance) {ShutdownMode = ShutdownMode.OnMainWindowClose}; var lifetime = new ClassicDesktopStyleApplicationLifetime() {ShutdownMode = ShutdownMode.OnMainWindowClose};
Instance.ApplicationLifetime = lifetime; SetupWithLifetime(lifetime);
SetupWithoutStarting();
lifetime.Start(Array.Empty<string>()); lifetime.Start(Array.Empty<string>());
} }

9
src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs

@ -5,12 +5,12 @@ using System.Threading;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Threading;
namespace Avalonia.Controls.ApplicationLifetimes namespace Avalonia.Controls.ApplicationLifetimes
{ {
public class ClassicDesktopStyleApplicationLifetime : IClassicDesktopStyleApplicationLifetime, IDisposable public class ClassicDesktopStyleApplicationLifetime : IClassicDesktopStyleApplicationLifetime, IDisposable
{ {
private readonly Application _app;
private int _exitCode; private int _exitCode;
private CancellationTokenSource _cts; private CancellationTokenSource _cts;
private bool _isShuttingDown; private bool _isShuttingDown;
@ -34,12 +34,11 @@ namespace Avalonia.Controls.ApplicationLifetimes
_activeLifetime?._windows.Add((Window)sender); _activeLifetime?._windows.Add((Window)sender);
} }
public ClassicDesktopStyleApplicationLifetime(Application app) public ClassicDesktopStyleApplicationLifetime()
{ {
if (_activeLifetime != null) if (_activeLifetime != null)
throw new InvalidOperationException( throw new InvalidOperationException(
"Can not have multiple active ClassicDesktopStyleApplicationLifetime instances and the previously created one was not disposed"); "Can not have multiple active ClassicDesktopStyleApplicationLifetime instances and the previously created one was not disposed");
_app = app;
_activeLifetime = this; _activeLifetime = this;
} }
@ -103,7 +102,7 @@ namespace Avalonia.Controls.ApplicationLifetimes
Startup?.Invoke(this, new ControlledApplicationLifetimeStartupEventArgs(args)); Startup?.Invoke(this, new ControlledApplicationLifetimeStartupEventArgs(args));
_cts = new CancellationTokenSource(); _cts = new CancellationTokenSource();
MainWindow?.Show(); MainWindow?.Show();
_app.Run(_cts.Token); Dispatcher.UIThread.MainLoop(_cts.Token);
Environment.ExitCode = _exitCode; Environment.ExitCode = _exitCode;
return _exitCode; return _exitCode;
} }
@ -124,7 +123,7 @@ namespace Avalonia
this T builder, string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose) this T builder, string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose)
where T : AppBuilderBase<T>, new() where T : AppBuilderBase<T>, new()
{ {
var lifetime = new ClassicDesktopStyleApplicationLifetime(builder.Instance) {ShutdownMode = shutdownMode}; var lifetime = new ClassicDesktopStyleApplicationLifetime() {ShutdownMode = shutdownMode};
builder.SetupWithLifetime(lifetime); builder.SetupWithLifetime(lifetime);
return lifetime.Start(args); return lifetime.Start(args);
} }

2
src/Avalonia.Controls/AutoCompleteBox.cs

@ -704,7 +704,7 @@ namespace Avalonia.Controls
added.Add(e.NewValue); added.Add(e.NewValue);
} }
OnSelectionChanged(new SelectionChangedEventArgs(SelectionChangedEvent, removed, added)); OnSelectionChanged(new SelectionChangedEventArgs(SelectionChangedEvent, added, removed));
} }
/// <summary> /// <summary>

13
src/Avalonia.Controls/ColumnDefinition.cs

@ -26,6 +26,16 @@ namespace Avalonia.Controls
public static readonly StyledProperty<GridLength> WidthProperty = public static readonly StyledProperty<GridLength> WidthProperty =
AvaloniaProperty.Register<ColumnDefinition, GridLength>(nameof(Width), new GridLength(1, GridUnitType.Star)); AvaloniaProperty.Register<ColumnDefinition, GridLength>(nameof(Width), new GridLength(1, GridUnitType.Star));
/// <summary>
/// Initializes static members of the <see cref="ColumnDefinition"/> class.
/// </summary>
static ColumnDefinition()
{
AffectsParentMeasure(MinWidthProperty, MaxWidthProperty);
WidthProperty.Changed.AddClassHandler<DefinitionBase>(OnUserSizePropertyChanged);
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ColumnDefinition"/> class. /// Initializes a new instance of the <see cref="ColumnDefinition"/> class.
/// </summary> /// </summary>
@ -68,7 +78,6 @@ namespace Avalonia.Controls
} }
set set
{ {
Parent?.InvalidateMeasure();
SetValue(MaxWidthProperty, value); SetValue(MaxWidthProperty, value);
} }
} }
@ -84,7 +93,6 @@ namespace Avalonia.Controls
} }
set set
{ {
Parent?.InvalidateMeasure();
SetValue(MinWidthProperty, value); SetValue(MinWidthProperty, value);
} }
} }
@ -100,7 +108,6 @@ namespace Avalonia.Controls
} }
set set
{ {
Parent?.InvalidateMeasure();
SetValue(WidthProperty, value); SetValue(WidthProperty, value);
} }
} }

54
src/Avalonia.Controls/DefinitionBase.cs

@ -7,9 +7,6 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Utilities; using Avalonia.Utilities;
namespace Avalonia.Controls namespace Avalonia.Controls
@ -50,6 +47,8 @@ namespace Avalonia.Controls
} }
} }
} }
Parent?.InvalidateMeasure();
} }
/// <summary> /// <summary>
@ -63,6 +62,8 @@ namespace Avalonia.Controls
_sharedState.RemoveMember(this); _sharedState.RemoveMember(this);
_sharedState = null; _sharedState = null;
} }
Parent?.InvalidateMeasure();
} }
/// <summary> /// <summary>
@ -114,6 +115,36 @@ namespace Avalonia.Controls
} }
} }
/// <remarks>
/// Notifies parent <see cref="Grid"/> or size scope that definition size has been changed.
/// </remarks>
internal static void OnUserSizePropertyChanged(DefinitionBase definition, AvaloniaPropertyChangedEventArgs e)
{
if (definition.Parent == null)
{
return;
}
if (definition._sharedState != null)
{
definition._sharedState.Invalidate();
}
else
{
GridUnitType oldUnitType = ((GridLength)e.OldValue).GridUnitType;
GridUnitType newUnitType = ((GridLength)e.NewValue).GridUnitType;
if (oldUnitType != newUnitType)
{
definition.Parent.Invalidate();
}
else
{
definition.Parent.InvalidateMeasure();
}
}
}
/// <summary> /// <summary>
/// Returns <c>true</c> if this definition is a part of shared group. /// Returns <c>true</c> if this definition is a part of shared group.
/// </summary> /// </summary>
@ -730,5 +761,22 @@ namespace Avalonia.Controls
SharedSizeGroupProperty.Changed.AddClassHandler<DefinitionBase>(OnSharedSizeGroupPropertyChanged); SharedSizeGroupProperty.Changed.AddClassHandler<DefinitionBase>(OnSharedSizeGroupPropertyChanged);
PrivateSharedSizeScopeProperty.Changed.AddClassHandler<DefinitionBase>(OnPrivateSharedSizeScopePropertyChanged); PrivateSharedSizeScopeProperty.Changed.AddClassHandler<DefinitionBase>(OnPrivateSharedSizeScopePropertyChanged);
} }
/// <summary>
/// Marks a property on a definition as affecting the parent grid's measurement.
/// </summary>
/// <param name="properties">The properties.</param>
protected static void AffectsParentMeasure(params AvaloniaProperty[] properties)
{
void Invalidate(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as DefinitionBase)?.Parent?.InvalidateMeasure();
}
foreach (var property in properties)
{
property.Changed.Subscribe(Invalidate);
}
}
} }
} }

1
src/Avalonia.Controls/DesktopApplicationExtensions.cs

@ -50,6 +50,7 @@ namespace Avalonia.Controls
/// On desktop-style platforms runs the application's main loop with custom CancellationToken /// On desktop-style platforms runs the application's main loop with custom CancellationToken
/// without setting a lifetime. /// without setting a lifetime.
/// </summary> /// </summary>
/// <param name="app">The application.</param>
/// <param name="token">The token to track.</param> /// <param name="token">The token to track.</param>
public static void Run(this Application app, CancellationToken token) public static void Run(this Application app, CancellationToken token)
{ {

23
src/Avalonia.Controls/Grid.cs

@ -6,6 +6,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -24,13 +25,14 @@ namespace Avalonia.Controls
{ {
static Grid() static Grid()
{ {
IsSharedSizeScopeProperty.Changed.AddClassHandler<Control>(DefinitionBase.OnIsSharedSizeScopePropertyChanged);
ShowGridLinesProperty.Changed.AddClassHandler<Grid>(OnShowGridLinesPropertyChanged); ShowGridLinesProperty.Changed.AddClassHandler<Grid>(OnShowGridLinesPropertyChanged);
ColumnProperty.Changed.AddClassHandler<Grid>(OnCellAttachedPropertyChanged); IsSharedSizeScopeProperty.Changed.AddClassHandler<Control>(DefinitionBase.OnIsSharedSizeScopePropertyChanged);
ColumnSpanProperty.Changed.AddClassHandler<Grid>(OnCellAttachedPropertyChanged); ColumnProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
RowProperty.Changed.AddClassHandler<Grid>(OnCellAttachedPropertyChanged); ColumnSpanProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
RowSpanProperty.Changed.AddClassHandler<Grid>(OnCellAttachedPropertyChanged); RowProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
RowSpanProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
AffectsParentMeasure<Grid>(ColumnProperty, ColumnSpanProperty, RowProperty, RowSpanProperty); AffectsParentMeasure<Grid>(ColumnProperty, ColumnSpanProperty, RowProperty, RowSpanProperty);
} }
@ -177,6 +179,7 @@ namespace Avalonia.Controls
if (_data == null) { _data = new ExtendedData(); } if (_data == null) { _data = new ExtendedData(); }
_data.ColumnDefinitions = value; _data.ColumnDefinitions = value;
_data.ColumnDefinitions.Parent = this; _data.ColumnDefinitions.Parent = this;
InvalidateMeasure();
} }
} }
@ -197,6 +200,7 @@ namespace Avalonia.Controls
if (_data == null) { _data = new ExtendedData(); } if (_data == null) { _data = new ExtendedData(); }
_data.RowDefinitions = value; _data.RowDefinitions = value;
_data.RowDefinitions.Parent = this; _data.RowDefinitions.Parent = this;
InvalidateMeasure();
} }
} }
@ -568,6 +572,15 @@ namespace Avalonia.Controls
return (arrangeSize); return (arrangeSize);
} }
/// <summary>
/// <see cref="Panel.ChildrenChanged"/>
/// </summary>
protected override void ChildrenChanged(object sender, NotifyCollectionChangedEventArgs e)
{
CellsStructureDirty = true;
base.ChildrenChanged(sender, e);
}
/// <summary> /// <summary>
/// Invalidates grid caches and makes the grid dirty for measure. /// Invalidates grid caches and makes the grid dirty for measure.
/// </summary> /// </summary>

8
src/Avalonia.Controls/ItemsControl.cs

@ -489,18 +489,20 @@ namespace Avalonia.Controls
bool wrap) bool wrap)
{ {
IInputElement result; IInputElement result;
var c = from;
do do
{ {
result = container.GetControl(direction, from, wrap); result = container.GetControl(direction, c, wrap);
from = from ?? result;
if (result?.Focusable == true) if (result?.Focusable == true)
{ {
return result; return result;
} }
from = result; c = result;
} while (from != null); } while (c != null && c != from);
return null; return null;
} }

3
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs

@ -273,7 +273,8 @@ namespace Avalonia.Controls.Platform
if (item.IsTopLevel) if (item.IsTopLevel)
{ {
if (item.Parent.SelectedItem?.IsSubMenuOpen == true) if (item != item.Parent.SelectedItem &&
item.Parent.SelectedItem?.IsSubMenuOpen == true)
{ {
item.Parent.SelectedItem.Close(); item.Parent.SelectedItem.Close();
SelectItemAndAncestors(item); SelectItemAndAncestors(item);

6
src/Avalonia.Controls/Platform/InProcessDragSource.cs

@ -21,7 +21,7 @@ namespace Avalonia.Platform
private DragDropEffects _allowedEffects; private DragDropEffects _allowedEffects;
private IDataObject _draggedData; private IDataObject _draggedData;
private IInputElement _lastRoot; private IInputRoot _lastRoot;
private Point _lastPosition; private Point _lastPosition;
private StandardCursorType _lastCursorType; private StandardCursorType _lastCursorType;
private object _originalCursor; private object _originalCursor;
@ -56,7 +56,7 @@ namespace Avalonia.Platform
return DragDropEffects.None; return DragDropEffects.None;
} }
private DragDropEffects RaiseEventAndUpdateCursor(RawDragEventType type, IInputElement root, Point pt, RawInputModifiers modifiers) private DragDropEffects RaiseEventAndUpdateCursor(RawDragEventType type, IInputRoot root, Point pt, RawInputModifiers modifiers)
{ {
_lastPosition = pt; _lastPosition = pt;
@ -91,7 +91,7 @@ namespace Avalonia.Platform
return StandardCursorType.No; return StandardCursorType.No;
} }
private void UpdateCursor(IInputElement root, DragDropEffects effect) private void UpdateCursor(IInputRoot root, DragDropEffects effect)
{ {
if (_lastRoot != root) if (_lastRoot != root)
{ {

2
src/Avalonia.Controls/Primitives/PopupRoot.cs

@ -41,6 +41,8 @@ namespace Avalonia.Controls.Primitives
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PopupRoot"/> class. /// Initializes a new instance of the <see cref="PopupRoot"/> class.
/// </summary> /// </summary>
/// <param name="parent">The popup parent.</param>
/// <param name="impl">The popup implementation.</param>
/// <param name="dependencyResolver"> /// <param name="dependencyResolver">
/// The dependency resolver to use. If null the default dependency resolver will be used. /// The dependency resolver to use. If null the default dependency resolver will be used.
/// </param> /// </param>

4
src/Avalonia.Controls/Primitives/Thumb.cs

@ -83,6 +83,8 @@ namespace Avalonia.Controls.Primitives
Vector = (Vector)_lastPoint, Vector = (Vector)_lastPoint,
}; };
PseudoClasses.Add(":pressed");
RaiseEvent(ev); RaiseEvent(ev);
} }
@ -102,6 +104,8 @@ namespace Avalonia.Controls.Primitives
RaiseEvent(ev); RaiseEvent(ev);
} }
PseudoClasses.Remove(":pressed");
} }
} }
} }

2
src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs

@ -227,6 +227,7 @@ namespace Avalonia.Controls.Remote.Server
Input?.Invoke(new RawKeyEventArgs( Input?.Invoke(new RawKeyEventArgs(
KeyboardDevice, KeyboardDevice,
0, 0,
InputRoot,
key.IsDown ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp, key.IsDown ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp,
(Key)key.Key, (Key)key.Key,
GetAvaloniaRawInputModifiers(key.Modifiers))); GetAvaloniaRawInputModifiers(key.Modifiers)));
@ -241,6 +242,7 @@ namespace Avalonia.Controls.Remote.Server
Input?.Invoke(new RawTextInputEventArgs( Input?.Invoke(new RawTextInputEventArgs(
KeyboardDevice, KeyboardDevice,
0, 0,
InputRoot,
text.Text)); text.Text));
}, DispatcherPriority.Input); }, DispatcherPriority.Input);
} }

13
src/Avalonia.Controls/RowDefinition.cs

@ -26,6 +26,16 @@ namespace Avalonia.Controls
public static readonly StyledProperty<GridLength> HeightProperty = public static readonly StyledProperty<GridLength> HeightProperty =
AvaloniaProperty.Register<RowDefinition, GridLength>(nameof(Height), new GridLength(1, GridUnitType.Star)); AvaloniaProperty.Register<RowDefinition, GridLength>(nameof(Height), new GridLength(1, GridUnitType.Star));
/// <summary>
/// Initializes static members of the <see cref="RowDefinition"/> class.
/// </summary>
static RowDefinition()
{
AffectsParentMeasure(MaxHeightProperty, MinHeightProperty);
HeightProperty.Changed.AddClassHandler<DefinitionBase>(OnUserSizePropertyChanged);
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RowDefinition"/> class. /// Initializes a new instance of the <see cref="RowDefinition"/> class.
/// </summary> /// </summary>
@ -68,7 +78,6 @@ namespace Avalonia.Controls
} }
set set
{ {
Parent?.InvalidateMeasure();
SetValue(MaxHeightProperty, value); SetValue(MaxHeightProperty, value);
} }
} }
@ -84,7 +93,6 @@ namespace Avalonia.Controls
} }
set set
{ {
Parent?.InvalidateMeasure();
SetValue(MinHeightProperty, value); SetValue(MinHeightProperty, value);
} }
} }
@ -100,7 +108,6 @@ namespace Avalonia.Controls
} }
set set
{ {
Parent?.InvalidateMeasure();
SetValue(HeightProperty, value); SetValue(HeightProperty, value);
} }
} }

18
src/Avalonia.Input/DragDropDevice.cs

@ -11,7 +11,7 @@ namespace Avalonia.Input
private Interactive _lastTarget = null; private Interactive _lastTarget = null;
private Interactive GetTarget(IInputElement root, Point local) private Interactive GetTarget(IInputRoot root, Point local)
{ {
var target = root.InputHitTest(local)?.GetSelfAndVisualAncestors()?.OfType<Interactive>()?.FirstOrDefault(); var target = root.InputHitTest(local)?.GetSelfAndVisualAncestors()?.OfType<Interactive>()?.FirstOrDefault();
if (target != null && DragDrop.GetAllowDrop(target)) if (target != null && DragDrop.GetAllowDrop(target))
@ -19,7 +19,7 @@ namespace Avalonia.Input
return null; return null;
} }
private DragDropEffects RaiseDragEvent(Interactive target, IInputElement inputRoot, Point point, RoutedEvent<DragEventArgs> routedEvent, DragDropEffects operation, IDataObject data, InputModifiers modifiers) private DragDropEffects RaiseDragEvent(Interactive target, IInputRoot inputRoot, Point point, RoutedEvent<DragEventArgs> routedEvent, DragDropEffects operation, IDataObject data, InputModifiers modifiers)
{ {
if (target == null) if (target == null)
return DragDropEffects.None; return DragDropEffects.None;
@ -38,13 +38,13 @@ namespace Avalonia.Input
return args.DragEffects; return args.DragEffects;
} }
private DragDropEffects DragEnter(IInputElement inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers) private DragDropEffects DragEnter(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
{ {
_lastTarget = GetTarget(inputRoot, point); _lastTarget = GetTarget(inputRoot, point);
return RaiseDragEvent(_lastTarget, inputRoot, point, DragDrop.DragEnterEvent, effects, data, modifiers); return RaiseDragEvent(_lastTarget, inputRoot, point, DragDrop.DragEnterEvent, effects, data, modifiers);
} }
private DragDropEffects DragOver(IInputElement inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers) private DragDropEffects DragOver(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
{ {
var target = GetTarget(inputRoot, point); var target = GetTarget(inputRoot, point);
@ -77,7 +77,7 @@ namespace Avalonia.Input
} }
} }
private DragDropEffects Drop(IInputElement inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers) private DragDropEffects Drop(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
{ {
try try
{ {
@ -100,16 +100,16 @@ namespace Avalonia.Input
switch (e.Type) switch (e.Type)
{ {
case RawDragEventType.DragEnter: case RawDragEventType.DragEnter:
e.Effects = DragEnter(e.InputRoot, e.Location, e.Data, e.Effects, e.Modifiers); e.Effects = DragEnter(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
break; break;
case RawDragEventType.DragOver: case RawDragEventType.DragOver:
e.Effects = DragOver(e.InputRoot, e.Location, e.Data, e.Effects, e.Modifiers); e.Effects = DragOver(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
break; break;
case RawDragEventType.DragLeave: case RawDragEventType.DragLeave:
DragLeave(e.InputRoot); DragLeave(e.Root);
break; break;
case RawDragEventType.Drop: case RawDragEventType.Drop:
e.Effects = Drop(e.InputRoot, e.Location, e.Data, e.Effects, e.Modifiers); e.Effects = Drop(e.Root, e.Location, e.Data, e.Effects, e.Modifiers);
break; break;
} }
} }

102
src/Avalonia.Input/KeyboardDevice.cs

@ -70,66 +70,60 @@ namespace Avalonia.Input
{ {
if(e.Handled) if(e.Handled)
return; return;
IInputElement element = FocusedElement;
if (element != null) var element = FocusedElement ?? e.Root;
{
var keyInput = e as RawKeyEventArgs;
if (keyInput != null) if (e is RawKeyEventArgs keyInput)
{
switch (keyInput.Type)
{ {
switch (keyInput.Type) case RawKeyEventType.KeyDown:
{ case RawKeyEventType.KeyUp:
case RawKeyEventType.KeyDown: var routedEvent = keyInput.Type == RawKeyEventType.KeyDown
case RawKeyEventType.KeyUp: ? InputElement.KeyDownEvent
var routedEvent = keyInput.Type == RawKeyEventType.KeyDown : InputElement.KeyUpEvent;
? InputElement.KeyDownEvent
: InputElement.KeyUpEvent; KeyEventArgs ev = new KeyEventArgs
{
KeyEventArgs ev = new KeyEventArgs RoutedEvent = routedEvent,
{ Device = this,
RoutedEvent = routedEvent, Key = keyInput.Key,
Device = this, KeyModifiers = KeyModifiersUtils.ConvertToKey(keyInput.Modifiers),
Key = keyInput.Key, Source = element,
KeyModifiers = KeyModifiersUtils.ConvertToKey(keyInput.Modifiers), };
Source = element,
}; IVisual currentHandler = element;
while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown)
IVisual currentHandler = element; {
while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown) var bindings = (currentHandler as IInputElement)?.KeyBindings;
{ if (bindings != null)
var bindings = (currentHandler as IInputElement)?.KeyBindings; foreach (var binding in bindings)
if(bindings!=null) {
foreach (var binding in bindings) if (ev.Handled)
{ break;
if(ev.Handled) binding.TryHandle(ev);
break; }
binding.TryHandle(ev); currentHandler = currentHandler.VisualParent;
} }
currentHandler = currentHandler.VisualParent;
} element.RaiseEvent(ev);
e.Handled = ev.Handled;
element.RaiseEvent(ev); break;
e.Handled = ev.Handled;
break;
}
} }
}
var text = e as RawTextInputEventArgs; if (e is RawTextInputEventArgs text)
{
if (text != null) var ev = new TextInputEventArgs()
{ {
var ev = new TextInputEventArgs() Device = this,
{ Text = text.Text,
Device = this, Source = element,
Text = text.Text, RoutedEvent = InputElement.TextInputEvent
Source = element, };
RoutedEvent = InputElement.TextInputEvent
}; element.RaiseEvent(ev);
e.Handled = ev.Handled;
element.RaiseEvent(ev);
e.Handled = ev.Handled;
}
} }
} }
} }

6
src/Avalonia.Input/Raw/RawDragEvent.cs

@ -2,7 +2,6 @@
{ {
public class RawDragEvent : RawInputEventArgs public class RawDragEvent : RawInputEventArgs
{ {
public IInputElement InputRoot { get; }
public Point Location { get; set; } public Point Location { get; set; }
public IDataObject Data { get; } public IDataObject Data { get; }
public DragDropEffects Effects { get; set; } public DragDropEffects Effects { get; set; }
@ -10,11 +9,10 @@
public InputModifiers Modifiers { get; } public InputModifiers Modifiers { get; }
public RawDragEvent(IDragDropDevice inputDevice, RawDragEventType type, public RawDragEvent(IDragDropDevice inputDevice, RawDragEventType type,
IInputElement inputRoot, Point location, IDataObject data, DragDropEffects effects, RawInputModifiers modifiers) IInputRoot root, Point location, IDataObject data, DragDropEffects effects, RawInputModifiers modifiers)
:base(inputDevice, 0) :base(inputDevice, 0, root)
{ {
Type = type; Type = type;
InputRoot = inputRoot;
Location = location; Location = location;
Data = data; Data = data;
Effects = effects; Effects = effects;

9
src/Avalonia.Input/Raw/RawInputEventArgs.cs

@ -21,12 +21,14 @@ namespace Avalonia.Input.Raw
/// </summary> /// </summary>
/// <param name="device">The associated device.</param> /// <param name="device">The associated device.</param>
/// <param name="timestamp">The event timestamp.</param> /// <param name="timestamp">The event timestamp.</param>
public RawInputEventArgs(IInputDevice device, ulong timestamp) /// <param name="root">The root from which the event originates.</param>
public RawInputEventArgs(IInputDevice device, ulong timestamp, IInputRoot root)
{ {
Contract.Requires<ArgumentNullException>(device != null); Contract.Requires<ArgumentNullException>(device != null);
Device = device; Device = device;
Timestamp = timestamp; Timestamp = timestamp;
Root = root;
} }
/// <summary> /// <summary>
@ -34,6 +36,11 @@ namespace Avalonia.Input.Raw
/// </summary> /// </summary>
public IInputDevice Device { get; } public IInputDevice Device { get; }
/// <summary>
/// Gets the root from which the event originates.
/// </summary>
public IInputRoot Root { get; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the event was handled. /// Gets or sets a value indicating whether the event was handled.
/// </summary> /// </summary>

3
src/Avalonia.Input/Raw/RawKeyEventArgs.cs

@ -14,9 +14,10 @@ namespace Avalonia.Input.Raw
public RawKeyEventArgs( public RawKeyEventArgs(
IKeyboardDevice device, IKeyboardDevice device,
ulong timestamp, ulong timestamp,
IInputRoot root,
RawKeyEventType type, RawKeyEventType type,
Key key, RawInputModifiers modifiers) Key key, RawInputModifiers modifiers)
: base(device, timestamp) : base(device, timestamp, root)
{ {
Key = key; Key = key;
Type = type; Type = type;

8
src/Avalonia.Input/Raw/RawPointerEventArgs.cs

@ -44,22 +44,16 @@ namespace Avalonia.Input.Raw
RawPointerEventType type, RawPointerEventType type,
Point position, Point position,
RawInputModifiers inputModifiers) RawInputModifiers inputModifiers)
: base(device, timestamp) : base(device, timestamp, root)
{ {
Contract.Requires<ArgumentNullException>(device != null); Contract.Requires<ArgumentNullException>(device != null);
Contract.Requires<ArgumentNullException>(root != null); Contract.Requires<ArgumentNullException>(root != null);
Root = root;
Position = position; Position = position;
Type = type; Type = type;
InputModifiers = inputModifiers; InputModifiers = inputModifiers;
} }
/// <summary>
/// Gets the root from which the event originates.
/// </summary>
public IInputRoot Root { get; }
/// <summary> /// <summary>
/// Gets the mouse position, in client DIPs. /// Gets the mouse position, in client DIPs.
/// </summary> /// </summary>

11
src/Avalonia.Input/Raw/RawTextInputEventArgs.cs

@ -5,11 +5,16 @@ namespace Avalonia.Input.Raw
{ {
public class RawTextInputEventArgs : RawInputEventArgs public class RawTextInputEventArgs : RawInputEventArgs
{ {
public string Text { get; set; } public RawTextInputEventArgs(
IKeyboardDevice device,
public RawTextInputEventArgs(IKeyboardDevice device, ulong timestamp, string text) : base(device, timestamp) ulong timestamp,
IInputRoot root,
string text)
: base(device, timestamp, root)
{ {
Text = text; Text = text;
} }
public string Text { get; set; }
} }
} }

4
src/Avalonia.Native/WindowImplBase.cs

@ -204,7 +204,7 @@ namespace Avalonia.Native
{ {
Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1); Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1);
var args = new RawTextInputEventArgs(_keyboard, timeStamp, text); var args = new RawTextInputEventArgs(_keyboard, timeStamp, _inputRoot, text);
Input?.Invoke(args); Input?.Invoke(args);
@ -215,7 +215,7 @@ namespace Avalonia.Native
{ {
Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1); Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1);
var args = new RawKeyEventArgs(_keyboard, timeStamp, (RawKeyEventType)type, (Key)key, (RawInputModifiers)modifiers); var args = new RawKeyEventArgs(_keyboard, timeStamp, _inputRoot, (RawKeyEventType)type, (Key)key, (RawInputModifiers)modifiers);
Input?.Invoke(args); Input?.Invoke(args);

7
src/Avalonia.Themes.Default/Accents/BaseDark.xaml

@ -14,7 +14,9 @@
<Color x:Key="ThemeBorderHighColor">#FFA0A0A0</Color> <Color x:Key="ThemeBorderHighColor">#FFA0A0A0</Color>
<Color x:Key="ThemeControlLowColor">#FF282828</Color> <Color x:Key="ThemeControlLowColor">#FF282828</Color>
<Color x:Key="ThemeControlMidColor">#FF505050</Color> <Color x:Key="ThemeControlMidColor">#FF505050</Color>
<Color x:Key="ThemeControlMidHighColor">#FF686868</Color>
<Color x:Key="ThemeControlHighColor">#FF808080</Color> <Color x:Key="ThemeControlHighColor">#FF808080</Color>
<Color x:Key="ThemeControlVeryHighColor">#FFEFEBEF</Color>
<Color x:Key="ThemeControlHighlightLowColor">#FFA8A8A8</Color> <Color x:Key="ThemeControlHighlightLowColor">#FFA8A8A8</Color>
<Color x:Key="ThemeControlHighlightMidColor">#FF828282</Color> <Color x:Key="ThemeControlHighlightMidColor">#FF828282</Color>
<Color x:Key="ThemeControlHighlightHighColor">#FF505050</Color> <Color x:Key="ThemeControlHighlightHighColor">#FF505050</Color>
@ -32,7 +34,9 @@
<SolidColorBrush x:Key="ThemeBorderHighBrush" Color="{DynamicResource ThemeBorderHighColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeBorderHighBrush" Color="{DynamicResource ThemeBorderHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlLowBrush" Color="{DynamicResource ThemeControlLowColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlLowBrush" Color="{DynamicResource ThemeControlLowColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlMidBrush" Color="{DynamicResource ThemeControlMidColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlMidBrush" Color="{DynamicResource ThemeControlMidColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlMidHighBrush" Color="{DynamicResource ThemeControlMidHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighBrush" Color="{DynamicResource ThemeControlHighColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighBrush" Color="{DynamicResource ThemeControlHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlVeryHighBrush" Color="{DynamicResource ThemeControlVeryHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighlightLowBrush" Color="{DynamicResource ThemeControlHighlightLowColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighlightLowBrush" Color="{DynamicResource ThemeControlHighlightLowColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighlightMidBrush" Color="{DynamicResource ThemeControlHighlightMidColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighlightMidBrush" Color="{DynamicResource ThemeControlHighlightMidColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighlightHighBrush" Color="{DynamicResource ThemeControlHighlightHighColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighlightHighBrush" Color="{DynamicResource ThemeControlHighlightHighColor}"></SolidColorBrush>
@ -61,6 +65,7 @@
<sys:Double x:Key="FontSizeNormal">12</sys:Double> <sys:Double x:Key="FontSizeNormal">12</sys:Double>
<sys:Double x:Key="FontSizeLarge">16</sys:Double> <sys:Double x:Key="FontSizeLarge">16</sys:Double>
<sys:Double x:Key="ScrollBarThickness">10</sys:Double> <sys:Double x:Key="ScrollBarThickness">18</sys:Double>
<sys:Double x:Key="ScrollBarThumbThickness">8</sys:Double>
</Style.Resources> </Style.Resources>
</Style> </Style>

16
src/Avalonia.Themes.Default/Accents/BaseLight.xaml

@ -12,9 +12,14 @@
<Color x:Key="ThemeBorderLowColor">#FFAAAAAA</Color> <Color x:Key="ThemeBorderLowColor">#FFAAAAAA</Color>
<Color x:Key="ThemeBorderMidColor">#FF888888</Color> <Color x:Key="ThemeBorderMidColor">#FF888888</Color>
<Color x:Key="ThemeBorderHighColor">#FF333333</Color> <Color x:Key="ThemeBorderHighColor">#FF333333</Color>
<Color x:Key="ThemeControlLowColor">#FFFFFFFF</Color>
<Color x:Key="ThemeControlMidColor">#FFAAAAAA</Color>
<Color x:Key="ThemeControlHighColor">#FF888888</Color> <Color x:Key="ThemeControlLowColor">#FF868999</Color>
<Color x:Key="ThemeControlMidColor">#FFF5F5F5</Color>
<Color x:Key="ThemeControlMidHighColor">#FFC2C3C9</Color>
<Color x:Key="ThemeControlHighColor">#FF686868</Color>
<Color x:Key="ThemeControlVeryHighColor">#FF5B5B5B</Color>
<Color x:Key="ThemeControlHighlightLowColor">#FFF0F0F0</Color> <Color x:Key="ThemeControlHighlightLowColor">#FFF0F0F0</Color>
<Color x:Key="ThemeControlHighlightMidColor">#FFD0D0D0</Color> <Color x:Key="ThemeControlHighlightMidColor">#FFD0D0D0</Color>
<Color x:Key="ThemeControlHighlightHighColor">#FF808080</Color> <Color x:Key="ThemeControlHighlightHighColor">#FF808080</Color>
@ -32,7 +37,9 @@
<SolidColorBrush x:Key="ThemeBorderHighBrush" Color="{DynamicResource ThemeBorderHighColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeBorderHighBrush" Color="{DynamicResource ThemeBorderHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlLowBrush" Color="{DynamicResource ThemeControlLowColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlLowBrush" Color="{DynamicResource ThemeControlLowColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlMidBrush" Color="{DynamicResource ThemeControlMidColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlMidBrush" Color="{DynamicResource ThemeControlMidColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlMidHighBrush" Color="{DynamicResource ThemeControlMidHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighBrush" Color="{DynamicResource ThemeControlHighColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighBrush" Color="{DynamicResource ThemeControlHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlVeryHighBrush" Color="{DynamicResource ThemeControlVeryHighColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighlightLowBrush" Color="{DynamicResource ThemeControlHighlightLowColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighlightLowBrush" Color="{DynamicResource ThemeControlHighlightLowColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighlightMidBrush" Color="{DynamicResource ThemeControlHighlightMidColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighlightMidBrush" Color="{DynamicResource ThemeControlHighlightMidColor}"></SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighlightHighBrush" Color="{DynamicResource ThemeControlHighlightHighColor}"></SolidColorBrush> <SolidColorBrush x:Key="ThemeControlHighlightHighBrush" Color="{DynamicResource ThemeControlHighlightHighColor}"></SolidColorBrush>
@ -61,6 +68,7 @@
<sys:Double x:Key="FontSizeNormal">12</sys:Double> <sys:Double x:Key="FontSizeNormal">12</sys:Double>
<sys:Double x:Key="FontSizeLarge">16</sys:Double> <sys:Double x:Key="FontSizeLarge">16</sys:Double>
<sys:Double x:Key="ScrollBarThickness">10</sys:Double> <sys:Double x:Key="ScrollBarThickness">18</sys:Double>
<sys:Double x:Key="ScrollBarThumbThickness">8</sys:Double>
</Style.Resources> </Style.Resources>
</Style> </Style>

8
src/Avalonia.Themes.Default/ContextMenu.xaml

@ -11,19 +11,11 @@
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"> Padding="{TemplateBinding Padding}">
<ScrollViewer> <ScrollViewer>
<Panel>
<ItemsPresenter Name="PART_ItemsPresenter" <ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}" Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}" ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}" ItemTemplate="{TemplateBinding ItemTemplate}"
KeyboardNavigation.TabNavigation="Continue"/> KeyboardNavigation.TabNavigation="Continue"/>
<Rectangle Name="iconSeparator"
Fill="{DynamicResource ThemeControlMidBrush}"
HorizontalAlignment="Left"
IsHitTestVisible="False"
Margin="29,2,0,2"
Width="1"/>
</Panel>
</ScrollViewer> </ScrollViewer>
</Border> </Border>
</ControlTemplate> </ControlTemplate>

29
src/Avalonia.Themes.Default/MenuItem.xaml

@ -4,14 +4,14 @@
<Style Selector="MenuItem"> <Style Selector="MenuItem">
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="6,0"/> <Setter Property="Padding" Value="6 0"/>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Border Name="root" <Border Name="root"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"> BorderThickness="{TemplateBinding BorderThickness}">
<Grid ColumnDefinitions="22,13,*,20"> <Grid ColumnDefinitions="20,5,*,20">
<ContentPresenter Name="icon" <ContentPresenter Name="icon"
Content="{TemplateBinding Icon}" Content="{TemplateBinding Icon}"
Width="16" Width="16"
@ -50,20 +50,12 @@
<Border Background="{TemplateBinding Background}" <Border Background="{TemplateBinding Background}"
BorderBrush="{DynamicResource ThemeBorderMidBrush}" BorderBrush="{DynamicResource ThemeBorderMidBrush}"
BorderThickness="{TemplateBinding BorderThickness}"> BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer> <ScrollViewer>
<Panel>
<ItemsPresenter Name="PART_ItemsPresenter" <ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}" Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}" ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}" ItemTemplate="{TemplateBinding ItemTemplate}"
Margin="2"/> Margin="4 2"/>
<Rectangle Name="iconSeparator"
Fill="{DynamicResource ThemeControlMidBrush}"
HorizontalAlignment="Left"
IsHitTestVisible="False"
Margin="29,2,0,2"
Width="1"/>
</Panel>
</ScrollViewer> </ScrollViewer>
</Border> </Border>
</Popup> </Popup>
@ -77,13 +69,14 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Separator Background="{DynamicResource ThemeControlMidBrush}" <Separator Background="{DynamicResource ThemeControlMidBrush}"
Margin="29,1,0,1" Margin="20,1,0,1"
Height="1"/> Height="1"/>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</Style> </Style>
<Style Selector="Menu > MenuItem"> <Style Selector="Menu > MenuItem">
<Setter Property="Padding" Value="6 0"/>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Border Name="root" <Border Name="root"
@ -108,19 +101,11 @@
BorderBrush="{DynamicResource ThemeBorderMidBrush}" BorderBrush="{DynamicResource ThemeBorderMidBrush}"
BorderThickness="{TemplateBinding BorderThickness}"> BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer> <ScrollViewer>
<Panel> <ItemsPresenter Name="PART_ItemsPresenter"
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}" Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}" ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}" ItemTemplate="{TemplateBinding ItemTemplate}"
Margin="2"/> Margin="2"/>
<Rectangle Name="iconSeparator"
Fill="{DynamicResource ThemeControlMidBrush}"
HorizontalAlignment="Left"
IsHitTestVisible="False"
Margin="29,2,0,2"
Width="1"/>
</Panel>
</ScrollViewer> </ScrollViewer>
</Border> </Border>
</Popup> </Popup>

6
src/Avalonia.Themes.Default/RepeatButton.xaml

@ -33,12 +33,8 @@
<Setter Property="BorderBrush" <Setter Property="BorderBrush"
Value="{DynamicResource ThemeBorderMidBrush}" /> Value="{DynamicResource ThemeBorderMidBrush}" />
</Style> </Style>
<Style Selector="RepeatButton:pressed /template/ ContentPresenter">
<Setter Property="Background"
Value="{DynamicResource ThemeControlHighBrush}" />
</Style>
<Style Selector="RepeatButton:disabled"> <Style Selector="RepeatButton:disabled">
<Setter Property="Opacity" <Setter Property="Opacity"
Value="{DynamicResource ThemeDisabledOpacity}" /> Value="{DynamicResource ThemeDisabledOpacity}" />
</Style> </Style>
</Styles> </Styles>

264
src/Avalonia.Themes.Default/ScrollBar.xaml

@ -1,128 +1,140 @@
<Styles xmlns="https://github.com/avaloniaui"> <Styles xmlns="https://github.com/avaloniaui">
<Style Selector="ScrollBar"> <Style Selector="ScrollBar">
<Setter Property="Template"> <Setter Property="Cursor" Value="Arrow" />
<ControlTemplate> <Setter Property="Template">
<Border Background="{DynamicResource ThemeControlMidBrush}"> <ControlTemplate>
<Grid RowDefinitions="Auto,*,Auto"> <Border Background="{DynamicResource ThemeControlMidBrush}">
<RepeatButton Name="PART_LineUpButton" <Grid RowDefinitions="Auto,*,Auto">
Classes="repeat" <RepeatButton Name="PART_LineUpButton" HorizontalAlignment="Center"
Grid.Row="0" Classes="repeat"
Grid.Column="0" Grid.Row="0"
Focusable="False"> Focusable="False"
<Path Data="M 0,4 C0,4 0,6 0,6 0,6 3.5,2.5 3.5,2.5 3.5,2.5 7,6 7,6 7,6 7,4 7,4 7,4 3.5,0.5 3.5,0.5 3.5,0.5 0,4 0,4 z" MinHeight="{DynamicResource ScrollBarThickness}">
Stretch="Uniform" <Path Data="M 0 4 L 8 4 L 4 0 Z" />
Fill="{DynamicResource ThemeForegroundLowBrush}" /> </RepeatButton>
</RepeatButton> <Track Grid.Row="1"
<Track Grid.Row="1" Grid.Column="1"
Grid.Column="1" Minimum="{TemplateBinding Minimum}"
Minimum="{TemplateBinding Minimum}" Maximum="{TemplateBinding Maximum}"
Maximum="{TemplateBinding Maximum}" Value="{TemplateBinding Value, Mode=TwoWay}"
Value="{TemplateBinding Value, Mode=TwoWay}" ViewportSize="{TemplateBinding ViewportSize}"
ViewportSize="{TemplateBinding ViewportSize}" Orientation="{TemplateBinding Orientation}"
Orientation="{TemplateBinding Orientation}" IsDirectionReversed="True">
IsDirectionReversed="True"> <Track.DecreaseButton>
<Track.DecreaseButton> <RepeatButton Name="PART_PageUpButton"
<RepeatButton Name="PART_PageUpButton" Classes="repeattrack"
Classes="repeattrack" Focusable="False"/>
Focusable="False"/> </Track.DecreaseButton>
</Track.DecreaseButton> <Track.IncreaseButton>
<Track.IncreaseButton> <RepeatButton Name="PART_PageDownButton"
<RepeatButton Name="PART_PageDownButton" Classes="repeattrack"
Classes="repeattrack" Focusable="False"/>
Focusable="False"/> </Track.IncreaseButton>
</Track.IncreaseButton> <Thumb Name="thumb"/>
<Thumb Name="thumb"/> </Track>
</Track> <RepeatButton Name="PART_LineDownButton" HorizontalAlignment="Center"
<RepeatButton Name="PART_LineDownButton" Classes="repeat"
Classes="repeat" Grid.Row="2"
Grid.Row="2" Grid.Column="2"
Grid.Column="2" Focusable="False"
Focusable="False"> MinHeight="{DynamicResource ScrollBarThickness}">
<Path Data="M 0,2.5 C0,2.5 0,0.5 0,0.5 0,0.5 3.5,4 3.5,4 3.5,4 7,0.5 7,0.5 7,0.5 7,2.5 7,2.5 7,2.5 3.5,6 3.5,6 3.5,6 0,2.5 0,2.5 z" <Path Data="M 0 0 L 4 4 L 8 0 Z" />
Stretch="Uniform" </RepeatButton>
Fill="{DynamicResource ThemeForegroundLowBrush}" /> </Grid>
</RepeatButton> </Border>
</Grid> </ControlTemplate>
</Border> </Setter>
</ControlTemplate> </Style>
</Setter> <Style Selector="ScrollBar:horizontal">
</Style> <Setter Property="Height" Value="{DynamicResource ScrollBarThickness}" />
<Style Selector="ScrollBar:horizontal"> <Setter Property="Template">
<Setter Property="Height" Value="{DynamicResource ScrollBarThickness}" /> <ControlTemplate>
<Setter Property="Template"> <Border Background="{DynamicResource ThemeControlMidBrush}">
<ControlTemplate> <Grid ColumnDefinitions="Auto,*,Auto">
<Border Background="{DynamicResource ThemeControlMidBrush}"> <RepeatButton Name="PART_LineUpButton" VerticalAlignment="Center"
<Grid ColumnDefinitions="Auto,*,Auto"> Classes="repeat"
<RepeatButton Name="PART_LineUpButton" Grid.Row="0"
Classes="repeat" Grid.Column="0"
Grid.Row="0" Focusable="False"
Grid.Column="0" MinWidth="{DynamicResource ScrollBarThickness}">
Focusable="False"> <Path Data="M 4 0 L 4 8 L 0 4 Z" />
<Path Data="M 3.18,7 C3.18,7 5,7 5,7 5,7 1.81,3.5 1.81,3.5 1.81,3.5 5,0 5,0 5,0 3.18,0 3.18,0 3.18,0 0,3.5 0,3.5 0,3.5 3.18,7 3.18,7 z" </RepeatButton>
Stretch="Uniform" <Track Grid.Row="1"
Fill="{DynamicResource ThemeForegroundLowBrush}" /> Grid.Column="1"
</RepeatButton> Minimum="{TemplateBinding Minimum}"
<Track Grid.Row="1" Maximum="{TemplateBinding Maximum}"
Grid.Column="1" Value="{TemplateBinding Value, Mode=TwoWay}"
Minimum="{TemplateBinding Minimum}" ViewportSize="{TemplateBinding ViewportSize}"
Maximum="{TemplateBinding Maximum}" Orientation="{TemplateBinding Orientation}">
Value="{TemplateBinding Value, Mode=TwoWay}" <Track.DecreaseButton>
ViewportSize="{TemplateBinding ViewportSize}" <RepeatButton Name="PART_PageUpButton"
Orientation="{TemplateBinding Orientation}"> Classes="repeattrack"
<Track.DecreaseButton> Focusable="False"/>
<RepeatButton Name="PART_PageUpButton" </Track.DecreaseButton>
Classes="repeattrack" <Track.IncreaseButton>
Focusable="False"/> <RepeatButton Name="PART_PageDownButton"
</Track.DecreaseButton> Classes="repeattrack"
<Track.IncreaseButton> Focusable="False"/>
<RepeatButton Name="PART_PageDownButton" </Track.IncreaseButton>
Classes="repeattrack" <Thumb Name="thumb"/>
Focusable="False"/> </Track>
</Track.IncreaseButton> <RepeatButton Name="PART_LineDownButton" VerticalAlignment="Center"
<Thumb Name="thumb"/> Classes="repeat"
</Track> Grid.Row="2"
<RepeatButton Name="PART_LineDownButton" Grid.Column="2"
Classes="repeat" Focusable="False"
Grid.Row="2" MinWidth="{DynamicResource ScrollBarThickness}">
Grid.Column="2" <Path Data="M 0 0 L 4 4 L 0 8 Z" />
Focusable="False"> </RepeatButton>
<Path Data="M 1.81,7 C1.81,7 0,7 0,7 0,7 3.18,3.5 3.18,3.5 3.18,3.5 0,0 0,0 0,0 1.81,0 1.81,0 1.81,0 5,3.5 5,3.5 5,3.5 1.81,7 1.81,7 z" </Grid>
Stretch="Uniform" </Border>
Fill="{DynamicResource ThemeForegroundLowBrush}" /> </ControlTemplate>
</RepeatButton> </Setter>
</Grid> </Style>
</Border> <Style Selector="ScrollBar /template/ Thumb#thumb">
</ControlTemplate> <Setter Property="Background" Value="{DynamicResource ThemeControlMidHighBrush}"/>
</Setter> <Setter Property="Template">
</Style> <Setter.Value>
<Style Selector="ScrollBar /template/ Thumb#thumb"> <ControlTemplate>
<Setter Property="Background" Value="{DynamicResource ThemeControlHighBrush}"/> <Border Background="{TemplateBinding Background}"/>
<Setter Property="Template"> </ControlTemplate>
<Setter.Value> </Setter.Value>
<ControlTemplate> </Setter>
<Border Background="{TemplateBinding Background}"/> </Style>
</ControlTemplate> <Style Selector="ScrollBar /template/ Thumb#thumb:pointerover">
</Setter.Value> <Setter Property="Background" Value="{DynamicResource ThemeControlHighBrush}"/>
</Setter> </Style>
</Style> <Style Selector="ScrollBar /template/ Thumb#thumb:pressed">
<Style Selector="ScrollBar:horizontal /template/ Thumb#thumb"> <Setter Property="Background" Value="{DynamicResource ThemeControlVeryHighBrush}"/>
<Setter Property="MinWidth" Value="{DynamicResource ScrollBarThickness}" /> </Style>
</Style> <Style Selector="ScrollBar:horizontal /template/ Thumb#thumb">
<Style Selector="ScrollBar:vertical"> <Setter Property="MinWidth" Value="{DynamicResource ScrollBarThickness}" />
<Setter Property="Width" Value="{DynamicResource ScrollBarThickness}" /> <Setter Property="Height" Value="{DynamicResource ScrollBarThumbThickness}" />
</Style> </Style>
<Style Selector="ScrollBar:vertical /template/ Thumb#thumb"> <Style Selector="ScrollBar:vertical">
<Setter Property="MinHeight" Value="{DynamicResource ScrollBarThickness}" /> <Setter Property="Width" Value="{DynamicResource ScrollBarThickness}" />
</Style> </Style>
<Style Selector="ScrollBar /template/ RepeatButton.repeat"> <Style Selector="ScrollBar:vertical /template/ Thumb#thumb">
<Setter Property="Padding" Value="2" /> <Setter Property="MinHeight" Value="{DynamicResource ScrollBarThickness}" />
<Setter Property="BorderThickness" Value="0" /> <Setter Property="Width" Value="{DynamicResource ScrollBarThumbThickness}" />
</Style> </Style>
<Style Selector="ScrollBar /template/ RepeatButton.repeattrack"> <Style Selector="ScrollBar /template/ RepeatButton.repeat">
<Setter Property="Template"> <Setter Property="Padding" Value="2" />
<ControlTemplate> <Setter Property="BorderThickness" Value="0" />
<Border Background="{TemplateBinding Background}" /> </Style>
</ControlTemplate> <Style Selector="ScrollBar /template/ RepeatButton.repeattrack">
</Setter> <Setter Property="Template">
</Style> <ControlTemplate>
<Border Background="{TemplateBinding Background}" />
</ControlTemplate>
</Setter>
</Style>
<Style Selector="ScrollBar /template/ RepeatButton > Path">
<Setter Property="Fill" Value="{DynamicResource ThemeForegroundLowBrush}" />
</Style>
<Style Selector="ScrollBar /template/ RepeatButton:pointerover > Path">
<Setter Property="Fill" Value="{DynamicResource ThemeAccentBrush}" />
</Style>
</Styles> </Styles>

1
src/Avalonia.Themes.Default/ScrollViewer.xaml

@ -36,6 +36,7 @@
Visibility="{TemplateBinding VerticalScrollBarVisibility}" Visibility="{TemplateBinding VerticalScrollBarVisibility}"
Grid.Column="1" Grid.Column="1"
Focusable="False"/> Focusable="False"/>
<Panel Grid.Row="1" Grid.Column="1" Background="{DynamicResource ThemeControlMidBrush}"/>
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>

19
src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs

@ -148,6 +148,19 @@ namespace Avalonia.Rendering.SceneGraph
return (VisualNode)node; return (VisualNode)node;
} }
private static object GetOrCreateChildNode(Scene scene, IVisual child, VisualNode parent)
{
var result = (VisualNode)scene.FindNode(child);
if (result != null && result.Parent != parent)
{
Deindex(scene, result);
result = null;
}
return result ?? CreateNode(scene, child, parent);
}
private static void Update(DrawingContext context, Scene scene, VisualNode node, Rect clip, bool forceRecurse) private static void Update(DrawingContext context, Scene scene, VisualNode node, Rect clip, bool forceRecurse)
{ {
var visual = node.Visual; var visual = node.Visual;
@ -231,7 +244,7 @@ namespace Avalonia.Rendering.SceneGraph
{ {
foreach (var child in visual.VisualChildren.OrderBy(x => x, ZIndexComparer.Instance)) foreach (var child in visual.VisualChildren.OrderBy(x => x, ZIndexComparer.Instance))
{ {
var childNode = scene.FindNode(child) ?? CreateNode(scene, child, node); var childNode = GetOrCreateChildNode(scene, child, node);
Update(context, scene, (VisualNode)childNode, clip, forceRecurse); Update(context, scene, (VisualNode)childNode, clip, forceRecurse);
} }
@ -240,6 +253,10 @@ namespace Avalonia.Rendering.SceneGraph
} }
} }
} }
else
{
contextImpl.BeginUpdate(node).Dispose();
}
} }
private void UpdateSize(Scene scene) private void UpdateSize(Scene scene)

12
src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs

@ -119,6 +119,11 @@ namespace Avalonia.Rendering.SceneGraph
throw new ObjectDisposedException("Visual node for {node.Visual}"); throw new ObjectDisposedException("Visual node for {node.Visual}");
} }
if (child.Parent != this)
{
throw new AvaloniaInternalException("VisualNode added to wrong parent.");
}
EnsureChildrenCreated(); EnsureChildrenCreated();
_children.Add(child); _children.Add(child);
} }
@ -155,6 +160,11 @@ namespace Avalonia.Rendering.SceneGraph
throw new ObjectDisposedException("Visual node for {node.Visual}"); throw new ObjectDisposedException("Visual node for {node.Visual}");
} }
if (node.Parent != this)
{
throw new AvaloniaInternalException("VisualNode added to wrong parent.");
}
EnsureChildrenCreated(); EnsureChildrenCreated();
_children[index] = node; _children[index] = node;
} }
@ -218,7 +228,7 @@ namespace Avalonia.Rendering.SceneGraph
if (first < _children?.Count) if (first < _children?.Count)
{ {
EnsureChildrenCreated(); EnsureChildrenCreated();
for (int i = first; i < _children.Count - first; i++) for (int i = first; i < _children.Count; i++)
{ {
_children[i].Dispose(); _children[i].Dispose();
} }

4
src/Avalonia.X11/X11Window.cs

@ -455,7 +455,7 @@ namespace Avalonia.X11
key = (X11Key)XKeycodeToKeysym(_x11.Display, ev.KeyEvent.keycode, index ? 0 : 1).ToInt32(); key = (X11Key)XKeycodeToKeysym(_x11.Display, ev.KeyEvent.keycode, index ? 0 : 1).ToInt32();
ScheduleInput(new RawKeyEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), ScheduleInput(new RawKeyEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), _inputRoot,
ev.type == XEventName.KeyPress ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp, ev.type == XEventName.KeyPress ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp,
X11KeyTransform.ConvertKey(key), TranslateModifiers(ev.KeyEvent.state)), ref ev); X11KeyTransform.ConvertKey(key), TranslateModifiers(ev.KeyEvent.state)), ref ev);
@ -470,7 +470,7 @@ namespace Avalonia.X11
if (text[0] < ' ' || text[0] == 0x7f) //Control codes or DEL if (text[0] < ' ' || text[0] == 0x7f) //Control codes or DEL
return; return;
} }
ScheduleInput(new RawTextInputEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), text), ScheduleInput(new RawTextInputEventArgs(_keyboard, (ulong)ev.KeyEvent.time.ToInt64(), _inputRoot, text),
ref ev); ref ev);
} }
} }

6
src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs

@ -114,10 +114,10 @@ namespace Avalonia.Markup.Xaml.XamlIl
InitializeSre(); InitializeSre();
var asm = localAssembly == null ? null : _sreTypeSystem.GetAssembly(localAssembly); var asm = localAssembly == null ? null : _sreTypeSystem.GetAssembly(localAssembly);
var compiler = new AvaloniaXamlIlCompiler(new XamlIlTransformerConfiguration(_sreTypeSystem, asm, var compiler = new AvaloniaXamlIlCompiler(new XamlIlTransformerConfiguration(_sreTypeSystem, asm,
_sreMappings, _sreXmlns, AvaloniaXamlIlLanguage.CustomValueConverter), _sreMappings, _sreXmlns, AvaloniaXamlIlLanguage.CustomValueConverter),
_sreContextType); _sreContextType) { EnableIlVerification = true };
var tb = _sreBuilder.DefineType("Builder_" + Guid.NewGuid().ToString("N") + "_" + uri); var tb = _sreBuilder.DefineType("Builder_" + Guid.NewGuid().ToString("N") + "_" + uri);
IXamlIlType overrideType = null; IXamlIlType overrideType = null;

2
src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github

@ -1 +1 @@
Subproject commit c7155c5f6c1a5153ee2d8cd78e5d1524dd6744cf Subproject commit ad9915e19398a49c5a11b66000c361659ca692b3

6
src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs

@ -212,17 +212,17 @@ namespace Avalonia.Win32.Interop.Wpf
protected override void OnMouseLeave(MouseEventArgs e) => MouseEvent(RawPointerEventType.LeaveWindow, e); protected override void OnMouseLeave(MouseEventArgs e) => MouseEvent(RawPointerEventType.LeaveWindow, e);
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
=> _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint) e.Timestamp, RawKeyEventType.KeyDown, => _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint) e.Timestamp, _inputRoot, RawKeyEventType.KeyDown,
(Key) e.Key, (Key) e.Key,
GetModifiers(null))); GetModifiers(null)));
protected override void OnKeyUp(KeyEventArgs e) protected override void OnKeyUp(KeyEventArgs e)
=> _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint)e.Timestamp, RawKeyEventType.KeyUp, => _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint)e.Timestamp, _inputRoot, RawKeyEventType.KeyUp,
(Key)e.Key, (Key)e.Key,
GetModifiers(null))); GetModifiers(null)));
protected override void OnTextInput(TextCompositionEventArgs e) protected override void OnTextInput(TextCompositionEventArgs e)
=> _ttl.Input?.Invoke(new RawTextInputEventArgs(_keyboard, (uint) e.Timestamp, e.Text)); => _ttl.Input?.Invoke(new RawTextInputEventArgs(_keyboard, (uint) e.Timestamp, _inputRoot, e.Text));
void ITopLevelImpl.SetCursor(IPlatformHandle cursor) void ITopLevelImpl.SetCursor(IPlatformHandle cursor)
{ {

9
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -1031,6 +1031,9 @@ namespace Avalonia.Win32.Interop
[DllImport("shcore.dll")] [DllImport("shcore.dll")]
public static extern long GetDpiForMonitor(IntPtr hmonitor, MONITOR_DPI_TYPE dpiType, out uint dpiX, out uint dpiY); public static extern long GetDpiForMonitor(IntPtr hmonitor, MONITOR_DPI_TYPE dpiType, out uint dpiX, out uint dpiY);
[DllImport("gdi32.dll")]
public static extern int GetDeviceCaps(IntPtr hdc, DEVICECAP nIndex);
[DllImport("shcore.dll")] [DllImport("shcore.dll")]
public static extern void GetScaleFactorForMonitor(IntPtr hMon, out uint pScale); public static extern void GetScaleFactorForMonitor(IntPtr hMon, out uint pScale);
@ -1147,6 +1150,12 @@ namespace Avalonia.Win32.Interop
} }
} }
public enum DEVICECAP
{
HORZRES = 8,
DESKTOPHORZRES = 118
}
public enum PROCESS_DPI_AWARENESS public enum PROCESS_DPI_AWARENESS
{ {
PROCESS_DPI_UNAWARE = 0, PROCESS_DPI_UNAWARE = 0,

4
src/Windows/Avalonia.Win32/OleDropTarget.cs

@ -8,13 +8,13 @@ namespace Avalonia.Win32
{ {
class OleDropTarget : IDropTarget class OleDropTarget : IDropTarget
{ {
private readonly IInputElement _target; private readonly IInputRoot _target;
private readonly ITopLevelImpl _tl; private readonly ITopLevelImpl _tl;
private readonly IDragDropDevice _dragDevice; private readonly IDragDropDevice _dragDevice;
private IDataObject _currentDrag = null; private IDataObject _currentDrag = null;
public OleDropTarget(ITopLevelImpl tl, IInputElement target) public OleDropTarget(ITopLevelImpl tl, IInputRoot target)
{ {
_dragDevice = AvaloniaLocator.Current.GetService<IDragDropDevice>(); _dragDevice = AvaloniaLocator.Current.GetService<IDragDropDevice>();
_tl = tl; _tl = tl;

26
src/Windows/Avalonia.Win32/ScreenImpl.cs

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Win32.Interop;
using static Avalonia.Win32.Interop.UnmanagedMethods; using static Avalonia.Win32.Interop.UnmanagedMethods;
namespace Avalonia.Win32 namespace Avalonia.Win32
@ -28,9 +29,28 @@ namespace Avalonia.Win32
(IntPtr monitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr data) => (IntPtr monitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr data) =>
{ {
MONITORINFO monitorInfo = MONITORINFO.Create(); MONITORINFO monitorInfo = MONITORINFO.Create();
if (GetMonitorInfo(monitor,ref monitorInfo)) if (GetMonitorInfo(monitor, ref monitorInfo))
{ {
GetDpiForMonitor(monitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var x, out _); var dpi = 1.0;
var shcore = LoadLibrary("shcore.dll");
var method = GetProcAddress(shcore, nameof(GetDpiForMonitor));
if (method != IntPtr.Zero)
{
GetDpiForMonitor(monitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var x, out _);
dpi = (double)x;
}
else
{
var hdc = GetDC(IntPtr.Zero);
double virtW = GetDeviceCaps(hdc, DEVICECAP.HORZRES);
double physW = GetDeviceCaps(hdc, DEVICECAP.DESKTOPHORZRES);
dpi = (96d * physW / virtW);
ReleaseDC(IntPtr.Zero, hdc);
}
RECT bounds = monitorInfo.rcMonitor; RECT bounds = monitorInfo.rcMonitor;
RECT workingArea = monitorInfo.rcWork; RECT workingArea = monitorInfo.rcWork;
@ -40,7 +60,7 @@ namespace Avalonia.Win32
new PixelRect(workingArea.left, workingArea.top, workingArea.right - workingArea.left, new PixelRect(workingArea.left, workingArea.top, workingArea.right - workingArea.left,
workingArea.bottom - workingArea.top); workingArea.bottom - workingArea.top);
screens[index] = screens[index] =
new WinScreen((double)x / 96.0d, avaloniaBounds, avaloniaWorkArea, monitorInfo.dwFlags == 1, new WinScreen(dpi / 96.0d, avaloniaBounds, avaloniaWorkArea, monitorInfo.dwFlags == 1,
monitor); monitor);
index++; index++;
} }

4
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -508,6 +508,7 @@ namespace Avalonia.Win32
e = new RawKeyEventArgs( e = new RawKeyEventArgs(
WindowsKeyboardDevice.Instance, WindowsKeyboardDevice.Instance,
timestamp, timestamp,
_owner,
RawKeyEventType.KeyDown, RawKeyEventType.KeyDown,
KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers); KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
break; break;
@ -521,6 +522,7 @@ namespace Avalonia.Win32
e = new RawKeyEventArgs( e = new RawKeyEventArgs(
WindowsKeyboardDevice.Instance, WindowsKeyboardDevice.Instance,
timestamp, timestamp,
_owner,
RawKeyEventType.KeyUp, RawKeyEventType.KeyUp,
KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers); KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
break; break;
@ -528,7 +530,7 @@ namespace Avalonia.Win32
// Ignore control chars // Ignore control chars
if (ToInt32(wParam) >= 32) if (ToInt32(wParam) >= 32)
{ {
e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, _owner,
new string((char)ToInt32(wParam), 1)); new string((char)ToInt32(wParam), 1));
} }

12
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Validation.cs

@ -78,6 +78,18 @@ namespace Avalonia.Base.UnitTests
Assert.Equal(10, target.GetValue(Class1.AttachedProperty)); Assert.Equal(10, target.GetValue(Class1.AttachedProperty));
} }
[Fact]
public void PropertyChanged_Event_Uses_Coerced_Value()
{
var inst = new Class1();
inst.PropertyChanged += (sender, e) =>
{
Assert.Equal(10, e.NewValue);
};
inst.SetValue(Class1.QuxProperty, 15);
}
private class Class1 : AvaloniaObject private class Class1 : AvaloniaObject
{ {
public static readonly StyledProperty<int> QuxProperty = public static readonly StyledProperty<int> QuxProperty =

18
tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs

@ -16,7 +16,7 @@ namespace Avalonia.Controls.UnitTests
public void Should_Set_ExitCode_After_Shutdown() public void Should_Set_ExitCode_After_Shutdown()
{ {
using (UnitTestApplication.Start(TestServices.MockThreadingInterface)) using (UnitTestApplication.Start(TestServices.MockThreadingInterface))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
lifetime.Shutdown(1337); lifetime.Shutdown(1337);
@ -31,7 +31,7 @@ namespace Avalonia.Controls.UnitTests
public void Should_Close_All_Remaining_Open_Windows_After_Explicit_Exit_Call() public void Should_Close_All_Remaining_Open_Windows_After_Explicit_Exit_Call()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
var windows = new List<Window> { new Window(), new Window(), new Window(), new Window() }; var windows = new List<Window> { new Window(), new Window(), new Window(), new Window() };
@ -50,7 +50,7 @@ namespace Avalonia.Controls.UnitTests
public void Should_Only_Exit_On_Explicit_Exit() public void Should_Only_Exit_On_Explicit_Exit()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
lifetime.ShutdownMode = ShutdownMode.OnExplicitShutdown; lifetime.ShutdownMode = ShutdownMode.OnExplicitShutdown;
@ -84,7 +84,7 @@ namespace Avalonia.Controls.UnitTests
public void Should_Exit_After_MainWindow_Closed() public void Should_Exit_After_MainWindow_Closed()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
lifetime.ShutdownMode = ShutdownMode.OnMainWindowClose; lifetime.ShutdownMode = ShutdownMode.OnMainWindowClose;
@ -112,7 +112,7 @@ namespace Avalonia.Controls.UnitTests
public void Should_Exit_After_Last_Window_Closed() public void Should_Exit_After_Last_Window_Closed()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
lifetime.ShutdownMode = ShutdownMode.OnLastWindowClose; lifetime.ShutdownMode = ShutdownMode.OnLastWindowClose;
@ -142,7 +142,7 @@ namespace Avalonia.Controls.UnitTests
public void Show_Should_Add_Window_To_OpenWindows() public void Show_Should_Add_Window_To_OpenWindows()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
var window = new Window(); var window = new Window();
@ -156,7 +156,7 @@ namespace Avalonia.Controls.UnitTests
public void Window_Should_Be_Added_To_OpenWindows_Only_Once() public void Window_Should_Be_Added_To_OpenWindows_Only_Once()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
var window = new Window(); var window = new Window();
@ -174,7 +174,7 @@ namespace Avalonia.Controls.UnitTests
public void Close_Should_Remove_Window_From_OpenWindows() public void Close_Should_Remove_Window_From_OpenWindows()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
var window = new Window(); var window = new Window();
@ -197,7 +197,7 @@ namespace Avalonia.Controls.UnitTests
windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object)); windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object));
using (UnitTestApplication.Start(services)) using (UnitTestApplication.Start(services))
using(var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using(var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
var window = new Window(); var window = new Window();

286
tests/Avalonia.Controls.UnitTests/GridTests.cs

@ -1,11 +1,6 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Platform;
using Avalonia.UnitTests;
using Moq;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -34,7 +29,6 @@ namespace Avalonia.Controls.UnitTests
private Grid CreateGrid(params (string name, GridLength width, double minWidth, double maxWidth)[] columns) private Grid CreateGrid(params (string name, GridLength width, double minWidth, double maxWidth)[] columns)
{ {
var grid = new Grid(); var grid = new Grid();
foreach (var k in columns.Select(c => new ColumnDefinition foreach (var k in columns.Select(c => new ColumnDefinition
{ {
@ -1178,6 +1172,41 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(0, grids[0].ColumnDefinitions[0].ActualWidth); Assert.Equal(0, grids[0].ColumnDefinitions[0].ActualWidth);
} }
[Fact]
public void Size_Group_Definition_Resizes_Are_Tracked()
{
var grids = new[] {
CreateGrid(("A", new GridLength(5, GridUnitType.Pixel)), (null, new GridLength())),
CreateGrid(("A", new GridLength(5, GridUnitType.Pixel)), (null, new GridLength())) };
var scope = new Grid();
foreach (var xgrids in grids)
scope.Children.Add(xgrids);
var root = new Grid();
root.UseLayoutRounding = false;
root.SetValue(Grid.IsSharedSizeScopeProperty, true);
root.Children.Add(scope);
root.Measure(new Size(50, 50));
root.Arrange(new Rect(new Point(), new Point(50, 50)));
PrintColumnDefinitions(grids[0]);
Assert.Equal(5, grids[0].ColumnDefinitions[0].ActualWidth);
Assert.Equal(5, grids[1].ColumnDefinitions[0].ActualWidth);
grids[0].ColumnDefinitions[0].Width = new GridLength(10, GridUnitType.Pixel);
foreach (Grid grid in grids)
{
grid.Measure(new Size(50, 50));
grid.Arrange(new Rect(new Point(), new Point(50, 50)));
}
PrintColumnDefinitions(grids[0]);
Assert.Equal(10, grids[0].ColumnDefinitions[0].ActualWidth);
Assert.Equal(10, grids[1].ColumnDefinitions[0].ActualWidth);
}
[Fact] [Fact]
public void Collection_Changes_Are_Tracked() public void Collection_Changes_Are_Tracked()
{ {
@ -1270,11 +1299,11 @@ namespace Avalonia.Controls.UnitTests
// grid.Measure(new Size(100, 100)); // grid.Measure(new Size(100, 100));
// grid.Arrange(new Rect(new Point(), new Point(100, 100))); // grid.Arrange(new Rect(new Point(), new Point(100, 100)));
// PrintColumnDefinitions(grid); // PrintColumnDefinitions(grid);
// NOTE: THIS IS BROKEN IN WPF // NOTE: THIS IS BROKEN IN WPF
// all in group are equal to width (MinWidth) of the sizer in the second column // all in group are equal to width (MinWidth) of the sizer in the second column
// Assert.All(grid.ColumnDefinitions.Where(cd => cd.SharedSizeGroup == "A"), cd => Assert.Equal(6 + 1 * 6, cd.ActualWidth)); // Assert.All(grid.ColumnDefinitions.Where(cd => cd.SharedSizeGroup == "A"), cd => Assert.Equal(6 + 1 * 6, cd.ActualWidth));
// NOTE: THIS IS BROKEN IN WPF // NOTE: THIS IS BROKEN IN WPF
// grid.ColumnDefinitions[2].SharedSizeGroup = null; // grid.ColumnDefinitions[2].SharedSizeGroup = null;
@ -1382,6 +1411,245 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(100, 100), grid.Bounds.Size); Assert.Equal(new Size(100, 100), grid.Bounds.Size);
} }
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Changing_Column_Width_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
if (setUsingAvaloniaProperty)
grid.ColumnDefinitions[0][ColumnDefinition.WidthProperty] = new GridLength(5);
else
grid.ColumnDefinitions[0].Width = new GridLength(5);
});
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Changing_Column_MinWidth_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
if (setUsingAvaloniaProperty)
grid.ColumnDefinitions[0][ColumnDefinition.MinWidthProperty] = 5;
else
grid.ColumnDefinitions[0].MinWidth = 5;
});
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Changing_Column_MaxWidth_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
if (setUsingAvaloniaProperty)
grid.ColumnDefinitions[0][ColumnDefinition.MaxWidthProperty] = 5;
else
grid.ColumnDefinitions[0].MaxWidth = 5;
});
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Changing_Row_Height_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
{
var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
if (setUsingAvaloniaProperty)
grid.RowDefinitions[0][RowDefinition.HeightProperty] = new GridLength(5);
else
grid.RowDefinitions[0].Height = new GridLength(5);
});
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Changing_Row_MinHeight_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
{
var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
if (setUsingAvaloniaProperty)
grid.RowDefinitions[0][RowDefinition.MinHeightProperty] = 5;
else
grid.RowDefinitions[0].MinHeight = 5;
});
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Changing_Row_MaxHeight_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
{
var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
if (setUsingAvaloniaProperty)
grid.RowDefinitions[0][RowDefinition.MaxHeightProperty] = 5;
else
grid.RowDefinitions[0].MaxHeight = 5;
});
}
[Fact]
public void Adding_Column_Should_Invalidate_Grid()
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
grid.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(5)));
});
}
[Fact]
public void Adding_Row_Should_Invalidate_Grid()
{
var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
grid.RowDefinitions.Add(new RowDefinition(new GridLength(5)));
});
}
[Fact]
public void Replacing_Columns_Should_Invalidate_Grid()
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
grid.ColumnDefinitions = ColumnDefinitions.Parse("2*,1*");
});
}
[Fact]
public void Replacing_Rows_Should_Invalidate_Grid()
{
var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
grid.RowDefinitions = RowDefinitions.Parse("2*,1*");
});
}
[Fact]
public void Removing_Column_Should_Invalidate_Grid()
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
grid.ColumnDefinitions.RemoveAt(0);
});
}
[Fact]
public void Removing_Row_Should_Invalidate_Grid()
{
var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
Change_Property_And_Verify_Measure_Requested(grid, () =>
{
grid.RowDefinitions.RemoveAt(0);
});
}
[Fact]
public void Removing_Child_Should_Invalidate_Grid_And_Be_Operational()
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("*,Auto") };
grid.Children.Add(new Decorator() { [Grid.ColumnProperty] = 0 });
grid.Children.Add(new Decorator() { Width = 10, Height = 10, [Grid.ColumnProperty] = 1 });
var size = new Size(100, 100);
grid.Measure(size);
grid.Arrange(new Rect(size));
Assert.True(grid.IsMeasureValid);
Assert.True(grid.IsArrangeValid);
Assert.Equal(90, grid.Children[0].Bounds.Width);
Assert.Equal(10, grid.Children[1].Bounds.Width);
grid.Children.RemoveAt(1);
Assert.False(grid.IsMeasureValid);
Assert.False(grid.IsArrangeValid);
grid.Measure(size);
grid.Arrange(new Rect(size));
Assert.True(grid.IsMeasureValid);
Assert.True(grid.IsArrangeValid);
Assert.Equal(100, grid.Children[0].Bounds.Width);
}
[Fact]
public void Adding_Child_Should_Invalidate_Grid_And_Be_Operational()
{
var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("*,Auto") };
grid.Children.Add(new Decorator() { [Grid.ColumnProperty] = 0 });
var size = new Size(100, 100);
grid.Measure(size);
grid.Arrange(new Rect(size));
Assert.True(grid.IsMeasureValid);
Assert.True(grid.IsArrangeValid);
Assert.Equal(100, grid.Children[0].Bounds.Width);
grid.Children.Add(new Decorator() { Width = 10, Height = 10, [Grid.ColumnProperty] = 1 });
Assert.False(grid.IsMeasureValid);
Assert.False(grid.IsArrangeValid);
grid.Measure(size);
grid.Arrange(new Rect(size));
Assert.True(grid.IsMeasureValid);
Assert.True(grid.IsArrangeValid);
Assert.Equal(90, grid.Children[0].Bounds.Width);
Assert.Equal(10, grid.Children[1].Bounds.Width);
}
private static void Change_Property_And_Verify_Measure_Requested(Grid grid, Action change)
{
grid.Measure(new Size(100, 100));
grid.Arrange(new Rect(grid.DesiredSize));
Assert.True(grid.IsMeasureValid);
Assert.True(grid.IsArrangeValid);
change();
Assert.False(grid.IsMeasureValid);
Assert.False(grid.IsArrangeValid);
}
private class TestControl : Control private class TestControl : Control
{ {
public Size MeasureSize { get; set; } public Size MeasureSize { get; set; }

28
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -1000,6 +1000,26 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.Equal(new[] { "Bar" }, selectedItems); Assert.Equal(new[] { "Bar" }, selectedItems);
} }
[Fact]
public void MoveSelection_Wrap_Does_Not_Hang_With_No_Focusable_Controls()
{
// Issue #3094.
var target = new TestSelector
{
Template = Template(),
Items = new[]
{
new ListBoxItem { Focusable = false },
new ListBoxItem { Focusable = false },
},
SelectedIndex = 0,
};
target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100));
target.MoveSelection(NavigationDirection.Next, true);
}
private FuncControlTemplate Template() private FuncControlTemplate Template()
{ {
return new FuncControlTemplate<SelectingItemsControl>((control, scope) => return new FuncControlTemplate<SelectingItemsControl>((control, scope) =>
@ -1044,5 +1064,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
public List<string> Items { get; set; } = new List<string>() { "a", "b", "c", "d", "e" }; public List<string> Items { get; set; } = new List<string>() { "a", "b", "c", "d", "e" };
public string Selected { get; set; } = "b"; public string Selected { get; set; } = "b";
} }
private class TestSelector : SelectingItemsControl
{
public new bool MoveSelection(NavigationDirection direction, bool wrap)
{
return base.MoveSelection(direction, wrap);
}
}
} }
} }

1
tests/Avalonia.Controls.UnitTests/TopLevelTests.cs

@ -182,6 +182,7 @@ namespace Avalonia.Controls.UnitTests
var input = new RawKeyEventArgs( var input = new RawKeyEventArgs(
new Mock<IKeyboardDevice>().Object, new Mock<IKeyboardDevice>().Object,
0, 0,
target,
RawKeyEventType.KeyDown, RawKeyEventType.KeyDown,
Key.A, RawInputModifiers.None); Key.A, RawInputModifiers.None);
impl.Object.Input(input); impl.Object.Input(input);

90
tests/Avalonia.Input.UnitTests/KeyboardDeviceTests.cs

@ -0,0 +1,90 @@
using Avalonia.Input.Raw;
using Avalonia.Interactivity;
using Moq;
using Xunit;
namespace Avalonia.Input.UnitTests
{
public class KeyboardDeviceTests
{
[Fact]
public void Keypresses_Should_Be_Sent_To_Root_If_No_Focused_Element()
{
var target = new KeyboardDevice();
var root = new Mock<IInputRoot>();
target.ProcessRawEvent(
new RawKeyEventArgs(
target,
0,
root.Object,
RawKeyEventType.KeyDown,
Key.A,
RawInputModifiers.None));
root.Verify(x => x.RaiseEvent(It.IsAny<KeyEventArgs>()));
}
[Fact]
public void Keypresses_Should_Be_Sent_To_Focused_Element()
{
var target = new KeyboardDevice();
var focused = new Mock<IInputElement>();
var root = Mock.Of<IInputRoot>();
target.SetFocusedElement(
focused.Object,
NavigationMethod.Unspecified,
InputModifiers.None);
target.ProcessRawEvent(
new RawKeyEventArgs(
target,
0,
root,
RawKeyEventType.KeyDown,
Key.A,
RawInputModifiers.None));
focused.Verify(x => x.RaiseEvent(It.IsAny<KeyEventArgs>()));
}
[Fact]
public void TextInput_Should_Be_Sent_To_Root_If_No_Focused_Element()
{
var target = new KeyboardDevice();
var root = new Mock<IInputRoot>();
target.ProcessRawEvent(
new RawTextInputEventArgs(
target,
0,
root.Object,
"Foo"));
root.Verify(x => x.RaiseEvent(It.IsAny<TextInputEventArgs>()));
}
[Fact]
public void TextInput_Should_Be_Sent_To_Focused_Element()
{
var target = new KeyboardDevice();
var focused = new Mock<IInputElement>();
var root = Mock.Of<IInputRoot>();
target.SetFocusedElement(
focused.Object,
NavigationMethod.Unspecified,
InputModifiers.None);
target.ProcessRawEvent(
new RawTextInputEventArgs(
target,
0,
root,
"Foo"));
focused.Verify(x => x.RaiseEvent(It.IsAny<TextInputEventArgs>()));
}
}
}

6
tests/Avalonia.ReactiveUI.UnitTests/AutoSuspendHelperTest.cs

@ -45,7 +45,7 @@ namespace Avalonia.ReactiveUI.UnitTests
public void AutoSuspendHelper_Should_Immediately_Fire_IsLaunchingNew() public void AutoSuspendHelper_Should_Immediately_Fire_IsLaunchingNew()
{ {
using (UnitTestApplication.Start(TestServices.MockWindowingPlatform)) using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
using (var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using (var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
var isLaunchingReceived = false; var isLaunchingReceived = false;
var application = AvaloniaLocator.Current.GetService<Application>(); var application = AvaloniaLocator.Current.GetService<Application>();
@ -86,7 +86,7 @@ namespace Avalonia.ReactiveUI.UnitTests
public void ShouldPersistState_Should_Fire_On_App_Exit_When_SuspensionDriver_Is_Initialized() public void ShouldPersistState_Should_Fire_On_App_Exit_When_SuspensionDriver_Is_Initialized()
{ {
using (UnitTestApplication.Start(TestServices.MockWindowingPlatform)) using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
using (var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current)) using (var lifetime = new ClassicDesktopStyleApplicationLifetime())
{ {
var shouldPersistReceived = false; var shouldPersistReceived = false;
var application = AvaloniaLocator.Current.GetService<Application>(); var application = AvaloniaLocator.Current.GetService<Application>();
@ -105,4 +105,4 @@ namespace Avalonia.ReactiveUI.UnitTests
} }
} }
} }
} }

12
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/DeferredDrawingContextImplTests.cs

@ -17,7 +17,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
public void Should_Add_VisualNode() public void Should_Add_VisualNode()
{ {
var parent = new VisualNode(new TestRoot(), null); var parent = new VisualNode(new TestRoot(), null);
var child = new VisualNode(Mock.Of<IVisual>(), null); var child = new VisualNode(Mock.Of<IVisual>(), parent);
var layers = new SceneLayers(parent.Visual); var layers = new SceneLayers(parent.Visual);
var target = new DeferredDrawingContextImpl(null, layers); var target = new DeferredDrawingContextImpl(null, layers);
@ -32,7 +32,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
public void Should_Not_Replace_Identical_VisualNode() public void Should_Not_Replace_Identical_VisualNode()
{ {
var parent = new VisualNode(new TestRoot(), null); var parent = new VisualNode(new TestRoot(), null);
var child = new VisualNode(Mock.Of<IVisual>(), null); var child = new VisualNode(Mock.Of<IVisual>(), parent);
var layers = new SceneLayers(parent.Visual); var layers = new SceneLayers(parent.Visual);
parent.AddChild(child); parent.AddChild(child);
@ -50,8 +50,8 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
public void Should_Replace_Different_VisualNode() public void Should_Replace_Different_VisualNode()
{ {
var parent = new VisualNode(new TestRoot(), null); var parent = new VisualNode(new TestRoot(), null);
var child1 = new VisualNode(Mock.Of<IVisual>(), null); var child1 = new VisualNode(Mock.Of<IVisual>(), parent);
var child2 = new VisualNode(Mock.Of<IVisual>(), null); var child2 = new VisualNode(Mock.Of<IVisual>(), parent);
var layers = new SceneLayers(parent.Visual); var layers = new SceneLayers(parent.Visual);
parent.AddChild(child1); parent.AddChild(child1);
@ -78,8 +78,8 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
var layers = new SceneLayers(root); var layers = new SceneLayers(root);
var target = new DeferredDrawingContextImpl(null, layers); var target = new DeferredDrawingContextImpl(null, layers);
var child1 = new VisualNode(Mock.Of<IVisual>(), null) { LayerRoot = root }; var child1 = new VisualNode(Mock.Of<IVisual>(), node) { LayerRoot = root };
var child2 = new VisualNode(Mock.Of<IVisual>(), null) { LayerRoot = root }; var child2 = new VisualNode(Mock.Of<IVisual>(), node) { LayerRoot = root };
target.BeginUpdate(node); target.BeginUpdate(node);
using (target.BeginUpdate(child1)) { } using (target.BeginUpdate(child1)) { }

52
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

@ -577,6 +577,58 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
} }
} }
[Fact]
public void Should_Not_Dispose_Active_VisualNode_When_Control_Reparented_And_Child_Made_Invisible()
{
// Issue #3115
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{
StackPanel panel;
Border border1;
Border border2;
var tree = new TestRoot
{
Width = 100,
Height = 100,
Child = panel = new StackPanel
{
Children =
{
(border1 = new Border
{
Background = Brushes.Red,
}),
(border2 = new Border
{
Background = Brushes.Green,
}),
}
}
};
tree.Measure(Size.Infinity);
tree.Arrange(new Rect(tree.DesiredSize));
var scene = new Scene(tree);
var sceneBuilder = new SceneBuilder();
sceneBuilder.UpdateAll(scene);
var decorator = new Decorator();
tree.Child = null;
decorator.Child = panel;
tree.Child = decorator;
border1.IsVisible = false;
scene = scene.CloneScene();
sceneBuilder.Update(scene, decorator);
var panelNode = (VisualNode)scene.FindNode(panel);
Assert.Equal(2, panelNode.Children.Count);
Assert.False(panelNode.Children[0].Disposed);
Assert.False(panelNode.Children[1].Disposed);
}
}
[Fact] [Fact]
public void Should_Update_ClipBounds_For_Negative_Margin() public void Should_Update_ClipBounds_For_Negative_Margin()
{ {

21
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/VisualNodeTests.cs

@ -24,7 +24,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
var node = new VisualNode(Mock.Of<IVisual>(), null); var node = new VisualNode(Mock.Of<IVisual>(), null);
var collection = node.Children; var collection = node.Children;
node.AddChild(Mock.Of<IVisualNode>()); node.AddChild(Mock.Of<IVisualNode>(x => x.Parent == node));
Assert.NotSame(collection, node.Children); Assert.NotSame(collection, node.Children);
} }
@ -101,5 +101,24 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
node.SortChildren(scene); node.SortChildren(scene);
} }
[Fact]
public void TrimChildren_Should_Work_Correctly()
{
var parent = new VisualNode(Mock.Of<IVisual>(), null);
var child1 = new VisualNode(Mock.Of<IVisual>(), parent);
var child2 = new VisualNode(Mock.Of<IVisual>(), parent);
var child3 = new VisualNode(Mock.Of<IVisual>(), parent);
parent.AddChild(child1);
parent.AddChild(child2);
parent.AddChild(child3);
parent.TrimChildren(2);
Assert.Equal(2, parent.Children.Count);
Assert.False(child1.Disposed);
Assert.False(child2.Disposed);
Assert.True(child3.Disposed);
}
} }
} }

Loading…
Cancel
Save