diff options
| author | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-01-24 10:18:34 +0100 |
|---|---|---|
| committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-02-07 18:59:59 +0100 |
| commit | d141d6894960dba7c62d67400a31a49a4abcdb08 (patch) | |
| tree | 8711444671b98ec1f0d889dc9cfc9c0ef013efc3 /src/plugins/platforms/wasm/qwasmwindow.cpp | |
| parent | 62be4ab5be41b09eea16e5675ed4a74c795e58d9 (diff) | |
Transfer the key handling logic to QWasmWindow
Also, use the embind approach as the rest of the events do, and
introduce a KeyEvent class which simplifies and streamlines event
support.
The event translator has been given a more specific function of
just handling the dead keys. Rest of the translation functionality
is coded directly in KeyEvent for more encapsulation.
Change-Id: I11b0262fc42fe920206ecc6de0d434b9d9ab9998
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmwindow.cpp')
| -rw-r--r-- | src/plugins/platforms/wasm/qwasmwindow.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index e0156584e5f..2e75c39cee2 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -11,6 +11,9 @@ #include "qwasmbase64iconstore.h" #include "qwasmdom.h" +#include "qwasmclipboard.h" +#include "qwasmintegration.h" +#include "qwasmkeytranslator.h" #include "qwasmwindow.h" #include "qwasmwindowclientarea.h" #include "qwasmscreen.h" @@ -31,11 +34,13 @@ QT_BEGIN_NAMESPACE Q_GUI_EXPORT int qt_defaultDpiX(); -QWasmWindow::QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingStore *backingStore) +QWasmWindow::QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, + QWasmCompositor *compositor, QWasmBackingStore *backingStore) : QPlatformWindow(w), m_window(w), m_compositor(compositor), m_backingStore(backingStore), + m_deadKeySupport(deadKeySupport), m_document(dom::document()), m_qtWindow(m_document.call<emscripten::val>("createElement", emscripten::val("div"))), m_windowContents(m_document.call<emscripten::val>("createElement", emscripten::val("div"))), @@ -89,15 +94,15 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingSt m_compositor->addWindow(this); - const auto callback = std::function([this](emscripten::val event) { + const auto pointerCallback = std::function([this](emscripten::val event) { if (processPointer(*PointerEvent::fromWeb(event))) event.call<void>("preventDefault"); }); m_pointerEnterCallback = - std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerenter", callback); + std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerenter", pointerCallback); m_pointerLeaveCallback = - std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerleave", callback); + std::make_unique<qstdweb::EventCallback>(m_qtWindow, "pointerleave", pointerCallback); m_dropCallback = std::make_unique<qstdweb::EventCallback>( m_qtWindow, "drop", [this](emscripten::val event) { @@ -110,6 +115,15 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingSt if (processWheel(*WheelEvent::fromWeb(event))) event.call<void>("preventDefault"); }); + + const auto keyCallback = std::function([this](emscripten::val event) { + if (processKey(*KeyEvent::fromWebWithDeadKeyTranslation(event, m_deadKeySupport))) + event.call<void>("preventDefault"); + }); + + m_keyDownCallback = + std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keydown", keyCallback); + m_keyUpCallback = std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keyup", keyCallback); } QWasmWindow::~QWasmWindow() @@ -433,6 +447,26 @@ void QWasmWindow::applyWindowState() setGeometry(newGeom); } +bool QWasmWindow::processKey(const KeyEvent &event) +{ + constexpr bool ProceedToNativeEvent = false; + Q_ASSERT(event.type == EventType::KeyDown || event.type == EventType::KeyUp); + + const auto clipboardResult = + QWasmIntegration::get()->getWasmClipboard()->processKeyboard(event); + + using ProcessKeyboardResult = QWasmClipboard::ProcessKeyboardResult; + if (clipboardResult == ProcessKeyboardResult::NativeClipboardEventNeeded) + return ProceedToNativeEvent; + + const auto result = QWindowSystemInterface::handleKeyEvent( + 0, event.type == EventType::KeyDown ? QEvent::KeyPress : QEvent::KeyRelease, event.key, + event.modifiers, event.text); + return clipboardResult == ProcessKeyboardResult::NativeClipboardEventAndCopiedDataNeeded + ? ProceedToNativeEvent + : result; +} + bool QWasmWindow::processPointer(const PointerEvent &event) { if (event.pointerType != PointerType::Mouse) @@ -548,6 +582,9 @@ void QWasmWindow::requestActivateWindow() if (window()->isTopLevel()) raise(); + + m_canvas.call<void>("focus"); + QPlatformWindow::requestActivateWindow(); } |
