1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0032638: Draw Harness, ViewerTest - HTML input range misbehavior in WebAssembly

ViewerTest_EventManager - added tracking of EMSCRIPTEN_EVENT_FOCUSOUT event.
onWasmMouseCallback() has been adjusted to return FALSE for EMSCRIPTEN_EVENT_TARGET_WINDOW
target to avoid misbehavior of other HTML controls.

WNT_Window::ProcessMessage() now handles WM_SETFOCUS/WM_KILLFOCUS instead of WM_ACTIVATE to track focus changes.

AIS_ViewController::ProcessFocus() now redirects to AIS_ViewController::ResetViewInput() on focus loss.
This fixes issues when key action (like WASD navigation) keep working even after releasing key if window has been switched.
This commit is contained in:
kgv
2021-10-22 15:59:19 +03:00
committed by smoskvin
parent 19da974edc
commit 5f69cfa70c
8 changed files with 102 additions and 10 deletions

View File

@@ -655,7 +655,8 @@ static EM_BOOL onWasmMouseCallback (int theEventType, const EmscriptenMouseEvent
EmscriptenMouseEvent anEvent = *theEvent;
anEvent.targetX -= occJSGetBoundingClientLeft();
anEvent.targetY -= occJSGetBoundingClientTop();
return aWindow->ProcessMouseEvent (*aViewCtrl, theEventType, &anEvent) ? EM_TRUE : EM_FALSE;
aWindow->ProcessMouseEvent (*aViewCtrl, theEventType, &anEvent);
return EM_FALSE;
}
return aWindow->ProcessMouseEvent (*aViewCtrl, theEventType, theEvent) ? EM_TRUE : EM_FALSE;
@@ -702,6 +703,19 @@ static EM_BOOL onWasmKeyCallback (int theEventType, const EmscriptenKeyboardEven
}
return EM_FALSE;
}
//! Handle focus change event.
static EM_BOOL onWasmFocusCallback (int theEventType, const EmscriptenFocusEvent* theEvent, void*)
{
Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
if (!aViewCtrl.IsNull()
&& !ViewerTest::CurrentView().IsNull())
{
Handle(Wasm_Window) aWindow = Handle(Wasm_Window)::DownCast (ViewerTest::CurrentView()->Window());
return aWindow->ProcessFocusEvent (*aViewCtrl, theEventType, theEvent) ? EM_TRUE : EM_FALSE;
}
return EM_FALSE;
}
#endif
// ==============================================================================
@@ -777,6 +791,9 @@ void ViewerTest_EventManager::SetupWindowCallbacks (const Handle(Aspect_Window)&
// keyboard input requires a focusable element or EMSCRIPTEN_EVENT_TARGET_WINDOW
emscripten_set_keydown_callback (aTargetId, anOpaque, toUseCapture, onWasmKeyCallback);
emscripten_set_keyup_callback (aTargetId, anOpaque, toUseCapture, onWasmKeyCallback);
//emscripten_set_focus_callback (aTargetId, anOpaque, toUseCapture, onWasmFocusCallback);
//emscripten_set_focusin_callback (aTargetId, anOpaque, toUseCapture, onWasmFocusCallback);
emscripten_set_focusout_callback (aTargetId, anOpaque, toUseCapture, onWasmFocusCallback);
#else
(void )theWin;
#endif