fredsa / gwt-dnd

Library providing easy to use mouse or touch based drag-and-drop capabilities to GWT
42 stars 41 forks source link

Miscalculation of DragContext's mouseX and mouseY when the drag handle is not the draggable. #159

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Does the issue occur in "quirks mode", "standards mode" or both? If you
don't know, does your HTML page contains a DOCTYPE declaration?
standards mode

What version of GWT are you using? 1.4.60? 2.0.4? Other?
2.3.0

What version of the gwt-dnd jar file or library file are you using?
3.1.1

What operating system(s) are you using? Windows? Linux? Mac?
Windows

Does the issue occur in web mode, development mode (formerly "hosted
mode"), both or don't know?
At least dev mode.

What browser(s) do you use? Chrome, Firefox, IE, Safari, other?

What is the browser version (if you know) from Help->About?

What steps will reproduce the problem? Please attach sample code if you can.
class MouseDragHandler :

  public void onMouseDown(MouseDownEvent event) {
    ...
    Widget sender = (Widget) event.getSource();
    int x = event.getX();
    int y = event.getY();
    ...
    // mouse down (not first mouse move) determines draggable widget
    mouseDownWidget = sender;
    context.draggable = dragHandleMap.get(mouseDownWidget).getDragable();
    ... 
    mouseDownOffsetX = x;
    mouseDownOffsetY = y;
    WidgetLocation loc1 = new WidgetLocation(mouseDownWidget, null);
    if (mouseDownWidget != context.draggable) {
      WidgetLocation loc2 = new WidgetLocation(context.draggable, null);
      mouseDownOffsetX += loc1.getLeft() - loc2.getLeft();
      mouseDownOffsetY += loc1.getTop() - loc2.getTop();
    }
    ...

mouseDownOffsetX and mouseDownOffsetY are the mouse offset coordinates from the 
draggable's (top, left).

And :
  public void onMouseMove(MouseMoveEvent event) {
    ...
    if (dragging == ACTIVELY_DRAGGING || dragging == DRAGGING_NO_MOVEMENT_YET) {
        ...
    } else {
      if (mouseDownWidget != null) {
        ...
          // set context.mouseX/Y before startDragging() is called
          Location location = new WidgetLocation(mouseDownWidget, null);
          context.mouseX = mouseDownOffsetX + location.getLeft();
          context.mouseY = mouseDownOffsetY + location.getTop();

          startDragging();
          ...

When startDragging() is called, context.mouseX and mouseY are computed by 
adding the draggable offset to the drag handle's location.

For the same reason, at the end of onMouseDown(), the computing of 
mouseDownPageOffsetX ( = mouseDownOffsetX + loc1.getLeft()) and 
mouseDownPageOffsetY don't seems to be correct.

What is the expected output? What do you see instead?

Do you have a workaround?
In onMouseMove(), maybe the location used should be the context.draggable's one 
:
          Location location = new WidgetLocation(context.draggable, null);

Please provide any additional information below.

Original issue reported on code.google.com by frederic...@gmail.com on 6 Apr 2012 at 2:14