Only prevent the default browser event handling when the specific event types aren't disabled by the user, patch contributed by Jonas Platte
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index b415f5a..776bd3d 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -350,8 +350,10 @@ Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEve
default:
return 0;
}
- SDL_SendMouseButton(window_data->window, 0, eventType == EMSCRIPTEN_EVENT_MOUSEDOWN ? SDL_PRESSED : SDL_RELEASED, sdl_button);
- return 1;
+
+ SDL_EventType sdl_event_type = (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN ? SDL_PRESSED : SDL_RELEASED);
+ SDL_SendMouseButton(window_data->window, 0, sdl_event_type, sdl_button);
+ return SDL_GetEventState(sdl_event_type) == SDL_ENABLE;
}
EM_BOOL
@@ -377,7 +379,7 @@ Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEven
}
SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
- return 1;
+ return SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE;
}
EM_BOOL
@@ -385,7 +387,7 @@ Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, vo
{
SDL_WindowData *window_data = userData;
SDL_SendMouseWheel(window_data->window, 0, wheelEvent->deltaX, -wheelEvent->deltaY, SDL_MOUSEWHEEL_NORMAL);
- return 1;
+ return SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE;
}
EM_BOOL
@@ -397,8 +399,10 @@ Emscripten_HandleFocus(int eventType, const EmscriptenFocusEvent *wheelEvent, vo
if (eventType == EMSCRIPTEN_EVENT_BLUR) {
SDL_ResetKeyboard();
}
+
+
SDL_SendWindowEvent(window_data->window, eventType == EMSCRIPTEN_EVENT_FOCUS ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
- return 1;
+ return SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE;
}
EM_BOOL
@@ -407,6 +411,7 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
SDL_WindowData *window_data = userData;
int i;
double client_w, client_h;
+ int preventDefault = 0;
SDL_TouchID deviceId = 1;
if (SDL_AddTouch(deviceId, "") < 0) {
@@ -434,22 +439,33 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
}
SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
+
+ if (!preventDefault && SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
+ preventDefault = 1;
+ }
} else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
if ((window_data->finger_touching) && (window_data->first_finger == id)) {
SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, x, y);
}
SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
+
+ if (!preventDefault && SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
+ preventDefault = 1;
+ }
} else {
if ((window_data->finger_touching) && (window_data->first_finger == id)) {
SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
window_data->finger_touching = SDL_FALSE;
}
SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
+
+ if (!preventDefault && SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
+ preventDefault = 1;
+ }
}
}
-
- return 1;
+ return preventDefault;
}
EM_BOOL
@@ -479,16 +495,19 @@ Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, voi
break;
}
}
- SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ?
- SDL_PRESSED : SDL_RELEASED, scancode);
+ SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode);
}
}
- /* if we prevent keydown, we won't get keypress
- * also we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
+ SDL_bool prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
+
+ /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
+ * we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
*/
- return SDL_GetEventState(SDL_TEXTINPUT) != SDL_ENABLE || eventType != EMSCRIPTEN_EVENT_KEYDOWN
- || keyEvent->keyCode == 8 /* backspace */ || keyEvent->keyCode == 9 /* tab */;
+ if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && keyEvent->keyCode != 8 /* backspace */ && keyEvent->keyCode != 9 /* tab */)
+ prevent_default = SDL_FALSE;
+
+ return prevent_default;
}
EM_BOOL
@@ -498,7 +517,7 @@ Emscripten_HandleKeyPress(int eventType, const EmscriptenKeyboardEvent *keyEvent
if (Emscripten_ConvertUTF32toUTF8(keyEvent->charCode, text)) {
SDL_SendKeyboardText(text);
}
- return 1;
+ return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE;
}
EM_BOOL