浏览代码

Make style selector internals internal.

Steven Kirk 2 年之前
父节点
当前提交
04c50f8bf2

+ 1 - 2
src/Avalonia.Base/Styling/Activators/IStyleActivator.cs

@@ -15,8 +15,7 @@ namespace Avalonia.Styling.Activators
     /// - The activation state can be re-evaluated at any time by calling <see cref="GetIsActive"/>
     /// - No error or completion messages
     /// </remarks>
-    [Unstable]
-    public interface IStyleActivator : IDisposable
+    internal interface IStyleActivator : IDisposable
     {
         /// <summary>
         /// Gets a value indicating whether the style is subscribed.

+ 1 - 2
src/Avalonia.Base/Styling/Activators/IStyleActivatorSink.cs

@@ -5,8 +5,7 @@ namespace Avalonia.Styling.Activators
     /// <summary>
     /// Receives notifications from an <see cref="IStyleActivator"/>.
     /// </summary>
-    [Unstable]
-    public interface IStyleActivatorSink
+    internal interface IStyleActivatorSink
     {
         /// <summary>
         /// Called when the subscribed activator value changes.

+ 6 - 6
src/Avalonia.Base/Styling/ChildSelector.cs

@@ -19,13 +19,13 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        public override bool InTemplate => _parent.InTemplate;
+        internal override bool InTemplate => _parent.InTemplate;
 
         /// <inheritdoc/>
-        public override bool IsCombinator => true;
+        internal override bool IsCombinator => true;
 
         /// <inheritdoc/>
-        public override Type? TargetType => null;
+        internal override Type? TargetType => null;
 
         public override string ToString(Style? owner)
         {
@@ -37,7 +37,7 @@ namespace Avalonia.Styling
             return _selectorString;
         }
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             var controlParent = ((ILogical)control).LogicalParent;
 
@@ -64,7 +64,7 @@ namespace Avalonia.Styling
             }
         }
 
-        protected override Selector? MovePrevious() => null;
-        protected override Selector? MovePreviousOrParent() => _parent;
+        private protected override Selector? MovePrevious() => null;
+        private protected override Selector? MovePreviousOrParent() => _parent;
     }
 }

+ 6 - 6
src/Avalonia.Base/Styling/DescendentSelector.cs

@@ -17,13 +17,13 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        public override bool IsCombinator => true;
+        internal override bool IsCombinator => true;
 
         /// <inheritdoc/>
-        public override bool InTemplate => _parent.InTemplate;
+        internal override bool InTemplate => _parent.InTemplate;
 
         /// <inheritdoc/>
-        public override Type? TargetType => null;
+        internal override Type? TargetType => null;
 
         public override string ToString(Style? owner)
         {
@@ -35,7 +35,7 @@ namespace Avalonia.Styling
             return _selectorString;
         }
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             var c = (ILogical)control;
             var descendantMatches = new OrActivatorBuilder();
@@ -69,7 +69,7 @@ namespace Avalonia.Styling
             }
         }
 
-        protected override Selector? MovePrevious() => null;
-        protected override Selector? MovePreviousOrParent() => _parent;
+        private protected override Selector? MovePrevious() => null;
+        private protected override Selector? MovePreviousOrParent() => _parent;
     }
 }

+ 6 - 6
src/Avalonia.Base/Styling/NestingSelector.cs

@@ -7,13 +7,13 @@ namespace Avalonia.Styling
     /// </summary>
     internal class NestingSelector : Selector
     {
-        public override bool InTemplate => false;
-        public override bool IsCombinator => false;
-        public override Type? TargetType => null;
+        internal override bool InTemplate => false;
+        internal override bool IsCombinator => false;
+        internal override Type? TargetType => null;
 
         public override string ToString(Style? owner) => owner?.Parent?.ToString() ?? "^";
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             if (parent is Style s && s.Selector is not null)
             {
@@ -32,7 +32,7 @@ namespace Avalonia.Styling
                 "Nesting selector was specified but cannot determine parent selector.");
         }
 
-        protected override Selector? MovePrevious() => null;
-        protected override Selector? MovePreviousOrParent() => null;
+        private protected override Selector? MovePrevious() => null;
+        private protected override Selector? MovePreviousOrParent() => null;
     }
 }

+ 6 - 6
src/Avalonia.Base/Styling/NotSelector.cs

@@ -26,13 +26,13 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        public override bool InTemplate => _argument.InTemplate;
+        internal override bool InTemplate => _argument.InTemplate;
 
         /// <inheritdoc/>
-        public override bool IsCombinator => false;
+        internal override bool IsCombinator => false;
 
         /// <inheritdoc/>
-        public override Type? TargetType => _previous?.TargetType;
+        internal override Type? TargetType => _previous?.TargetType;
 
         /// <inheritdoc/>
         public override string ToString(Style? owner)
@@ -45,7 +45,7 @@ namespace Avalonia.Styling
             return _selectorString;
         }
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             var innerResult = _argument.Match(control, parent, subscribe);
 
@@ -66,7 +66,7 @@ namespace Avalonia.Styling
             }
         }
 
-        protected override Selector? MovePrevious() => _previous;
-        protected override Selector? MovePreviousOrParent() => _previous;
+        private protected override Selector? MovePrevious() => _previous;
+        private protected override Selector? MovePreviousOrParent() => _previous;
     }
 }

+ 7 - 7
src/Avalonia.Base/Styling/NthChildSelector.cs

@@ -12,7 +12,7 @@ namespace Avalonia.Styling
     /// <remarks>
     /// Element indices are 1-based.
     /// </remarks>
-    public class NthChildSelector : Selector
+    internal class NthChildSelector : Selector
     {
         private const string NthChildSelectorName = "nth-child";
         private const string NthLastChildSelectorName = "nth-last-child";
@@ -39,16 +39,16 @@ namespace Avalonia.Styling
 
         }
 
-        public override bool InTemplate => _previous?.InTemplate ?? false;
+        internal override bool InTemplate => _previous?.InTemplate ?? false;
 
-        public override bool IsCombinator => false;
+        internal override bool IsCombinator => false;
 
-        public override Type? TargetType => _previous?.TargetType;
+        internal override Type? TargetType => _previous?.TargetType;
 
         public int Step { get; }
         public int Offset { get; }
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             if (!(control is ILogical logical))
             {
@@ -103,8 +103,8 @@ namespace Avalonia.Styling
             return match ? SelectorMatch.AlwaysThisInstance : SelectorMatch.NeverThisInstance;
         }
 
-        protected override Selector? MovePrevious() => _previous;
-        protected override Selector? MovePreviousOrParent() => _previous;
+        private protected override Selector? MovePrevious() => _previous;
+        private protected override Selector? MovePreviousOrParent() => _previous;
 
         public override string ToString(Style? owner)
         {

+ 1 - 1
src/Avalonia.Base/Styling/NthLastChildSelector.cs

@@ -8,7 +8,7 @@ namespace Avalonia.Styling
     /// <remarks>
     /// Element indices are 1-based.
     /// </remarks>
-    public class NthLastChildSelector : NthChildSelector
+    internal class NthLastChildSelector : NthChildSelector
     {
         /// <summary>
         /// Creates an instance of <see cref="NthLastChildSelector"/>

+ 6 - 6
src/Avalonia.Base/Styling/OrSelector.cs

@@ -36,13 +36,13 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        public override bool InTemplate => false;
+        internal override bool InTemplate => false;
 
         /// <inheritdoc/>
-        public override bool IsCombinator => false;
+        internal override bool IsCombinator => false;
 
         /// <inheritdoc/>
-        public override Type? TargetType => _targetType ??= EvaluateTargetType();
+        internal override Type? TargetType => _targetType ??= EvaluateTargetType();
 
         /// <inheritdoc/>
         public override string ToString(Style? owner)
@@ -55,7 +55,7 @@ namespace Avalonia.Styling
             return _selectorString;
         }
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             var activators = new OrActivatorBuilder();
             var neverThisInstance = false;
@@ -94,8 +94,8 @@ namespace Avalonia.Styling
             }
         }
 
-        protected override Selector? MovePrevious() => null;
-        protected override Selector? MovePreviousOrParent() => null;
+        private protected override Selector? MovePrevious() => null;
+        private protected override Selector? MovePreviousOrParent() => null;
 
         internal override void ValidateNestingSelector(bool inControlTheme)
         {

+ 6 - 6
src/Avalonia.Base/Styling/PropertyEqualsSelector.cs

@@ -28,13 +28,13 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        public override bool InTemplate => _previous?.InTemplate ?? false;
+        internal override bool InTemplate => _previous?.InTemplate ?? false;
 
         /// <inheritdoc/>
-        public override bool IsCombinator => false;
+        internal override bool IsCombinator => false;
 
         /// <inheritdoc/>
-        public override Type? TargetType => _previous?.TargetType;
+        internal override Type? TargetType => _previous?.TargetType;
 
         /// <inheritdoc/>
         public override string ToString(Style? owner)
@@ -73,7 +73,7 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             if (subscribe)
             {
@@ -88,8 +88,8 @@ namespace Avalonia.Styling
             
         }
 
-        protected override Selector? MovePrevious() => _previous;
-        protected override Selector? MovePreviousOrParent() => _previous;
+        private protected override Selector? MovePrevious() => _previous;
+        private protected override Selector? MovePreviousOrParent() => _previous;
 
         [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = TrimmingMessages.TypeConvertionSupressWarningMessage)]
         [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = TrimmingMessages.TypeConvertionSupressWarningMessage)]

+ 7 - 7
src/Avalonia.Base/Styling/Selector.cs

@@ -14,7 +14,7 @@ namespace Avalonia.Styling
         /// Gets a value indicating whether either this selector or a previous selector has moved
         /// into a template.
         /// </summary>
-        public abstract bool InTemplate { get; }
+        internal abstract bool InTemplate { get; }
 
         /// <summary>
         /// Gets a value indicating whether this selector is a combinator.
@@ -22,12 +22,12 @@ namespace Avalonia.Styling
         /// <remarks>
         /// A combinator is a selector such as Child or Descendent which links simple selectors.
         /// </remarks>
-        public abstract bool IsCombinator { get; }
+        internal abstract bool IsCombinator { get; }
 
         /// <summary>
         /// Gets the target type of the selector, if available.
         /// </summary>
-        public abstract Type? TargetType { get; }
+        internal abstract Type? TargetType { get; }
 
         /// <summary>
         /// Tries to match the selector with a control.
@@ -41,7 +41,7 @@ namespace Avalonia.Styling
         /// or simply return an immediate result.
         /// </param>
         /// <returns>A <see cref="SelectorMatch"/>.</returns>
-        public SelectorMatch Match(StyledElement control, IStyle? parent = null, bool subscribe = true)
+        internal SelectorMatch Match(StyledElement control, IStyle? parent = null, bool subscribe = true)
         {
             // First match the selector until a combinator is found. Selectors are stored from 
             // right-to-left, so MatchUntilCombinator reverses this order because the type selector
@@ -88,17 +88,17 @@ namespace Avalonia.Styling
         /// or simply return an immediate result.
         /// </param>
         /// <returns>A <see cref="SelectorMatch"/>.</returns>
-        protected abstract SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe);
+        private protected abstract SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe);
 
         /// <summary>
         /// Moves to the previous selector.
         /// </summary>
-        protected abstract Selector? MovePrevious();
+        private protected abstract Selector? MovePrevious();
 
         /// <summary>
         /// Moves to the previous selector or the parent selector.
         /// </summary>
-        protected abstract Selector? MovePreviousOrParent();
+        private protected abstract Selector? MovePreviousOrParent();
 
         internal virtual void ValidateNestingSelector(bool inControlTheme)
         {

+ 2 - 2
src/Avalonia.Base/Styling/SelectorMatch.cs

@@ -8,7 +8,7 @@ namespace Avalonia.Styling
     /// <summary>
     /// Describes how a <see cref="SelectorMatch"/> matches a control and its type.
     /// </summary>
-    public enum SelectorMatchResult
+    internal enum SelectorMatchResult
     {
         /// <summary>
         /// The selector never matches this type.
@@ -43,7 +43,7 @@ namespace Avalonia.Styling
     /// A selector match describes whether and how a <see cref="Selector"/> matches a control, and
     /// in addition whether the selector can ever match a control of the same type.
     /// </remarks>
-    public readonly record struct SelectorMatch
+    internal readonly record struct SelectorMatch
     {
         /// <summary>
         /// A selector match with the result of <see cref="SelectorMatchResult.NeverThisType"/>.

+ 6 - 6
src/Avalonia.Base/Styling/TemplateSelector.cs

@@ -18,13 +18,13 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        public override bool InTemplate => true;
+        internal override bool InTemplate => true;
 
         /// <inheritdoc/>
-        public override bool IsCombinator => true;
+        internal override bool IsCombinator => true;
 
         /// <inheritdoc/>
-        public override Type? TargetType => null;
+        internal override Type? TargetType => null;
 
         public override string ToString(Style? owner)
         {
@@ -36,7 +36,7 @@ namespace Avalonia.Styling
             return _selectorString;
         }
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             var templatedParent = control.TemplatedParent as StyledElement;
 
@@ -48,7 +48,7 @@ namespace Avalonia.Styling
             return _parent.Match(templatedParent, parent, subscribe);
         }
 
-        protected override Selector? MovePrevious() => null;
-        protected override Selector? MovePreviousOrParent() => _parent;
+        private protected override Selector? MovePrevious() => null;
+        private protected override Selector? MovePreviousOrParent() => _parent;
     }
 }

+ 6 - 6
src/Avalonia.Base/Styling/TypeNameAndClassSelector.cs

@@ -58,7 +58,7 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        public override bool InTemplate => _previous?.InTemplate ?? false;
+        internal override bool InTemplate => _previous?.InTemplate ?? false;
 
         /// <summary>
         /// Gets the name of the control to match.
@@ -66,10 +66,10 @@ namespace Avalonia.Styling
         public string? Name { get; set; }
 
         /// <inheritdoc/>
-        public override Type? TargetType => _targetType ?? _previous?.TargetType;
+        internal override Type? TargetType => _targetType ?? _previous?.TargetType;
 
         /// <inheritdoc/>
-        public override bool IsCombinator => false;
+        internal override bool IsCombinator => false;
 
         /// <summary>
         /// Whether the selector matches the concrete <see cref="TargetType"/> or any object which
@@ -89,7 +89,7 @@ namespace Avalonia.Styling
         }
 
         /// <inheritdoc/>
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
         {
             if (TargetType != null)
             {
@@ -134,8 +134,8 @@ namespace Avalonia.Styling
             return Name == null ? SelectorMatch.AlwaysThisType : SelectorMatch.AlwaysThisInstance;
         }
 
-        protected override Selector? MovePrevious() => _previous;
-        protected override Selector? MovePreviousOrParent() => _previous;
+        private protected override Selector? MovePrevious() => _previous;
+        private protected override Selector? MovePreviousOrParent() => _previous;
 
         private string BuildSelectorString(Style? owner)
         {

+ 18 - 18
tests/Avalonia.Benchmarks/Styling/SelectorBenchmark.cs

@@ -37,62 +37,62 @@ namespace Avalonia.Benchmarks.Styling
         }
 
         [Benchmark]
-        public SelectorMatch IsSelector_NoMatch()
+        public void IsSelector_NoMatch()
         {
-            return _isCalendarSelector.Match(_notMatchingControl);
+            _isCalendarSelector.Match(_notMatchingControl);
         }
 
         [Benchmark]
-        public SelectorMatch IsSelector_Match()
+        public void IsSelector_Match()
         {
-            return _isCalendarSelector.Match(_matchingControl);
+            _isCalendarSelector.Match(_matchingControl);
         }
 
         [Benchmark]
-        public SelectorMatch ClassSelector_NoMatch()
+        public void ClassSelector_NoMatch()
         {
-            return _classSelector.Match(_notMatchingControl);
+            _classSelector.Match(_notMatchingControl);
         }
 
         [Benchmark]
-        public SelectorMatch ClassSelector_Match()
+        public void ClassSelector_Match()
         {
-            return _classSelector.Match(_matchingControl);
+            _classSelector.Match(_matchingControl);
         }
 
         [Benchmark]
-        public SelectorMatch OrSelector_One_Match()
+        public void OrSelector_One_Match()
         {
-            return _orSelectorTwo.Match(_matchingControl);
+            _orSelectorTwo.Match(_matchingControl);
         }
 
         [Benchmark]
-        public SelectorMatch OrSelector_Five_Match()
+        public void OrSelector_Five_Match()
         {
-            return _orSelectorFive.Match(_matchingControl);
+            _orSelectorFive.Match(_matchingControl);
         }
     }
 
     internal class AlwaysMatchSelector : Selector
     {
-        public override bool InTemplate => false;
+        internal override bool InTemplate => false;
 
-        public override bool IsCombinator => false;
+        internal override bool IsCombinator => false;
 
-        public override Type TargetType => null;
+        internal override Type TargetType => null;
 
         public override string ToString(Style owner)
         {
             return "Always";
         }
 
-        protected override SelectorMatch Evaluate(StyledElement control, IStyle parent, bool subscribe)
+        private protected override SelectorMatch Evaluate(StyledElement control, IStyle parent, bool subscribe)
         {
             return SelectorMatch.AlwaysThisType;
         }
 
-        protected override Selector MovePrevious() => null;
+        private protected override Selector MovePrevious() => null;
 
-        protected override Selector MovePreviousOrParent() => null;
+        private protected override Selector MovePreviousOrParent() => null;
     }
 }

+ 2 - 2
tests/Avalonia.UnitTests/StyleHelpers.cs

@@ -6,9 +6,9 @@ namespace Avalonia.UnitTests
 {
     public static class StyleHelpers
     {
-        public static SelectorMatchResult TryAttach(Style style, StyledElement element, object? host = null)
+        public static void TryAttach(Style style, StyledElement element, object? host = null)
         {
-            return style.TryAttach(element, host ?? element, PropertyStore.FrameType.Style);
+            style.TryAttach(element, host ?? element, PropertyStore.FrameType.Style);
         }
     }
 }