From b84f1cbdccff985de2e67492cd5ecdecd62fcacd Mon Sep 17 00:00:00 2001 From: huangweichen Date: Wed, 1 Jan 2025 21:13:09 +0800 Subject: [PATCH] =?UTF-8?q?focus=E6=96=B0=E5=A2=9Ecapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangweichen --- arkui/ace_engine/native/BUILD.gn | 1 + arkui/ace_engine/native/libace.ndk.json | 16 ++++ .../native/native_interface_focus.h | 91 +++++++++++++++++++ arkui/ace_engine/native/native_type.h | 6 ++ 4 files changed, 114 insertions(+) create mode 100644 arkui/ace_engine/native/native_interface_focus.h diff --git a/arkui/ace_engine/native/BUILD.gn b/arkui/ace_engine/native/BUILD.gn index f8f7ff274..b48b73ada 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 f72f7e8f1..8dc60535e 100644 --- a/arkui/ace_engine/native/libace.ndk.json +++ b/arkui/ace_engine/native/libace.ndk.json @@ -2558,5 +2558,21 @@ { "first_introduced": "16", "name": "OH_ArkUI_PostFrameCallback" + }, + { + "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 000000000..39588c617 --- /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 18f28994e..c29a29d7a 100644 --- a/arkui/ace_engine/native/native_type.h +++ b/arkui/ace_engine/native/native_type.h @@ -1965,6 +1965,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. */ -- Gitee