• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 /**
17  * @addtogroup ArkUI_NativeModule
18  * @{
19  *
20  * @brief Provides focus capabilities of ArkUI on the native side, such as focus transfer operaions.
21  *
22  * @since 15
23  */
24 
25 /**
26  * @file native_interface_focus.h
27  *
28  * @brief Declares the APIs used to control the focus system.
29  *
30  * @library libace_ndk.z.so
31  * @syscap SystemCapability.ArkUI.ArkUI.Full
32  * @since 15
33  */
34 
35 #ifndef ARKUI_NATIVE_INTERFACE_FOCUS_H
36 #define ARKUI_NATIVE_INTERFACE_FOCUS_H
37 
38 #include "napi/native_api.h"
39 #include "native_type.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @brief Determines the priority of key event processing when component cannot handle the key event.
47  *
48  * @since 15
49  */
50  typedef enum {
51     /** Key events are used to move focus. */
52     ARKUI_KEY_PROCESSING_MODE_FOCUS_NAVIGATION = 0,
53     /** Key events bubble up to ancestors. */
54     ARKUI_KEY_PROCESSING_MODE_FOCUS_ANCESTOR_EVENT,
55 } ArkUI_KeyProcessingMode;
56 
57 /**
58  * @brief Apply focus for a specific node.
59  *
60  * @param node The node.
61  * @return The error code.
62  *         {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful.
63  *         {@link ARKUI_ERROR_CODE_FOCUS_NON_FOCUSABLE} if the node is not focusable.
64  *         {@link ARKUI_ERROR_CODE_FOCUS_NON_FOCUSABLE_ANCESTOR} if the node has unfocusable ancestor.
65  *         {@link ARKUI_ERROR_CODE_FOCUS_NON_EXISTENT} if the node is not exists.
66  * @since 15
67  */
68 ArkUI_ErrorCode OH_ArkUI_FocusRequest(ArkUI_NodeHandle node);
69 
70 /**
71  * @brief Clear current focus to root scope.
72  *
73  * @param uiContext Indicates the pointer to a UI instance.
74  * @since 15
75  */
76 void OH_ArkUI_FocusClear(ArkUI_ContextHandle uiContext);
77 
78 /**
79  * @brief Set the focus active state in current window, the focus node would show its focus box.
80  *
81  * @param uiContext Indicates the pointer to a UI instance.
82  * @param isActive Set the state to be active or inactive.
83  * @param isAutoInactive When touch event or mouse-pressed event triggerd,
84  *                    "true" indicates to set state to inactive,
85  *                    "false" indicates to maintain the state until relative API is called.
86  * @since 15
87  */
88 void OH_ArkUI_FocusActivate(ArkUI_ContextHandle uiContext, bool isActive, bool isAutoInactive);
89 
90 /**
91  * @brief Set the focus transfer behaviour when current focus view changes.
92  *
93  * @param uiContext Indicates the pointer to a UI instance.
94  * @param autoTransfer Indicates whether to transfer focus when focus view show.
95  * @since 15
96  */
97 void OH_ArkUI_FocusSetAutoTransfer(ArkUI_ContextHandle uiContext, bool autoTransfer);
98 
99 /**
100  * @brief Set the priority of key event processing when component cannot handle the key event.
101  *
102  * @param uiContext Indicates the pointer to a UI instance.
103  * @param mode Indicates the key processing mode.
104  * @since 15
105  */
106 void OH_ArkUI_FocusSetKeyProcessingMode(ArkUI_ContextHandle uiContext, ArkUI_KeyProcessingMode mode);
107 
108 #ifdef __cplusplus
109 };
110 #endif
111 
112 #endif // ARKUI_NATIVE_INTERFACE_FOCUS_H