• 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 #include "interfaces/native/native_interface_focus.h"
17 #include "interfaces/native/node/node_model.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
OH_ArkUI_FocusRequest(ArkUI_NodeHandle node)23 ArkUI_ErrorCode OH_ArkUI_FocusRequest(ArkUI_NodeHandle node)
24 {
25     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
26     if (!impl || !node) {
27         return ARKUI_ERROR_CODE_FOCUS_NON_EXISTENT;
28     }
29     auto ret = impl->getNodeModifiers()->getFrameNodeModifier()->requestFocus(node->uiNodeHandle);
30     return static_cast<ArkUI_ErrorCode>(ret);
31 }
32 
OH_ArkUI_FocusClear(ArkUI_ContextHandle uiContext)33 void OH_ArkUI_FocusClear(ArkUI_ContextHandle uiContext)
34 {
35     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
36     if (!impl || !uiContext) {
37         return;
38     }
39     auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
40     impl->getNodeModifiers()->getFrameNodeModifier()->clearFocus(context->id);
41 }
42 
OH_ArkUI_FocusActivate(ArkUI_ContextHandle uiContext,bool isActive,bool isAutoInactive)43 void OH_ArkUI_FocusActivate(ArkUI_ContextHandle uiContext, bool isActive, bool isAutoInactive)
44 {
45     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
46     if (!impl || !uiContext) {
47         return;
48     }
49     auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
50     impl->getNodeModifiers()->getFrameNodeModifier()->focusActivate(context->id, isActive, isAutoInactive);
51 }
52 
OH_ArkUI_FocusSetAutoTransfer(ArkUI_ContextHandle uiContext,bool autoTransfer)53 void OH_ArkUI_FocusSetAutoTransfer(ArkUI_ContextHandle uiContext, bool autoTransfer)
54 {
55     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
56     if (!impl || !uiContext) {
57         return;
58     }
59     auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
60     impl->getNodeModifiers()->getFrameNodeModifier()->setAutoFocusTransfer(context->id, autoTransfer);
61 }
62 
OH_ArkUI_FocusSetKeyProcessingMode(ArkUI_ContextHandle uiContext,ArkUI_KeyProcessingMode mode)63 void OH_ArkUI_FocusSetKeyProcessingMode(ArkUI_ContextHandle uiContext, ArkUI_KeyProcessingMode mode)
64 {
65     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
66     if (!impl || !uiContext) {
67         return;
68     }
69     auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
70     impl->getNodeModifiers()->getFrameNodeModifier()->setKeyProcessingMode(context->id, static_cast<ArkUI_Int32>(mode));
71 }
72 #ifdef __cplusplus
73 };
74 #endif
75