diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 35bf8de5a2ea..742909bfa734 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -2163,13 +2163,11 @@ nsChildView::GetDocumentAccessible(nsIAccessible** aAccessible) // occurs in this view. NSPasteboard* globalDragPboard = nil; -// gLastDragView and gLastDragEvent are only non-null during calls to |mouseDragged:| -// in our native NSView. They are used to communicate information to the drag service -// during drag invocation (starting a drag in from the view). All drag service drag -// invocations happen only while these two global variables are non-null, while |mouseDragged:| -// is on the stack. +// gLastDragView and gLastDragMouseDownEvent are used to communicate information +// to the drag service during drag invocation (starting a drag in from the view). +// gLastDragView is only non-null while mouseDragged is on the call stack. NSView* gLastDragView = nil; -NSEvent* gLastDragEvent = nil; +NSEvent* gLastDragMouseDownEvent = nil; + (void)initialize { @@ -3012,6 +3010,9 @@ static const PRInt32 sShadowInvalidationInterval = 100; mLastMouseDownEvent = [theEvent retain]; } + [gLastDragMouseDownEvent release]; + gLastDragMouseDownEvent = [theEvent retain]; + nsAutoRetainCocoaObject kungFuDeathGrip(self); if ([self maybeRollup:theEvent] || @@ -3231,7 +3232,6 @@ static const PRInt32 sShadowInvalidationInterval = 100; return; gLastDragView = self; - gLastDragEvent = theEvent; nsMouseEvent geckoEvent(PR_TRUE, NS_MOUSE_MOVE, nsnull, nsMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; @@ -3268,9 +3268,8 @@ static const PRInt32 sShadowInvalidationInterval = 100; // Note, sending the above event might have destroyed our widget since we didn't retain. // Fine so long as we don't access any local variables from here on. - gLastDragView = nil; - gLastDragEvent = nil; + // XXX maybe call markedTextSelectionChanged:client: here? NS_OBJC_END_TRY_ABORT_BLOCK; @@ -5953,6 +5952,8 @@ static BOOL keyUpAlreadySentKeyDown = NO; [globalDragPboard release]; globalDragPboard = nil; + [gLastDragMouseDownEvent release]; + gLastDragMouseDownEvent = nil; NS_OBJC_END_TRY_ABORT_BLOCK; } diff --git a/widget/src/cocoa/nsDragService.mm b/widget/src/cocoa/nsDragService.mm index 10f54580eb09..547a6b752d5b 100644 --- a/widget/src/cocoa/nsDragService.mm +++ b/widget/src/cocoa/nsDragService.mm @@ -75,7 +75,7 @@ extern PRLogModuleInfo* sCocoaLog; extern NSPasteboard* globalDragPboard; extern NSView* gLastDragView; -extern NSEvent* gLastDragEvent; +extern NSEvent* gLastDragMouseDownEvent; extern PRBool gUserCancelledDrag; // This global makes the transferable array available to Cocoa's promised @@ -166,7 +166,7 @@ nsDragService::ConstructDragImage(nsIDOMNode* aDOMNode, { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; - NSPoint screenPoint = [[gLastDragView window] convertBaseToScreen:[gLastDragEvent locationInWindow]]; + NSPoint screenPoint = [[gLastDragView window] convertBaseToScreen:[gLastDragMouseDownEvent locationInWindow]]; // Y coordinates are bottom to top, so reverse this if ([[NSScreen screens] count] > 0) screenPoint.y = NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]) - screenPoint.y; @@ -303,12 +303,12 @@ nsDragService::InvokeDragSession(nsIDOMNode* aDOMNode, nsISupportsArray* aTransf // We need to retain the view and the event during the drag in case either gets destroyed. mNativeDragView = [gLastDragView retain]; - mNativeDragEvent = [gLastDragEvent retain]; + mNativeDragEvent = [gLastDragMouseDownEvent retain]; gUserCancelledDrag = PR_FALSE; [mNativeDragView dragImage:image at:localPoint - offset:NSMakeSize(0,0) + offset:NSZeroSize event:mNativeDragEvent pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] source:mNativeDragView