From 6caa06f52b93c17cb2cd3fcb154fc8610788921d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 29 Jul 2019 18:48:44 +0200 Subject: [PATCH] Remove PopupContentHost. It's no longer needed now the bug fix in 669c6511d6158c6f7440ea4927f36971134251d1 is in place. --- src/Avalonia.Controls/Primitives/Popup.cs | 60 ++----------------- .../Primitives/PopupTests.cs | 2 - 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/Popup.cs b/src/Avalonia.Controls/Primitives/Popup.cs index dc92347c9d..18d90c0315 100644 --- a/src/Avalonia.Controls/Primitives/Popup.cs +++ b/src/Avalonia.Controls/Primitives/Popup.cs @@ -84,7 +84,6 @@ namespace Avalonia.Controls.Primitives private IDisposable _nonClientListener; bool _ignoreIsOpenChanged = false; private List _bindings = new List(); - private PopupContentHost _decorator = new PopupContentHost(); /// /// Initializes static members of the class. @@ -237,10 +236,8 @@ namespace Avalonia.Controls.Primitives _bindings.Add(_popupRoot.BindConstraints(this, WidthProperty, MinWidthProperty, MaxWidthProperty, HeightProperty, MinHeightProperty, MaxHeightProperty, TopmostProperty)); - _bindings.Add(_decorator.Bind(PopupContentHost.ChildProperty, this[~ChildProperty])); - _popupRoot.SetContent(_decorator); - + _popupRoot.SetContent(Child); ((ISetLogicalParent)_popupRoot).SetParent(this); @@ -400,15 +397,15 @@ namespace Avalonia.Controls.Primitives private bool IsChildOrThis(IVisual child) { - return _decorator.FindCommonVisualAncestor(child) == _decorator; + return ((IVisual)_popupRoot)?.FindCommonVisualAncestor(child) == _popupRoot; } public bool IsInsidePopup(IVisual visual) { - return _decorator.FindCommonVisualAncestor(visual) == _decorator; + return ((IVisual)_popupRoot)?.FindCommonVisualAncestor(visual) == _popupRoot; } - public bool IsPointerOverPopup => _decorator.IsPointerOver; + public bool IsPointerOverPopup => ((IInputElement)_popupRoot).IsPointerOver; private void WindowDeactivated(object sender, EventArgs e) { @@ -446,54 +443,5 @@ namespace Avalonia.Controls.Primitives _owner._ignoreIsOpenChanged = false; } } - - // For some reason when PopupRoot.Content is bound directly to Child weird stuff happens - class PopupContentHost : Control - { - /// - /// Defines the property. - /// - public static readonly StyledProperty ChildProperty = - AvaloniaProperty.Register(nameof(Child)); - - static PopupContentHost() - { - ChildProperty.Changed.AddClassHandler(x => x.ChildChanged); - } - - public IControl Child - { - get { return GetValue(ChildProperty); } - set { SetValue(ChildProperty, value); } - } - - /// - protected override Size MeasureOverride(Size availableSize) - { - if (Child == null) - return Size.Empty; - Child.Measure(availableSize); - return Child.DesiredSize; - } - - /// - protected override Size ArrangeOverride(Size finalSize) - { - Child?.Arrange(new Rect(finalSize)); - return finalSize; - } - - - private void ChildChanged(AvaloniaPropertyChangedEventArgs e) - { - var oldChild = (Control)e.OldValue; - var newChild = (Control)e.NewValue; - - if (oldChild != null) VisualChildren.Remove(oldChild); - - if (newChild != null) - VisualChildren.Add(newChild); - } - } } } diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs index ccdfe8af33..c61e3d1f68 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs @@ -253,7 +253,6 @@ namespace Avalonia.Controls.UnitTests.Primitives new[] { "ContentPresenter", - "PopupContentHost", "ContentPresenter", "Border", }, @@ -267,7 +266,6 @@ namespace Avalonia.Controls.UnitTests.Primitives new object[] { popupRoot, - target, // PopupContentHost doesn't really need a templated parent, but gets assigned one target, null, },