Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions site/source/docs/api_reference/html5.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ Defines
EMSCRIPTEN_EVENT_MOUSEMOVE
EMSCRIPTEN_EVENT_MOUSEENTER
EMSCRIPTEN_EVENT_MOUSELEAVE
EMSCRIPTEN_EVENT_CONTEXTMENU

Emscripten mouse events.

Expand All @@ -405,7 +406,7 @@ Struct

.. c:type:: EmscriptenMouseEvent

The event structure passed in `mouse events <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#interface-MouseEvent>`_: `click <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-click>`_, `mousedown <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-mousedown>`_, `mouseup <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-mouseup>`_, `dblclick <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-dblclick>`_, `mousemove <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-mousemove>`_, `mouseenter <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-mouseenter>`_ and `mouseleave <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-mouseleave>`_.
The event structure passed in `mouse events <https://w3c.github.io/pointerevents/#mouseevent>`_: `click <https://w3c.github.io/pointerevents/#click>`_, `mousedown <https://w3c.github.io/pointerevents/#mousedown>`_, `mouseup <https://w3c.github.io/pointerevents/#mouseup>`_, `dblclick <https://w3c.github.io/pointerevents/#dblclick>`_, `mousemove <https://w3c.github.io/pointerevents/#mousemove>`_, `mouseenter <https://w3c.github.io/pointerevents/#mouseenter>`_, `mouseleave <https://w3c.github.io/pointerevents/#mouseleave>`_ and `contextmenu <https://w3c.github.io/pointerevents/#contextmenu>`_.


.. c:member:: double timestamp
Expand Down Expand Up @@ -498,6 +499,7 @@ Functions
EMSCRIPTEN_RESULT emscripten_set_mousemove_callback(const char *target, void *userData, bool useCapture, em_mouse_callback_func callback)
EMSCRIPTEN_RESULT emscripten_set_mouseenter_callback(const char *target, void *userData, bool useCapture, em_mouse_callback_func callback)
EMSCRIPTEN_RESULT emscripten_set_mouseleave_callback(const char *target, void *userData, bool useCapture, em_mouse_callback_func callback)
EMSCRIPTEN_RESULT emscripten_set_contextmenu_callback(const char *target, void *userData, bool useCapture, em_mouse_callback_func callback)

Registers a callback function for receiving browser-generated `mouse input events <https://developer.mozilla.org/en/DOM/MouseEvent>`_.

Expand Down Expand Up @@ -1369,7 +1371,7 @@ Functions

Registers a callback function for receiving the `pointerlockchange <http://www.w3.org/TR/pointerlock/#pointerlockchange-and-pointerlockerror-events>`_ event.

Pointer lock hides the mouse cursor and exclusively gives the target element relative mouse movement events via the `mousemove <https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-mousemove>`_ event.
Pointer lock hides the mouse cursor and exclusively gives the target element relative mouse movement events via the `mousemove <https://w3c.github.io/pointerevents/#mousemove>`_ event.

:param target: |target-parameter-doc|
:type target: const char*
Expand Down
5 changes: 5 additions & 0 deletions src/lib/libhtml5.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ var LibraryHTML5 = {
emscripten_set_mouseout_callback_on_thread: (target, userData, useCapture, callbackfunc, targetThread) =>
registerMouseEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefs.EMSCRIPTEN_EVENT_MOUSEOUT }}}, "mouseout", targetThread),

emscripten_set_contextmenu_callback_on_thread__proxy: 'sync',
emscripten_set_contextmenu_callback_on_thread__deps: ['$registerMouseEventCallback'],
emscripten_set_contextmenu_callback_on_thread: (target, userData, useCapture, callbackfunc, targetThread) =>
registerMouseEventCallback(target, userData, useCapture, callbackfunc, {{{ cDefs.EMSCRIPTEN_EVENT_CONTEXTMENU }}}, "contextmenu", targetThread),

// HTML5 does not really have a polling API for mouse events, so implement one
// manually by returning the data from the most recently received event. This
// requires that user has registered at least some no-op function as an event
Expand Down
1 change: 1 addition & 0 deletions src/lib/libsigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ sigs = {
emscripten_set_canvas_element_size__sig: 'ipii',
emscripten_set_canvas_size__sig: 'vii',
emscripten_set_click_callback_on_thread__sig: 'ippipp',
emscripten_set_contextmenu_callback_on_thread__sig: 'ippipp',
emscripten_set_dblclick_callback_on_thread__sig: 'ippipp',
emscripten_set_devicemotion_callback_on_thread__sig: 'ipipp',
emscripten_set_deviceorientation_callback_on_thread__sig: 'ipipp',
Expand Down
1 change: 1 addition & 0 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@
"EMSCRIPTEN_EVENT_MOUSEOUT",
"EMSCRIPTEN_EVENT_CANVASRESIZED",
"EMSCRIPTEN_EVENT_POINTERLOCKERROR",
"EMSCRIPTEN_EVENT_CONTEXTMENU",

"EMSCRIPTEN_RESULT_SUCCESS",
"EMSCRIPTEN_RESULT_DEFERRED",
Expand Down
1 change: 1 addition & 0 deletions src/struct_info_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"EMSCRIPTEN_EVENT_BLUR": 12,
"EMSCRIPTEN_EVENT_CANVASRESIZED": 37,
"EMSCRIPTEN_EVENT_CLICK": 4,
"EMSCRIPTEN_EVENT_CONTEXTMENU": 39,
"EMSCRIPTEN_EVENT_DBLCLICK": 7,
"EMSCRIPTEN_EVENT_DEVICEMOTION": 17,
"EMSCRIPTEN_EVENT_DEVICEORIENTATION": 16,
Expand Down
1 change: 1 addition & 0 deletions src/struct_info_generated_wasm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"EMSCRIPTEN_EVENT_BLUR": 12,
"EMSCRIPTEN_EVENT_CANVASRESIZED": 37,
"EMSCRIPTEN_EVENT_CLICK": 4,
"EMSCRIPTEN_EVENT_CONTEXTMENU": 39,
"EMSCRIPTEN_EVENT_DBLCLICK": 7,
"EMSCRIPTEN_EVENT_DEVICEMOTION": 17,
"EMSCRIPTEN_EVENT_DEVICEORIENTATION": 16,
Expand Down
3 changes: 3 additions & 0 deletions system/include/emscripten/html5.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ extern "C" {
#define EMSCRIPTEN_EVENT_MOUSEOUT 36
#define EMSCRIPTEN_EVENT_CANVASRESIZED 37
#define EMSCRIPTEN_EVENT_POINTERLOCKERROR 38
#define EMSCRIPTEN_EVENT_CONTEXTMENU 39

#define EMSCRIPTEN_EVENT_TARGET_INVALID 0
#define EMSCRIPTEN_EVENT_TARGET_DOCUMENT ((const char*)1)
Expand Down Expand Up @@ -142,6 +143,7 @@ EMSCRIPTEN_RESULT emscripten_set_mouseenter_callback_on_thread(const char * _Non
EMSCRIPTEN_RESULT emscripten_set_mouseleave_callback_on_thread(const char * _Nonnull target, void *userData, bool useCapture, em_mouse_callback_func callback, pthread_t targetThread);
EMSCRIPTEN_RESULT emscripten_set_mouseover_callback_on_thread(const char * _Nonnull target, void *userData, bool useCapture, em_mouse_callback_func callback, pthread_t targetThread);
EMSCRIPTEN_RESULT emscripten_set_mouseout_callback_on_thread(const char * _Nonnull target, void *userData, bool useCapture, em_mouse_callback_func callback, pthread_t targetThread);
EMSCRIPTEN_RESULT emscripten_set_contextmenu_callback_on_thread(const char * _Nonnull target, void *userData, bool useCapture, em_mouse_callback_func callback, pthread_t targetThread);

EMSCRIPTEN_RESULT emscripten_get_mouse_status(EmscriptenMouseEvent * _Nonnull mouseState);

Expand Down Expand Up @@ -440,6 +442,7 @@ EMSCRIPTEN_RESULT emscripten_html5_remove_event_listener(const char * _Nonnull t
#define emscripten_set_mouseleave_callback(target, userData, useCapture, callback) emscripten_set_mouseleave_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD)
#define emscripten_set_mouseover_callback(target, userData, useCapture, callback) emscripten_set_mouseover_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD)
#define emscripten_set_mouseout_callback(target, userData, useCapture, callback) emscripten_set_mouseout_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD)
#define emscripten_set_contextmenu_callback(target, userData, useCapture, callback) emscripten_set_contextmenu_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD)
#define emscripten_set_wheel_callback(target, userData, useCapture, callback) emscripten_set_wheel_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD)
#define emscripten_set_resize_callback(target, userData, useCapture, callback) emscripten_set_resize_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD)
#define emscripten_set_scroll_callback(target, userData, useCapture, callback) emscripten_set_scroll_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD)
Expand Down
4 changes: 3 additions & 1 deletion test/browser/test_html5_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static inline const char *emscripten_event_type_to_string(int eventType) {
const char *events[] = { "(invalid)", "(none)", "keypress", "keydown", "keyup", "click", "mousedown", "mouseup", "dblclick", "mousemove", "wheel", "resize",
"scroll", "blur", "focus", "focusin", "focusout", "deviceorientation", "devicemotion", "orientationchange", "fullscreenchange", "pointerlockchange",
"visibilitychange", "touchstart", "touchend", "touchmove", "touchcancel", "gamepadconnected", "gamepaddisconnected", "beforeunload",
"batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "(invalid)" };
"batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "canvasresized", "pointerlockerror", "contextmenu", "(invalid)" };
++eventType;
if (eventType < 0) eventType = 0;
if (eventType >= sizeof(events)/sizeof(events[0])) eventType = sizeof(events)/sizeof(events[0])-1;
Expand Down Expand Up @@ -273,6 +273,8 @@ int main() {
ASSERT_RESULT(emscripten_set_mouseover_callback);
ret = emscripten_set_mouseout_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, 1, mouse_callback);
ASSERT_RESULT(emscripten_set_mouseout_callback);
ret = emscripten_set_contextmenu_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, 1, mouse_callback);
ASSERT_RESULT(emscripten_set_contextmenu_callback);

ret = emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, 1, wheel_callback);
ASSERT_RESULT(emscripten_set_wheel_callback);
Expand Down
2 changes: 1 addition & 1 deletion test/browser/test_html5_gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static inline const char *emscripten_event_type_to_string(int eventType) {
const char *events[] = { "(invalid)", "(none)", "keypress", "keydown", "keyup", "click", "mousedown", "mouseup", "dblclick", "mousemove", "wheel", "resize",
"scroll", "blur", "focus", "focusin", "focusout", "deviceorientation", "devicemotion", "orientationchange", "fullscreenchange", "pointerlockchange",
"visibilitychange", "touchstart", "touchend", "touchmove", "touchcancel", "gamepadconnected", "gamepaddisconnected", "beforeunload",
"batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "(invalid)" };
"batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "canvasresized", "pointerlockerror", "contextmenu", "(invalid)" };
++eventType;
if (eventType < 0) eventType = 0;
if (eventType >= sizeof(events)/sizeof(events[0])) eventType = sizeof(events)/sizeof(events[0])-1;
Expand Down
1 change: 1 addition & 0 deletions test/browser/test_html5_unknown_event_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int main(int argc, char **argv) {
assert(emscripten_set_mouseleave_callback("this_dom_element_does_not_exist", 0, 0, mouse_cb) == EMSCRIPTEN_RESULT_UNKNOWN_TARGET);
assert(emscripten_set_mouseover_callback("this_dom_element_does_not_exist", 0, 0, mouse_cb) == EMSCRIPTEN_RESULT_UNKNOWN_TARGET);
assert(emscripten_set_mouseout_callback("this_dom_element_does_not_exist", 0, 0, mouse_cb) == EMSCRIPTEN_RESULT_UNKNOWN_TARGET);
assert(emscripten_set_contextmenu_callback("this_dom_element_does_not_exist", 0, 0, mouse_cb) == EMSCRIPTEN_RESULT_UNKNOWN_TARGET);

assert(emscripten_set_wheel_callback("this_dom_element_does_not_exist", 0, 1, wheel_cb) == EMSCRIPTEN_RESULT_UNKNOWN_TARGET);

Expand Down
5 changes: 3 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 268493,
"a.out.js": 268603,
"a.out.nodebug.wasm": 587520,
"total": 856013,
"total": 856123,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down Expand Up @@ -876,6 +876,7 @@
"emscripten_set_canvas_element_size",
"emscripten_set_canvas_size",
"emscripten_set_click_callback_on_thread",
"emscripten_set_contextmenu_callback_on_thread",
"emscripten_set_dblclick_callback_on_thread",
"emscripten_set_devicemotion_callback_on_thread",
"emscripten_set_deviceorientation_callback_on_thread",
Expand Down
2 changes: 1 addition & 1 deletion test/test_keyboard_codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static inline const char *emscripten_event_type_to_string(int eventType) {
const char *events[] = { "(invalid)", "(none)", "keypress", "keydown", "keyup", "click", "mousedown", "mouseup", "dblclick", "mousemove", "wheel", "resize",
"scroll", "blur", "focus", "focusin", "focusout", "deviceorientation", "devicemotion", "orientationchange", "fullscreenchange", "pointerlockchange",
"visibilitychange", "touchstart", "touchend", "touchmove", "touchcancel", "gamepadconnected", "gamepaddisconnected", "beforeunload",
"batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "(invalid)" };
"batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "canvasresized", "pointerlockerror", "contextmenu", "(invalid)" };
++eventType;
if (eventType < 0) eventType = 0;
if (eventType >= sizeof(events)/sizeof(events[0])) eventType = sizeof(events)/sizeof(events[0])-1;
Expand Down