1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef ARKUI_NATIVE_EVENT_UI_INPUT_EVENT_IMPL_H
16 #define ARKUI_NATIVE_EVENT_UI_INPUT_EVENT_IMPL_H
17 #pragma once
18
19 #include "interfaces/native/ui_input_event.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 extern thread_local ArkUI_ErrorCode g_latestEventStatus;
26 extern thread_local ArkUI_ErrorCode g_scenarioSupportCheckResult;
27
28 typedef enum {
29 AXIS_EVENT_ID = 0, // defined in ace_engine/frameworks/core/event/axis_event.h
30 TOUCH_EVENT_ID = 1, // defined in ace_engine/frameworks/core/event/touch_event.h
31 C_TOUCH_EVENT_ID = 2, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h
32 C_MOUSE_EVENT_ID = 3, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h
33 C_AXIS_EVENT_ID = 4, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h
34 C_KEY_EVENT_ID = 5, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h
35 C_FOCUS_AXIS_EVENT_ID = 6, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h
36 C_CLICK_EVENT_ID = 7, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h
37 C_HOVER_EVENT_ID = 8, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h
38 } ArkUIEventTypeId;
39
40 struct ArkUI_UIInputEvent {
41 ArkUI_UIInputEvent_Type inputType;
42 ArkUIEventTypeId eventTypeId;
43 void* inputEvent;
44 bool isCloned = false;
45 int32_t apiVersion = 0;
46 };
47
48 typedef enum {
49 S_UNKNOWN = 0, // unknown scenario
50 S_NODE_TOUCH_EVENT = 1 << 0, // 0x00000001 callback of NODE_TOUCH_EVENT
51 S_NODE_ON_TOUCH_INTERCEPT = 1 << 1, // 0x00000002 callback of NODE_ON_TOUCH_INTERCEPT
52 S_NODE_ON_MOUSE = 1 << 2, // 0x00000004 callback of NODE_ON_MOUSE
53 S_NODE_ON_KEY_EVENT = 1 << 3, // 0x00000008 callback of NODE_ON_KEY_EVENT
54 S_NODE_ON_KEY_PRE_IME = 1 << 4, // 0x00000010 callback of NODE_ON_KEY_PRE_IME
55 S_NODE_ON_FOCUS_AXIS = 1 << 5, // 0x00000020 callback of NODE_ON_FOCUS_AXIS
56 S_NODE_DISPATCH_KEY_EVENT = 1 << 6, // 0x00000040 callback of NODE_DISPATCH_KEY_EVENT
57 S_NODE_ON_AXIS = 1 << 7, // 0x00000080 callback of NODE_ON_AXIS
58 S_NODE_ON_CLICK_EVENT = 1 << 8, // 0x00000100 callback of NODE_ON_CLICK_EVENT
59 S_NODE_ON_HOVER_EVENT = 1 << 9, // 0x00000200 callback of NODE_ON_HOVER_EVENT
60 S_NODE_ON_HOVER_MOVE = 1 << 10, // 0x00000400 callback of NODE_ON_HOVER_MOVE
61 S_GESTURE_TOUCH_EVENT = 1 << 11, // 0x00000800 gesture triggered by touch
62 S_GESTURE_AXIS_EVENT = 1 << 12, // 0x00001000 gesture triggered by axis
63 S_GESTURE_MOUSE_EVENT = 1 << 13, // 0x00002000 gesture triggered by mouse
64 S_GESTURE_CLICK_EVENT = 1 << 14, // 0x00004000 click or tap gesture triggered by keyboard
65 S_NXC_ON_TOUCH_INTERCEPT = 1 << 15, // 0x00008000 nativeXComponent OnTouchIntercept
66 S_NXC_DISPATCH_AXIS_EVENT = 1 << 16, // 0x00010000 nativeXComponent UIAxisEventCallback
67 S_ALL_C_MOUSE_EVENT = S_NODE_ON_MOUSE | S_GESTURE_MOUSE_EVENT, // 0x00002004 2 scenarios give c mouse event
68 S_ALL_C_TOUCH_EVENT = S_NODE_TOUCH_EVENT | S_NODE_ON_TOUCH_INTERCEPT |
69 S_NODE_ON_HOVER_EVENT, // 0x00000203 3 scenarios give c touch event
70 S_ALL_C_KEY_EVENT = S_NODE_ON_KEY_EVENT | S_NODE_ON_KEY_PRE_IME |
71 S_NODE_DISPATCH_KEY_EVENT, // 0x00000058 3 scenarios give c key event
72 } ArkUIEventScenario;
73
74 ArkUI_ErrorCode CheckIsSupportedScenario(uint32_t scenarioExpr, const ArkUI_UIInputEvent* event);
75
CheckSupportedScenarioAndResetEventStatus(uint32_t scenarioExpr,const ArkUI_UIInputEvent * event)76 inline void CheckSupportedScenarioAndResetEventStatus(uint32_t scenarioExpr, const ArkUI_UIInputEvent* event)
77 {
78 g_scenarioSupportCheckResult = CheckIsSupportedScenario(scenarioExpr, event);
79 g_latestEventStatus = ARKUI_ERROR_CODE_NO_ERROR;
80 }
81
82 #define RETURN_RET_WITH_STATUS_CHECK(ret, errorCode) \
83 do { \
84 g_latestEventStatus = \
85 g_scenarioSupportCheckResult == ARKUI_ERROR_CODE_NO_ERROR ? (errorCode) : g_scenarioSupportCheckResult; \
86 return ret; \
87 } while (0)
88
89 #define RETURN_WITH_STATUS_CHECK(errorCode) \
90 do { \
91 g_latestEventStatus = \
92 g_scenarioSupportCheckResult == ARKUI_ERROR_CODE_NO_ERROR ? (errorCode) : g_scenarioSupportCheckResult; \
93 return; \
94 } while (0)
95
96 #ifdef __cplusplus
97 };
98 #endif
99 #endif // ARKUI_NATIVE_EVENT_UI_INPUT_EVENT_IMPL_H