From 71bf9d8eda0fc407d4e2f496a39127e2b2035f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=89=AC=E6=96=8C?= Date: Tue, 30 Apr 2024 15:34:18 +0800 Subject: [PATCH] wxOSX: Relax DoDragDrop() constraints. DoDragDrop() not assert 'It must be called in response to a mouse down or drag event.'. But when the user start DnD something from a frame rendered by CEF or similar framework, it should be perfectly valid. --- src/osx/cocoa/dnd.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/osx/cocoa/dnd.mm b/src/osx/cocoa/dnd.mm index 00b6c3d159e0..1c16ca77e627 100644 --- a/src/osx/cocoa/dnd.mm +++ b/src/osx/cocoa/dnd.mm @@ -494,8 +494,21 @@ - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type if (view) { NSEvent* theEvent = (NSEvent*)wxTheApp->MacGetCurrentEvent(); - wxASSERT_MSG(theEvent, "DoDragDrop must be called in response to a mouse down or drag event."); - + // relax the constraint set for DoDragDrop(). + // if the user start DnD something from a frame rendered by CEF or similar framework, it should be perfectly valid. + if (theEvent == nil){ + NSPoint mouse_location = [NSEvent mouseLocation]; + theEvent = [NSEvent mouseEventWithType:NSEventTypeLeftMouseDragged + location:mouse_location + modifierFlags:0 + timestamp: 0 + windowNumber: [NSWindow windowNumberAtPoint:mouse_location belowWindowWithWindowNumber:0] + context:nil + eventNumber: 0 + clickCount: 0 + pressure: 1.0]; + } + gCurrentSource = this; DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];