26 case ::UI_MOUSE_EVENT_BUTTON_NONE:
28 case ::UI_MOUSE_EVENT_BUTTON_LEFT:
29 return makeQOhosOptional(Qt::LeftButton);
30 case ::UI_MOUSE_EVENT_BUTTON_RIGHT:
31 return makeQOhosOptional(Qt::RightButton);
32 case ::UI_MOUSE_EVENT_BUTTON_MIDDLE:
33 return makeQOhosOptional(Qt::MiddleButton);
34 case ::UI_MOUSE_EVENT_BUTTON_BACK:
35 return makeQOhosOptional(Qt::BackButton);
36 case ::UI_MOUSE_EVENT_BUTTON_FORWARD:
37 return makeQOhosOptional(Qt::ForwardButton);
46 case ::UI_MOUSE_EVENT_ACTION_UNKNOWN:
48 case ::UI_MOUSE_EVENT_ACTION_PRESS:
49 return makeQOhosOptional(QEvent::MouseButtonPress);
50 case ::UI_MOUSE_EVENT_ACTION_RELEASE:
51 return makeQOhosOptional(QEvent::MouseButtonRelease);
52 case ::UI_MOUSE_EVENT_ACTION_MOVE:
53 return makeQOhosOptional(QEvent::MouseMove);
59class QOhosNativeNodeMouseInputHandler
final :
public std::enable_shared_from_this<QOhosNativeNodeMouseInputHandler>
63 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
64 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef,
72 ch::steady_clock::time_point timestamp;
76 void processMouseEventsInQtThread(std::vector<MouseEvent> &&batch);
78 static bool mayDropMouseEvent(
79 ch::steady_clock::time_point now,
const MouseEvent &event,
const MouseEvent &nextEvent);
81 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
82 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
85 std::function<
void(
std::function<
void(std::vector<MouseEvent> &)>)> m_optMouseEventsHandler;
98void QOhosNativeNodeMouseInputHandler::
handleMouseEvent(::ArkUI_UIInputEvent *uiInputEvent)
100 auto mouseButton =
QArkUi::callArkUi(
101 Q_OHOS_NAMED_FUNC(::OH_ArkUI_MouseEvent_GetMouseButton), uiInputEvent);
102 auto mouseAction =
QArkUi::callArkUi(
103 Q_OHOS_NAMED_FUNC(::OH_ArkUI_MouseEvent_GetMouseAction), uiInputEvent);
105 auto localPosition = QPointF(
106 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_PointerEvent_GetX), uiInputEvent),
107 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_PointerEvent_GetY), uiInputEvent));
109 auto displayPosition = QPointF(
110 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_PointerEvent_GetDisplayX), uiInputEvent),
111 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_PointerEvent_GetDisplayY), uiInputEvent));
113 auto eventTime =
QArkUi::callArkUi(
114 Q_OHOS_NAMED_FUNC(::OH_ArkUI_UIInputEvent_GetEventTime), uiInputEvent);
117 .timestampMs = ch::duration_cast<ch::milliseconds>(ch::nanoseconds(eventTime)),
118 .localPosition = localPosition,
119 .globalPosition = displayPosition,
120 .button = tryMapNativeNodeMouseButtonToQt(mouseButton).valueOr(Qt::NoButton),
121 .eventType = tryMapNativeNodeMouseActionToQt(mouseAction).valueOr(QEvent::None),
122 .modifiers = readKeyModifiersFromOhosUiInputEvent(uiInputEvent),
125 m_hoverEventsGenerator->handleQOhosMouseEvent(mouseEvent);
127 if (!m_optMouseEventsHandler) {
128 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
129 m_optMouseEventsHandler = makeQtOhosBatchingQtRequestsHandler<std::vector<MouseEvent>>(
130 m_imEventHandlerRef.toQObjectThreadSafeRef(),
131 [weakSelf](std::vector<MouseEvent> &&batch) {
132 auto sharedSelf = weakSelf.lock();
134 sharedSelf->processMouseEventsInQtThread(std::move(batch));
138 m_optMouseEventsHandler(
139 [&](std::vector<MouseEvent> &batch) {
140 auto now = std::chrono::steady_clock::now();
141 MouseEvent newEvent{now, mouseEvent};
142 if (!batch.empty() && mayDropMouseEvent(now, batch.back(), newEvent))
144 batch.push_back(newEvent);
193 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
194 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef,
195 std::shared_ptr<QOhosHoverEventsGenerator> hoverEventsGenerator)
197 auto mouseInputHandler = std::make_shared<QOhosNativeNodeMouseInputHandler>(qWindowRef, imEventHandlerRef, hoverEventsGenerator);
198 return [mouseInputHandler](::ArkUI_UIInputEvent *uiInputEvent) {
199 mouseInputHandler->handleMouseEvent(uiInputEvent);