Sunday, December 2, 2012

get x/y of mouse click relative to a Dom mouse event.

I have some rather complex click handling code on a widget that has
the following sort of structure:

@Override
public void onBrowserEvent(Event event) {
event.cancelBubble(true);
event.preventDefault();

switch (DOM.eventGetType(event)) {

case Event.ONCLICK:


int x = Event.getCurrentEvent().getClientX();
int y = Event.getCurrentEvent().getClientY();

//how to get relative X/Y from the element that was clicked.

(stuff to run onclick)

case Event....(handles other forms of mouse action)




This works well, and lets handle everything as needed.
However, because I am using a Event rather then a ClickEvent, theres
no easy way to get the x/y of the click relative to the element that
fired it.
Is there any way to get this information?
I dont think I can cast to ClickEvent, so I need to parse over the
whole dom tree to convert from screen x/y to element-relative x/y?
Seems complex Is there a better way?

Thanks,
Thomas

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

No comments:

Post a Comment