diff --git a/arkui/ace_engine/native/BUILD.gn b/arkui/ace_engine/native/BUILD.gn index f8f7ff2746bf12bfd81dd20c3727968cda6863f7..b48b73ada3d60b5a9903bbb79167cbdd0c55399d 100644 --- a/arkui/ace_engine/native/BUILD.gn +++ b/arkui/ace_engine/native/BUILD.gn @@ -33,6 +33,7 @@ if (!is_arkui_x) { "native_gesture.h", "native_interface.h", "native_interface_accessibility.h", + "native_interface_focus.h", "native_key_event.h", "native_node.h", "native_node_napi.h", diff --git a/arkui/ace_engine/native/libace.ndk.json b/arkui/ace_engine/native/libace.ndk.json index 93b14a1c3adaebadd714c34a09f269a366be891f..e0fd5bcfb72bf6813c56149961bce066ea7376c2 100644 --- a/arkui/ace_engine/native/libace.ndk.json +++ b/arkui/ace_engine/native/libace.ndk.json @@ -2574,5 +2574,21 @@ { "first_introduced": "16", "name": "OH_ArkUI_UnregisterDrawCallbackOnNodeHandle" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_FocusRequest" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_FocusClear" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_FocusActivate" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_FocusSetAutoTransfer" } ] \ No newline at end of file diff --git a/arkui/ace_engine/native/native_interface_focus.h b/arkui/ace_engine/native/native_interface_focus.h new file mode 100644 index 0000000000000000000000000000000000000000..39588c617c08413e616f30a4c45ea4b127bdac4d --- /dev/null +++ b/arkui/ace_engine/native/native_interface_focus.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup ArkUI_NativeModule + * @{ + * + * @brief Provides focus capabilities of ArkUI on the native side, such as focus transfer operaions. + * + * @since 16 + */ + +/** + * @file native_interface_focus.h + * + * @brief Declares the APIs used to control the focus system. + * + * @library libace_ndk.z.so + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 16 + */ + +#ifndef ARKUI_NATIVE_INTERFACE_FOCUS_H +#define ARKUI_NATIVE_INTERFACE_FOCUS_H + +#include "napi/native_api.h" +#include "native_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Apply focus for a specific node. + * + * @param node The node. + * @return The error code. + * {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ARKUI_ERROR_CODE_FOCUS_NON_FOCUSABLE} if the node is not focusable. + * {@link ARKUI_ERROR_CODE_FOCUS_NON_FOCUSABLE_ANCESTOR} if the node has unfocusable ancestor. + * {@link ARKUI_ERROR_CODE_FOCUS_NON_EXISTENT} if the node is not exists. + * @since 16 + */ +ArkUI_ErrorCode OH_ArkUI_FocusRequest(ArkUI_NodeHandle node); + +/** + * @brief Clear current focus to root scope. + * + * @param uiContext Indicates the pointer to a UI instance. + * @since 16 + */ +void OH_ArkUI_FocusClear(ArkUI_ContextHandle uiContext); + +/** + * @brief Set the focus active state in current window, the focus node would show its focus box. + * + * @param uiContext Indicates the pointer to a UI instance. + * @param isActive Set the state to be active or inactive. + * @param isAutoInactive When touch event or mouse-pressed event triggerd, + * "true" indicates to set state to inactive, + * "false" indicates to maintain the state until relative API is called. + * @since 16 + */ +void OH_ArkUI_FocusActivate(ArkUI_ContextHandle uiContext, bool isActive, bool isAutoInactive); + +/** + * @brief Set the focus transfer behaviour when current focus view changes. + * + * @param uiContext Indicates the pointer to a UI instance. + * @param autoTransfer Indicates whether to transfer focus when focus view show. + * @since 16 + */ +void OH_ArkUI_FocusSetAutoTransfer(ArkUI_ContextHandle uiContext, bool autoTransfer); + +#ifdef __cplusplus +}; +#endif + +#endif // ARKUI_NATIVE_INTERFACE_FOCUS_H \ No newline at end of file diff --git a/arkui/ace_engine/native/native_type.h b/arkui/ace_engine/native/native_type.h index e1cffe2c7160c7db22a837345b9f31bc46e40cd2..fe1b0abe09bac3ae98d0974c95c2d462576c1e03 100644 --- a/arkui/ace_engine/native/native_type.h +++ b/arkui/ace_engine/native/native_type.h @@ -1979,6 +1979,12 @@ typedef enum { ARKUI_ERROR_CODE_GET_INFO_FAILED = 106201, /** The buffer size is not large enough. */ ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR = 106202, + /** The node requesting focus is not focusable. */ + ARKUI_ERROR_CODE_FOCUS_NON_FOCUSABLE = 150001, + /** The node requesting focus has unfocusable ancestor. */ + ARKUI_ERROR_CODE_FOCUS_NON_FOCUSABLE_ANCESTOR = 150002, + /** The node requesting focus does not exists. */ + ARKUI_ERROR_CODE_FOCUS_NON_EXISTENT = 150003, /** The component is not a scroll container. */ ARKUI_ERROR_CODE_NON_SCROLLABLE_CONTAINER = 180001, /** The buffer is not large enough. */