Drag exclusions for drag controllers

45 views
Skip to first unread message

Nathan Byrd

unread,
Oct 27, 2011, 10:22:46 PM10/27/11
to gwt-dnd
I am writing a new web GUI (stackconfig.googlecode.com) for creating
configuration snippets with an interface similar to the kids
programming language Scratch or the javascript toolkit Waterbear. One
of the needs for the interface is to be able to drag blocks around
while configuring those blocks using form controls within the block.
From what I have seen, when similar requests have come up, the answer
is to provide a drag controller on a title bar or similar, which
unfortunately is not desirable in my case. After digging through the
code I have come up with what I believe may be a good solution for
this.

Attached is a patch to add a new HasDragExclusion interface that drag
handlers can implement in order to indicate whether a particular click
should be considered for dragging or excluded. In my case, I am using
it to exclude clicks on form elements, although this could be useful
for other use cases, such as temporarily disabling click capturing
based on application state, etc. See below for an example
implementation of this interface:

public boolean shouldExcludeDrag(EventTarget eventTarget) {
if(Element.is(eventTarget)) {
String targetTagName = Element.as(eventTarget).getTagName();
if(targetTagName.equalsIgnoreCase("input") ||
targetTagName.equalsIgnoreCase("select") ||
targetTagName.equalsIgnoreCase("textarea") ||
targetTagName.equalsIgnoreCase("option")) {
return true;
}
}
return false;
}

@Override
public boolean shouldExcludeMouseDrag(MouseDownEvent mouseDownEvent) {
return
shouldExcludeDrag(mouseDownEvent.getNativeEvent().getEventTarget());
}

@Override
public boolean shouldExcludeTouchDrag(TouchStartEvent touchStartEvent) {
return
shouldExcludeDrag(touchStartEvent.getNativeEvent().getEventTarget());
}


Please let me know if you have any questions or comments, or if you
know of any way to implement the same behavior without this patch.

Thank you,

Nathan Byrd

dragexclusion.patch

Fred Sauer

unread,
Oct 28, 2011, 12:18:44 AM10/28/11
to gwt...@googlegroups.com
If you set drag sensitivity > 0 you should be able to allow click interactivity with widgets that are draggable.


Nathan Byrd

--
You received this message because you are subscribed to the Google Groups "gwt-dnd" group.
To post to this group, send email to gwt...@googlegroups.com.
To unsubscribe from this group, send email to gwt-dnd+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gwt-dnd?hl=en.




--
Fred Sauer
Developer Advocate
G
ooglInc.
1600 Amphitheatre Parkway
Mountain View, CA 94043
fre...@google.com


Nathan Byrd

unread,
Oct 28, 2011, 12:40:58 AM10/28/11
to gwt...@googlegroups.com
I had tried that, but unfortunately that didn't work for me. It looks
like MouseDragHandler in onMouseDown() calls event.preventDefault()
before the conditional for drag sensitivity, so the original click
event is cancelled even with sensitivity > 0. I thought about trying
to move the event.preventDefault() instead, but didn't want to do that
in case it was intentional so that the behavior stays the same. If
that isn't necessary that might be another option though.

Thank you,

Nathan

Nathan Byrd

unread,
Oct 28, 2011, 12:41:36 AM10/28/11
to gwt...@googlegroups.com
Thank you for the quick reply. I had tried that, but unfortunately
that didn't work either. It looks like MouseDragHandler calls

event.preventDefault() before the conditional for drag sensitivity, so
the original click event is cancelled even with sensitivity > 0. I
thought about trying to move the .preventDefault() instead, but didn't

want to do that in case it was intentional so that the behavior stays
the same. If that isn't necessary that might be another option
though.

luke

unread,
Nov 15, 2011, 7:20:02 PM11/15/11
to gwt-dnd
I just want to second this thread. This is exactly the feature that
I'm after too. I'd prefer to go forward with the 'master' version of
gwt-dnd, rather than having this custom patch on it. Any thoughts
about applying this feature?

Fred Sauer

unread,
Jan 21, 2012, 7:26:52 PM1/21/12
to gwt...@googlegroups.com
Patches welcome :)
fr...@allen-sauer.com

Andigator

unread,
Jan 23, 2012, 1:21:48 PM1/23/12
to gwt-dnd
+1 for this as well. My OnClick handlers are never reached due to
event.preventDefault(). I suppose I will revert to an older version
of gwt-dnd because this changes the behavior of our application.

Norbert

unread,
May 10, 2012, 6:26:32 AM5/10/12
to gwt...@googlegroups.com
+1 here as well :)

We need this feature, too.
Reply all
Reply to author
Forward
0 new messages