Browse Source

Rename IStyleRoot -> ILogicalRoot.

The root of our logical tree is denoted by `IStyleRoot` for historical reasons: before #1594, styling was defined in `Avalonia.Styling` but the logical tree was defined in `Avalonia.Controls`. The styling system needed a root but because it was lower-level than the logical tree it had to define its own root type which was then repurposed for use by the logical tree.

Since #1594 the logical tree is defined in `Avalonia.Styling` as well so we might as well call `IStyleRoot` what it is: the logical tree root.
Steven Kirk 5 years ago
parent
commit
ae1475ad43

+ 1 - 1
src/Avalonia.Controls/Application.cs

@@ -32,7 +32,7 @@ namespace Avalonia
     /// method.
     /// - Tracks the lifetime of the application.
     /// </remarks>
-    public class Application : AvaloniaObject, IDataContextProvider, IGlobalDataTemplates, IGlobalStyles, IStyleRoot, IResourceNode
+    public class Application : AvaloniaObject, IDataContextProvider, IGlobalDataTemplates, IGlobalStyles, IResourceNode
     {
         /// <summary>
         /// The application-global data templates.

+ 4 - 5
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<Control> _layers = new List<Control>();
         
 
@@ -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);

+ 2 - 1
src/Avalonia.Controls/TopLevel.cs

@@ -30,7 +30,8 @@ namespace Avalonia.Controls
         ILayoutRoot,
         IRenderRoot,
         ICloseable,
-        IStyleRoot,
+        IStyleHost,
+        ILogicalRoot,
         IWeakSubscriber<ResourcesChangedEventArgs>
     {
         /// <summary>

+ 9 - 0
src/Avalonia.Styling/LogicalTree/ILogicalRoot.cs

@@ -0,0 +1,9 @@
+namespace Avalonia.LogicalTree
+{
+    /// <summary>
+    /// Represents a root of a logical tree.
+    /// </summary>
+    public interface ILogicalRoot : ILogical
+    {
+    }
+}

+ 2 - 3
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
         /// <param name="source">The control being attached/detached.</param>
         /// <param name="parent">The <see cref="Parent"/>.</param>
         public LogicalTreeAttachmentEventArgs(
-            IStyleRoot root,
+            ILogicalRoot root,
             ILogical source,
             ILogical parent)
         {
@@ -34,7 +33,7 @@ namespace Avalonia.LogicalTree
         /// <summary>
         /// Gets the root of the logical tree that the control is being attached to or detached from.
         /// </summary>
-        public IStyleRoot Root { get; }
+        public ILogicalRoot Root { get; }
 
         /// <summary>
         /// Gets the control that was attached or detached from the logical tree.

+ 15 - 15
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<ILogical> _logicalChildren;
         private IResourceDictionary _resources;
         private Styles _styles;
@@ -81,7 +81,7 @@ namespace Avalonia
         /// </summary>
         public StyledElement()
         {
-            _styleRoot = this as IStyleRoot;
+            _logicalRoot = this as ILogicalRoot;
         }
 
         /// <summary>
@@ -307,7 +307,7 @@ namespace Avalonia
         /// <summary>
         /// Gets a value indicating whether the element is attached to a rooted logical tree.
         /// </summary>
-        bool ILogical.IsAttachedToLogicalTree => _styleRoot != null;
+        bool ILogical.IsAttachedToLogicalTree => _logicalRoot != null;
 
         /// <summary>
         /// 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);

+ 1 - 1
src/Avalonia.Styling/Styling/IGlobalStyles.cs

@@ -6,7 +6,7 @@ namespace Avalonia.Styling
     /// <summary>
     /// Defines the style host that provides styles global to the application.
     /// </summary>
-    public interface IGlobalStyles : IStyleRoot
+    public interface IGlobalStyles : IStyleHost
     {
     }
 }

+ 0 - 12
src/Avalonia.Styling/Styling/IStyleRoot.cs

@@ -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
-{
-    /// <summary>
-    /// Denotes the root <see cref="IStyleHost"/> in a tree.
-    /// </summary>
-    public interface IStyleRoot : IStyleHost
-    {
-    }
-}

+ 3 - 3
tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs

@@ -60,7 +60,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
             var parentMock = new Mock<Control>();
             parentMock.As<IContentPresenterHost>();
             parentMock.As<IRenderRoot>();
-            parentMock.As<IStyleRoot>();
+            parentMock.As<ILogicalRoot>();
 
             (target as ISetLogicalParent).SetParent(parentMock.Object);
 
@@ -105,7 +105,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
 
             var parentMock = new Mock<Control>();
             parentMock.As<IRenderRoot>();
-            parentMock.As<IStyleRoot>();
+            parentMock.As<ILogicalRoot>();
             parentMock.As<ILogical>().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<Control>();
             parentMock.As<IContentPresenterHost>();
             parentMock.As<IRenderRoot>();
-            parentMock.As<IStyleRoot>();
+            parentMock.As<ILogicalRoot>();
 
             (target as ISetLogicalParent).SetParent(parentMock.Object);
 

+ 2 - 1
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; }

+ 2 - 1
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();
 

+ 2 - 1
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();