Browse Source

Enable nullability for InputElement, Interactive, Visual

pull/5955/head
Max Katz 5 years ago
parent
commit
3984ba2ec5
  1. 2
      src/Avalonia.Controls/Control.cs
  2. 4
      src/Avalonia.Controls/IControl.cs
  3. 2
      src/Avalonia.Input/IInputElement.cs
  4. 2
      src/Avalonia.Input/InputElement.cs
  5. 4
      src/Avalonia.Input/KeyboardDevice.cs
  6. 8
      src/Avalonia.Input/MouseDevice.cs
  7. 2
      src/Avalonia.Interactivity/IInteractive.cs
  8. 2
      src/Avalonia.Interactivity/Interactive.cs
  9. 2
      src/Avalonia.Layout/Layoutable.cs
  10. 6
      src/Avalonia.Styling/Controls/ISetInheritanceParent.cs
  11. 6
      src/Avalonia.Styling/Controls/ISetLogicalParent.cs
  12. 6
      src/Avalonia.Styling/IDataContextProvider.cs
  13. 6
      src/Avalonia.Styling/IStyledElement.cs
  14. 2
      src/Avalonia.Styling/StyledElement.cs
  15. 4
      src/Avalonia.Styling/Styling/ISetterValue.cs
  16. 50
      src/Avalonia.Visuals/Visual.cs
  17. 16
      src/Avalonia.Visuals/VisualTree/IVisual.cs

2
src/Avalonia.Controls/Control.cs

@ -201,7 +201,7 @@ namespace Avalonia.Controls
{ {
base.OnLostFocus(e); base.OnLostFocus(e);
if (_focusAdorner != null) if (_focusAdorner?.Parent != null)
{ {
var adornerLayer = (IPanel)_focusAdorner.Parent; var adornerLayer = (IPanel)_focusAdorner.Parent;
adornerLayer.Children.Remove(_focusAdorner); adornerLayer.Children.Remove(_focusAdorner);

4
src/Avalonia.Controls/IControl.cs

@ -3,6 +3,8 @@ using Avalonia.Input;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.VisualTree; using Avalonia.VisualTree;
#nullable enable
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
@ -15,6 +17,6 @@ namespace Avalonia.Controls
INamed, INamed,
IStyledElement IStyledElement
{ {
new IControl Parent { get; } new IControl? Parent { get; }
} }
} }

2
src/Avalonia.Input/IInputElement.cs

@ -3,6 +3,8 @@ using System.Collections.Generic;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.VisualTree; using Avalonia.VisualTree;
#nullable enable
namespace Avalonia.Input namespace Avalonia.Input
{ {
/// <summary> /// <summary>

2
src/Avalonia.Input/InputElement.cs

@ -9,6 +9,8 @@ using Avalonia.Input.TextInput;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.VisualTree; using Avalonia.VisualTree;
#nullable enable
namespace Avalonia.Input namespace Avalonia.Input
{ {
/// <summary> /// <summary>

4
src/Avalonia.Input/KeyboardDevice.cs

@ -60,7 +60,7 @@ namespace Avalonia.Input
ie.IsKeyboardFocusWithin = false; ie.IsKeyboardFocusWithin = false;
} }
el = (IInputElement)el.VisualParent; el = (IInputElement?)el.VisualParent;
} }
} }
@ -212,7 +212,7 @@ namespace Avalonia.Input
Source = element, Source = element,
}; };
IVisual currentHandler = element; IVisual? currentHandler = element;
while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown) while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown)
{ {
var bindings = (currentHandler as IInputElement)?.KeyBindings; var bindings = (currentHandler as IInputElement)?.KeyBindings;

8
src/Avalonia.Input/MouseDevice.cs

@ -377,7 +377,7 @@ namespace Avalonia.Input
e.Source = element; e.Source = element;
e.Handled = false; e.Handled = false;
element.RaiseEvent(e); element.RaiseEvent(e);
element = (IInputElement)element.VisualParent; element = (IInputElement?)element.VisualParent;
} }
root.PointerOverElement = null; root.PointerOverElement = null;
@ -444,7 +444,7 @@ namespace Avalonia.Input
branch = el; branch = el;
break; break;
} }
el = (IInputElement)el.VisualParent; el = (IInputElement?)el.VisualParent;
} }
el = root.PointerOverElement; el = root.PointerOverElement;
@ -460,7 +460,7 @@ namespace Avalonia.Input
e.Source = el; e.Source = el;
e.Handled = false; e.Handled = false;
el.RaiseEvent(e); el.RaiseEvent(e);
el = (IInputElement)el.VisualParent; el = (IInputElement?)el.VisualParent;
} }
el = root.PointerOverElement = element; el = root.PointerOverElement = element;
@ -471,7 +471,7 @@ namespace Avalonia.Input
e.Source = el; e.Source = el;
e.Handled = false; e.Handled = false;
el.RaiseEvent(e); el.RaiseEvent(e);
el = (IInputElement)el.VisualParent; el = (IInputElement?)el.VisualParent;
} }
} }

2
src/Avalonia.Interactivity/IInteractive.cs

@ -1,5 +1,7 @@
using System; using System;
#nullable enable
namespace Avalonia.Interactivity namespace Avalonia.Interactivity
{ {
/// <summary> /// <summary>

2
src/Avalonia.Interactivity/Interactive.cs

@ -3,6 +3,8 @@ using System.Collections.Generic;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.VisualTree; using Avalonia.VisualTree;
#nullable enable
namespace Avalonia.Interactivity namespace Avalonia.Interactivity
{ {
/// <summary> /// <summary>

2
src/Avalonia.Layout/Layoutable.cs

@ -782,7 +782,7 @@ namespace Avalonia.Layout
} }
/// <inheritdoc/> /// <inheritdoc/>
protected sealed override void OnVisualParentChanged(IVisual oldParent, IVisual newParent) protected sealed override void OnVisualParentChanged(IVisual? oldParent, IVisual? newParent)
{ {
LayoutHelper.InvalidateSelfAndChildrenMeasure(this); LayoutHelper.InvalidateSelfAndChildrenMeasure(this);

6
src/Avalonia.Styling/Controls/ISetInheritanceParent.cs

@ -1,3 +1,5 @@
#nullable enable
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
@ -14,6 +16,6 @@ namespace Avalonia.Controls
/// Sets the control's inheritance parent. /// Sets the control's inheritance parent.
/// </summary> /// </summary>
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
void SetParent(IAvaloniaObject parent); void SetParent(IAvaloniaObject? parent);
} }
} }

6
src/Avalonia.Styling/Controls/ISetLogicalParent.cs

@ -1,5 +1,7 @@
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
#nullable enable
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
@ -14,6 +16,6 @@ namespace Avalonia.Controls
/// Sets the control's parent. /// Sets the control's parent.
/// </summary> /// </summary>
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
void SetParent(ILogical parent); void SetParent(ILogical? parent);
} }
} }

6
src/Avalonia.Styling/IDataContextProvider.cs

@ -1,4 +1,6 @@
namespace Avalonia #nullable enable
namespace Avalonia
{ {
/// <summary> /// <summary>
/// Defines an element with a data context that can be used for binding. /// Defines an element with a data context that can be used for binding.
@ -8,6 +10,6 @@
/// <summary> /// <summary>
/// Gets or sets the element's data context. /// Gets or sets the element's data context.
/// </summary> /// </summary>
object DataContext { get; set; } object? DataContext { get; set; }
} }
} }

6
src/Avalonia.Styling/IStyledElement.cs

@ -4,6 +4,8 @@ using Avalonia.Controls;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.Styling; using Avalonia.Styling;
#nullable enable
namespace Avalonia namespace Avalonia
{ {
public interface IStyledElement : public interface IStyledElement :
@ -17,7 +19,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// Occurs when the control has finished initialization. /// Occurs when the control has finished initialization.
/// </summary> /// </summary>
event EventHandler Initialized; event EventHandler? Initialized;
/// <summary> /// <summary>
/// Gets a value that indicates whether the element has finished initialization. /// Gets a value that indicates whether the element has finished initialization.
@ -32,6 +34,6 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets the control's logical parent. /// Gets the control's logical parent.
/// </summary> /// </summary>
IStyledElement Parent { get; } IStyledElement? Parent { get; }
} }
} }

2
src/Avalonia.Styling/StyledElement.cs

@ -465,7 +465,7 @@ namespace Avalonia
/// Sets the styled element's inheritance parent. /// Sets the styled element's inheritance parent.
/// </summary> /// </summary>
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
void ISetInheritanceParent.SetParent(IAvaloniaObject parent) void ISetInheritanceParent.SetParent(IAvaloniaObject? parent)
{ {
InheritanceParent = parent; InheritanceParent = parent;
} }

4
src/Avalonia.Styling/Styling/ISetterValue.cs

@ -1,4 +1,6 @@
namespace Avalonia.Styling #nullable enable
namespace Avalonia.Styling
{ {
/// <summary> /// <summary>
/// Customizes the behavior of a class when added as a value to an <see cref="ISetter"/>. /// Customizes the behavior of a class when added as a value to an <see cref="ISetter"/>.

50
src/Avalonia.Visuals/Visual.cs

@ -11,6 +11,8 @@ using Avalonia.Rendering;
using Avalonia.Utilities; using Avalonia.Utilities;
using Avalonia.VisualTree; using Avalonia.VisualTree;
#nullable enable
namespace Avalonia namespace Avalonia
{ {
/// <summary> /// <summary>
@ -45,8 +47,8 @@ namespace Avalonia
/// <summary> /// <summary>
/// Defines the <see cref="Clip"/> property. /// Defines the <see cref="Clip"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<Geometry> ClipProperty = public static readonly StyledProperty<Geometry?> ClipProperty =
AvaloniaProperty.Register<Visual, Geometry>(nameof(Clip)); AvaloniaProperty.Register<Visual, Geometry?>(nameof(Clip));
/// <summary> /// <summary>
/// Defines the <see cref="IsVisibleProperty"/> property. /// Defines the <see cref="IsVisibleProperty"/> property.
@ -63,14 +65,14 @@ namespace Avalonia
/// <summary> /// <summary>
/// Defines the <see cref="OpacityMask"/> property. /// Defines the <see cref="OpacityMask"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<IBrush> OpacityMaskProperty = public static readonly StyledProperty<IBrush?> OpacityMaskProperty =
AvaloniaProperty.Register<Visual, IBrush>(nameof(OpacityMask)); AvaloniaProperty.Register<Visual, IBrush?>(nameof(OpacityMask));
/// <summary> /// <summary>
/// Defines the <see cref="RenderTransform"/> property. /// Defines the <see cref="RenderTransform"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<ITransform> RenderTransformProperty = public static readonly StyledProperty<ITransform?> RenderTransformProperty =
AvaloniaProperty.Register<Visual, ITransform>(nameof(RenderTransform)); AvaloniaProperty.Register<Visual, ITransform?>(nameof(RenderTransform));
/// <summary> /// <summary>
/// Defines the <see cref="RenderTransformOrigin"/> property. /// Defines the <see cref="RenderTransformOrigin"/> property.
@ -81,8 +83,8 @@ namespace Avalonia
/// <summary> /// <summary>
/// Defines the <see cref="IVisual.VisualParent"/> property. /// Defines the <see cref="IVisual.VisualParent"/> property.
/// </summary> /// </summary>
public static readonly DirectProperty<Visual, IVisual> VisualParentProperty = public static readonly DirectProperty<Visual, IVisual?> VisualParentProperty =
AvaloniaProperty.RegisterDirect<Visual, IVisual>("VisualParent", o => o._visualParent); AvaloniaProperty.RegisterDirect<Visual, IVisual?>(nameof(IVisual.VisualParent), o => o._visualParent);
/// <summary> /// <summary>
/// Defines the <see cref="ZIndex"/> property. /// Defines the <see cref="ZIndex"/> property.
@ -92,8 +94,8 @@ namespace Avalonia
private Rect _bounds; private Rect _bounds;
private TransformedBounds? _transformedBounds; private TransformedBounds? _transformedBounds;
private IRenderRoot _visualRoot; private IRenderRoot? _visualRoot;
private IVisual _visualParent; private IVisual? _visualParent;
/// <summary> /// <summary>
/// Initializes static members of the <see cref="Visual"/> class. /// Initializes static members of the <see cref="Visual"/> class.
@ -128,12 +130,12 @@ namespace Avalonia
/// <summary> /// <summary>
/// Raised when the control is attached to a rooted visual tree. /// Raised when the control is attached to a rooted visual tree.
/// </summary> /// </summary>
public event EventHandler<VisualTreeAttachmentEventArgs> AttachedToVisualTree; public event EventHandler<VisualTreeAttachmentEventArgs>? AttachedToVisualTree;
/// <summary> /// <summary>
/// Raised when the control is detached from a rooted visual tree. /// Raised when the control is detached from a rooted visual tree.
/// </summary> /// </summary>
public event EventHandler<VisualTreeAttachmentEventArgs> DetachedFromVisualTree; public event EventHandler<VisualTreeAttachmentEventArgs>? DetachedFromVisualTree;
/// <summary> /// <summary>
/// Gets the bounds of the control relative to its parent. /// Gets the bounds of the control relative to its parent.
@ -161,7 +163,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets or sets the geometry clip for this visual. /// Gets or sets the geometry clip for this visual.
/// </summary> /// </summary>
public Geometry Clip public Geometry? Clip
{ {
get { return GetValue(ClipProperty); } get { return GetValue(ClipProperty); }
set { SetValue(ClipProperty, value); } set { SetValue(ClipProperty, value); }
@ -174,7 +176,7 @@ namespace Avalonia
{ {
get get
{ {
IVisual node = this; IVisual? node = this;
while (node != null) while (node != null)
{ {
@ -211,7 +213,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets or sets the opacity mask of the control. /// Gets or sets the opacity mask of the control.
/// </summary> /// </summary>
public IBrush OpacityMask public IBrush? OpacityMask
{ {
get { return GetValue(OpacityMaskProperty); } get { return GetValue(OpacityMaskProperty); }
set { SetValue(OpacityMaskProperty, value); } set { SetValue(OpacityMaskProperty, value); }
@ -220,7 +222,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets or sets the render transform of the control. /// Gets or sets the render transform of the control.
/// </summary> /// </summary>
public ITransform RenderTransform public ITransform? RenderTransform
{ {
get { return GetValue(RenderTransformProperty); } get { return GetValue(RenderTransformProperty); }
set { SetValue(RenderTransformProperty, value); } set { SetValue(RenderTransformProperty, value); }
@ -261,7 +263,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets the root of the visual tree, if the control is attached to a visual tree. /// Gets the root of the visual tree, if the control is attached to a visual tree.
/// </summary> /// </summary>
protected IRenderRoot VisualRoot => _visualRoot ?? (this as IRenderRoot); protected IRenderRoot? VisualRoot => _visualRoot ?? (this as IRenderRoot);
/// <summary> /// <summary>
/// Gets a value indicating whether this control is attached to a visual root. /// Gets a value indicating whether this control is attached to a visual root.
@ -276,12 +278,12 @@ namespace Avalonia
/// <summary> /// <summary>
/// Gets the control's parent visual. /// Gets the control's parent visual.
/// </summary> /// </summary>
IVisual IVisual.VisualParent => _visualParent; IVisual? IVisual.VisualParent => _visualParent;
/// <summary> /// <summary>
/// Gets the root of the visual tree, if the control is attached to a visual tree. /// Gets the root of the visual tree, if the control is attached to a visual tree.
/// </summary> /// </summary>
IRenderRoot IVisual.VisualRoot => VisualRoot; IRenderRoot? IVisual.VisualRoot => VisualRoot;
TransformedBounds? IVisual.TransformedBounds TransformedBounds? IVisual.TransformedBounds
{ {
@ -476,12 +478,12 @@ namespace Avalonia
/// </summary> /// </summary>
/// <param name="oldParent">The old visual parent.</param> /// <param name="oldParent">The old visual parent.</param>
/// <param name="newParent">The new visual parent.</param> /// <param name="newParent">The new visual parent.</param>
protected virtual void OnVisualParentChanged(IVisual oldParent, IVisual newParent) protected virtual void OnVisualParentChanged(IVisual? oldParent, IVisual? newParent)
{ {
RaisePropertyChanged( RaisePropertyChanged(
VisualParentProperty, VisualParentProperty,
new Optional<IVisual>(oldParent), new Optional<IVisual?>(oldParent),
new BindingValue<IVisual>(newParent), new BindingValue<IVisual?>(newParent),
BindingPriority.LocalValue); BindingPriority.LocalValue);
} }
@ -582,7 +584,7 @@ namespace Avalonia
/// Sets the visual parent of the Visual. /// Sets the visual parent of the Visual.
/// </summary> /// </summary>
/// <param name="value">The visual parent.</param> /// <param name="value">The visual parent.</param>
private void SetVisualParent(Visual value) private void SetVisualParent(Visual? value)
{ {
if (_visualParent == value) if (_visualParent == value)
{ {
@ -634,7 +636,7 @@ namespace Avalonia
} }
} }
private static void SetVisualParent(IList children, Visual parent) private static void SetVisualParent(IList children, Visual? parent)
{ {
var count = children.Count; var count = children.Count;

16
src/Avalonia.Visuals/VisualTree/IVisual.cs

@ -3,6 +3,8 @@ using Avalonia.Collections;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Rendering; using Avalonia.Rendering;
#nullable enable
namespace Avalonia.VisualTree namespace Avalonia.VisualTree
{ {
/// <summary> /// <summary>
@ -21,12 +23,12 @@ namespace Avalonia.VisualTree
/// <summary> /// <summary>
/// Raised when the control is attached to a rooted visual tree. /// Raised when the control is attached to a rooted visual tree.
/// </summary> /// </summary>
event EventHandler<VisualTreeAttachmentEventArgs> AttachedToVisualTree; event EventHandler<VisualTreeAttachmentEventArgs>? AttachedToVisualTree;
/// <summary> /// <summary>
/// Raised when the control is detached from a rooted visual tree. /// Raised when the control is detached from a rooted visual tree.
/// </summary> /// </summary>
event EventHandler<VisualTreeAttachmentEventArgs> DetachedFromVisualTree; event EventHandler<VisualTreeAttachmentEventArgs>? DetachedFromVisualTree;
/// <summary> /// <summary>
/// Gets the bounds of the control relative to its parent. /// Gets the bounds of the control relative to its parent.
@ -46,7 +48,7 @@ namespace Avalonia.VisualTree
/// <summary> /// <summary>
/// Gets or sets the geometry clip for this visual. /// Gets or sets the geometry clip for this visual.
/// </summary> /// </summary>
Geometry Clip { get; set; } Geometry? Clip { get; set; }
/// <summary> /// <summary>
/// Gets a value indicating whether this control is attached to a visual root. /// Gets a value indicating whether this control is attached to a visual root.
@ -71,12 +73,12 @@ namespace Avalonia.VisualTree
/// <summary> /// <summary>
/// Gets or sets the opacity mask for the control. /// Gets or sets the opacity mask for the control.
/// </summary> /// </summary>
IBrush OpacityMask { get; set; } IBrush? OpacityMask { get; set; }
/// <summary> /// <summary>
/// Gets or sets the render transform of the control. /// Gets or sets the render transform of the control.
/// </summary> /// </summary>
ITransform RenderTransform { get; set; } ITransform? RenderTransform { get; set; }
/// <summary> /// <summary>
/// Gets or sets the render transform origin of the control. /// Gets or sets the render transform origin of the control.
@ -91,12 +93,12 @@ namespace Avalonia.VisualTree
/// <summary> /// <summary>
/// Gets the control's parent visual. /// Gets the control's parent visual.
/// </summary> /// </summary>
IVisual VisualParent { get; } IVisual? VisualParent { get; }
/// <summary> /// <summary>
/// Gets the root of the visual tree, if the control is attached to a visual tree. /// Gets the root of the visual tree, if the control is attached to a visual tree.
/// </summary> /// </summary>
IRenderRoot VisualRoot { get; } IRenderRoot? VisualRoot { get; }
/// <summary> /// <summary>
/// Gets or sets the Z index of the node. /// Gets or sets the Z index of the node.

Loading…
Cancel
Save