diff options
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmevent.h')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmevent.h | 117 |
1 files changed, 110 insertions, 7 deletions
diff --git a/src/plugins/platforms/wasm/qwasmevent.h b/src/plugins/platforms/wasm/qwasmevent.h index df9276b746..6ada5393e3 100644 --- a/src/plugins/platforms/wasm/qwasmevent.h +++ b/src/plugins/platforms/wasm/qwasmevent.h @@ -5,11 +5,12 @@ #define QWASMEVENT_H #include "qwasmplatform.h" +#include "qwasmdom.h" #include <QtCore/qglobal.h> #include <QtCore/qnamespace.h> #include <QtGui/qevent.h> - +#include <private/qstdweb_p.h> #include <QPoint> #include <emscripten/html5.h> @@ -17,16 +18,29 @@ QT_BEGIN_NAMESPACE +class QWasmDeadKeySupport; +class QWindow; + enum class EventType { + DragEnd, + DragOver, + DragStart, + Drop, + KeyDown, + KeyUp, PointerDown, PointerMove, PointerUp, PointerEnter, PointerLeave, + PointerCancel, + Wheel, }; enum class PointerType { Mouse, + Touch, + Pen, Other, }; @@ -35,6 +49,8 @@ enum class WindowArea { Client, }; +enum class DeltaMode { Pixel, Line, Page }; + namespace KeyboardModifier { namespace internal { @@ -107,17 +123,46 @@ QFlags<Qt::KeyboardModifier> getForEvent<EmscriptenKeyboardEvent>( } // namespace KeyboardModifier -struct Q_CORE_EXPORT Event +struct Event { + Event(EventType type, emscripten::val webEvent); + ~Event(); + Event(const Event &other); + Event(Event &&other); + Event &operator=(const Event &other); + Event &operator=(Event &&other); + + emscripten::val webEvent; EventType type; + emscripten::val target() const { return webEvent["target"]; } }; -struct Q_CORE_EXPORT MouseEvent : public Event +struct KeyEvent : public Event { - QPoint point; - Qt::MouseButton mouseButton; - Qt::MouseButtons mouseButtons; + static std::optional<KeyEvent> + fromWebWithDeadKeyTranslation(emscripten::val webEvent, QWasmDeadKeySupport *deadKeySupport); + + KeyEvent(EventType type, emscripten::val webEvent); + ~KeyEvent(); + KeyEvent(const KeyEvent &other); + KeyEvent(KeyEvent &&other); + KeyEvent &operator=(const KeyEvent &other); + KeyEvent &operator=(KeyEvent &&other); + + Qt::Key key; QFlags<Qt::KeyboardModifier> modifiers; + bool deadKey; + QString text; +}; + +struct MouseEvent : public Event +{ + MouseEvent(EventType type, emscripten::val webEvent); + ~MouseEvent(); + MouseEvent(const MouseEvent &other); + MouseEvent(MouseEvent &&other); + MouseEvent &operator=(const MouseEvent &other); + MouseEvent &operator=(MouseEvent &&other); static constexpr Qt::MouseButton buttonFromWeb(int webButton) { switch (webButton) { @@ -153,14 +198,72 @@ struct Q_CORE_EXPORT MouseEvent : public Event return QEvent::None; } } + + QPointF localPoint; + QPointF pointInPage; + QPointF pointInViewport; + Qt::MouseButton mouseButton; + Qt::MouseButtons mouseButtons; + QFlags<Qt::KeyboardModifier> modifiers; }; -struct Q_CORE_EXPORT PointerEvent : public MouseEvent +struct PointerEvent : public MouseEvent { static std::optional<PointerEvent> fromWeb(emscripten::val webEvent); + PointerEvent(EventType type, emscripten::val webEvent); + ~PointerEvent(); + PointerEvent(const PointerEvent &other); + PointerEvent(PointerEvent &&other); + PointerEvent &operator=(const PointerEvent &other); + PointerEvent &operator=(PointerEvent &&other); + PointerType pointerType; int pointerId; + qreal pressure; + qreal tiltX; + qreal tiltY; + qreal tangentialPressure; + qreal twist; + qreal width; + qreal height; + bool isPrimary; +}; + +struct DragEvent : public MouseEvent +{ + static std::optional<DragEvent> fromWeb(emscripten::val webEvent, QWindow *targetQWindow); + + DragEvent(EventType type, emscripten::val webEvent, QWindow *targetQWindow); + ~DragEvent(); + DragEvent(const DragEvent &other); + DragEvent(DragEvent &&other); + DragEvent &operator=(const DragEvent &other); + DragEvent &operator=(DragEvent &&other); + + void cancelDragStart(); + void acceptDragOver(); + void acceptDrop(); + + Qt::DropAction dropAction; + dom::DataTransfer dataTransfer; + QWindow *targetWindow; +}; + +struct WheelEvent : public MouseEvent +{ + static std::optional<WheelEvent> fromWeb(emscripten::val webEvent); + + WheelEvent(EventType type, emscripten::val webEvent); + ~WheelEvent(); + WheelEvent(const WheelEvent &other); + WheelEvent(WheelEvent &&other); + WheelEvent &operator=(const WheelEvent &other); + WheelEvent &operator=(WheelEvent &&other); + + DeltaMode deltaMode; + bool webkitDirectionInvertedFromDevice; + QPointF delta; }; QT_END_NAMESPACE |