Sunday, August 3, 2025

Don't use the GWT mouse button constants with Elemental2

PSA:  GWT uses old mouse button constants in com.google.gwt.dom.client.NativeEvent:

public static final int BUTTON_LEFT = 1;
public static final int BUTTON_MIDDLE = 4;
public static final int BUTTON_RIGHT = 2;

These are not the correct values to use with Elemental2 elemental2.dom.MouseEvent.button.

JavaScript now uses https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button so these are the correct values:

public static final int BUTTON_LEFT = 0;
public static final int BUTTON_MIDDLE = 1;
public static final int BUTTON_RIGHT = 2;

The keyboard key code constants are also old in GWT, but that one was obvious, as GWT has key codes as integers, while Elemental2 has key codes as strings.

I couldn't find any definitions for these new mouse buttons or key codes.  I still need to have a look at projects like Akasha and Elemento, as hopefully they fix these Elemental2 gotchas.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/cd71cff3-b9d5-47a4-a61f-9e69881b62c0n%40googlegroups.com.

No comments:

Post a Comment