5#include <QtCore/private/qohoslogger_p.h>
6#include <qohosinputmethodeventhandler.h>
7#include <qohosjsmain.h>
8#include <qohosplatformintegration.h>
10#include <render/qohosbatchingrequestshandler.h>
20class QOhosNativeGesturesHandler
final :
public QEnableSharedFromThis<QOhosNativeGesturesHandler>
24 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
30 void processGestureEventsInQtThread(std::vector<QOhosNativeGestureEvent> &&batch);
32 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
34 QOhosConsumer<QOhosNativeGestureEvent> m_gestureEventsHandler;
38 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
48 if (!m_gestureEventsHandler) {
49 auto weakSelf = sharedFromThis().toWeakRef();
50 m_gestureEventsHandler = makeQtOhosSimpleBatchingQtRequestsHandler<QOhosNativeGestureEvent>(
51 m_qWindowRef.toQObjectThreadSafeRef(),
52 [weakSelf](std::vector<QOhosNativeGestureEvent> &&batch) {
53 auto sharedSelf = weakSelf.toStrongRef();
54 if (!sharedSelf.isNull())
55 sharedSelf->processGestureEventsInQtThread(std::move(batch));
59 m_gestureEventsHandler(event);
62void QOhosNativeGesturesHandler::processGestureEventsInQtThread(std::vector<QOhosNativeGestureEvent> &&batch)
64 auto *inputMethodEventHandler =
67 if (inputMethodEventHandler ==
nullptr) {
68 qOhosPrintfError(
"Cannot dispatch gesture event: inputMethodEventHandler is nullptr.");
72 const auto now =
std::chrono::steady_clock::now();
74 const auto mayDropGestureEvent = [now](
const auto &event,
const auto &nextEvent) {
75 return now - event.timestamp >= gestureEventMinAgeForDrop
76 && event.gestureType == nextEvent.gestureType
77 && event.deviceType == nextEvent.deviceType;
81 QtOhos::removeMatchingWithLookahead(
82 batch.begin(), batch.end(), mayDropGestureEvent),
85 for (
auto &event : batch) {
86 m_qtThreadEventTransformer(event);
88 inputMethodEventHandler->onGestureEventFromNativeNode(
90 .targetWindow = m_qWindowRef.data(),
91 .timestamp = event.gestureTimestamp,
93 .localPosition = event.localPosition,
94 .globalPosition = event.globalPosition,
95 .gestureType = event.gestureType,
96 .deviceType = event.deviceType,
104 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
105 std::function<
void(QOhosNativeGestureEvent &)> optQtThreadEventTransformer)
107 auto gesturesHandler = QSharedPointer<QOhosNativeGesturesHandler>::create(
109 optQtThreadEventTransformer
110 ? std::move(optQtThreadEventTransformer)
111 : [](QOhosNativeGestureEvent &) {
113 return [gesturesHandler](
const QOhosNativeGestureEvent &event) {
114 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)