@ -6,6 +6,7 @@ using Avalonia.Controls;
using Avalonia.Headless ;
using Avalonia.Input ;
using Avalonia.Input.Raw ;
using Avalonia.Media ;
using Avalonia.Rendering ;
using Avalonia.UnitTests ;
@ -494,6 +495,60 @@ namespace Avalonia.Base.UnitTests.Input
result ) ;
}
[Fact]
public void Disabled_Element_Should_Set_PointerOver_On_Visual_Parent ( )
{
using var app = UnitTestApplication . Start ( new TestServices ( inputManager : new InputManager ( ) ) ) ;
var renderer = new Mock < IHitTester > ( ) ;
var deviceMock = CreatePointerDeviceMock ( ) ;
var impl = CreateTopLevelImplMock ( ) ;
var disabledChild = new Border
{
Background = Brushes . Red ,
Width = 1 0 0 ,
Height = 1 0 0 ,
IsEnabled = false
} ;
var visualParent = new Border
{
Background = Brushes . Black ,
Width = 1 0 0 ,
Height = 1 0 0 ,
Child = disabledChild
} ;
var logicalParent = new Border
{
Background = Brushes . Blue ,
Width = 1 0 0 ,
Height = 1 0 0
} ;
// Change the logical parent and check that we're correctly hit testing on the visual tree.
// This scenario is made up because it's easy to test.
// In the real world, this happens with nested Popups from MenuItems (but that's very cumbersome to test).
( ( ISetLogicalParent ) disabledChild ) . SetParent ( null ) ;
( ( ISetLogicalParent ) disabledChild ) . SetParent ( logicalParent ) ;
var root = CreateInputRoot (
impl . Object ,
new Panel
{
Children = { visualParent }
} ,
renderer . Object ) ;
Assert . False ( visualParent . IsPointerOver ) ;
SetHit ( renderer , disabledChild ) ;
impl . Object . Input ! ( CreateRawPointerMovedArgs ( deviceMock . Object , root , new Point ( 5 0 , 5 0 ) ) ) ;
Assert . True ( visualParent . IsPointerOver ) ;
Assert . False ( logicalParent . IsPointerOver ) ;
}
private static void AddEnteredExitedHandlers (
EventHandler < PointerEventArgs > handler ,
params IInputElement [ ] controls )