8#include <QtCore/private/qmakearray_p.h>
9#include <QtCore/private/qstringiterator_p.h>
10#include <QtCore/qregularexpression.h>
19 return qstrncmp(key, WebDeadKeyValue.data(), WebDeadKeyValue.size()) == 0;
24 if (
auto mapping = QWasmKeyTranslator::mapWebKeyTextToQtKey(code.c_str()))
27 static QRegularExpression regex(QString(QStringLiteral(R"re((?:Key|Digit)(\w))re")));
28 const auto codeQString = QString::fromStdString(code);
29 const auto match = regex.match(codeQString);
31 if (!match.hasMatch())
32 return Qt::Key_unknown;
34 constexpr size_t CharacterIndex = 1;
35 return static_cast<Qt::Key>(match.capturedView(CharacterIndex).at(0).toLatin1());
39 QFlags<Qt::KeyboardModifier> modifiers)
42 auto mapped = getKeyFromCode(code);
45 return Qt::Key_Dead_Diaeresis;
47 return Qt::Key_Dead_Acute;
49 return Qt::Key_Dead_Circumflex;
51 return Qt::Key_Dead_Tilde;
52 case Qt::Key_QuoteLeft:
53 return modifiers.testFlag(Qt::ShiftModifier) ? Qt::Key_Dead_Tilde : Qt::Key_Dead_Grave;
55 return Qt::Key_Dead_Circumflex;
56 case Qt::Key_Apostrophe:
57 return modifiers.testFlag(Qt::ShiftModifier) ? Qt::Key_Dead_Diaeresis
59 case Qt::Key_AsciiTilde:
60 return Qt::Key_Dead_Tilde;
62 return Qt::Key_unknown;
64 }
else if (
auto mapping = QWasmKeyTranslator::mapWebKeyTextToQtKey(key.c_str())) {
69 QString str = QString::fromUtf8(key.c_str()).toUpper();
71 return Qt::Key_unknown;
73 QStringIterator i(str);
74 return static_cast<Qt::Key>(i.next(0));
106 const auto code = event[
"code"].as<
std::string>();
107 const auto webKey = event[
"key"].as<
std::string>();
108 deadKey = isDeadKeyEvent(webKey.c_str());
110 modifiers = KeyboardModifier::getForEvent(event);
111 key = webKeyToQtKey(code, webKey, deadKey, modifiers);
113 text = QString::fromUtf8(webKey);
117 if (key == Qt::Key_Tab)
134 const auto eventType = ([&event]() ->
std::optional<
EventType> {
135 const auto eventTypeString = event[
"type"].as<
std::string>();
137 if (eventTypeString ==
"keydown")
138 return EventType::KeyDown;
139 else if (eventTypeString ==
"keyup")
140 return EventType::KeyUp;
146 auto result =
KeyEvent(*eventType, event);
154 mouseButton = MouseEvent::buttonFromWeb(event[
"button"].as<
int>());
155 mouseButtons = MouseEvent::buttonsFromWeb(event[
"buttons"].as<
unsigned short>());
160 if (type == EventType::PointerDown)
161 mouseButtons |= mouseButton;
162 localPoint = QPointF(event[
"offsetX"].as<qreal>(), event[
"offsetY"].as<qreal>());
163 pointInPage = QPointF(event[
"pageX"].as<qreal>(), event[
"pageY"].as<qreal>());
164 pointInViewport = QPointF(event[
"clientX"].as<qreal>(), event[
"clientY"].as<qreal>());
165 modifiers = KeyboardModifier::getForEvent(event);
180 pointerId = event[
"pointerId"].as<
int>();
181 pointerType = ([type = event[
"pointerType"].as<std::string>()]() {
190 width = event[
"width"].as<qreal>();
191 height = event[
"height"].as<qreal>();
192 pressure = event[
"pressure"].as<qreal>();
193 tiltX = event[
"tiltX"].as<qreal>();
194 tiltY = event[
"tiltY"].as<qreal>();
195 tangentialPressure = event[
"tangentialPressure"].as<qreal>();
196 twist = event[
"twist"].as<qreal>();
197 isPrimary = event[
"isPrimary"].as<
bool>();
212 const auto eventType = ([&event]() ->
std::optional<
EventType> {
213 const auto eventTypeString = event[
"type"].as<
std::string>();
215 if (eventTypeString ==
"pointermove")
216 return EventType::PointerMove;
217 else if (eventTypeString ==
"pointerup")
218 return EventType::PointerUp;
219 else if (eventTypeString ==
"pointerdown")
220 return EventType::PointerDown;
221 else if (eventTypeString ==
"pointerenter")
222 return EventType::PointerEnter;
223 else if (eventTypeString ==
"pointerleave")
224 return EventType::PointerLeave;
236 dropAction = ([event]() {
237 const std::string effect = event[
"dataTransfer"][
"dropEffect"].as<std::string>();
239 if (effect ==
"copy")
240 return Qt::CopyAction;
241 else if (effect ==
"move")
242 return Qt::MoveAction;
243 else if (effect ==
"link")
244 return Qt::LinkAction;
245 return Qt::IgnoreAction;
261 const auto eventType = ([&event]() ->
std::optional<
EventType> {
262 const auto eventTypeString = event[
"type"].as<
std::string>();
263 if (eventTypeString ==
"dragend")
264 return EventType::DragEnd;
265 if (eventTypeString ==
"dragover")
266 return EventType::DragOver;
267 if (eventTypeString ==
"dragstart")
268 return EventType::DragStart;
269 if (eventTypeString ==
"drop")
270 return EventType::Drop;
271 if (eventTypeString ==
"dragleave")
272 return EventType::DragLeave;
277 return DragEvent(*eventType, event, targetWindow);
282 Q_ASSERT_X(type == EventType::DragStart, Q_FUNC_INFO,
"Only supported for DragStart");
283 webEvent.call<
void>(
"preventDefault");
288 Q_ASSERT_X(type == EventType::DragOver, Q_FUNC_INFO,
"Only supported for DragOver");
289 webEvent.call<
void>(
"preventDefault");
294 Q_ASSERT_X(type == EventType::Drop, Q_FUNC_INFO,
"Only supported for Drop");
295 webEvent.call<
void>(
"preventDefault");
301 const int deltaMode = event[
"deltaMode"].as<
int>();
302 const auto jsWheelEventType = emscripten::val::global(
"WheelEvent");
303 if (deltaMode == jsWheelEventType[
"DOM_DELTA_PIXEL"].as<
int>())
305 else if (deltaMode == jsWheelEventType[
"DOM_DELTA_LINE"].as<
int>())
310 delta = QPointF(event[
"deltaX"].as<qreal>(), event[
"deltaY"].as<qreal>());
327 const auto eventType = ([&event]() ->
std::optional<
EventType> {
328 const auto eventTypeString = event[
"type"].as<
std::string>();
330 if (eventTypeString ==
"wheel")
331 return EventType::Wheel;
void applyDeadKeyTranslations(KeyEvent *event)
Combined button and popup list for selecting options.
constexpr std::string_view WebDeadKeyValue
bool isDeadKeyEvent(const char *key)
Qt::Key webKeyToQtKey(const std::string &code, const std::string &key, bool isDeadKey, QFlags< Qt::KeyboardModifier > modifiers)
Qt::Key getKeyFromCode(const std::string &code)
DragEvent & operator=(const DragEvent &other)
DragEvent(EventType type, emscripten::val webEvent, QWindow *targetQWindow)
DragEvent(const DragEvent &other)
DragEvent(DragEvent &&other)
DragEvent & operator=(DragEvent &&other)
Event & operator=(const Event &other)
Event & operator=(Event &&other)
Event(EventType type, emscripten::val webEvent)
Event(const Event &other)
KeyEvent(KeyEvent &&other)
KeyEvent & operator=(const KeyEvent &other)
KeyEvent(EventType type, emscripten::val webEvent)
KeyEvent & operator=(KeyEvent &&other)
KeyEvent(const KeyEvent &other)
MouseEvent(MouseEvent &&other)
MouseEvent(const MouseEvent &other)
MouseEvent(EventType type, emscripten::val webEvent)
MouseEvent & operator=(MouseEvent &&other)
MouseEvent & operator=(const MouseEvent &other)
PointerEvent(const PointerEvent &other)
PointerEvent(PointerEvent &&other)
PointerEvent(EventType type, emscripten::val webEvent)
PointerEvent & operator=(PointerEvent &&other)
PointerEvent & operator=(const PointerEvent &other)
WheelEvent & operator=(WheelEvent &&other)
WheelEvent(const WheelEvent &other)
WheelEvent(WheelEvent &&other)
WheelEvent(EventType type, emscripten::val webEvent)
bool webkitDirectionInvertedFromDevice
WheelEvent & operator=(const WheelEvent &other)