* {@link MouseEventDetails#getRelativeY()} are relative to.
* @return a MouseEventDetails containing information from the event
*/
public static MouseEventDetails buildMouseEventDetails(NativeEvent evt,
Element relativeToElement) {
MouseEventDetails mouseEventDetails = new MouseEventDetails();
mouseEventDetails.setType(Event.getTypeInt(evt.getType()));
mouseEventDetails.setClientX(Util.getTouchOrMouseClientX(evt));
mouseEventDetails.setClientY(Util.getTouchOrMouseClientY(evt));
if (evt.getButton() == NativeEvent.BUTTON_LEFT) {
mouseEventDetails.setButton(MouseButton.LEFT);
} else if (evt.getButton() == NativeEvent.BUTTON_RIGHT) {
mouseEventDetails.setButton(MouseButton.RIGHT);
} else if (evt.getButton() == NativeEvent.BUTTON_MIDDLE) {
mouseEventDetails.setButton(MouseButton.MIDDLE);
} else {
// IE8 does not always report a button. Assume left.
mouseEventDetails.setButton(MouseButton.LEFT);
}
mouseEventDetails.setAltKey(evt.getAltKey());
mouseEventDetails.setCtrlKey(evt.getCtrlKey());
mouseEventDetails.setMetaKey(evt.getMetaKey());
mouseEventDetails.setShiftKey(evt.getShiftKey());
if (relativeToElement != null) {
mouseEventDetails.setRelativeX(getRelativeX(
mouseEventDetails.getClientX(), relativeToElement));
mouseEventDetails.setRelativeY(getRelativeY(
mouseEventDetails.getClientY(), relativeToElement));
}
return mouseEventDetails;
}