• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "core/interfaces/native/node/frame_node_modifier.h"
16 #include <cstdlib>
17 #include <unistd.h>
18 #include <vector>
19 
20 #include "base/error/error_code.h"
21 #include "core/common/builder_util.h"
22 #include "core/common/color_inverter.h"
23 #include "base/utils/multi_thread.h"
24 #include "core/components_ng/base/inspector.h"
25 #include "core/components_ng/base/view_abstract.h"
26 #include "core/components_ng/pattern/custom_frame_node/custom_frame_node.h"
27 #include "core/components_ng/pattern/custom/custom_measure_layout_node.h"
28 #include "core/interfaces/arkoala/arkoala_api.h"
29 #include "core/interfaces/native/node/frame_node_modifier_multi_thread.h"
30 #include "core/pipeline_ng/pipeline_context.h"
31 #include "bridge/common/utils/engine_helper.h"
32 
33 namespace OHOS::Ace::NG {
34 enum class ExpandMode : uint32_t {
35     NOT_EXPAND = 0,
36     EXPAND,
37     LAZY_EXPAND,
38 };
39 
40 enum EventQueryType {
41     ON_CLICK = 0,
42 };
43 
IsModifiable(ArkUINodeHandle node)44 ArkUI_Bool IsModifiable(ArkUINodeHandle node)
45 {
46     auto* currentNode = reinterpret_cast<UINode*>(node);
47     CHECK_NULL_RETURN(currentNode, false);
48     auto* frameNode = AceType::DynamicCast<UINode>(currentNode);
49     CHECK_NULL_RETURN(frameNode, false);
50     return frameNode->GetTag() == "CustomFrameNode";
51 }
52 
CreateFrameNode()53 ArkUINodeHandle CreateFrameNode()
54 {
55     auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
56     auto node = NG::CustomFrameNode::GetOrCreateCustomFrameNode(nodeId);
57     node->SetExclusiveEventForChild(true);
58     node->SetIsArkTsFrameNode(true);
59     return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(node));
60 }
61 
InvalidateInFrameNode(ArkUINodeHandle node)62 void InvalidateInFrameNode(ArkUINodeHandle node)
63 {
64     auto* frameNode = reinterpret_cast<FrameNode*>(node);
65     CHECK_NULL_VOID(frameNode);
66     CHECK_NULL_VOID(AceType::InstanceOf<CustomFrameNode>(frameNode));
67     auto pattern = frameNode->GetPattern<CustomFrameNodePattern>();
68     CHECK_NULL_VOID(pattern);
69     auto renderContext = frameNode->GetRenderContext();
70     CHECK_NULL_VOID(renderContext);
71     pattern->Invalidate();
72     renderContext->RequestNextFrame();
73 }
74 
ApplyAttributesFinish(ArkUINodeHandle node)75 void ApplyAttributesFinish(ArkUINodeHandle node)
76 {
77     auto* frameNode = reinterpret_cast<FrameNode*>(node);
78     CHECK_NULL_VOID(frameNode);
79     frameNode->MarkModifyDone();
80 }
81 
GetParentNode(UINode * node)82 RefPtr<FrameNode> GetParentNode(UINode* node)
83 {
84     auto uiNode = AceType::Claim<UINode>(node);
85     auto parent = uiNode->GetParent();
86     while (parent != nullptr && !AceType::InstanceOf<FrameNode>(parent)) {
87         parent = parent->GetParent();
88     }
89     return (parent == nullptr || parent->GetTag() == V2::PAGE_ETS_TAG || parent->GetTag() == V2::STAGE_ETS_TAG)
90                ? nullptr : AceType::DynamicCast<FrameNode>(parent);
91 }
92 
AddBuilderNodeInFrameNode(ArkUINodeHandle node,ArkUINodeHandle child)93 void AddBuilderNodeInFrameNode(ArkUINodeHandle node, ArkUINodeHandle child)
94 {
95     auto* currentNode = reinterpret_cast<UINode*>(node);
96     CHECK_NULL_VOID(currentNode);
97     auto* childNode = reinterpret_cast<UINode*>(child);
98     CHECK_NULL_VOID(childNode);
99     auto childRef = Referenced::Claim<UINode>(childNode);
100     CHECK_NULL_VOID(childRef);
101     auto parentNode = childRef->GetParent();
102     CHECK_NULL_VOID(parentNode && parentNode == currentNode);
103     std::list<RefPtr<UINode>> nodes;
104     BuilderUtils::GetBuilderNodes(childRef, nodes);
105     BuilderUtils::AddBuilderToParent(childRef->GetParent(), nodes);
106 }
107 
AppendChildInFrameNode(ArkUINodeHandle node,ArkUINodeHandle child)108 ArkUI_Bool AppendChildInFrameNode(ArkUINodeHandle node, ArkUINodeHandle child)
109 {
110     auto* currentNode = reinterpret_cast<UINode*>(node);
111     CHECK_NULL_RETURN(currentNode, true);
112     auto* childNode = reinterpret_cast<UINode*>(child);
113     auto childRef = Referenced::Claim<UINode>(childNode);
114     CHECK_NULL_RETURN(childRef, true);
115     if (childRef->GetParent() != nullptr && childRef->GetParent() != currentNode) {
116         return false;
117     }
118     currentNode->AddChild(childRef);
119     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
120     return true;
121 }
122 
InsertChildAfterInFrameNode(ArkUINodeHandle node,ArkUINodeHandle child,ArkUINodeHandle sibling)123 ArkUI_Bool InsertChildAfterInFrameNode(ArkUINodeHandle node, ArkUINodeHandle child, ArkUINodeHandle sibling)
124 {
125     auto* currentNode = reinterpret_cast<UINode*>(node);
126     CHECK_NULL_RETURN(currentNode, true);
127     auto* childNode = reinterpret_cast<UINode*>(child);
128     CHECK_NULL_RETURN(childNode, true);
129     if (childNode->GetParent() != nullptr && childNode->GetParent() != currentNode) {
130         return false;
131     }
132     auto index = -1;
133     auto* siblingNode = reinterpret_cast<UINode*>(sibling);
134     index = currentNode->GetChildIndex(Referenced::Claim<UINode>(siblingNode));
135     currentNode->AddChild(Referenced::Claim<UINode>(childNode), index + 1);
136     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
137     return true;
138 }
139 
RemoveBuilderNodeInFrameNode(ArkUINodeHandle node,ArkUINodeHandle child)140 void RemoveBuilderNodeInFrameNode(ArkUINodeHandle node, ArkUINodeHandle child)
141 {
142     auto* currentNode = reinterpret_cast<UINode*>(node);
143     CHECK_NULL_VOID(currentNode);
144     auto* childNode = reinterpret_cast<UINode*>(child);
145     CHECK_NULL_VOID(childNode);
146     auto childRef = Referenced::Claim<UINode>(childNode);
147     auto parentNode = childRef->GetParent();
148     CHECK_NULL_VOID(parentNode && parentNode == currentNode);
149     std::list<RefPtr<UINode>> nodes;
150     BuilderUtils::GetBuilderNodes(childRef, nodes);
151     BuilderUtils::RemoveBuilderFromParent(parentNode, nodes);
152 }
153 
RemoveChildInFrameNode(ArkUINodeHandle node,ArkUINodeHandle child)154 void RemoveChildInFrameNode(ArkUINodeHandle node, ArkUINodeHandle child)
155 {
156     auto* currentNode = reinterpret_cast<UINode*>(node);
157     CHECK_NULL_VOID(currentNode);
158     auto* childNode = reinterpret_cast<UINode*>(child);
159     currentNode->RemoveChild(Referenced::Claim<UINode>(childNode));
160     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
161 }
162 
ClearBuilderNodeInFrameNode(ArkUINodeHandle node)163 void ClearBuilderNodeInFrameNode(ArkUINodeHandle node)
164 {
165     auto* currentNode = reinterpret_cast<UINode*>(node);
166     CHECK_NULL_VOID(currentNode);
167     auto currentRef = Referenced::Claim<UINode>(currentNode);
168     std::list<RefPtr<NG::UINode>> nodes;
169     CHECK_NULL_VOID(currentRef);
170     for (const auto& child : currentRef->GetChildren()) {
171         BuilderUtils::GetBuilderNodes(child, nodes);
172     }
173     BuilderUtils::RemoveBuilderFromParent(currentRef, nodes);
174 }
175 
ClearChildrenInFrameNode(ArkUINodeHandle node)176 void ClearChildrenInFrameNode(ArkUINodeHandle node)
177 {
178     auto* currentNode = reinterpret_cast<FrameNode*>(node);
179     // This function has a mirror function (XxxMultiThread) and needs to be modified synchronously.
180     FREE_NODE_CHECK(currentNode, ClearChildrenInFrameNode, node);
181     CHECK_NULL_VOID(currentNode);
182     currentNode->Clean();
183     currentNode->MarkNeedFrameFlushDirty(NG::PROPERTY_UPDATE_MEASURE);
184 }
185 
GetChildrenCount(ArkUINodeHandle node,ArkUI_Bool isExpanded)186 ArkUI_Uint32 GetChildrenCount(ArkUINodeHandle node, ArkUI_Bool isExpanded)
187 {
188     auto* currentNode = reinterpret_cast<FrameNode*>(node);
189     CHECK_NULL_RETURN(currentNode, 0);
190     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
191     CHECK_NULL_RETURN(frameNode, 0);
192     if (isExpanded) {
193         frameNode->GetAllChildrenWithBuild(false);
194     }
195     return isExpanded ? frameNode->GetAllChildrenWithBuild(false).size()
196                       : frameNode->GetTotalChildCountWithoutExpanded();
197 }
198 
GetChild(ArkUINodeHandle node,ArkUI_Int32 index,ArkUI_Uint32 expandMode)199 ArkUINodeHandle GetChild(ArkUINodeHandle node, ArkUI_Int32 index, ArkUI_Uint32 expandMode)
200 {
201     auto* currentNode = reinterpret_cast<FrameNode*>(node);
202     CHECK_NULL_RETURN(currentNode, nullptr);
203     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
204     CHECK_NULL_RETURN(frameNode, nullptr);
205     CHECK_NULL_RETURN(index >= 0, nullptr);
206     auto expandModeResult = static_cast<ExpandMode>(expandMode);
207     if (expandModeResult == ExpandMode::EXPAND) {
208         frameNode->GetAllChildrenWithBuild(false);
209     }
210     FrameNode* child = nullptr;
211     if (expandModeResult == ExpandMode::EXPAND || expandModeResult == ExpandMode::NOT_EXPAND) {
212         child = frameNode->GetFrameNodeChildByIndex(index, false, expandModeResult == ExpandMode::EXPAND);
213     } else if (expandModeResult == ExpandMode::LAZY_EXPAND) {
214         child = frameNode->GetFrameNodeChildByIndexWithoutBuild(index);
215         if (child == nullptr) {
216             return GetChild(node, index, static_cast<ArkUI_Uint32>(ExpandMode::EXPAND));
217         }
218     }
219     return reinterpret_cast<ArkUINodeHandle>(child);
220 }
221 
GetFirstChildIndexWithoutExpand(ArkUINodeHandle node,ArkUI_Uint32 * index)222 ArkUI_Int32 GetFirstChildIndexWithoutExpand(ArkUINodeHandle node, ArkUI_Uint32* index)
223 {
224     auto* currentNode = reinterpret_cast<FrameNode*>(node);
225     CHECK_NULL_RETURN(currentNode, ERROR_CODE_PARAM_INVALID);
226     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
227     CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
228     auto child = frameNode->GetFrameNodeChildByIndex(0, false, false);
229     CHECK_NULL_RETURN(child, ERROR_CODE_PARAM_INVALID);
230     auto* childNode = reinterpret_cast<FrameNode*>(child);
231     auto childRef = Referenced::Claim<FrameNode>(childNode);
232     *index = frameNode->GetFrameNodeIndex(childRef, true);
233     return ERROR_CODE_NO_ERROR;
234 }
235 
GetLastChildIndexWithoutExpand(ArkUINodeHandle node,ArkUI_Uint32 * index)236 ArkUI_Int32 GetLastChildIndexWithoutExpand(ArkUINodeHandle node, ArkUI_Uint32* index)
237 {
238     auto* currentNode = reinterpret_cast<FrameNode*>(node);
239     CHECK_NULL_RETURN(currentNode, ERROR_CODE_PARAM_INVALID);
240     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
241     CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
242     size_t size = static_cast<size_t>(frameNode->GetTotalChildCountWithoutExpanded());
243     CHECK_NULL_RETURN(size > 0, ERROR_CODE_PARAM_INVALID);
244     auto child = frameNode->GetFrameNodeChildByIndex(size - 1, false, false);
245     CHECK_NULL_RETURN(child, ERROR_CODE_PARAM_INVALID);
246     auto* childNode = reinterpret_cast<FrameNode*>(child);
247     auto childRef = Referenced::Claim<FrameNode>(childNode);
248     *index = frameNode->GetFrameNodeIndex(childRef, true);
249     return ERROR_CODE_NO_ERROR;
250 }
251 
GetFirst(ArkUINodeHandle node,ArkUI_Bool isExpanded)252 ArkUINodeHandle GetFirst(ArkUINodeHandle node, ArkUI_Bool isExpanded)
253 {
254     auto* currentNode = reinterpret_cast<FrameNode*>(node);
255     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
256     CHECK_NULL_RETURN(frameNode, nullptr);
257     if (isExpanded) {
258         frameNode->GetAllChildrenWithBuild(false);
259     }
260     auto child = frameNode->GetFrameNodeChildByIndex(0, false, isExpanded);
261     return reinterpret_cast<ArkUINodeHandle>(child);
262 }
263 
GetNextSibling(ArkUINodeHandle node,ArkUI_Bool isExpanded)264 ArkUINodeHandle GetNextSibling(ArkUINodeHandle node, ArkUI_Bool isExpanded)
265 {
266     auto* currentNode = reinterpret_cast<FrameNode*>(node);
267     CHECK_NULL_RETURN(currentNode, nullptr);
268     auto parent = GetParentNode(currentNode);
269     CHECK_NULL_RETURN(parent, nullptr);
270     auto index = -1;
271     if (isExpanded) {
272         parent->GetAllChildrenWithBuild(false);
273         index = parent->GetChildTrueIndex(Referenced::Claim<FrameNode>(currentNode));
274     } else {
275         index = parent->GetFrameNodeIndex(Referenced::Claim<FrameNode>(currentNode), false);
276     }
277     CHECK_NULL_RETURN(index > -1, nullptr);
278     auto sibling = parent->GetFrameNodeChildByIndex(index + 1, false, isExpanded);
279     return reinterpret_cast<ArkUINodeHandle>(sibling);
280 }
281 
GetPreviousSibling(ArkUINodeHandle node,ArkUI_Bool isExpanded)282 ArkUINodeHandle GetPreviousSibling(ArkUINodeHandle node, ArkUI_Bool isExpanded)
283 {
284     auto* currentNode = reinterpret_cast<FrameNode*>(node);
285     CHECK_NULL_RETURN(currentNode, nullptr);
286     auto parent = GetParentNode(currentNode);
287     CHECK_NULL_RETURN(parent, nullptr);
288     auto index = -1;
289     if (isExpanded) {
290         parent->GetAllChildrenWithBuild(false);
291         index = parent->GetChildTrueIndex(Referenced::Claim<FrameNode>(currentNode));
292     } else {
293         index = parent->GetFrameNodeIndex(Referenced::Claim<FrameNode>(currentNode), false);
294     }
295     CHECK_NULL_RETURN(index > 0, nullptr);
296     auto sibling = parent->GetFrameNodeChildByIndex(index - 1, false, isExpanded);
297     return reinterpret_cast<ArkUINodeHandle>(sibling);
298 }
299 
GetParent(ArkUINodeHandle node)300 ArkUINodeHandle GetParent(ArkUINodeHandle node)
301 {
302     auto* currentNode = reinterpret_cast<UINode*>(node);
303     CHECK_NULL_RETURN(currentNode, nullptr);
304     auto parent = GetParentNode(currentNode);
305     return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(parent));
306 }
307 
GetIdByNodePtr(ArkUINodeHandle node)308 ArkUI_Int32 GetIdByNodePtr(ArkUINodeHandle node)
309 {
310     auto* currentNode = reinterpret_cast<UINode*>(node);
311     CHECK_NULL_RETURN(currentNode, -1);
312     auto nodeId = currentNode->GetId();
313     return nodeId;
314 }
315 
GetPositionToParent(ArkUINodeHandle node,ArkUI_Float32 (* parentOffset)[2],ArkUI_Bool useVp)316 void GetPositionToParent(ArkUINodeHandle node, ArkUI_Float32 (*parentOffset)[2], ArkUI_Bool useVp)
317 {
318     auto* currentNode = reinterpret_cast<FrameNode*>(node);
319     CHECK_NULL_VOID(currentNode);
320     auto currFrameRect = currentNode->GetRectWithRender();
321     auto offset = currFrameRect.GetOffset();
322     if (useVp) {
323         (*parentOffset)[0] = PipelineBase::Px2VpWithCurrentDensity(offset.GetX());
324         (*parentOffset)[1] = PipelineBase::Px2VpWithCurrentDensity(offset.GetY());
325     } else {
326         (*parentOffset)[0] = offset.GetX();
327         (*parentOffset)[1] = offset.GetY();
328     }
329 }
330 
GetPositionToScreen(ArkUINodeHandle node,ArkUI_Float32 (* screenPosition)[2],ArkUI_Bool useVp)331 void GetPositionToScreen(ArkUINodeHandle node, ArkUI_Float32 (*screenPosition)[2], ArkUI_Bool useVp)
332 {
333     auto* currentNode = reinterpret_cast<FrameNode*>(node);
334     CHECK_NULL_VOID(currentNode);
335     auto offset = currentNode->GetPositionToScreen();
336     if (useVp) {
337         (*screenPosition)[0] = PipelineBase::Px2VpWithCurrentDensity(offset.GetX());
338         (*screenPosition)[1] = PipelineBase::Px2VpWithCurrentDensity(offset.GetY());
339     } else {
340         (*screenPosition)[0] = offset.GetX();
341         (*screenPosition)[1] = offset.GetY();
342     }
343 }
344 
GetPositionToWindow(ArkUINodeHandle node,ArkUI_Float32 (* windowOffset)[2],ArkUI_Bool useVp)345 void GetPositionToWindow(ArkUINodeHandle node, ArkUI_Float32 (*windowOffset)[2], ArkUI_Bool useVp)
346 {
347     auto* currentNode = reinterpret_cast<FrameNode*>(node);
348     CHECK_NULL_VOID(currentNode);
349     auto offset = currentNode->GetOffsetRelativeToWindow();
350     if (useVp) {
351         (*windowOffset)[0] = PipelineBase::Px2VpWithCurrentDensity(offset.GetX());
352         (*windowOffset)[1] = PipelineBase::Px2VpWithCurrentDensity(offset.GetY());
353     } else {
354         (*windowOffset)[0] = offset.GetX();
355         (*windowOffset)[1] = offset.GetY();
356     }
357 }
358 
GetGlobalPositionOnDisplay(ArkUINodeHandle node,ArkUI_Float32 (* globalDisplayPosition)[2],ArkUI_Bool useVp)359 void GetGlobalPositionOnDisplay(ArkUINodeHandle node, ArkUI_Float32 (*globalDisplayPosition)[2], ArkUI_Bool useVp)
360 {
361     auto* currentNode = reinterpret_cast<FrameNode*>(node);
362     CHECK_NULL_VOID(currentNode);
363     auto offset = currentNode->GetGlobalPositionOnDisplay();
364     if (useVp) {
365         (*globalDisplayPosition)[0] = PipelineBase::Px2VpWithCurrentDensity(offset.GetX());
366         (*globalDisplayPosition)[1] = PipelineBase::Px2VpWithCurrentDensity(offset.GetY());
367     } else {
368         (*globalDisplayPosition)[0] = offset.GetX();
369         (*globalDisplayPosition)[1] = offset.GetY();
370     }
371 }
372 
GetPositionToParentWithTransform(ArkUINodeHandle node,ArkUI_Float32 (* parentPosition)[2],ArkUI_Bool useVp)373 void GetPositionToParentWithTransform(ArkUINodeHandle node, ArkUI_Float32 (*parentPosition)[2], ArkUI_Bool useVp)
374 {
375     auto* currentNode = reinterpret_cast<FrameNode*>(node);
376     CHECK_NULL_VOID(currentNode);
377     auto offset = currentNode->GetPositionToParentWithTransform();
378     if (useVp) {
379         (*parentPosition)[0] = PipelineBase::Px2VpWithCurrentDensity(offset.GetX());
380         (*parentPosition)[1] = PipelineBase::Px2VpWithCurrentDensity(offset.GetY());
381     } else {
382         (*parentPosition)[0] = offset.GetX();
383         (*parentPosition)[1] = offset.GetY();
384     }
385 }
386 
GetPositionToScreenWithTransform(ArkUINodeHandle node,ArkUI_Float32 (* screenPosition)[2],ArkUI_Bool useVp)387 void GetPositionToScreenWithTransform(ArkUINodeHandle node, ArkUI_Float32 (*screenPosition)[2], ArkUI_Bool useVp)
388 {
389     auto* currentNode = reinterpret_cast<FrameNode*>(node);
390     CHECK_NULL_VOID(currentNode);
391     auto offset = currentNode->GetPositionToScreenWithTransform();
392     if (useVp) {
393         (*screenPosition)[0] = PipelineBase::Px2VpWithCurrentDensity(offset.GetX());
394         (*screenPosition)[1] = PipelineBase::Px2VpWithCurrentDensity(offset.GetY());
395     } else {
396         (*screenPosition)[0] = offset.GetX();
397         (*screenPosition)[1] = offset.GetY();
398     }
399 }
400 
GetPositionToWindowWithTransform(ArkUINodeHandle node,ArkUI_Float32 (* windowPosition)[2],ArkUI_Bool useVp)401 void GetPositionToWindowWithTransform(ArkUINodeHandle node, ArkUI_Float32 (*windowPosition)[2], ArkUI_Bool useVp)
402 {
403     auto* currentNode = reinterpret_cast<FrameNode*>(node);
404     CHECK_NULL_VOID(currentNode);
405     auto offset = currentNode->GetPositionToWindowWithTransform();
406     if (useVp) {
407         (*windowPosition)[0] = PipelineBase::Px2VpWithCurrentDensity(offset.GetX());
408         (*windowPosition)[1] = PipelineBase::Px2VpWithCurrentDensity(offset.GetY());
409     } else {
410         (*windowPosition)[0] = offset.GetX();
411         (*windowPosition)[1] = offset.GetY();
412     }
413 }
414 
GetMeasuredSize(ArkUINodeHandle node)415 ArkUI_Float32* GetMeasuredSize(ArkUINodeHandle node)
416 {
417     auto* currentNode = reinterpret_cast<FrameNode*>(node);
418     CHECK_NULL_RETURN(currentNode, nullptr);
419     auto offset = currentNode->GetGeometryNode()->GetFrameSize();
420     ArkUI_Float32* ret = new ArkUI_Float32[2];
421     ret[0] = offset.Width();
422     ret[1] = offset.Height();
423     return ret;
424 }
425 
GetLayoutPosition(ArkUINodeHandle node)426 ArkUI_Float32* GetLayoutPosition(ArkUINodeHandle node)
427 {
428     auto* currentNode = reinterpret_cast<FrameNode*>(node);
429     CHECK_NULL_RETURN(currentNode, nullptr);
430     auto offset = currentNode->GetGeometryNode()->GetMarginFrameOffset();
431     ArkUI_Float32* ret = new ArkUI_Float32[2];
432     ret[0] = offset.GetX();
433     ret[1] = offset.GetY();
434     return ret;
435 }
436 
GetInspectorId(ArkUINodeHandle node)437 ArkUI_CharPtr GetInspectorId(ArkUINodeHandle node)
438 {
439     auto* currentNode = reinterpret_cast<FrameNode*>(node);
440     CHECK_NULL_RETURN(currentNode, "");
441     auto inspectorIdProp = currentNode->GetInspectorId();
442     if (inspectorIdProp.has_value()) {
443         static std::string inspectorId;
444         inspectorId = inspectorIdProp.value();
445         return inspectorId.c_str();
446     }
447 
448     return "";
449 }
450 
GetNodeType(ArkUINodeHandle node)451 ArkUI_CharPtr GetNodeType(ArkUINodeHandle node)
452 {
453     auto* currentNode = reinterpret_cast<FrameNode*>(node);
454     CHECK_NULL_RETURN(currentNode, "");
455     static std::string nodeType;
456     nodeType = currentNode->GetTag();
457     return nodeType.c_str();
458 }
459 
IsVisible(ArkUINodeHandle node)460 ArkUI_Bool IsVisible(ArkUINodeHandle node)
461 {
462     auto* currentNode = reinterpret_cast<FrameNode*>(node);
463     CHECK_NULL_RETURN(currentNode, false);
464     auto isVisible = currentNode->IsVisible();
465     auto parentNode = currentNode->GetParent();
466     while (isVisible && parentNode) {
467         if (AceType::InstanceOf<FrameNode>(*parentNode)) {
468             isVisible = isVisible && AceType::DynamicCast<FrameNode>(parentNode)->IsVisible();
469         } else if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_FIFTEEN)) {
470             break;
471         }
472 
473         parentNode = parentNode->GetParent();
474     }
475     return isVisible;
476 }
477 
IsAttached(ArkUINodeHandle node)478 ArkUI_Bool IsAttached(ArkUINodeHandle node)
479 {
480     auto* currentNode = reinterpret_cast<FrameNode*>(node);
481     CHECK_NULL_RETURN(currentNode, false);
482     return currentNode->IsOnMainTree();
483 }
484 
GetInspectorInfo(ArkUINodeHandle node)485 ArkUI_CharPtr GetInspectorInfo(ArkUINodeHandle node)
486 {
487     auto* currentNode = reinterpret_cast<FrameNode*>(node);
488     CHECK_NULL_RETURN(currentNode, "{}");
489     static std::string inspectorInfo;
490     inspectorInfo = NG::Inspector::GetInspectorOfNode(OHOS::Ace::AceType::Claim<FrameNode>(currentNode));
491     return inspectorInfo.c_str();
492 }
493 
GetFrameNodeById(ArkUI_Int32 nodeId)494 ArkUINodeHandle GetFrameNodeById(ArkUI_Int32 nodeId)
495 {
496     auto node = OHOS::Ace::ElementRegister::GetInstance()->GetNodeById(nodeId);
497     return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(node));
498 }
499 
GetFrameNodeByUniqueId(ArkUI_Int32 uniqueId)500 ArkUINodeHandle GetFrameNodeByUniqueId(ArkUI_Int32 uniqueId)
501 {
502     auto node = AceType::DynamicCast<NG::UINode>(OHOS::Ace::ElementRegister::GetInstance()->GetNodeById(uniqueId));
503     CHECK_NULL_RETURN(node, nullptr);
504     if (node->GetTag() == "root" || node->GetTag() == "stage" || node->GetTag() == "page") {
505         return nullptr;
506     }
507 
508     if (!AceType::InstanceOf<NG::FrameNode>(node) || AceType::InstanceOf<NG::CustomMeasureLayoutNode>(node)) {
509         auto parent = node->GetParent();
510         if (parent && parent->GetTag() == V2::RECYCLE_VIEW_ETS_TAG) {
511             parent = parent->GetParent();
512         }
513         if (parent && parent->GetTag() == V2::COMMON_VIEW_ETS_TAG) {
514             node = parent;
515         } else {
516             node = node->GetFrameChildByIndexWithoutExpanded(0);
517         }
518     }
519 
520     return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(node));
521 }
522 
GetFrameNodeByKey(ArkUI_CharPtr key)523 ArkUINodeHandle GetFrameNodeByKey(ArkUI_CharPtr key)
524 {
525     auto node = NG::Inspector::GetFrameNodeByKey(key, true);
526     return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(node));
527 }
528 
GetAttachedFrameNodeById(ArkUI_CharPtr key)529 ArkUINodeHandle GetAttachedFrameNodeById(ArkUI_CharPtr key)
530 {
531     auto pipeline = NG::PipelineContext::GetCurrentContextSafely();
532     if (pipeline && !pipeline->CheckThreadSafe()) {
533         LOGF_ABORT("GetAttachedNodeHandleById doesn't run on UI thread");
534     }
535     auto node = ElementRegister::GetInstance()->GetAttachedFrameNodeById(key);
536     CHECK_NULL_RETURN(node, nullptr);
537     return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(node));
538 }
539 
PropertyUpdate(ArkUINodeHandle node)540 void PropertyUpdate(ArkUINodeHandle node)
541 {
542     auto* uiNode = reinterpret_cast<UINode*>(node);
543     if (uiNode) {
544         uiNode->MarkDirtyNode(PROPERTY_UPDATE_DIFF);
545     }
546 }
547 
GetLast(ArkUINodeHandle node,ArkUI_Bool isExpanded)548 ArkUINodeHandle GetLast(ArkUINodeHandle node, ArkUI_Bool isExpanded)
549 {
550     auto* currentNode = reinterpret_cast<FrameNode*>(node);
551     CHECK_NULL_RETURN(currentNode, nullptr);
552     auto* frameNode = AceType::DynamicCast<FrameNode>(currentNode);
553     CHECK_NULL_RETURN(frameNode, nullptr);
554     size_t size = isExpanded ? frameNode->GetAllChildrenWithBuild(false).size()
555                              : static_cast<size_t>(frameNode->GetTotalChildCountWithoutExpanded());
556     CHECK_NULL_RETURN(size > 0, nullptr);
557     auto child = frameNode->GetFrameNodeChildByIndex(size - 1, false, isExpanded);
558     return reinterpret_cast<ArkUINodeHandle>(child);
559 }
560 
GetFirstUINode(ArkUINodeHandle node)561 ArkUINodeHandle GetFirstUINode(ArkUINodeHandle node)
562 {
563     auto* currentNode = reinterpret_cast<UINode*>(node);
564     CHECK_NULL_RETURN(currentNode, nullptr);
565     auto child = currentNode->GetFirstChild();
566     return reinterpret_cast<ArkUINodeHandle>(AceType::RawPtr(child));
567 }
568 
GetLayoutSize(ArkUINodeHandle node,ArkUI_Int32 * size)569 void GetLayoutSize(ArkUINodeHandle node, ArkUI_Int32* size)
570 {
571     auto* currentNode = reinterpret_cast<FrameNode*>(node);
572     CHECK_NULL_VOID(currentNode);
573     auto renderContext = currentNode->GetRenderContext();
574     CHECK_NULL_VOID(renderContext);
575     auto rectSize = renderContext->GetPaintRectWithoutTransform().GetSize();
576     size[0] = rectSize.Width();
577     size[1] = rectSize.Height();
578 }
579 
GetLayoutPositionWithoutMargin(ArkUINodeHandle node)580 ArkUI_Float32* GetLayoutPositionWithoutMargin(ArkUINodeHandle node)
581 {
582     auto* currentNode = reinterpret_cast<FrameNode*>(node);
583     CHECK_NULL_RETURN(currentNode, nullptr);
584     auto rect = currentNode->GetPaintRectWithTransform();
585     ArkUI_Float32* ret = new ArkUI_Float32[2];
586     ret[0] = rect.GetX();
587     ret[1] = rect.GetY();
588     return ret;
589 }
590 
SetSystemColorModeChangeEvent(ArkUINodeHandle node,void * userData,void * onColorModeChange)591 ArkUI_Int32 SetSystemColorModeChangeEvent(ArkUINodeHandle node, void* userData, void* onColorModeChange)
592 {
593     auto* frameNode = reinterpret_cast<FrameNode*>(node);
594     CHECK_NULL_RETURN(frameNode, 0);
595     auto onColorChange = [userData, onColorModeChange](int32_t colorMode) {
596         using FuncType = float (*)(int32_t, void*);
597         FuncType func = reinterpret_cast<FuncType>(onColorModeChange);
598         func(colorMode, userData);
599     };
600     ViewAbstract::SetSystemColorModeChangeEvent(frameNode, onColorChange);
601     return 1;
602 }
603 
ResetSystemColorModeChangeEvent(ArkUINodeHandle node)604 void ResetSystemColorModeChangeEvent(ArkUINodeHandle node)
605 {
606     auto* frameNode = reinterpret_cast<FrameNode*>(node);
607     CHECK_NULL_VOID(frameNode);
608     ViewAbstract::SetSystemColorModeChangeEvent(frameNode, nullptr);
609 }
610 
SetDrawCompleteEvent(ArkUINodeHandle node,void * userData,void * onDraw)611 ArkUI_Int32 SetDrawCompleteEvent(ArkUINodeHandle node, void* userData, void* onDraw)
612 {
613     auto* frameNode = reinterpret_cast<FrameNode*>(node);
614     CHECK_NULL_RETURN(frameNode, -1);
615     auto onDrawCallBack = [userData, onDraw]() {
616         using FuncType = void (*)(void*);
617         FuncType func = reinterpret_cast<FuncType>(onDraw);
618         if (!func) {
619             return;
620         }
621         func(userData);
622     };
623     ViewAbstract::SetDrawCompleteEvent(frameNode, std::move(onDrawCallBack));
624     return 0;
625 }
626 
ResetDrawCompleteEvent(ArkUINodeHandle node)627 ArkUI_Int32 ResetDrawCompleteEvent(ArkUINodeHandle node)
628 {
629     auto* frameNode = reinterpret_cast<FrameNode*>(node);
630     CHECK_NULL_RETURN(frameNode, -1);
631     ViewAbstract::SetDrawCompleteEvent(frameNode, nullptr);
632     return 0;
633 }
634 
SetLayoutEvent(ArkUINodeHandle node,void * userData,void * onLayout)635 ArkUI_Int32 SetLayoutEvent(ArkUINodeHandle node, void* userData, void* onLayout)
636 {
637     auto* frameNode = reinterpret_cast<FrameNode*>(node);
638     CHECK_NULL_RETURN(frameNode, -1);
639     auto onLayoutCallBack = [userData, onLayout]() {
640         using FuncType = void (*)(void*);
641         FuncType func = reinterpret_cast<FuncType>(onLayout);
642         if (!func) {
643             return;
644         }
645         func(userData);
646     };
647     ViewAbstract::SetLayoutEvent(frameNode, std::move(onLayoutCallBack));
648     return 0;
649 }
650 
ResetLayoutEvent(ArkUINodeHandle node)651 ArkUI_Int32 ResetLayoutEvent(ArkUINodeHandle node)
652 {
653     auto* frameNode = reinterpret_cast<FrameNode*>(node);
654     CHECK_NULL_RETURN(frameNode, -1);
655     ViewAbstract::SetLayoutEvent(frameNode, nullptr);
656     return 0;
657 }
658 
SetCrossLanguageOptions(ArkUINodeHandle node,bool attributeSetting)659 ArkUI_Int32 SetCrossLanguageOptions(ArkUINodeHandle node, bool attributeSetting)
660 {
661     auto* currentNode = reinterpret_cast<UINode*>(node);
662     CHECK_NULL_RETURN(currentNode, ERROR_CODE_PARAM_INVALID);
663     static const std::vector<const char*> nodeTypeArray = { OHOS::Ace::V2::SCROLL_ETS_TAG,
664         OHOS::Ace::V2::SWIPER_ETS_TAG, OHOS::Ace::V2::LIST_ETS_TAG, OHOS::Ace::V2::LIST_ITEM_ETS_TAG,
665         OHOS::Ace::V2::LIST_ITEM_GROUP_ETS_TAG, OHOS::Ace::V2::WATERFLOW_ETS_TAG, OHOS::Ace::V2::FLOW_ITEM_ETS_TAG,
666         OHOS::Ace::V2::GRID_ETS_TAG, OHOS::Ace::V2::GRID_ITEM_ETS_TAG, OHOS::Ace::V2::TEXT_ETS_TAG,
667         OHOS::Ace::V2::TEXTINPUT_ETS_TAG, OHOS::Ace::V2::TEXTAREA_ETS_TAG, OHOS::Ace::V2::COLUMN_ETS_TAG,
668         OHOS::Ace::V2::ROW_ETS_TAG, OHOS::Ace::V2::STACK_ETS_TAG, OHOS::Ace::V2::FLEX_ETS_TAG,
669         OHOS::Ace::V2::RELATIVE_CONTAINER_ETS_TAG, OHOS::Ace::V2::PROGRESS_ETS_TAG,
670         OHOS::Ace::V2::LOADING_PROGRESS_ETS_TAG, OHOS::Ace::V2::IMAGE_ETS_TAG, OHOS::Ace::V2::BUTTON_ETS_TAG,
671         OHOS::Ace::V2::CHECKBOX_ETS_TAG, OHOS::Ace::V2::RADIO_ETS_TAG, OHOS::Ace::V2::SLIDER_ETS_TAG,
672         OHOS::Ace::V2::TOGGLE_ETS_TAG, OHOS::Ace::V2::XCOMPONENT_ETS_TAG };
673     auto pos = std::find(nodeTypeArray.begin(), nodeTypeArray.end(), currentNode->GetTag());
674     if (pos == nodeTypeArray.end()) {
675         return ERROR_CODE_PARAM_INVALID;
676     }
677     currentNode->SetIsCrossLanguageAttributeSetting(attributeSetting);
678     return ERROR_CODE_NO_ERROR;
679 }
680 
GetCrossLanguageOptions(ArkUINodeHandle node)681 ArkUI_Bool GetCrossLanguageOptions(ArkUINodeHandle node)
682 {
683     auto* currentNode = reinterpret_cast<UINode*>(node);
684     CHECK_NULL_RETURN(currentNode, false);
685     return currentNode->isCrossLanguageAttributeSetting();
686 }
687 
CheckIfCanCrossLanguageAttributeSetting(ArkUINodeHandle node)688 ArkUI_Bool CheckIfCanCrossLanguageAttributeSetting(ArkUINodeHandle node)
689 {
690     auto* currentNode = reinterpret_cast<UINode*>(node);
691     CHECK_NULL_RETURN(currentNode, false);
692     return currentNode -> IsCNode() ? currentNode->isCrossLanguageAttributeSetting() : false;
693 }
694 
GetInteractionEventBindingInfo(ArkUINodeHandle node,int eventType)695 EventBindingInfo GetInteractionEventBindingInfo(ArkUINodeHandle node, int eventType)
696 {
697     auto* currentNode = reinterpret_cast<UINode*>(node);
698     EventBindingInfo bindingInfo {};
699     CHECK_NULL_RETURN(currentNode, bindingInfo);
700     if (eventType != EventQueryType::ON_CLICK) {
701         return bindingInfo;
702     }
703     auto info = currentNode->GetInteractionEventBindingInfo();
704     bindingInfo.baseEventRegistered = info.baseEventRegistered;
705     bindingInfo.nodeEventRegistered = info.nodeEventRegistered;
706     bindingInfo.nativeEventRegistered= info.nativeEventRegistered;
707     bindingInfo.builtInEventRegistered= info.builtInEventRegistered;
708     return bindingInfo;
709 }
710 
RunScopedTask(ArkUI_Int32 instanceId,void * userData,void (* callback)(void * userData))711 void RunScopedTask(ArkUI_Int32 instanceId, void* userData, void (*callback)(void* userData))
712 {
713     ContainerScope scope(instanceId);
714     callback(userData);
715 }
716 
SetSystemFontStyleChangeEvent(ArkUINodeHandle node,void * userData,void * onFontStyleChange)717 ArkUI_Int32 SetSystemFontStyleChangeEvent(ArkUINodeHandle node, void* userData, void* onFontStyleChange)
718 {
719     auto* frameNode = reinterpret_cast<FrameNode*>(node);
720     CHECK_NULL_RETURN(frameNode, 0);
721     auto onFontChange = [userData, onFontStyleChange](float fontSize, float fontWeight) {
722         ArkUISystemFontStyleEvent fontStyle = new ArkUI_SystemFontStyleEvent();
723         fontStyle->fontSize = fontSize;
724         fontStyle->fontWeight = fontWeight;
725         using FuncType = float (*)(ArkUISystemFontStyleEvent, void*);
726         FuncType func = reinterpret_cast<FuncType>(onFontStyleChange);
727         func(fontStyle, userData);
728     };
729     ViewAbstract::SetSystemFontChangeEvent(frameNode, onFontChange);
730     return 1;
731 }
732 
ResetSystemFontStyleChangeEvent(ArkUINodeHandle node)733 void ResetSystemFontStyleChangeEvent(ArkUINodeHandle node)
734 {
735     auto* frameNode = reinterpret_cast<FrameNode*>(node);
736     CHECK_NULL_VOID(frameNode);
737     ViewAbstract::SetSystemFontChangeEvent(frameNode, nullptr);
738 }
739 
GetCustomPropertyCapiByKey(ArkUINodeHandle node,ArkUI_CharPtr key,char ** value,ArkUI_Uint32 * size)740 ArkUI_Uint32 GetCustomPropertyCapiByKey(ArkUINodeHandle node, ArkUI_CharPtr key, char** value, ArkUI_Uint32* size)
741 {
742     auto* frameNode = reinterpret_cast<FrameNode*>(node);
743     CHECK_NULL_RETURN(frameNode, 0);
744     std::string capiCustomProperty;
745     if (!frameNode->IsCNode() || !frameNode->GetCapiCustomProperty(key, capiCustomProperty)) {
746         return 0;
747     }
748     *size = capiCustomProperty.size();
749     *value = new char[*size + 1];
750     capiCustomProperty.copy(*value, *size);
751     (*value)[*size] = '\0';
752     return 1;
753 }
754 
FreeCustomPropertyCharPtr(char * value,ArkUI_Uint32 size)755 void FreeCustomPropertyCharPtr(char* value, ArkUI_Uint32 size)
756 {
757     CHECK_NULL_VOID(value);
758     delete[] value;
759     value = nullptr;
760 }
761 
SetCustomPropertyModiferByKey(ArkUINodeHandle node,void * callback,void * getCallback,void * getCustomPropertyMap)762 void SetCustomPropertyModiferByKey(ArkUINodeHandle node, void* callback, void* getCallback,
763     void* getCustomPropertyMap)
764 {
765     auto* frameNode = reinterpret_cast<FrameNode*>(node);
766     CHECK_NULL_VOID(frameNode);
767     std::function<bool()>* func = reinterpret_cast<std::function<bool()>*>(callback);
768     std::function<std::string(const std::string&)>* getFunc =
769         reinterpret_cast<std::function<std::string(const std::string&)>*>(getCallback);
770     std::function<std::string()>* getMapFunc =
771         reinterpret_cast<std::function<std::string()>*>(getCustomPropertyMap);
772     frameNode->SetJSCustomProperty(*func, *getFunc, std::move(*getMapFunc));
773 }
774 
AddCustomProperty(ArkUINodeHandle node,ArkUI_CharPtr key,ArkUI_CharPtr value)775 void AddCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key, ArkUI_CharPtr value)
776 {
777     auto* uiNode = reinterpret_cast<UINode*>(node);
778     CHECK_NULL_VOID(uiNode);
779     auto pipeline = uiNode->GetContextRefPtr();
780     if (pipeline && !pipeline->CheckThreadSafe()) {
781         LOGW("AddCustomProperty doesn't run on UI thread");
782         return;
783     }
784     ViewAbstract::AddCustomProperty(uiNode, key, value);
785 }
786 
RemoveCustomProperty(ArkUINodeHandle node,ArkUI_CharPtr key)787 void RemoveCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key)
788 {
789     auto* uiNode = reinterpret_cast<UINode*>(node);
790     CHECK_NULL_VOID(uiNode);
791     auto pipeline = uiNode->GetContextRefPtr();
792     if (pipeline && !pipeline->CheckThreadSafe()) {
793         LOGW("RemoveCustomProperty doesn't run on UI thread");
794         return;
795     }
796     ViewAbstract::RemoveCustomProperty(uiNode, key);
797 }
798 
GetCurrentPageRootNode(ArkUINodeHandle node)799 ArkUINodeHandle GetCurrentPageRootNode(ArkUINodeHandle node)
800 {
801     auto uiNode = reinterpret_cast<UINode*>(node);
802     CHECK_NULL_RETURN(uiNode, nullptr);
803     auto rootNode = uiNode->GetCurrentPageRootNode();
804     return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(rootNode));
805 }
806 
GetNodeTag(ArkUINodeHandle node)807 ArkUI_Int32 GetNodeTag(ArkUINodeHandle node)
808 {
809     auto uiNode = reinterpret_cast<UINode*>(node);
810     CHECK_NULL_RETURN(uiNode, 0);
811     return uiNode->IsCNode();
812 }
813 
GetActiveChildrenInfo(ArkUINodeHandle handle,ArkUINodeHandle ** items,ArkUI_Int32 * size)814 void GetActiveChildrenInfo(ArkUINodeHandle handle, ArkUINodeHandle** items, ArkUI_Int32* size)
815 {
816     auto* frameNode = reinterpret_cast<FrameNode*>(handle);
817     CHECK_NULL_VOID(frameNode);
818     auto childList = frameNode->GetActiveChildren();
819     *size = childList.size();
820     *items = new ArkUINodeHandle[*size];
821     int32_t i = 0;
822     for (auto& child : childList) {
823         (*items)[i++] = reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(child));
824     }
825 }
826 
GetCustomProperty(ArkUINodeHandle node,ArkUI_CharPtr key,char ** value)827 void GetCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key, char** value)
828 {
829     auto* frameNode = reinterpret_cast<FrameNode*>(node);
830     CHECK_NULL_VOID(frameNode);
831     std::string capiCustomProperty;
832     if (frameNode->IsCNode()) {
833         frameNode->GetCapiCustomProperty(key, capiCustomProperty);
834     } else {
835         frameNode->GetJSCustomProperty(key, capiCustomProperty);
836     }
837     auto size = capiCustomProperty.size();
838     *value = new char[size + 1];
839     capiCustomProperty.copy(*value, size);
840     (*value)[size] = '\0';
841 }
842 
AddExtraCustomProperty(ArkUINodeHandle node,ArkUI_CharPtr key,void * extraData)843 void AddExtraCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key, void* extraData)
844 {
845     auto* frameNode = reinterpret_cast<FrameNode*>(node);
846     CHECK_NULL_VOID(frameNode);
847     auto pipeline = frameNode->GetContextRefPtr();
848     if (pipeline && !pipeline->CheckThreadSafe()) {
849         LOGW("AddExtraCustomProperty doesn't run on UI thread");
850         return;
851     }
852     frameNode->AddExtraCustomProperty(key, extraData);
853 }
854 
GetExtraCustomProperty(ArkUINodeHandle node,ArkUI_CharPtr key)855 void* GetExtraCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key)
856 {
857     auto* frameNode = reinterpret_cast<FrameNode*>(node);
858     CHECK_NULL_RETURN(frameNode, nullptr);
859     auto pipeline = frameNode->GetContextRefPtr();
860     if (pipeline && !pipeline->CheckThreadSafe()) {
861         LOGW("GetExtraCustomProperty doesn't run on UI thread");
862         return nullptr;
863     }
864     return frameNode->GetExtraCustomProperty(key);
865 }
866 
RemoveExtraCustomProperty(ArkUINodeHandle node,ArkUI_CharPtr key)867 void RemoveExtraCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key)
868 {
869     auto* frameNode = reinterpret_cast<FrameNode*>(node);
870     CHECK_NULL_VOID(frameNode);
871     auto pipeline = frameNode->GetContextRefPtr();
872     if (pipeline && !pipeline->CheckThreadSafe()) {
873         LOGW("RemoveExtraCustomProperty doesn't run on UI thread");
874         return;
875     }
876     frameNode->RemoveExtraCustomProperty(key);
877 }
878 
GetCustomPropertyByKey(ArkUINodeHandle node,ArkUI_CharPtr key,char ** value,ArkUI_Uint32 * size)879 void GetCustomPropertyByKey(ArkUINodeHandle node, ArkUI_CharPtr key, char** value, ArkUI_Uint32* size)
880 {
881     auto* frameNode = reinterpret_cast<FrameNode*>(node);
882     CHECK_NULL_VOID(frameNode);
883     auto pipeline = frameNode->GetContextRefPtr();
884     if (pipeline && !pipeline->CheckThreadSafe()) {
885         LOGW("GetCustomPropertyByKey doesn't run on UI thread");
886         return;
887     }
888     std::string customProperty;
889     if (!frameNode->GetCustomPropertyByKey(key, customProperty)) {
890         return;
891     }
892     *size = customProperty.size();
893     *value = new char[*size + 1];
894     customProperty.copy(*value, *size);
895     (*value)[*size] = '\0';
896 }
897 
AddNodeDestroyCallback(ArkUINodeHandle node,ArkUI_CharPtr callbackKey,void (* onDestroy)(ArkUINodeHandle node))898 void AddNodeDestroyCallback(ArkUINodeHandle node, ArkUI_CharPtr callbackKey, void (*onDestroy)(ArkUINodeHandle node))
899 {
900     auto* frameNode = reinterpret_cast<FrameNode*>(node);
901     CHECK_NULL_VOID(frameNode);
902     auto pipeline = frameNode->GetContextRefPtr();
903     if (pipeline && !pipeline->CheckThreadSafe()) {
904         LOGW("AddNodeDestroyCallback doesn't run on UI thread");
905         return;
906     }
907     auto onDestroyCallback = [node, onDestroy]() {
908         onDestroy(node);
909     };
910     frameNode->AddNodeDestroyCallback(std::string(callbackKey), std::move(onDestroyCallback));
911 }
912 
RemoveNodeDestroyCallback(ArkUINodeHandle node,ArkUI_CharPtr callbackKey)913 void RemoveNodeDestroyCallback(ArkUINodeHandle node, ArkUI_CharPtr callbackKey)
914 {
915     auto* frameNode = reinterpret_cast<FrameNode*>(node);
916     CHECK_NULL_VOID(frameNode);
917     auto pipeline = frameNode->GetContextRefPtr();
918     if (pipeline && !pipeline->CheckThreadSafe()) {
919         LOGW("RemoveNodeDestroyCallback doesn't run on UI thread");
920         return;
921     }
922     frameNode->RemoveNodeDestroyCallback(std::string(callbackKey));
923 }
924 
RequestFocus(ArkUINodeHandle node)925 ArkUI_Int32 RequestFocus(ArkUINodeHandle node)
926 {
927     auto* frameNode = reinterpret_cast<FrameNode*>(node);
928     CHECK_NULL_RETURN(frameNode, ARKUI_ERROR_CODE_FOCUS_NON_EXISTENT);
929     return static_cast<ArkUI_Int32>(ViewAbstract::RequestFocus(frameNode));
930 }
931 
ClearFocus(ArkUI_Int32 instanceId)932 void ClearFocus(ArkUI_Int32 instanceId)
933 {
934     ViewAbstract::ClearFocus(instanceId);
935 }
936 
FocusActivate(ArkUI_Int32 instanceId,bool isActive,bool isAutoInactive)937 void FocusActivate(ArkUI_Int32 instanceId, bool isActive, bool isAutoInactive)
938 {
939     ViewAbstract::FocusActivate(instanceId, isActive, isAutoInactive);
940 }
941 
SetAutoFocusTransfer(ArkUI_Int32 instanceId,bool isAutoFocusTransfer)942 void SetAutoFocusTransfer(ArkUI_Int32 instanceId, bool isAutoFocusTransfer)
943 {
944     ViewAbstract::SetAutoFocusTransfer(instanceId, isAutoFocusTransfer);
945 }
946 
GetWindowInfoByNode(ArkUINodeHandle node,char ** name)947 ArkUI_Int32 GetWindowInfoByNode(ArkUINodeHandle node, char** name)
948 {
949     auto* frameNode = reinterpret_cast<FrameNode*>(node);
950     CHECK_NULL_RETURN(frameNode, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
951     if (!frameNode->IsOnMainTree()) {
952         return OHOS::Ace::ERROR_CODE_NATIVE_IMPL_NODE_NOT_ON_MAIN_TREE;
953     }
954     auto context = frameNode->GetAttachedContext();
955     CHECK_NULL_RETURN(context, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_NODE_NOT_ON_MAIN_TREE);
956     if (!context->CheckThreadSafe()) {
957         LOGF_ABORT("GetWindowInfoByNode doesn't run on UI thread");
958     }
959     auto window = context->GetWindow();
960     CHECK_NULL_RETURN(window, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_NODE_NOT_ON_MAIN_TREE);
961     std::string windowName = window->GetWindowName();
962     size_t nameSize = windowName.size();
963     *name = new char[nameSize + 1];
964     windowName.copy(*name, nameSize);
965     (*name)[nameSize] = '\0';
966     return OHOS::Ace::ERROR_CODE_NO_ERROR;
967 }
968 
MoveNodeTo(ArkUINodeHandle node,ArkUINodeHandle target_parent,ArkUI_Int32 index)969 ArkUI_Int32 MoveNodeTo(ArkUINodeHandle node, ArkUINodeHandle target_parent, ArkUI_Int32 index)
970 {
971     auto* moveNode = reinterpret_cast<UINode*>(node);
972     auto* toNode = reinterpret_cast<UINode*>(target_parent);
973     CHECK_NULL_RETURN(moveNode, ERROR_CODE_PARAM_INVALID);
974     CHECK_NULL_RETURN(toNode, ERROR_CODE_PARAM_INVALID);
975     static const std::vector<const char*> nodeTypeArray = {
976         OHOS::Ace::V2::STACK_ETS_TAG,
977         OHOS::Ace::V2::XCOMPONENT_ETS_TAG,
978         OHOS::Ace::V2::EMBEDDED_COMPONENT_ETS_TAG,
979     };
980     auto pos = std::find(nodeTypeArray.begin(), nodeTypeArray.end(), moveNode->GetTag());
981     if (pos == nodeTypeArray.end()) {
982         return ERROR_CODE_PARAM_INVALID;
983     }
984     auto pipeline = moveNode->GetContextRefPtr();
985     if (pipeline && !pipeline->CheckThreadSafe()) {
986         LOGF_ABORT("MoveNodeTo doesn't run on UI thread");
987     }
988     auto oldParent = moveNode->GetParent();
989     moveNode->setIsMoving(true);
990     auto moveNodeRef = AceType::Claim(moveNode);
991     if (oldParent) {
992         oldParent->RemoveChild(moveNodeRef);
993         OHOS::Ace::BuilderUtils::RemoveBuilderFromParent(oldParent, moveNodeRef);
994         oldParent->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
995     }
996     int32_t childCount = toNode->TotalChildCount();
997     if (index >= childCount || index < 0) {
998         toNode->AddChild(moveNodeRef);
999     } else {
1000         auto indexChild = toNode->GetChildAtIndex(index);
1001         toNode->AddChildBefore(moveNodeRef, indexChild);
1002     }
1003     if (moveNodeRef->GetParent() == AceType::Claim(toNode)) {
1004         OHOS::Ace::BuilderUtils::AddBuilderToParent(AceType::Claim(toNode), moveNodeRef);
1005     }
1006     toNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
1007     moveNode->setIsMoving(false);
1008     return ERROR_CODE_NO_ERROR;
1009 }
1010 
SetKeyProcessingMode(ArkUI_Int32 instanceId,ArkUI_Int32 mode)1011 void SetKeyProcessingMode(ArkUI_Int32 instanceId, ArkUI_Int32 mode)
1012 {
1013     auto container = Container::GetContainer(instanceId);
1014     CHECK_NULL_VOID(container);
1015     auto delegate = EngineHelper::GetDelegateByContainer(container);
1016     CHECK_NULL_VOID(delegate);
1017     delegate->SetKeyProcessingMode(mode);
1018 }
1019 
UpdateConfiguration(ArkUINodeHandle node)1020 void UpdateConfiguration(ArkUINodeHandle node)
1021 {
1022     auto* uiNode = reinterpret_cast<UINode*>(node);
1023     CHECK_NULL_VOID(uiNode);
1024     uiNode->UpdateConfigurationUpdate();
1025 }
1026 
AddSupportedUIStates(ArkUINodeHandle node,int32_t state,void * statesChangeHandler,bool isExcludeInner,void * userData)1027 void AddSupportedUIStates(
1028     ArkUINodeHandle node, int32_t state, void* statesChangeHandler, bool isExcludeInner, void* userData)
1029 {
1030     auto* frameNode = reinterpret_cast<FrameNode*>(node);
1031     CHECK_NULL_VOID(frameNode);
1032     auto eventHub = frameNode->GetEventHub<EventHub>();
1033     CHECK_NULL_VOID(eventHub);
1034     std::function<void(uint64_t)> onStatesChange = [userData, statesChangeHandler](uint64_t currentState) {
1035         using FuncType = float (*)(int32_t, void*);
1036         FuncType func = reinterpret_cast<FuncType>(statesChangeHandler);
1037         func(static_cast<int32_t >(currentState), userData);
1038     };
1039     eventHub->AddSupportedUIStateWithCallback(static_cast<uint64_t>(state), onStatesChange, false, isExcludeInner);
1040 }
1041 
RemoveSupportedUIStates(ArkUINodeHandle node,int32_t state)1042 void RemoveSupportedUIStates(ArkUINodeHandle node, int32_t state)
1043 {
1044     auto* frameNode = reinterpret_cast<FrameNode*>(node);
1045     CHECK_NULL_VOID(frameNode);
1046     auto eventHub = frameNode->GetEventHub<EventHub>();
1047     CHECK_NULL_VOID(eventHub);
1048     eventHub->RemoveSupportedUIState(static_cast<uint64_t>(state), false);
1049 }
1050 
SetForceDarkConfig(ArkUI_Int32 instanceId,bool forceDark,ArkUI_CharPtr nodeTag,uint32_t (* colorInvertFunc)(uint32_t color))1051 ArkUI_Int32 SetForceDarkConfig(
1052     ArkUI_Int32 instanceId, bool forceDark, ArkUI_CharPtr nodeTag, uint32_t (*colorInvertFunc)(uint32_t color))
1053 {
1054 #ifdef OHOS_PLATFORM
1055     if (getpid() != gettid()) {
1056         LOGF_ABORT("SetForceDarkConfig doesn't run on UI thread");
1057     }
1058 #endif
1059     if (!forceDark && colorInvertFunc) {
1060         return ERROR_CODE_NATIVE_IMPL_FORCE_DARK_CONFIG_INVALID;
1061     }
1062     if (forceDark) {
1063         auto invertFunc = [colorInvertFunc](uint32_t color) {
1064             return colorInvertFunc ? colorInvertFunc(color) : ColorInverter::DefaultInverter(color);
1065         };
1066         ColorInverter::GetInstance().EnableColorInvert(instanceId, nodeTag, std::move(invertFunc));
1067     } else {
1068         ColorInverter::GetInstance().DisableColorInvert(instanceId, nodeTag);
1069     }
1070     return ERROR_CODE_NO_ERROR;
1071 }
1072 
SetFocusDependence(ArkUINodeHandle node,ArkUI_Uint32 focusDependence)1073 void SetFocusDependence(ArkUINodeHandle node, ArkUI_Uint32 focusDependence)
1074 {
1075     auto* frameNode = reinterpret_cast<FrameNode*>(node);
1076     CHECK_NULL_VOID(frameNode);
1077     auto focusHub = frameNode->GetOrCreateFocusHub();
1078     CHECK_NULL_VOID(focusHub);
1079     focusHub->SetFocusDependence(static_cast<FocusDependence>(focusDependence));
1080 }
1081 
ResetFocusDependence(ArkUINodeHandle node)1082 void ResetFocusDependence(ArkUINodeHandle node)
1083 {
1084     auto* frameNode = reinterpret_cast<FrameNode*>(node);
1085     CHECK_NULL_VOID(frameNode);
1086     auto focusHub = frameNode->GetOrCreateFocusHub();
1087     CHECK_NULL_VOID(focusHub);
1088     focusHub->SetFocusDependence(FocusDependence::CHILD);
1089 }
1090 
1091 namespace NodeModifier {
GetFrameNodeModifier()1092 const ArkUIFrameNodeModifier* GetFrameNodeModifier()
1093 {
1094     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
1095     static const ArkUIFrameNodeModifier modifier = {
1096         .isModifiable = IsModifiable,
1097         .createFrameNode = CreateFrameNode,
1098         .invalidate = InvalidateInFrameNode,
1099         .addBuilderNode = AddBuilderNodeInFrameNode,
1100         .appendChild = AppendChildInFrameNode,
1101         .insertChildAfter = InsertChildAfterInFrameNode,
1102         .removeBuilderNode = RemoveBuilderNodeInFrameNode,
1103         .removeChild = RemoveChildInFrameNode,
1104         .clearBuilderNode = ClearBuilderNodeInFrameNode,
1105         .clearChildren = ClearChildrenInFrameNode,
1106         .getChildrenCount = GetChildrenCount,
1107         .getChild = GetChild,
1108         .getFirstChildIndexWithoutExpand = GetFirstChildIndexWithoutExpand,
1109         .getLastChildIndexWithoutExpand = GetLastChildIndexWithoutExpand,
1110         .getFirst = GetFirst,
1111         .getNextSibling = GetNextSibling,
1112         .getPreviousSibling = GetPreviousSibling,
1113         .getParent = GetParent,
1114         .getIdByNodePtr = GetIdByNodePtr,
1115         .getPositionToParent = GetPositionToParent,
1116         .getPositionToScreen = GetPositionToScreen,
1117         .getPositionToWindow = GetPositionToWindow,
1118         .getGlobalPositionOnDisplay = GetGlobalPositionOnDisplay,
1119         .getPositionToParentWithTransform = GetPositionToParentWithTransform,
1120         .getPositionToScreenWithTransform = GetPositionToScreenWithTransform,
1121         .getPositionToWindowWithTransform = GetPositionToWindowWithTransform,
1122         .getMeasuredSize = GetMeasuredSize,
1123         .getLayoutPosition = GetLayoutPosition,
1124         .getInspectorId = GetInspectorId,
1125         .getNodeType = GetNodeType,
1126         .isVisible = IsVisible,
1127         .isAttached = IsAttached,
1128         .getInspectorInfo = GetInspectorInfo,
1129         .getFrameNodeById = GetFrameNodeById,
1130         .getFrameNodeByUniqueId = GetFrameNodeByUniqueId,
1131         .getFrameNodeByKey = GetFrameNodeByKey,
1132         .getAttachedFrameNodeById = GetAttachedFrameNodeById,
1133         .propertyUpdate = PropertyUpdate,
1134         .getLast = GetLast,
1135         .getFirstUINode = GetFirstUINode,
1136         .getLayoutSize = GetLayoutSize,
1137         .getLayoutPositionWithoutMargin = GetLayoutPositionWithoutMargin,
1138         .setSystemColorModeChangeEvent = SetSystemColorModeChangeEvent,
1139         .resetSystemColorModeChangeEvent = ResetSystemColorModeChangeEvent,
1140         .setSystemFontStyleChangeEvent = SetSystemFontStyleChangeEvent,
1141         .resetSystemFontStyleChangeEvent = ResetSystemFontStyleChangeEvent,
1142         .getCustomPropertyCapiByKey = GetCustomPropertyCapiByKey,
1143         .setCustomPropertyModiferByKey = SetCustomPropertyModiferByKey,
1144         .addCustomProperty = AddCustomProperty,
1145         .removeCustomProperty = RemoveCustomProperty,
1146         .freeCustomPropertyCharPtr = FreeCustomPropertyCharPtr,
1147         .getCurrentPageRootNode = GetCurrentPageRootNode,
1148         .getNodeTag = GetNodeTag,
1149         .getActiveChildrenInfo = GetActiveChildrenInfo,
1150         .getCustomProperty = GetCustomProperty,
1151         .addExtraCustomProperty = AddExtraCustomProperty,
1152         .getExtraCustomProperty = GetExtraCustomProperty,
1153         .removeExtraCustomProperty = RemoveExtraCustomProperty,
1154         .getCustomPropertyByKey = GetCustomPropertyByKey,
1155         .addNodeDestroyCallback = AddNodeDestroyCallback,
1156         .removeNodeDestroyCallback = RemoveNodeDestroyCallback,
1157         .getWindowInfoByNode = GetWindowInfoByNode,
1158         .setDrawCompleteEvent = SetDrawCompleteEvent,
1159         .resetDrawCompleteEvent = ResetDrawCompleteEvent,
1160         .setLayoutEvent = SetLayoutEvent,
1161         .resetLayoutEvent = ResetLayoutEvent,
1162         .requestFocus = RequestFocus,
1163         .clearFocus = ClearFocus,
1164         .focusActivate = FocusActivate,
1165         .setAutoFocusTransfer = SetAutoFocusTransfer,
1166         .moveNodeTo = MoveNodeTo,
1167         .setCrossLanguageOptions = SetCrossLanguageOptions,
1168         .getCrossLanguageOptions = GetCrossLanguageOptions,
1169         .checkIfCanCrossLanguageAttributeSetting = CheckIfCanCrossLanguageAttributeSetting,
1170         .setKeyProcessingMode = SetKeyProcessingMode,
1171         .getInteractionEventBindingInfo = GetInteractionEventBindingInfo,
1172         .runScopedTask = RunScopedTask,
1173         .updateConfiguration = UpdateConfiguration,
1174         .addSupportedUIStates = AddSupportedUIStates,
1175         .removeSupportedUIStates = RemoveSupportedUIStates,
1176         .setForceDarkConfig = SetForceDarkConfig,
1177         .setFocusDependence = SetFocusDependence,
1178         .resetFocusDependence = ResetFocusDependence,
1179         .applyAttributesFinish = ApplyAttributesFinish,
1180     };
1181     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
1182     return &modifier;
1183 }
1184 
GetCJUIFrameNodeModifier()1185 const CJUIFrameNodeModifier* GetCJUIFrameNodeModifier()
1186 {
1187     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
1188     static const CJUIFrameNodeModifier modifier = {
1189         .isModifiable = IsModifiable,
1190         .createFrameNode = CreateFrameNode,
1191         .invalidate = InvalidateInFrameNode,
1192         .appendChild = AppendChildInFrameNode,
1193         .insertChildAfter = InsertChildAfterInFrameNode,
1194         .removeChild = RemoveChildInFrameNode,
1195         .clearChildren = ClearChildrenInFrameNode,
1196         .getChildrenCount = GetChildrenCount,
1197         .getChild = GetChild,
1198         .getFirst = GetFirst,
1199         .getNextSibling = GetNextSibling,
1200         .getPreviousSibling = GetPreviousSibling,
1201         .getParent = GetParent,
1202         .getIdByNodePtr = GetIdByNodePtr,
1203         .propertyUpdate = PropertyUpdate,
1204         .getLast = GetLast,
1205         .getPositionToParent = GetPositionToParent,
1206         .getPositionToScreen = GetPositionToScreen,
1207         .getPositionToWindow = GetPositionToWindow,
1208         .getGlobalPositionOnDisplay = GetGlobalPositionOnDisplay,
1209         .getPositionToParentWithTransform = GetPositionToParentWithTransform,
1210         .getPositionToScreenWithTransform = GetPositionToScreenWithTransform,
1211         .getPositionToWindowWithTransform = GetPositionToWindowWithTransform,
1212         .getMeasuredSize = GetMeasuredSize,
1213         .getLayoutPosition = GetLayoutPosition,
1214         .getInspectorId = GetInspectorId,
1215         .getNodeType = GetNodeType,
1216         .isVisible = IsVisible,
1217         .isAttached = IsAttached,
1218         .getInspectorInfo = GetInspectorInfo,
1219         .getFrameNodeById = GetFrameNodeById,
1220         .getFrameNodeByUniqueId = GetFrameNodeByUniqueId,
1221         .getFrameNodeByKey = GetFrameNodeByKey,
1222         .getFirstUINode = GetFirstUINode,
1223         .getLayoutSize = GetLayoutSize,
1224         .getLayoutPositionWithoutMargin = GetLayoutPositionWithoutMargin,
1225     };
1226     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
1227     return &modifier;
1228 }
1229 } // namespace NodeModifier
1230 } // namespace OHOS::Ace::NG
1231