diff --git a/src/Avalonia.Controls/Application.cs b/src/Avalonia.Controls/Application.cs index 9158ac7038..c49f7c3d09 100644 --- a/src/Avalonia.Controls/Application.cs +++ b/src/Avalonia.Controls/Application.cs @@ -32,7 +32,7 @@ namespace Avalonia /// method. /// - Tracks the lifetime of the application. /// - public class Application : AvaloniaObject, IDataContextProvider, IGlobalDataTemplates, IGlobalStyles, IStyleRoot, IResourceNode + public class Application : AvaloniaObject, IDataContextProvider, IGlobalDataTemplates, IGlobalStyles, IResourceNode { /// /// The application-global data templates. diff --git a/src/Avalonia.Controls/Primitives/VisualLayerManager.cs b/src/Avalonia.Controls/Primitives/VisualLayerManager.cs index 00652f21ba..385e7cc567 100644 --- a/src/Avalonia.Controls/Primitives/VisualLayerManager.cs +++ b/src/Avalonia.Controls/Primitives/VisualLayerManager.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Avalonia.LogicalTree; -using Avalonia.Styling; namespace Avalonia.Controls.Primitives { @@ -8,7 +7,7 @@ namespace Avalonia.Controls.Primitives { private const int AdornerZIndex = int.MaxValue - 100; private const int OverlayZIndex = int.MaxValue - 99; - private IStyleRoot _styleRoot; + private ILogicalRoot _logicalRoot; private readonly List _layers = new List(); @@ -53,7 +52,7 @@ namespace Avalonia.Controls.Primitives layer.ZIndex = zindex; VisualChildren.Add(layer); if (((ILogical)this).IsAttachedToLogicalTree) - ((ILogical)layer).NotifyAttachedToLogicalTree(new LogicalTreeAttachmentEventArgs(_styleRoot, layer, this)); + ((ILogical)layer).NotifyAttachedToLogicalTree(new LogicalTreeAttachmentEventArgs(_logicalRoot, layer, this)); InvalidateArrange(); } @@ -61,7 +60,7 @@ namespace Avalonia.Controls.Primitives protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) { base.OnAttachedToLogicalTree(e); - _styleRoot = e.Root; + _logicalRoot = e.Root; foreach (var l in _layers) ((ILogical)l).NotifyAttachedToLogicalTree(e); @@ -69,7 +68,7 @@ namespace Avalonia.Controls.Primitives protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) { - _styleRoot = null; + _logicalRoot = null; base.OnDetachedFromLogicalTree(e); foreach (var l in _layers) ((ILogical)l).NotifyDetachedFromLogicalTree(e); diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 799e6c81d6..cabadac7d6 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -30,7 +30,8 @@ namespace Avalonia.Controls ILayoutRoot, IRenderRoot, ICloseable, - IStyleRoot, + IStyleHost, + ILogicalRoot, IWeakSubscriber { /// diff --git a/src/Avalonia.Styling/LogicalTree/ILogicalRoot.cs b/src/Avalonia.Styling/LogicalTree/ILogicalRoot.cs new file mode 100644 index 0000000000..4a61544a6f --- /dev/null +++ b/src/Avalonia.Styling/LogicalTree/ILogicalRoot.cs @@ -0,0 +1,9 @@ +namespace Avalonia.LogicalTree +{ + /// + /// Represents a root of a logical tree. + /// + public interface ILogicalRoot : ILogical + { + } +} diff --git a/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs b/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs index dc1b801a5c..20ea82202e 100644 --- a/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs +++ b/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; -using Avalonia.Styling; namespace Avalonia.LogicalTree { @@ -19,7 +18,7 @@ namespace Avalonia.LogicalTree /// The control being attached/detached. /// The . public LogicalTreeAttachmentEventArgs( - IStyleRoot root, + ILogicalRoot root, ILogical source, ILogical parent) { @@ -34,7 +33,7 @@ namespace Avalonia.LogicalTree /// /// Gets the root of the logical tree that the control is being attached to or detached from. /// - public IStyleRoot Root { get; } + public ILogicalRoot Root { get; } /// /// Gets the control that was attached or detached from the logical tree. diff --git a/src/Avalonia.Styling/StyledElement.cs b/src/Avalonia.Styling/StyledElement.cs index 69c2d93247..f04f6fe9dc 100644 --- a/src/Avalonia.Styling/StyledElement.cs +++ b/src/Avalonia.Styling/StyledElement.cs @@ -59,7 +59,7 @@ namespace Avalonia private int _initCount; private string _name; private readonly Classes _classes = new Classes(); - private IStyleRoot _styleRoot; + private ILogicalRoot _logicalRoot; private IAvaloniaList _logicalChildren; private IResourceDictionary _resources; private Styles _styles; @@ -81,7 +81,7 @@ namespace Avalonia /// public StyledElement() { - _styleRoot = this as IStyleRoot; + _logicalRoot = this as ILogicalRoot; } /// @@ -307,7 +307,7 @@ namespace Avalonia /// /// Gets a value indicating whether the element is attached to a rooted logical tree. /// - bool ILogical.IsAttachedToLogicalTree => _styleRoot != null; + bool ILogical.IsAttachedToLogicalTree => _logicalRoot != null; /// /// Gets the styled element's logical parent. @@ -367,7 +367,7 @@ namespace Avalonia throw new InvalidOperationException("BeginInit was not called."); } - if (--_initCount == 0 && _styleRoot != null) + if (--_initCount == 0 && _logicalRoot != null) { InitializeStylesIfNeeded(); @@ -442,9 +442,9 @@ namespace Avalonia Parent = (IStyledElement)parent; - if (_styleRoot != null) + if (_logicalRoot != null) { - var e = new LogicalTreeAttachmentEventArgs(_styleRoot, this, old); + var e = new LogicalTreeAttachmentEventArgs(_logicalRoot, this, old); OnDetachedFromLogicalTreeCore(e); } @@ -458,9 +458,9 @@ namespace Avalonia } ((ILogical)this).NotifyResourcesChanged(new ResourcesChangedEventArgs()); - if (Parent is IStyleRoot || Parent?.IsAttachedToLogicalTree == true || this is IStyleRoot) + if (Parent is ILogicalRoot || Parent?.IsAttachedToLogicalTree == true || this is ILogicalRoot) { - var newRoot = FindStyleRoot(this); + var newRoot = FindLogicalRoot(this); if (newRoot == null) { @@ -667,11 +667,11 @@ namespace Avalonia } } - private static IStyleRoot FindStyleRoot(IStyleHost e) + private static ILogicalRoot FindLogicalRoot(IStyleHost e) { while (e != null) { - if (e is IStyleRoot root) + if (e is ILogicalRoot root) { return root; } @@ -697,7 +697,7 @@ namespace Avalonia private void OnAttachedToLogicalTreeCore(LogicalTreeAttachmentEventArgs e) { - if (this.GetLogicalParent() == null && !(this is IStyleRoot)) + if (this.GetLogicalParent() == null && !(this is ILogicalRoot)) { throw new InvalidOperationException( $"AttachedToLogicalTreeCore called for '{GetType().Name}' but control has no logical parent."); @@ -709,9 +709,9 @@ namespace Avalonia // - ListBox makes ListBoxItem a logical child // - ListBox template gets applied; making its Panel get attached to logical tree // - That AttachedToLogicalTree signal travels down to the ListBoxItem - if (_styleRoot == null) + if (_logicalRoot == null) { - _styleRoot = e.Root; + _logicalRoot = e.Root; InitializeStylesIfNeeded(true); @@ -727,9 +727,9 @@ namespace Avalonia private void OnDetachedFromLogicalTreeCore(LogicalTreeAttachmentEventArgs e) { - if (_styleRoot != null) + if (_logicalRoot != null) { - _styleRoot = null; + _logicalRoot = null; _styleDetach.OnNext(this); OnDetachedFromLogicalTree(e); DetachedFromLogicalTree?.Invoke(this, e); diff --git a/src/Avalonia.Styling/Styling/IGlobalStyles.cs b/src/Avalonia.Styling/Styling/IGlobalStyles.cs index 8bdf6f869b..51393ef0b3 100644 --- a/src/Avalonia.Styling/Styling/IGlobalStyles.cs +++ b/src/Avalonia.Styling/Styling/IGlobalStyles.cs @@ -6,7 +6,7 @@ namespace Avalonia.Styling /// /// Defines the style host that provides styles global to the application. /// - public interface IGlobalStyles : IStyleRoot + public interface IGlobalStyles : IStyleHost { } } diff --git a/src/Avalonia.Styling/Styling/IStyleRoot.cs b/src/Avalonia.Styling/Styling/IStyleRoot.cs deleted file mode 100644 index 56778dcb9f..0000000000 --- a/src/Avalonia.Styling/Styling/IStyleRoot.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) The Avalonia Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -namespace Avalonia.Styling -{ - /// - /// Denotes the root in a tree. - /// - public interface IStyleRoot : IStyleHost - { - } -} diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs index 59f3ae44c2..f7942a017d 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs @@ -60,7 +60,7 @@ namespace Avalonia.Controls.UnitTests.Presenters var parentMock = new Mock(); parentMock.As(); parentMock.As(); - parentMock.As(); + parentMock.As(); (target as ISetLogicalParent).SetParent(parentMock.Object); @@ -105,7 +105,7 @@ namespace Avalonia.Controls.UnitTests.Presenters var parentMock = new Mock(); parentMock.As(); - parentMock.As(); + parentMock.As(); parentMock.As().SetupGet(l => l.IsAttachedToLogicalTree).Returns(true); (contentControl as ISetLogicalParent).SetParent(parentMock.Object); @@ -150,7 +150,7 @@ namespace Avalonia.Controls.UnitTests.Presenters var parentMock = new Mock(); parentMock.As(); parentMock.As(); - parentMock.As(); + parentMock.As(); (target as ISetLogicalParent).SetParent(parentMock.Object); diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs index 7a6cf0fba7..308ab4b2b5 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs @@ -13,6 +13,7 @@ using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; using Avalonia.Input; using Avalonia.Layout; +using Avalonia.LogicalTree; using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.Styling; @@ -1062,7 +1063,7 @@ namespace Avalonia.Controls.UnitTests.Presenters }); } - private class TestScroller : ScrollContentPresenter, IRenderRoot, ILayoutRoot, IStyleRoot + private class TestScroller : ScrollContentPresenter, IRenderRoot, ILayoutRoot, ILogicalRoot { public IRenderer Renderer { get; } public Size ClientSize { get; } diff --git a/tests/Avalonia.UnitTests/TestRoot.cs b/tests/Avalonia.UnitTests/TestRoot.cs index 56d7f028f2..0daa55fffc 100644 --- a/tests/Avalonia.UnitTests/TestRoot.cs +++ b/tests/Avalonia.UnitTests/TestRoot.cs @@ -5,6 +5,7 @@ using System; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Layout; +using Avalonia.LogicalTree; using Avalonia.Media; using Avalonia.Platform; using Avalonia.Rendering; @@ -14,7 +15,7 @@ using Moq; namespace Avalonia.UnitTests { - public class TestRoot : Decorator, IFocusScope, ILayoutRoot, IInputRoot, IRenderRoot, IStyleRoot + public class TestRoot : Decorator, IFocusScope, ILayoutRoot, IInputRoot, IRenderRoot, IStyleHost, ILogicalRoot { private readonly NameScope _nameScope = new NameScope(); diff --git a/tests/Avalonia.UnitTests/TestTemplatedRoot.cs b/tests/Avalonia.UnitTests/TestTemplatedRoot.cs index b7e7a0276a..2f251a408e 100644 --- a/tests/Avalonia.UnitTests/TestTemplatedRoot.cs +++ b/tests/Avalonia.UnitTests/TestTemplatedRoot.cs @@ -6,13 +6,14 @@ using Avalonia.Controls; using Avalonia.Controls.Presenters; using Avalonia.Controls.Templates; using Avalonia.Layout; +using Avalonia.LogicalTree; using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.Styling; namespace Avalonia.UnitTests { - public class TestTemplatedRoot : ContentControl, ILayoutRoot, IRenderRoot, IStyleRoot + public class TestTemplatedRoot : ContentControl, ILayoutRoot, IRenderRoot, ILogicalRoot { private readonly NameScope _nameScope = new NameScope();