0

Is there a standard way to separate MouseClick and MouseDown events in GWT?

If I click and hold button I still get MouseClick event together with MouseUp.

if I just click I still get MouseDown event together with MouseClick.

1 Answer 1

6

These events have some differences. Handle events which you need in a particular situation.

The thing is that in a general case ClickEvent includes MouseDownEvent and MouseUpEvent and cannot take place without of them. MouseDownEvent and MouseUpEvent precede ClickEvent. The same way as ClickEvent precedes DoubleClickEvent. But MouseDownEvent doesn't garantee that an ClickEvent will occur.

  • MouseDownEvent occurs every time when a user presses on one of the mouse buttons inside any element.

  • MouseUpEvent occurs when a user releases one of any mouse buttons.

  • and ClickEvent consists of both of these events. ClickEvent occurs when there're both these events on the same element. It's something like a combination of the mouse down and mouse up events. ClickEvent is generated only for the left mouse button unlike MouseDownEvent and MouseUpEvent.

That's ClickEvent is generated when a mouse is down then up while over an elem. However, the mouse must stay within the same element, otherwise it won't occur.

For example, you pressed mouse down and moved outside of the element and release it. ClickEvent will not generated but MouseDownEvent will in this case.

And if you press mouse down and move outside the element, and move back in, then release it. ClickEvent will occur. And MouseDownEvent with MouseUpEvent will too.

If a user did click then this is the sequence of events:

  1. MouseDownEvent
  2. MouseUpEvent
  3. ClickEvent

ClickEvent fires only after a user has released his mouse button.

Butt there's a way to create ClickEvent without generating of MouseDownEvent and MouseUpEvent:

  • click event will fire if a user used tab key to move the focus to a link and press Enter, but the MouseDown and MouseUp events will not.

Alternatively, you can open a link without generating ClickEvent:

  • click right button on a link and select on a item of dropdown list (in this case only MouseDownEvent and MouseUpEvent will fire)
  • also you can just pick up and drag a link to a new tab

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.