SDL: SDL emscripten port: preventDefault should not be called on mousedown. Otherwise mouseup will not be fired outside iframe in... (0fbb9)

From 0fbb9c779c753b75a811e49bfa6dce51375038aa Mon Sep 17 00:00:00 2001
From: valid-ptr <[EMAIL REDACTED]>
Date: Wed, 17 May 2023 20:07:22 +0300
Subject: [PATCH] SDL emscripten port: preventDefault should not be called on
 mousedown. Otherwise mouseup will not be fired outside iframe in Chrome-based
 browsers

(cherry picked from commit 424bc4bcf75cebc86b693b4b920ee686ce6550ea)
---
 src/video/emscripten/SDL_emscriptenevents.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index e6c124efffda..fba4dfa25835 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -638,6 +638,7 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse
     Uint8 sdl_button_state;
     SDL_EventType sdl_event_type;
     double css_w, css_h;
+    SDL_bool prevent_default = SDL_FALSE; /* needed for iframe implementation in Chrome-based browsers. */
 
     switch (mouseEvent->button) {
     case 0:
@@ -662,6 +663,7 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse
     } else {
         sdl_button_state = SDL_RELEASED;
         sdl_event_type = SDL_EVENT_MOUSE_BUTTON_UP;
+        prevent_default = SDL_EventEnabled(sdl_event_type);
     }
     SDL_SendMouseButton(0, window_data->window, 0, sdl_button_state, sdl_button);
 
@@ -672,7 +674,7 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse
         return 0;
     }
 
-    return SDL_EventEnabled(sdl_event_type);
+    return prevent_default;
 }
 
 static EM_BOOL Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)