15class QOhosAxisEventHandler
final :
public std::enable_shared_from_this<QOhosAxisEventHandler>
19 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
20 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef);
26 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
27 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
29 std::optional<QPointF> m_localPosition;
30 std::optional<QPointF> m_globalPosition;
31 std::optional<
std::int32_t> m_wheelScrollLines;
33 QOhosConsumer<
const QOhosNativeGestureEvent &> m_nativeGesturesHandler;
110 const auto now =
std::chrono::steady_clock::now();
112 auto eventTimestamp = OH_ArkUI_UIInputEvent_GetEventTime(event);
113 auto localPosition = QArkUi::getPointerEventLocalPosition(event);
114 auto globalPosition = QArkUi::getPointerEventGlobalPosition(event);
115 double horizontalAxisValue = OH_ArkUI_AxisEvent_GetHorizontalAxisValue(event);
116 double verticalAxisValue = OH_ArkUI_AxisEvent_GetVerticalAxisValue(event);
117 auto eventToolType = OH_ArkUI_UIInputEvent_GetToolType(event);
118 auto eventAxisAction = OH_ArkUI_AxisEvent_GetAxisAction(event);
119 std::int32_t wheelScrollLines;
120 wheelScrollLines = OH_ArkUI_AxisEvent_GetScrollStep(event);
122 m_localPosition = localPosition;
123 m_globalPosition = globalPosition;
124 m_wheelScrollLines = wheelScrollLines;
127 .timestamp = eventTimestamp,
128 .localPoint = localPosition,
129 .globalPoint = globalPosition,
130 .horizontalValue = horizontalAxisValue,
131 .verticalValue = verticalAxisValue,
132 .eventToolType = eventToolType,
133 .scrollPhase = convertArkUiAxisEventActionToQtScrollPhase(eventAxisAction),
134 .wheelScrollLines = wheelScrollLines,
135 .modifiers = readKeyModifiersFromOhosUiInputEvent(event),
138 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
139 m_imEventHandlerRef.visitInQtThreadIfAlive(
140 [weakSelf, ohosWheelEvent, qWindowRef = m_qWindowRef](
auto &eventHandler) {
141 auto sharedSelf = weakSelf.lock();
145 eventHandler.onMouseWheelEvent(ohosWheelEvent, qWindowRef.data());
148 const auto totalScale = OH_ArkUI_AxisEvent_GetPinchAxisScaleValue(event);
150 if (qFuzzyIsNull(horizontalAxisValue) && qFuzzyIsNull(verticalAxisValue) && !qFuzzyIsNull(totalScale)) {
151 const auto deviceType = QArkUi::getPointingDeviceType(event);
152 const auto gestureType = getQtGestureType(
153 static_cast<InputEvent_AxisAction>(eventAxisAction)).value_or(Qt::ZoomNativeGesture);
157 .gestureTimestamp = eventTimestamp,
159 .localPosition = localPosition,
160 .globalPosition = globalPosition,
161 .gestureType = gestureType,
162 .deviceType = deviceType,
165 m_nativeGesturesHandler(newEvent);
171 if (!m_localPosition.has_value() || !m_globalPosition.has_value() || !m_wheelScrollLines.has_value()) {
173 "%s: Cannot create wheel event - incomplete data, ignoring coasting event.", Q_FUNC_INFO);
177 auto *coastingAxisEvent =
QArkUi::callArkUi(
178 Q_OHOS_NAMED_FUNC(::OH_ArkUI_UIInputEvent_GetCoastingAxisEvent), event);
179 auto eventTime =
QArkUi::callArkUi(
180 Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetEventTime), coastingAxisEvent);
181 auto phase =
QArkUi::callArkUi(
182 Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetPhase), coastingAxisEvent);
183 auto delta = QPointF(
184 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetDeltaX), coastingAxisEvent),
185 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetDeltaY), coastingAxisEvent));
187 const QFlags<OhosKeyboardModifier> coastingAxisEventModifiersFallback = {};
190 .timestamp = eventTime,
191 .localPoint = m_localPosition.value(),
192 .globalPoint = m_globalPosition.value(),
193 .horizontalValue = delta.x(),
194 .verticalValue = delta.y(),
195 .eventToolType = ::UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD,
196 .scrollPhase = convertArkUiCoastingAxisEventActionToQtScrollPhase(phase),
197 .wheelScrollLines = m_wheelScrollLines.value(),
198 .modifiers = coastingAxisEventModifiersFallback,
201 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
202 m_imEventHandlerRef.visitInQtThreadIfAlive(
203 [weakSelf, ohosWheelEvent, qWindowRef = m_qWindowRef](
auto &eventHandler) {
204 auto sharedSelf = weakSelf.lock();
205 QWindow *qWindow = qWindowRef.data();
206 if (!sharedSelf || qWindow ==
nullptr)
209 eventHandler.onMouseWheelEvent(ohosWheelEvent, qWindow);
216 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
217 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
219 auto handler = std::make_shared<QOhosAxisEventHandler>(qWindowRef, imEventHandlerRef);
220 return [handler](QOhosAxisEventType eventType, ::ArkUI_UIInputEvent *inputEvent) {
222 case QOhosAxisEventType::AxisEvent:
223 handler->handleUiAxisEvent(inputEvent);
225 case QOhosAxisEventType::CoastingAxisEvent:
226 handler->handleUiCoastingAxisEvent(inputEvent);