2

I'm using GWT 2.4 Drag and Drop API to drag elements for data transfer between widgets. Implementing the Drag and Drop behaviour was straight forward but I'm having problems changing the cursor while dragging an element. I've done a bit of research and I've found a few articles on how I could achieve this.

This article http://blog.vjeux.com/2012/css/css-cross-browser-drag-cursor.html suggests that it can be done by setting the cursor property to whichever acceptable value we would want. I've tried (cursor: -webkit-drag; or cursor: move;) on the element to be dragged or the element where an element can be dropped but only added a small image to the bottom right of the cursor icon.

Took a look at this http://www.html5rocks.com/en/tutorials/dnd/basics/, it is said that the cursor(effect) can be changed when dragging or dropping by setting effectAllowed and dropEffect from the dataTransfer object. Despite the GWT Drag and Drop API not exposing none of these properties, I can set them through JSNI yet the effect was the same as before (with CSS).

I've found these questions HTML5 Drag & Drop Change icon/cursor while dragging and Changing Mouse Cursor for HTML5 Drag Drop Files (GMail Drag Drop) on the same subject but none seemed to help to actually change/replace the icon while dragging.

Any help is appreciated.

Test environment:

Ubuntu 12.04.1 Chrome 22

Cheers,

Community
  • 1
  • 1
orangeeli
  • 43
  • 8

1 Answers1

0

I guess the easiest way is to use:

RootPanel.getBodyElement().getStyle().setCursor(Cursor.MOVE);

whenever you start moving and:

RootPanel.getBodyElement().getStyle().setCursor(Cursor.DEFAULT);

whenever your done.

Also you can set CSS-property:

cursor: whatever;

on whatever element you want. You would usually use it like this:

div.over-this-div-the-cursor-becomes-different:hover {
    cursor: move;
}

see: http://www.w3schools.com/cssref/pr_class_cursor.asp

Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
tommueller
  • 2,358
  • 2
  • 32
  • 44
  • This setCursor trick do not seems to work during if set during the DND – Jean-Michel Garcia Oct 15 '12 at 21:23
  • Thanks for your reply noise. I've tried what you have suggested but it didn't work. I've fiddled around with an example from this post http://stackoverflow.com/questions/10119514/html5-drag-drop-change-icon-cursor-while-dragging but the cursor didn't change. I haven't figured it out if you can change the cursor while dragging. Probably not. Most of the examples I've checked set the cursor before dragging. I have to keep digging or just get a work-around. Cheers – orangeeli Oct 19 '12 at 14:29
  • Hi orangeeli. Sorry, but as it seems, it is not possible to do that right now, at least in firefox. I just found this https://developer.mozilla.org/en-US/docs/DragDrop/DataTransfer#mozCursor Sorry for my inconvenient answer. – tommueller Oct 19 '12 at 16:05