5#include <QtCore/private/qohoslogger_p.h>
6#include <qohosinputmethodeventhandler.h>
7#include <qohosjsmain.h>
8#include <qohosplatformintegration.h>
10#include <render/qohosbatchingrequestshandler.h>
19class QOhosNativeGesturesHandler
final :
public QEnableSharedFromThis<QOhosNativeGesturesHandler>
23 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
29 void processGestureEventsInQtThread(std::vector<QOhosNativeGestureEvent> &&batch);
31 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
33 QOhosConsumer<QOhosNativeGestureEvent> m_gestureEventsHandler;
37 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
47 if (!m_gestureEventsHandler) {
48 auto weakSelf = sharedFromThis().toWeakRef();
49 m_gestureEventsHandler = makeQtOhosSimpleBatchingQtRequestsHandler<QOhosNativeGestureEvent>(
50 m_qWindowRef.toQObjectThreadSafeRef(),
51 [weakSelf](std::vector<QOhosNativeGestureEvent> &&batch) {
52 auto sharedSelf = weakSelf.toStrongRef();
53 if (!sharedSelf.isNull())
54 sharedSelf->processGestureEventsInQtThread(std::move(batch));
58 m_gestureEventsHandler(event);
61void QOhosNativeGesturesHandler::processGestureEventsInQtThread(std::vector<QOhosNativeGestureEvent> &&batch)
63 auto *inputMethodEventHandler =
66 if (inputMethodEventHandler ==
nullptr) {
67 qOhosPrintfError(
"Cannot dispatch gesture event: inputMethodEventHandler is nullptr.");
71 const auto now =
std::chrono::steady_clock::now();
73 const auto mayDropGestureEvent = [now](
const auto &event,
const auto &nextEvent) {
74 return now - event.timestamp >= gestureEventMinAgeForDrop
75 && event.gestureType == nextEvent.gestureType
76 && event.deviceType == nextEvent.deviceType;
80 QtOhos::removeMatchingWithLookahead(
81 batch.begin(), batch.end(), mayDropGestureEvent),
84 for (
auto &event : batch) {
85 m_qtThreadEventTransformer(event);
87 inputMethodEventHandler->onGestureEventFromNativeNode(
89 .targetWindow = m_qWindowRef.data(),
90 .timestamp = event.gestureTimestamp,
92 .localPosition = event.localPosition,
93 .globalPosition = event.globalPosition,
94 .gestureType = event.gestureType,
95 .deviceType = event.deviceType,
103 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
104 std::function<
void(QOhosNativeGestureEvent &)> optQtThreadEventTransformer)
106 auto gesturesHandler = QSharedPointer<QOhosNativeGesturesHandler>::create(
108 optQtThreadEventTransformer
109 ? std::move(optQtThreadEventTransformer)
110 : [](QOhosNativeGestureEvent &) {
112 return [gesturesHandler](
const QOhosNativeGestureEvent &event) {
113 gesturesHandler->processGestureEventInJsThread(event);
QOhosNativeGesturesHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef, std::function< void(QOhosNativeGestureEvent &)> qtThreadEventTransformer)
void processGestureEventInJsThread(const QOhosNativeGestureEvent &event)
Combined button and popup list for selecting options.
constexpr auto gestureEventMinAgeForDrop
QOhosConsumer< const QOhosNativeGestureEvent & > makeQOhosNativeGesturesHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef, std::function< void(QOhosNativeGestureEvent &)> optQtThreadEventTransformer=nullptr)