14class QOhosAxisEventHandler
final :
public std::enable_shared_from_this<QOhosAxisEventHandler>
18 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
19 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef);
25 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
26 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
28 QOhosOptional<QPointF> m_localPosition;
29 QOhosOptional<QPointF> m_globalPosition;
30 QOhosOptional<std::int32_t> m_wheelScrollLines;
32 QOhosConsumer<
const QOhosNativeGestureEvent &> m_nativeGesturesHandler;
109 const auto now =
std::chrono::steady_clock::now();
111 auto eventTimestamp = OH_ArkUI_UIInputEvent_GetEventTime(event);
112 auto localPosition = QArkUi::getPointerEventLocalPosition(event);
113 auto globalPosition = QArkUi::getPointerEventGlobalPosition(event);
114 double horizontalAxisValue = OH_ArkUI_AxisEvent_GetHorizontalAxisValue(event);
115 double verticalAxisValue = OH_ArkUI_AxisEvent_GetVerticalAxisValue(event);
116 auto eventToolType = OH_ArkUI_UIInputEvent_GetToolType(event);
117 auto eventAxisAction = OH_ArkUI_AxisEvent_GetAxisAction(event);
118 std::int32_t wheelScrollLines;
119 wheelScrollLines = OH_ArkUI_AxisEvent_GetScrollStep(event);
121 m_localPosition = makeQOhosOptional(localPosition);
122 m_globalPosition = makeQOhosOptional(globalPosition);
123 m_wheelScrollLines = makeQOhosOptional(wheelScrollLines);
126 .timestamp = eventTimestamp,
127 .localPoint = localPosition,
128 .globalPoint = globalPosition,
129 .horizontalValue = horizontalAxisValue,
130 .verticalValue = verticalAxisValue,
131 .eventToolType = eventToolType,
132 .scrollPhase = convertArkUiAxisEventActionToQtScrollPhase(eventAxisAction),
133 .wheelScrollLines = wheelScrollLines,
134 .modifiers = readKeyModifiersFromOhosUiInputEvent(event),
137 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
138 m_imEventHandlerRef.visitInQtThreadIfAlive(
139 [weakSelf, ohosWheelEvent, qWindowRef = m_qWindowRef](
auto &eventHandler) {
140 auto sharedSelf = weakSelf.lock();
144 eventHandler.onMouseWheelEvent(ohosWheelEvent, qWindowRef.data());
147 const auto totalScale = OH_ArkUI_AxisEvent_GetPinchAxisScaleValue(event);
149 if (qFuzzyIsNull(horizontalAxisValue) && qFuzzyIsNull(verticalAxisValue) && !qFuzzyIsNull(totalScale)) {
150 const auto deviceType = QArkUi::getTouchDeviceType(event);
151 const auto gestureType = getQtGestureType(
152 static_cast<InputEvent_AxisAction>(eventAxisAction)).value_or(Qt::ZoomNativeGesture);
156 .gestureTimestamp = eventTimestamp,
158 .localPosition = localPosition,
159 .globalPosition = globalPosition,
160 .gestureType = gestureType,
161 .deviceType = deviceType,
164 m_nativeGesturesHandler(newEvent);
170 if (!m_localPosition.has_value() || !m_globalPosition.has_value() || !m_wheelScrollLines.has_value()) {
172 "%s: Cannot create wheel event - incomplete data, ignoring coasting event.", Q_FUNC_INFO);
176 auto *coastingAxisEvent =
QArkUi::callArkUi(
177 Q_OHOS_NAMED_FUNC(::OH_ArkUI_UIInputEvent_GetCoastingAxisEvent), event);
178 auto eventTime =
QArkUi::callArkUi(
179 Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetEventTime), coastingAxisEvent);
180 auto phase =
QArkUi::callArkUi(
181 Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetPhase), coastingAxisEvent);
182 auto delta = QPointF(
183 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetDeltaX), coastingAxisEvent),
184 QArkUi::callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_CoastingAxisEvent_GetDeltaY), coastingAxisEvent));
186 const QFlags<OhosKeyboardModifier> coastingAxisEventModifiersFallback = {};
189 .timestamp = eventTime,
190 .localPoint = m_localPosition.value(),
191 .globalPoint = m_globalPosition.value(),
192 .horizontalValue = delta.x(),
193 .verticalValue = delta.y(),
194 .eventToolType = ::UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD,
195 .scrollPhase = convertArkUiCoastingAxisEventActionToQtScrollPhase(phase),
196 .wheelScrollLines = m_wheelScrollLines.value(),
197 .modifiers = coastingAxisEventModifiersFallback,
200 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
201 m_imEventHandlerRef.visitInQtThreadIfAlive(
202 [weakSelf, ohosWheelEvent, qWindowRef = m_qWindowRef](
auto &eventHandler) {
203 auto sharedSelf = weakSelf.lock();
204 QWindow *qWindow = qWindowRef.data();
205 if (!sharedSelf || qWindow ==
nullptr)
208 eventHandler.onMouseWheelEvent(ohosWheelEvent, qWindow);
215 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
216 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
218 auto handler = std::make_shared<QOhosAxisEventHandler>(qWindowRef, imEventHandlerRef);
219 return [handler](QOhosAxisEventType eventType, ::ArkUI_UIInputEvent *inputEvent) {
221 case QOhosAxisEventType::AxisEvent:
222 handler->handleUiAxisEvent(inputEvent);
224 case QOhosAxisEventType::CoastingAxisEvent:
225 handler->handleUiCoastingAxisEvent(inputEvent);