5#include <QtCore/private/qohoslogger_p.h>
6#include <private/qhighdpiscaling_p.h>
7#include <qohosinputmethodeventhandler.h>
8#include <qohosjsmain.h>
9#include <qohosplatformintegration.h>
10#include <qohosutils.h>
11#include <render/qohosbatchingrequestshandler.h>
21class QOhosNativeGesturesHandler
final :
public QEnableSharedFromThis<QOhosNativeGesturesHandler>
25 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
31 void processGestureEventsInQtThread(std::vector<QOhosNativeGestureEvent> &&batch);
33 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
35 QOhosConsumer<QOhosNativeGestureEvent> m_gestureEventsHandler;
39 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
49 if (!m_gestureEventsHandler) {
50 auto weakSelf = sharedFromThis().toWeakRef();
51 m_gestureEventsHandler = makeQtOhosSimpleBatchingQtRequestsHandler<QOhosNativeGestureEvent>(
52 m_qWindowRef.toQObjectThreadSafeRef(),
53 [weakSelf](std::vector<QOhosNativeGestureEvent> &&batch) {
54 auto sharedSelf = weakSelf.toStrongRef();
55 if (!sharedSelf.isNull())
56 sharedSelf->processGestureEventsInQtThread(std::move(batch));
60 m_gestureEventsHandler(event);
63void QOhosNativeGesturesHandler::processGestureEventsInQtThread(std::vector<QOhosNativeGestureEvent> &&batch)
65 auto *inputMethodEventHandler =
68 if (inputMethodEventHandler ==
nullptr) {
69 qOhosPrintfError(
"Cannot dispatch gesture event: inputMethodEventHandler is nullptr.");
73 const auto now =
std::chrono::steady_clock::now();
75 const auto mayDropGestureEvent = [now](
const auto &event,
const auto &nextEvent) {
76 return now - event.timestamp >= gestureEventMinAgeForDrop
77 && event.gestureType == nextEvent.gestureType
78 && event.deviceType == nextEvent.deviceType;
82 QtOhos::removeMatchingWithLookahead(
83 batch.begin(), batch.end(), mayDropGestureEvent),
86 const auto *platformScreen = m_qWindowRef.data()->screen()->handle();
88 for (
auto &event : batch) {
89 m_qtThreadEventTransformer(event);
91 auto screenBasedPosition = QHighDpi::fromNativePixels(
92 event.displayBasedPosition, platformScreen);
93 inputMethodEventHandler->onGestureEventFromNativeNode(
94 m_qWindowRef.data(), event.gestureTimestamp, event.value, event.localPosition,
95 screenBasedPosition, event.gestureType, event.deviceType);
102 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
103 std::function<
void(QOhosNativeGestureEvent &)> optQtThreadEventTransformer)
105 auto gesturesHandler = QSharedPointer<QOhosNativeGesturesHandler>::create(
107 optQtThreadEventTransformer
108 ? std::move(optQtThreadEventTransformer)
109 : [](QOhosNativeGestureEvent &) {
111 return [gesturesHandler](
const QOhosNativeGestureEvent &event) {
112 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)