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