Merged
重构轴事件处理,适配更多场景 - 3.27 #860
重构轴事件处理,适配更多场景 - 3.27 #860
Merged
MTChannnAdd on Jun 5, 2025
Total: 8 files changed+406-1
@@ -205,6 +205,8 @@ source_set("fml") {
205 205 
206 #"platform/ohos/message_loop_ohos_test.cc",206 #"platform/ohos/message_loop_ohos_test.cc",
207 #"platform/ohos/message_loop_ohos_test.h",207 #"platform/ohos/message_loop_ohos_test.h",
208+ "platform/ohos/dynamic_library_loader.cpp",
209+ "platform/ohos/dynamic_library_loader.h",
208 "platform/ohos/napi_util.h",210 "platform/ohos/napi_util.h",
209 "platform/ohos/ohos_trace_event.cc",211 "platform/ohos/ohos_trace_event.cc",
210 "platform/ohos/paths_ohos.cc",212 "platform/ohos/paths_ohos.cc",
@@ -216,6 +218,7 @@ source_set("fml") {
216 libs += [ "ace_napi.z" ]218 libs += [ "ace_napi.z" ]
217 libs += [ "uv" ]219 libs += [ "uv" ]
218 libs += [ "hitrace_ndk.z" ]220 libs += [ "hitrace_ndk.z" ]
221+ libs += [ "deviceinfo_ndk.z" ]
219 } else if (is_linux) {222 } else if (is_linux) {
220 sources += [223 sources += [
221 "platform/linux/message_loop_linux.cc",224 "platform/linux/message_loop_linux.cc",
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved.
3+ * Use of this source code is governed by a BSD-style license that can be
4+ * found in the LICENSE_HW file.
5+ */
6+ 
7+#include "dynamic_library_loader.h"
8+#include "deviceinfo.h"
9+#include "flutter/fml/logging.h"
10+ 
11+namespace flutter {
12+ 
13+DynamicLibraryLoader::DynamicLibraryLoader(const char* libName)
14+ : handle_(nullptr) {
15+ handle_ = dlopen(libName, RTLD_LAZY | RTLD_LOCAL);
16+ if (!handle_) {
17+ FML_LOG(ERROR) << "dlopen(" << libName << ") failed: " << dlerror();
18+ }
19+}
20+ 
21+DynamicLibraryLoader::~DynamicLibraryLoader() {
22+ if (handle_) {
23+ dlclose(handle_);
24+ }
25+}
26+ 
27+int DynamicLibraryLoader::GetApiVersion() {
28+ // 函数内 static,第一次调用时初始化一次,后面都直接返回缓存值
29+ static int api_version = OH_GetSdkApiVersion();
30+ return api_version;
31+}
32+ 
33+bool DynamicLibraryLoader::LoadSymbols(
34+ const std::vector<SymbolInfo>& symbolInfos) {
35+ if (!handle_)
36+ return false;
37+ 
38+ bool allLoaded = true;
39+ int currentApi = GetApiVersion();
40+ for (const auto& info : symbolInfos) {
41+ *info.target = nullptr; // 手动赋值为 nullptr,避免使用未初始化的指针
42+ if (currentApi >= info.minApi) {
43+ *info.target = dlsym(handle_, info.name);
44+ if (*info.target == nullptr) {
45+ FML_LOG(ERROR) << "dlsym failed for " << info.name << ": " << dlerror();
46+ allLoaded = false;
47+ } else {
48+ FML_LOG(INFO) << "Loaded symbol " << info.name;
49+ }
50+ } else {
51+ FML_LOG(INFO) << "Skipping " << info.name
52+ << " (requires API >= " << info.minApi
53+ << ", current = " << currentApi << ")";
54+ allLoaded = false;
55+ }
56+ }
57+ 
58+ return allLoaded;
59+}
60+ 
61+} // namespace flutter
@@ -0,0 +1,39 @@
1+/*
2+ * Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved.
3+ * Use of this source code is governed by a BSD-style license that can be
4+ * found in the LICENSE_HW file.
5+ */
6+ 
7+#ifndef FLUTTER_FML_PLATFORM_OHOS_DYNAMIC_LIBRARY_LOADER_H_
8+#define FLUTTER_FML_PLATFORM_OHOS_DYNAMIC_LIBRARY_LOADER_H_
9+ 
10+#include <dlfcn.h>
11+#include <cstdint>
12+#include <vector>
13+ 
14+namespace flutter {
15+ 
16+struct SymbolInfo {
17+ const char* name; // 符号名称
18+ void** target; // 接收函数指针的变量地址
19+ int minApi; // 最低支持的 API 版本
20+};
21+ 
22+class DynamicLibraryLoader {
23+ public:
24+ explicit DynamicLibraryLoader(const char* libName);
25+ ~DynamicLibraryLoader();
26+ 
27+ bool LoadSymbols(const std::vector<SymbolInfo>& symbolInfos);
28+ 
29+ bool IsLoaded() const { return handle_ != nullptr; }
30+ 
31+ static int GetApiVersion();
32+ 
33+ private:
34+ void* handle_;
35+};
36+ 
37+} // namespace flutter
38+ 
39+#endif // FLUTTER_FML_PLATFORM_OHOS_DYNAMIC_LIBRARY_LOADER_H_
@@ -22,6 +22,7 @@ import TextInputPlugin from '../plugin/editing/TextInputPlugin';
22import { accessibility } from '@kit.AccessibilityKit';22import { accessibility } from '@kit.AccessibilityKit';
23import { uiObserver } from '@kit.ArkUI';23import { uiObserver } from '@kit.ArkUI';
24import { common } from '@kit.AbilityKit';24import { common } from '@kit.AbilityKit';
25+import { deviceInfo } from '@kit.BasicServicesKit';
25 26 
26const TAG = "FlutterViewTag";27const TAG = "FlutterViewTag";
27const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS';28const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS';
@@ -685,7 +686,9 @@ export class FlutterView {
685 }686 }
686 687 
687 onMouseWheel(eventType: string, event: PanGestureEvent) {688 onMouseWheel(eventType: string, event: PanGestureEvent) {
688- this.flutterEngine?.getFlutterNapi()?.xComponentDisPatchMouseWheel(this.id, eventType, event);689+ if (deviceInfo.sdkApiVersion <= 15) { // API15 后通过轴事件处理滚动
690+ this.flutterEngine?.getFlutterNapi()?.xComponentDisPatchMouseWheel(this.id, eventType, event);
691+ }
689 }692 }
690 693 
691 addFirstFrameListener(listener: FirstFrameListener) {694 addFirstFrameListener(listener: FirstFrameListener) {
@@ -5,6 +5,8 @@
5 */5 */
6 6 
7#include "flutter/shell/platform/ohos/ohos_touch_processor.h"7#include "flutter/shell/platform/ohos/ohos_touch_processor.h"
8+#include <arkui/native_type.h>
9+#include <dlfcn.h>
8#include "flutter/fml/trace_event.h"10#include "flutter/fml/trace_event.h"
9#include "flutter/lib/ui/window/pointer_data_packet.h"11#include "flutter/lib/ui/window/pointer_data_packet.h"
10#include "flutter/shell/platform/ohos/ohos_shell_holder.h"12#include "flutter/shell/platform/ohos/ohos_shell_holder.h"
@@ -15,6 +17,11 @@ constexpr int MSEC_PER_SECOND = 1000;
15constexpr int PER_POINTER_MEMBER = 10;17constexpr int PER_POINTER_MEMBER = 10;
16constexpr int CHANGES_POINTER_MEMBER = 10;18constexpr int CHANGES_POINTER_MEMBER = 10;
17constexpr int TOUCH_EVENT_ADDITIONAL_ATTRIBUTES = 4;19constexpr int TOUCH_EVENT_ADDITIONAL_ATTRIBUTES = 4;
20+constexpr int DEFAULT_SCALE_DEVICE_ID = -101;
21+constexpr int DEFAULT_SRCOLL_DEVICE_ID = -102;
22+constexpr int DEFAULT_PANZOOM_DEVICE_ID = -103;
23+constexpr double ZOOM_IN = 10.0 / 8.0;
24+constexpr double ZOOM_OUT = 1.0 / ZOOM_IN;
18 25 
19PointerData::Change OhosTouchProcessor::getPointerChangeForAction(26PointerData::Change OhosTouchProcessor::getPointerChangeForAction(
20 int maskedAction) {27 int maskedAction) {
@@ -201,6 +208,234 @@ void OhosTouchProcessor::HandleTouchEvent(
201 PlatformViewOnTouchEvent(shell_holderID, toolType, component, touchEvent);208 PlatformViewOnTouchEvent(shell_holderID, toolType, component, touchEvent);
202}209}
203 210 
211+OhosTouchProcessor::OhosTouchProcessor()
212+ : apiVersion_(0),
213+ loader_(std::make_unique<DynamicLibraryLoader>(UI_INPUT_EVENT_LIB_NAME)),
214+ dynamicGetDeviceId_(nullptr),
215+ dynamicGetAxisAction_(nullptr),
216+ dynamicGetModifierKeyStates_(nullptr) {
217+ apiVersion_ = DynamicLibraryLoader::GetApiVersion();
218+ FML_LOG(INFO) << "Current SDK API Version: " << apiVersion_;
219+ 
220+ std::vector<SymbolInfo> symbols = {
221+ {"OH_ArkUI_UIInputEvent_GetDeviceId",
222+ reinterpret_cast<void**>(&dynamicGetDeviceId_), 14},
223+ {"OH_ArkUI_AxisEvent_GetAxisAction",
224+ reinterpret_cast<void**>(&dynamicGetAxisAction_), 15},
225+ {"OH_ArkUI_UIInputEvent_GetModifierKeyStates",
226+ reinterpret_cast<void**>(&dynamicGetModifierKeyStates_), 17},
227+ };
228+ 
229+ loader_->LoadSymbols(symbols);
230+}
231+ 
232+OhosTouchProcessor::~OhosTouchProcessor() {}
233+ 
234+// 处理轴事件:触控板中的捏合缩放和滚动抛滑手势,鼠标中的滚轮滑动和Ctrl+滚轮缩放
235+void OhosTouchProcessor::HandleAxisEvent(int64_t shell_holderID,
236+ OH_NativeXComponent* component,
237+ ArkUI_UIInputEvent* event) {
238+ if (event == nullptr) {
239+ return;
240+ }
241+ 
242+ if (apiVersion_ < 15) {
243+ // API15 前轴事件接口不完善,会走 XComponentBase::OnDispatchMouseWheelEvent
244+ // 处理滚动
245+ return;
246+ }
247+ 
248+ // 获取工具类型
249+ int32_t toolType = OH_ArkUI_UIInputEvent_GetToolType(event);
250+ if (toolType == UI_INPUT_EVENT_TOOL_TYPE_MOUSE) {
251+ // 鼠标滚轮事件
252+ uint64_t keys = 0;
253+ int32_t errorCode = dynamicGetModifierKeyStates_ != nullptr
254+ ? dynamicGetModifierKeyStates_(event, &keys)
255+ : 0;
256+ if (errorCode != ARKUI_ERROR_CODE_PARAM_INVALID &&
257+ keys & ARKUI_MODIFIER_KEY_CTRL) {
258+ // Ctrl+鼠标滚轮
259+ HandleScaleEvent(shell_holderID, component, event);
260+ } else {
261+ // 鼠标滚轮
262+ HandleScrollEvent(shell_holderID, component, event);
263+ }
264+ } else {
265+ // 捏合缩放和滚动抛滑
266+ HandlePanZooomEvent(shell_holderID, component, event);
267+ }
268+ return;
269+}
270+ 
271+// 处理Ctrl+鼠标滚轮缩放
272+void OhosTouchProcessor::HandleScaleEvent(int64_t shell_holderID,
273+ OH_NativeXComponent* component,
274+ ArkUI_UIInputEvent* event) {
275+ if (event == nullptr) {
276+ return;
277+ }
278+ 
279+ const int numTouchPoints = 1;
280+ std::unique_ptr<flutter::PointerDataPacket> packet =
281+ std::make_unique<flutter::PointerDataPacket>(numTouchPoints);
282+ PointerData pointerData;
283+ pointerData.Clear();
284+ 
285+ // 获取 PointerData 状态类型并处理缩放累计值
286+ int32_t axisAction = dynamicGetAxisAction_ != nullptr
287+ ? dynamicGetAxisAction_(event)
288+ : UI_TOUCH_EVENT_ACTION_CANCEL;
289+ switch (axisAction) {
290+ case UI_TOUCH_EVENT_ACTION_CANCEL:
291+ pointerData.change = PointerData::Change::kCancel;
292+ break;
293+ case UI_TOUCH_EVENT_ACTION_DOWN:
294+ pointerData.change = PointerData::Change::kPanZoomStart;
295+ // 重置累计值
296+ accumulatedScale_ = 1.0;
297+ break;
298+ case UI_TOUCH_EVENT_ACTION_MOVE:
299+ pointerData.change = PointerData::Change::kPanZoomUpdate;
300+ // 更新累计值
301+ accumulatedScale_ *= OH_ArkUI_AxisEvent_GetVerticalAxisValue(event) < 0
302+ ? ZOOM_IN
303+ : ZOOM_OUT;
304+ break;
305+ case UI_TOUCH_EVENT_ACTION_UP:
306+ pointerData.change = PointerData::Change::kPanZoomEnd;
307+ break;
308+ default:
309+ FML_LOG(ERROR) << "HandleScaleEvent: AxisAction is not defined";
310+ pointerData.change = PointerData::Change::kCancel;
311+ break;
312+ }
313+ pointerData.scale = accumulatedScale_;
314+ 
315+ pointerData.physical_x = OH_ArkUI_PointerEvent_GetX(event);
316+ pointerData.physical_y = OH_ArkUI_PointerEvent_GetY(event);
317+ pointerData.time_stamp =
318+ OH_ArkUI_UIInputEvent_GetEventTime(event) / MSEC_PER_SECOND;
319+ pointerData.device = dynamicGetDeviceId_ != nullptr
320+ ? dynamicGetDeviceId_(event)
321+ : DEFAULT_SCALE_DEVICE_ID;
322+ if (pointerData.device == -1) {
323+ // 如果 deviceId 为 -1,则设置为默认值
324+ pointerData.device = DEFAULT_SCALE_DEVICE_ID;
325+ }
326+ pointerData.kind = PointerData::DeviceKind::kTrackpad;
327+ 
328+ packet->SetPointerData(0, pointerData);
329+ auto ohos_shell_holder = reinterpret_cast<OHOSShellHolder*>(shell_holderID);
330+ ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket(
331+ std::move(packet));
332+ return;
333+}
334+ 
335+// 处理鼠标滚轮滚动
336+void OhosTouchProcessor::HandleScrollEvent(int64_t shell_holderID,
337+ OH_NativeXComponent* component,
338+ ArkUI_UIInputEvent* event) {
339+ const int numTouchPoints = 1;
340+ std::unique_ptr<flutter::PointerDataPacket> packet =
341+ std::make_unique<flutter::PointerDataPacket>(numTouchPoints);
342+ PointerData pointerData;
343+ pointerData.Clear();
344+ 
345+ // 处理滚动值
346+ pointerData.scroll_delta_x = OH_ArkUI_AxisEvent_GetHorizontalAxisValue(event);
347+ pointerData.scroll_delta_y = OH_ArkUI_AxisEvent_GetVerticalAxisValue(event);
348+ 
349+ pointerData.physical_x = OH_ArkUI_PointerEvent_GetX(event);
350+ pointerData.physical_y = OH_ArkUI_PointerEvent_GetY(event);
351+ pointerData.time_stamp =
352+ OH_ArkUI_UIInputEvent_GetEventTime(event) / MSEC_PER_SECOND;
353+ pointerData.device = dynamicGetDeviceId_ != nullptr
354+ ? dynamicGetDeviceId_(event)
355+ : DEFAULT_SRCOLL_DEVICE_ID;
356+ if (pointerData.device == -1) {
357+ // 如果 deviceId 为 -1,则设置为默认值
358+ pointerData.device = DEFAULT_SRCOLL_DEVICE_ID;
359+ }
360+ pointerData.kind = PointerData::DeviceKind::kMouse;
361+ pointerData.change = PointerData::Change::kHover;
362+ pointerData.signal_kind = PointerData::SignalKind::kScroll;
363+ 
364+ packet->SetPointerData(0, pointerData);
365+ auto ohos_shell_holder = reinterpret_cast<OHOSShellHolder*>(shell_holderID);
366+ ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket(
367+ std::move(packet));
368+ return;
369+}
370+ 
371+// 处理触控板双指捏合缩放和双指滚动抛滑
372+void OhosTouchProcessor::HandlePanZooomEvent(int64_t shell_holderID,
373+ OH_NativeXComponent* component,
374+ ArkUI_UIInputEvent* event) {
375+ const int numTouchPoints = 1;
376+ std::unique_ptr<flutter::PointerDataPacket> packet =
377+ std::make_unique<flutter::PointerDataPacket>(numTouchPoints);
378+ PointerData pointerData;
379+ pointerData.Clear();
380+ 
381+ // 获取 PointerData 状态类型并处理滑动累计值
382+ int32_t axisAction = dynamicGetAxisAction_ != nullptr
383+ ? dynamicGetAxisAction_(event)
384+ : UI_TOUCH_EVENT_ACTION_CANCEL;
385+ switch (axisAction) {
386+ case UI_TOUCH_EVENT_ACTION_CANCEL:
387+ pointerData.change = PointerData::Change::kCancel;
388+ break;
389+ case UI_TOUCH_EVENT_ACTION_DOWN:
390+ pointerData.change = PointerData::Change::kPanZoomStart;
391+ // 重置累计值
392+ accumulatedPanX_ = 0.0;
393+ accumulatedPanY_ = 0.0;
394+ break;
395+ case UI_TOUCH_EVENT_ACTION_MOVE:
396+ pointerData.change = PointerData::Change::kPanZoomUpdate;
397+ // 更新累计值
398+ accumulatedPanX_ += 0 - OH_ArkUI_AxisEvent_GetHorizontalAxisValue(event);
399+ accumulatedPanY_ += 0 - OH_ArkUI_AxisEvent_GetVerticalAxisValue(event);
400+ break;
401+ case UI_TOUCH_EVENT_ACTION_UP:
402+ pointerData.change = PointerData::Change::kPanZoomEnd;
403+ break;
404+ default:
405+ FML_LOG(ERROR) << "HandlePanZooomEvent: AxisAction is not defined";
406+ pointerData.change = PointerData::Change::kCancel;
407+ break;
408+ }
409+ pointerData.pan_x = accumulatedPanX_;
410+ pointerData.pan_y = accumulatedPanY_;
411+ 
412+ // 处理缩放值
413+ pointerData.scale = OH_ArkUI_AxisEvent_GetPinchAxisScaleValue(event);
414+ if (pointerData.scale == 0) {
415+ // 如果 scale 为 0,则设置为默认值 1.0
416+ pointerData.scale = 1.0;
417+ }
418+ 
419+ pointerData.physical_x = OH_ArkUI_PointerEvent_GetX(event);
420+ pointerData.physical_y = OH_ArkUI_PointerEvent_GetY(event);
421+ pointerData.time_stamp =
422+ OH_ArkUI_UIInputEvent_GetEventTime(event) / MSEC_PER_SECOND;
423+ pointerData.device = dynamicGetDeviceId_ != nullptr
424+ ? dynamicGetDeviceId_(event)
425+ : DEFAULT_PANZOOM_DEVICE_ID;
426+ if (pointerData.device == -1) {
427+ // 如果 deviceId 为 -1,则设置为默认值
428+ pointerData.device = DEFAULT_PANZOOM_DEVICE_ID;
429+ }
430+ pointerData.kind = PointerData::DeviceKind::kTrackpad;
431+ 
432+ packet->SetPointerData(0, pointerData);
433+ auto ohos_shell_holder = reinterpret_cast<OHOSShellHolder*>(shell_holderID);
434+ ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket(
435+ std::move(packet));
436+ return;
437+}
438+ 
204void OhosTouchProcessor::PlatformViewOnTouchEvent(439void OhosTouchProcessor::PlatformViewOnTouchEvent(
205 int64_t shellHolderID,440 int64_t shellHolderID,
206 OH_NativeXComponent_TouchPointToolType toolType,441 OH_NativeXComponent_TouchPointToolType toolType,
@@ -7,8 +7,10 @@
7#ifndef FLUTTER_SHELL_PLATFORM_OHOS_OHOS_TOUCH_PROCESSOR_H_7#ifndef FLUTTER_SHELL_PLATFORM_OHOS_OHOS_TOUCH_PROCESSOR_H_
8#define FLUTTER_SHELL_PLATFORM_OHOS_OHOS_TOUCH_PROCESSOR_H_8#define FLUTTER_SHELL_PLATFORM_OHOS_OHOS_TOUCH_PROCESSOR_H_
9#include <ace/xcomponent/native_interface_xcomponent.h>9#include <ace/xcomponent/native_interface_xcomponent.h>
10+#include <arkui/ui_input_event.h>
10#include <string>11#include <string>
11#include <vector>12#include <vector>
13+#include "flutter/fml/platform/ohos/dynamic_library_loader.h"
12#include "flutter/lib/ui/window/pointer_data.h"14#include "flutter/lib/ui/window/pointer_data.h"
13#include "napi_common.h"15#include "napi_common.h"
14 16 
@@ -27,6 +29,18 @@ class OhosTouchProcessor {
27 void HandleTouchEvent(int64_t shell_holderID,29 void HandleTouchEvent(int64_t shell_holderID,
28 OH_NativeXComponent* component,30 OH_NativeXComponent* component,
29 OH_NativeXComponent_TouchEvent* touchEvent);31 OH_NativeXComponent_TouchEvent* touchEvent);
32+ void HandleAxisEvent(int64_t shell_holderID,
33+ OH_NativeXComponent* component,
34+ ArkUI_UIInputEvent* event);
35+ void HandleScaleEvent(int64_t shell_holderID,
36+ OH_NativeXComponent* component,
37+ ArkUI_UIInputEvent* event);
38+ void HandleScrollEvent(int64_t shell_holderID,
39+ OH_NativeXComponent* component,
40+ ArkUI_UIInputEvent* event);
41+ void HandlePanZooomEvent(int64_t shell_holderID,
42+ OH_NativeXComponent* component,
43+ ArkUI_UIInputEvent* event);
30 void HandleMouseEvent(int64_t shell_holderID,44 void HandleMouseEvent(int64_t shell_holderID,
31 OH_NativeXComponent* component,45 OH_NativeXComponent* component,
32 OH_NativeXComponent_MouseEvent mouseEvent,46 OH_NativeXComponent_MouseEvent mouseEvent,
@@ -46,6 +60,25 @@ class OhosTouchProcessor {
46 public:60 public:
47 OH_NativeXComponent_TouchPointToolType touchType_;61 OH_NativeXComponent_TouchPointToolType touchType_;
48 62 
63+ public:
64+ OhosTouchProcessor();
65+ ~OhosTouchProcessor();
66+ 
67+ private:
68+ float accumulatedPanX_ = 0.0;
69+ float accumulatedPanY_ = 0.0;
70+ float accumulatedScale_ = 1.0;
71+ 
72+ private:
73+ int apiVersion_;
74+ std::unique_ptr<DynamicLibraryLoader> loader_;
75+ // 共享库名称
76+ static constexpr char UI_INPUT_EVENT_LIB_NAME[] = "libace_ndk.z.so";
77+ // 动态加载的函数指针
78+ int32_t (*dynamicGetDeviceId_)(ArkUI_UIInputEvent*);
79+ int32_t (*dynamicGetAxisAction_)(ArkUI_UIInputEvent*);
80+ int32_t (*dynamicGetModifierKeyStates_)(ArkUI_UIInputEvent*, uint64_t*);
81+ 
49 private:82 private:
50 std::shared_ptr<std::string[]> packagePacketData(83 std::shared_ptr<std::string[]> packagePacketData(
51 std::unique_ptr<OhosTouchProcessor::TouchPacket> touchPacket);84 std::unique_ptr<OhosTouchProcessor::TouchPacket> touchPacket);
@@ -244,6 +244,18 @@ void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) {
244 }244 }
245}245}
246 246 
247+void DispatchAxisEventCB(OH_NativeXComponent* component,
248+ ArkUI_UIInputEvent* event,
249+ ArkUI_UIInputEvent_Type type) {
250+ std::lock_guard<std::mutex> lock(
251+ XComponentAdapter::GetInstance()->xcomponentMap_mutex_);
252+ for (auto it : XComponentAdapter::GetInstance()->xcomponetMap_) {
253+ if (it.second->nativeXComponent_ == component) {
254+ it.second->OnDispatchAxisEvent(component, event, type);
255+ }
256+ }
257+}
258+ 
247void DispatchMouseEventCB(OH_NativeXComponent* component, void* window) {259void DispatchMouseEventCB(OH_NativeXComponent* component, void* window) {
248 std::lock_guard<std::mutex> lock(260 std::lock_guard<std::mutex> lock(
249 XComponentAdapter::GetInstance()->xcomponentMap_mutex_);261 XComponentAdapter::GetInstance()->xcomponentMap_mutex_);
@@ -505,6 +517,8 @@ void XComponentBase::SetNativeXComponent(
505 OH_NativeXComponent_RegisterCallback(nativeXComponent_, &callback_);517 OH_NativeXComponent_RegisterCallback(nativeXComponent_, &callback_);
506 OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent_,518 OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent_,
507 &mouseCallback_);519 &mouseCallback_);
520+ OH_NativeXComponent_RegisterUIInputEventCallback(
521+ nativeXComponent_, DispatchAxisEventCB, ARKUI_UIINPUTEVENT_TYPE_AXIS);
508 }522 }
509}523}
510 524 
@@ -659,6 +673,20 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component,
659 }673 }
660}674}
661 675 
676+void XComponentBase::OnDispatchAxisEvent(OH_NativeXComponent* component,
677+ ArkUI_UIInputEvent* event,
678+ ArkUI_UIInputEvent_Type type) {
679+ if (type == ARKUI_UIINPUTEVENT_TYPE_AXIS) {
680+ if (is_engine_attached_) {
681+ ohosTouchProcessor_.HandleAxisEvent(std::stoll(shellholderId_), component,
682+ event);
683+ } else {
684+ LOGE(
685+ "XComponentManger::DispatchAxisEvent XComponentBase is not attached");
686+ }
687+ }
688+}
689+ 
662void XComponentBase::OnDispatchMouseEvent(OH_NativeXComponent* component,690void XComponentBase::OnDispatchMouseEvent(OH_NativeXComponent* component,
663 void* window) {691 void* window) {
664 OH_NativeXComponent_MouseEvent mouseEvent;692 OH_NativeXComponent_MouseEvent mouseEvent;
@@ -36,6 +36,9 @@ class XComponentBase {
36 void OnSurfaceChanged(OH_NativeXComponent* component, void* window);36 void OnSurfaceChanged(OH_NativeXComponent* component, void* window);
37 void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window);37 void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window);
38 void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window);38 void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window);
39+ void OnDispatchAxisEvent(OH_NativeXComponent* component,
40+ ArkUI_UIInputEvent* event,
41+ ArkUI_UIInputEvent_Type type);
39 void OnDispatchMouseEvent(OH_NativeXComponent* component, void* window);42 void OnDispatchMouseEvent(OH_NativeXComponent* component, void* window);
40 void OnDispatchMouseWheelEvent(mouseWheelEvent event);43 void OnDispatchMouseWheelEvent(mouseWheelEvent event);
41 void OnDispatchMouseLeaveEvent(OH_NativeXComponent* component);44 void OnDispatchMouseLeaveEvent(OH_NativeXComponent* component);