public void ClickSuppressedOnMouseUpWithinChild() { // Agg currently fires mouse up events in child controls when the parent has the mouse captured // and is performing drag like operations. If the mouse goes down in the parent and comes up on the child // neither control should get a click event int rootClickCount = 0; int childClickCount = 0; lastClicked = null; var systemWindow = new TestHostWindow(300, 200) { Padding = new BorderDouble(20), BackgroundColor = RGBA_Bytes.Gray, Name = "System Window", }; var rootClickable = new GuiWidget() { Width = 50, HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.ParentBottomTop, Margin = new BorderDouble(50), Name = "rootClickable", BackgroundColor = RGBA_Bytes.Blue }; rootClickable.Click += (sender, e) => { var widget = sender as GuiWidget; rootClickCount += 1; var color = widget.BackgroundColor.AdjustSaturation(0.4); systemWindow.BackgroundColor = color.GetAsRGBA_Bytes(); lastClicked = widget; }; rootClickable.AfterDraw += widget_DrawSelection; var childClickable = new GuiWidget() { Width = 35, Height = 25, OriginRelativeParent = new VectorMath.Vector2(20, 15), Name = "childClickable", Margin = new BorderDouble(10), BackgroundColor = RGBA_Bytes.Orange }; childClickable.Click += (sender, e) => { var widget = sender as GuiWidget; childClickCount += 1; var color = widget.BackgroundColor.AdjustSaturation(0.4); systemWindow.BackgroundColor = color.GetAsRGBA_Bytes(); lastClicked = widget; }; childClickable.AfterDraw += widget_DrawSelection; rootClickable.AddChild(childClickable); systemWindow.AddChild(rootClickable); var bounds = rootClickable.BoundsRelativeToParent; double x = bounds.Left + 25; double y = bounds.Bottom + 8; var childBounds = childClickable.BoundsRelativeToParent; double childX = bounds.Left + childBounds.Left + 16; double childY = bounds.Bottom + childBounds.Bottom + 10; UiThread.RunOnIdle((Action)(async() => { try { MouseEventArgs mouseEvent; AutomationRunner testRunner = new AutomationRunner(); // Click should occur on mouse[down/up] within the controls bounds { // Move to a position within rootClickable for mousedown mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0); testRunner.SetMouseCursorPosition(systemWindow, (int)mouseEvent.X, (int)mouseEvent.Y); systemWindow.OnMouseDown(mouseEvent); await Task.Delay(1000); // Move to a position within rootClickable for mouseup mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, x + 119, y + 40, 0); testRunner.SetMouseCursorPosition(systemWindow, (int)mouseEvent.X, (int)mouseEvent.Y); systemWindow.OnMouseUp(mouseEvent); await Task.Delay(1000); Assert.IsTrue(rootClickCount == 1, "Expected 1 click on root widget"); } lastClicked = null; systemWindow.BackgroundColor = RGBA_Bytes.Gray; await Task.Delay(1000); // Click should not occur when mouse up occurs on child controls { // Move to a position within rootClickable for mousedown mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0); testRunner.SetMouseCursorPosition(systemWindow, (int)mouseEvent.X, (int)mouseEvent.Y); systemWindow.OnMouseDown(mouseEvent); await Task.Delay(1000); // Move to a position with the childClickable for mouseup mouseEvent = new MouseEventArgs(MouseButtons.Left, 1, childX, childY, 0); testRunner.SetMouseCursorPosition(systemWindow, (int)mouseEvent.X, (int)mouseEvent.Y); systemWindow.OnMouseUp(mouseEvent); await Task.Delay(1000); // There should be no increment in the click count Assert.IsTrue(rootClickCount == 1, "Expected click count to not increment on mouse up within child control"); } } catch (Exception ex) { systemWindow.ErrorMessage = ex.Message; systemWindow.TestsPassed = false; } UiThread.RunOnIdle(systemWindow.Close, 1); }), 1); systemWindow.ShowAsSystemWindow(); Assert.IsTrue(systemWindow.TestsPassed, systemWindow.ErrorMessage); }