Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 332599 - Inconsistent behavior when dragging and releasing mouse outside Canvas on MacOSX Cocoa
Summary: Inconsistent behavior when dragging and releasing mouse outside Canvas on Mac...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Scott Kovatch CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 329986
  Show dependency tree
 
Reported: 2010-12-15 02:42 EST by Alexander Nyßen CLA
Modified: 2011-01-25 16:35 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Nyßen CLA 2010-12-15 02:42:04 EST
Using the following snippet, 

public class Snippet {
	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell();
		shell.setLayout(new FillLayout());
		final Canvas canvas = new Canvas(shell, SWT.NONE);
		canvas.addListener(SWT.MouseExit, new Listener() {

			public void handleEvent(Event event) {
				System.out.println("Mouse exited: " + event);
			}
		});
		canvas.addListener(SWT.MouseUp, new Listener() {

			public void handleEvent(Event event) {
				System.out.println("Mouse up: " + event);
			}
		});
		shell.setSize(300, 300);
		shell.open();

		while (!shell.isDisposed()) {
			while (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
}

when clicking into the canvas area and releasing the mouse outside the viewer, on Windows XP, the mouse up event is received before the mouse exit event, while on MacOSX Cocoa, the mouse exit event is received before the mouse up event. As a GEF mechanism depends on the order of both events (see bug #329986), and as the mechanism is working on Windows XP as well as on MacOSX Carbon, the different behavior on MacOSX Cocoa seems to be a regression.
Comment 1 Scott Kovatch CLA 2010-12-15 13:51:55 EST
I would argue that Windows is wrong in this case. The mouse leaves the Canvas before the mouse is released, so I would expect the mouse exit to happen before the mouse up.
Comment 2 Scott Kovatch CLA 2010-12-15 20:29:56 EST
Actually, I see how this was working in Carbon. In Carbon we call runEnterExit() to generate MouseEnter and MouseExit after an event is handled in Display.readAndDispatch(). This means that the MouseExit will always happen after the MouseUp as desired.

In Cocoa we don't do it that way -- we call checkEnterExit during mouse event processing, and it's being called before the mouse down/up/moved is sent.

This is fixable; I just need to move the checkEnterExit after the calls to sendMouseEvent.
Comment 3 Alexander Nyßen CLA 2010-12-16 02:23:54 EST
From a conceptual viewpoint I would basically agree to your first comment, while one may also argue that a drag-operation could be regarded as being kind of "atomic" so that the exit event should not occur before the operation has been completed by a mouse up. 

From the technical viewpoint, the current behavior in carbon and windows (and potentially all other platforms except cocoa) seems to be quite practical (at least for GEF), as it perfectly supports the use case of dragging/resizing something out of the visible canvas area (in combination will a FigureCanvas that can scroll), while otherwise the drag/resize operation would be "interrrupted" by an exit event. 

While I would prefer to adjust the cocoa behavior to that of the other platforms (because I do not have to start caching events in GEF to keep track of intermediate exit events), the most important point for me would be to make the behavior consistent across platforms.
Comment 4 Scott Kovatch CLA 2010-12-16 12:01:47 EST
(In reply to comment #3)
> While I would prefer to adjust the cocoa behavior to that of the other
> platforms (because I do not have to start caching events in GEF to keep track
> of intermediate exit events), the most important point for me would be to make
> the behavior consistent across platforms.

This is one of those cases where changing the code to 'do the right thing' is pointless because the original behavior was set in stone so long ago. I have a patch that fixes this, but there's one other place in the code I need to check first.
Comment 5 Scott Kovatch CLA 2010-12-16 16:55:06 EST
Fixed > 2010-12-16. Fix for the problem in this bug was easy but Button and other controls that go into NSEventTrackingRunLoopMode needed more testing.
Comment 6 Scott Kovatch CLA 2010-12-16 16:55:17 EST
.