|
|
|
@ -1080,6 +1080,10 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
[Fact] |
|
|
|
public void GetPosition_On_Control_In_Popup_Called_From_Parent_Should_Return_Valid_Coordinates() |
|
|
|
{ |
|
|
|
// This test only applies when using a PopupRoot host and not an overlay popup.
|
|
|
|
if (UsePopupHost) |
|
|
|
return; |
|
|
|
|
|
|
|
using (CreateServices()) |
|
|
|
{ |
|
|
|
var popupContent = new Border() { Height = 100, Width = 100, Background = Brushes.Red }; |
|
|
|
@ -1088,18 +1092,18 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
var popupParent = new Border { Child = popup }; |
|
|
|
var root = PreparedWindow(popupParent); |
|
|
|
|
|
|
|
var raised = 0; |
|
|
|
|
|
|
|
root.LayoutManager.ExecuteInitialLayoutPass(); |
|
|
|
popup.Open(); |
|
|
|
root.LayoutManager.ExecuteLayoutPass(); |
|
|
|
|
|
|
|
var pointer = new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true); |
|
|
|
|
|
|
|
var pts = popupContent.PointToScreen(new Point(10, 10)); |
|
|
|
// Verify that the popup is positioned at 40,40 as descibed by the Horizontal/
|
|
|
|
// VerticalOffset: 10,10 becomes 50,50 in screen coordinates.
|
|
|
|
Assert.Equal(new PixelPoint(50, 50), popupContent.PointToScreen(new Point(10, 10))); |
|
|
|
|
|
|
|
Assert.Equal(new PixelPoint(50, 50), pts); |
|
|
|
// The popup parent is positioned at 0,0 in screen coordinates so client and
|
|
|
|
// screen coordinates are the same.
|
|
|
|
Assert.Equal(new PixelPoint(10, 10), popupParent.PointToScreen(new Point(10, 10))); |
|
|
|
|
|
|
|
// The event will be raised on the popup content at 50,50 (90,90 in screen coordinates)
|
|
|
|
var pointer = new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true); |
|
|
|
var ev = new PointerPressedEventArgs( |
|
|
|
popupContent, |
|
|
|
pointer, |
|
|
|
@ -1109,19 +1113,28 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed), |
|
|
|
KeyModifiers.None); |
|
|
|
|
|
|
|
Point pointRelativeToWindowContent = default; |
|
|
|
var contentRaised = 0; |
|
|
|
var parentRaised = 0; |
|
|
|
|
|
|
|
popupParent.AddHandler(Button.PointerPressedEvent, (s, e) => |
|
|
|
// The event is raised on the popup content in popup coordinates.
|
|
|
|
popupContent.AddHandler(Button.PointerPressedEvent, (s, e) => |
|
|
|
{ |
|
|
|
++raised; |
|
|
|
++contentRaised; |
|
|
|
Assert.Equal(new Point(50, 50), e.GetPosition(popupContent)); |
|
|
|
}); |
|
|
|
|
|
|
|
pointRelativeToWindowContent = e.GetPosition(popupParent); |
|
|
|
// The event is raised on the parent in root coordinates (which in this case are
|
|
|
|
// the same as screen coordinates).
|
|
|
|
popupParent.AddHandler(Button.PointerPressedEvent, (s, e) => |
|
|
|
{ |
|
|
|
++parentRaised; |
|
|
|
Assert.Equal(new Point(90, 90), e.GetPosition(popupParent)); |
|
|
|
}); |
|
|
|
|
|
|
|
popupContent.RaiseEvent(ev); |
|
|
|
|
|
|
|
Assert.Equal(1, raised); |
|
|
|
Assert.Equal(new Point(90, 90), pointRelativeToWindowContent); |
|
|
|
Assert.Equal(1, contentRaised); |
|
|
|
Assert.Equal(1, parentRaised); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1146,28 +1159,16 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
|
|
|
|
private IDisposable CreateServices() |
|
|
|
{ |
|
|
|
return UnitTestApplication.Start(TestServices.StyledWindow.With(windowingPlatform: |
|
|
|
new MockWindowingPlatform(() => MockWindowingPlatform.CreateWindowMock().Object, |
|
|
|
x => |
|
|
|
{ |
|
|
|
if(UsePopupHost) |
|
|
|
return null; |
|
|
|
return MockWindowingPlatform.CreatePopupMock(x).Object; |
|
|
|
}))); |
|
|
|
return UnitTestApplication.Start(TestServices.StyledWindow.With( |
|
|
|
windowingPlatform: CreateMockWindowingPlatform())); |
|
|
|
} |
|
|
|
|
|
|
|
private IDisposable CreateServicesWithFocus() |
|
|
|
{ |
|
|
|
return UnitTestApplication.Start(TestServices.StyledWindow.With(windowingPlatform: |
|
|
|
new MockWindowingPlatform(null, |
|
|
|
x => |
|
|
|
{ |
|
|
|
if (UsePopupHost) |
|
|
|
return null; |
|
|
|
return MockWindowingPlatform.CreatePopupMock(x).Object; |
|
|
|
}), |
|
|
|
focusManager: new FocusManager(), |
|
|
|
keyboardDevice: () => new KeyboardDevice())); |
|
|
|
return UnitTestApplication.Start(TestServices.StyledWindow.With( |
|
|
|
windowingPlatform: CreateMockWindowingPlatform(), |
|
|
|
focusManager: new FocusManager(), |
|
|
|
keyboardDevice: () => new KeyboardDevice())); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1184,6 +1185,23 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
KeyModifiers.None); |
|
|
|
} |
|
|
|
|
|
|
|
private MockWindowingPlatform CreateMockWindowingPlatform() |
|
|
|
{ |
|
|
|
return new MockWindowingPlatform(() => |
|
|
|
{ |
|
|
|
var mock = MockWindowingPlatform.CreateWindowMock(); |
|
|
|
|
|
|
|
mock.Setup(x => x.CreatePopup()).Returns(() => |
|
|
|
{ |
|
|
|
if (UsePopupHost) |
|
|
|
return null; |
|
|
|
return MockWindowingPlatform.CreatePopupMock(mock.Object).Object; |
|
|
|
}); |
|
|
|
|
|
|
|
return mock.Object; |
|
|
|
}, null); |
|
|
|
} |
|
|
|
|
|
|
|
private static Window PreparedWindow(object content = null) |
|
|
|
{ |
|
|
|
var w = new Window { Content = content }; |
|
|
|
|