8005405: [macosx] Drag and Drop: wrong animation when dropped outside any drop target.
Summary: Changed the calculation of the drag image offset
Reviewed-by: serb, kizune
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java Thu Jan 31 18:51:17 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java Mon Feb 04 13:54:53 2013 +0000
@@ -88,40 +88,25 @@
DragGestureEvent trigger = getTrigger();
InputEvent triggerEvent = trigger.getTriggerEvent();
- Point dragOrigin = trigger.getDragOrigin();
+ Point dragOrigin = new Point(trigger.getDragOrigin());
int extModifiers = (triggerEvent.getModifiers() | triggerEvent.getModifiersEx());
long timestamp = triggerEvent.getWhen();
int clickCount = ((triggerEvent instanceof MouseEvent) ? (((MouseEvent) triggerEvent).getClickCount()) : 1);
- // Get drag source component and its peer:
Component component = trigger.getComponent();
- Point componentOffset = new Point();
- ComponentPeer peer = component.getPeer();
-
- // For a lightweight component traverse up the hierarchy to the first heavyweight
- // which will be used as the ComponentModel for the native drag source.
- if (component.isLightweight()) {
- Point loc = component.getLocation();
- componentOffset.translate(loc.x, loc.y);
-
- for (Component parent = component.getParent(); parent != null; parent = parent.getParent()) {
- if (parent.isLightweight() == false) {
- peer = parent.getPeer();
- break;
- }
-
- loc = parent.getLocation();
- componentOffset.translate(loc.x, loc.y);
- }
+ // For a lightweight component traverse up the hierarchy to the root
+ Point loc = component.getLocation();
+ Component rootComponent = component;
+ while (!(rootComponent instanceof Window)) {
+ dragOrigin.translate(loc.x, loc.y);
+ rootComponent = rootComponent.getParent();
+ loc = rootComponent.getLocation();
}
- // Make sure the drop target is a ComponentModel:
- if (!(peer instanceof LWComponentPeer))
- throw new IllegalArgumentException("DragSource's peer must be a ComponentModel.");
-
- // Get model pointer (CButton.m and such) and its native peer:
- LWComponentPeer model = (LWComponentPeer) peer;
- CPlatformWindow platformWindow = (CPlatformWindow) model.getPlatformWindow();
+ //It sure will be LWComponentPeer instance as rootComponent is a Window
+ LWComponentPeer peer = (LWComponentPeer)rootComponent.getPeer();
+ //Get a pointer to a native window
+ CPlatformWindow platformWindow = (CPlatformWindow) peer.getPlatformWindow();
long nativeWindowPtr = platformWindow.getNSWindowPtr();
// Get drag cursor:
@@ -155,7 +140,7 @@
try {
// Create native dragging source:
final long nativeDragSource = createNativeDragSource(component, peer, nativeWindowPtr, transferable, triggerEvent,
- (int) (dragOrigin.getX() + componentOffset.x), (int) (dragOrigin.getY() + componentOffset.y), extModifiers,
+ (int) (dragOrigin.getX()), (int) (dragOrigin.getY()), extModifiers,
clickCount, timestamp, cursor, fDragCImage, dragImageOffset.x, dragImageOffset.y,
getDragSourceContext().getSourceActions(), formats, formatMap);
@@ -165,8 +150,8 @@
setNativeContext(nativeDragSource);
CCursorManager.getInstance().startDrag(
- (int) (dragOrigin.getX() + componentOffset.x),
- (int) (dragOrigin.getY() + componentOffset.y));
+ (int) (dragOrigin.getX()),
+ (int) (dragOrigin.getY()));
}
catch (Exception e) {
--- a/jdk/src/macosx/native/sun/awt/CDragSource.m Thu Jan 31 18:51:17 2013 +0400
+++ b/jdk/src/macosx/native/sun/awt/CDragSource.m Mon Feb 04 13:54:53 2013 +0000
@@ -443,9 +443,9 @@
NSGraphicsContext* graphicsContext = [NSGraphicsContext graphicsContextWithWindow:window];
// Convert mouse coordinates to NS:
- NSPoint location = NSMakePoint(fDragPos.x, fDragPos.y);
- NSPoint eventLocation = [fView convertPoint:location toView:nil];
-
+ NSPoint eventLocation = [fView convertPoint:NSMakePoint(fDragPos.x, fDragPos.y) toView:nil];
+ eventLocation.y = [[fView window] frame].size.height - eventLocation.y;
+
// Convert fTriggerEventTimeStamp to NS - AWTEvent.h defines UTC(nsEvent) as ((jlong)[event timestamp] * 1000):
NSTimeInterval timeStamp = fTriggerEventTimeStamp / 1000;
@@ -497,12 +497,9 @@
NSImage* dragImage = fDragImage;
// Get drag origin and offset:
- NSPoint dragOrigin;
- dragOrigin.x = fDragPos.x;
- dragOrigin.y = fDragPos.y;
- dragOrigin = [view convertPoint:[dragEvent locationInWindow] fromView:nil];
+ NSPoint dragOrigin = [dragEvent locationInWindow];
dragOrigin.x += fDragImageOffset.x;
- dragOrigin.y += [dragImage size].height + fDragImageOffset.y;
+ dragOrigin.y -= fDragImageOffset.y + [dragImage size].height;
// Drag offset values don't seem to matter:
NSSize dragOffset = NSMakeSize(0, 0);
@@ -516,7 +513,6 @@
DLog5(@" - drag image: %f, %f (%f x %f)", fDragImageOffset.x, fDragImageOffset.y, [dragImage size].width, [dragImage size].height);
DLog3(@" - event point (window) %f, %f", [dragEvent locationInWindow].x, [dragEvent locationInWindow].y);
DLog3(@" - drag point (view) %f, %f", dragOrigin.x, dragOrigin.y);
-
// Set up the fDragKeyModifier, so we know if the operation has changed
// Set up the fDragMouseModifier, so we can |= it later (since CoreDrag doesn't tell us mouse states during a drag)
fDragKeyModifiers = [DnDUtilities extractJavaExtKeyModifiersFromJavaExtModifiers:fModifiers];