1 /*
2 * Copyright (c) 2023 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 "core/interfaces/native/node/node_api.h"
17
18 #include <deque>
19 #include <securec.h>
20
21 #include "base/error/error_code.h"
22 #include "base/log/ace_trace.h"
23 #include "base/log/log_wrapper.h"
24 #include "base/utils/macros.h"
25 #include "base/utils/utils.h"
26 #include "core/common/container.h"
27 #include "core/components_ng/base/frame_node.h"
28 #include "core/components_ng/base/observer_handler.h"
29 #include "core/components_ng/base/view_stack_processor.h"
30 #include "core/components_ng/base/ui_node.h"
31 #include "core/components_ng/base/view_stack_processor.h"
32 #include "core/components_ng/pattern/navigation/navigation_stack.h"
33 #include "core/interfaces/arkoala/arkoala_api.h"
34 #include "core/interfaces/native/node/alphabet_indexer_modifier.h"
35 #include "core/interfaces/native/node/calendar_picker_modifier.h"
36 #include "core/interfaces/native/node/canvas_rendering_context_2d_modifier.h"
37 #include "core/interfaces/native/node/custom_dialog_model.h"
38 #include "core/interfaces/native/node/drag_adapter_impl.h"
39 #include "core/interfaces/native/node/grid_modifier.h"
40 #include "core/interfaces/native/node/image_animator_modifier.h"
41 #include "core/interfaces/native/node/node_adapter_impl.h"
42 #include "core/interfaces/native/node/node_animate.h"
43 #include "core/interfaces/native/node/node_canvas_modifier.h"
44 #include "core/interfaces/native/node/node_checkbox_modifier.h"
45 #include "core/interfaces/native/node/node_common_modifier.h"
46 #include "core/interfaces/native/node/node_drag_modifier.h"
47 #include "core/interfaces/native/node/node_date_picker_modifier.h"
48 #include "core/interfaces/native/node/node_image_modifier.h"
49 #include "core/interfaces/native/node/node_list_item_modifier.h"
50 #include "core/interfaces/native/node/node_list_modifier.h"
51 #include "core/interfaces/native/node/node_refresh_modifier.h"
52 #include "core/interfaces/native/node/node_scroll_modifier.h"
53 #include "core/interfaces/native/node/node_slider_modifier.h"
54 #include "core/interfaces/native/node/node_swiper_modifier.h"
55 #include "core/interfaces/native/node/node_span_modifier.h"
56 #include "core/interfaces/native/node/node_text_area_modifier.h"
57 #include "core/interfaces/native/node/node_text_input_modifier.h"
58 #include "core/interfaces/native/node/node_text_modifier.h"
59 #include "core/interfaces/native/node/node_textpicker_modifier.h"
60 #include "core/interfaces/native/node/node_timepicker_modifier.h"
61 #include "core/interfaces/native/node/node_toggle_modifier.h"
62 #include "core/interfaces/native/node/radio_modifier.h"
63 #include "core/interfaces/native/node/search_modifier.h"
64 #include "core/interfaces/native/node/select_modifier.h"
65 #include "core/interfaces/native/node/util_modifier.h"
66 #include "core/interfaces/native/node/view_model.h"
67 #include "core/interfaces/native/node/water_flow_modifier.h"
68 #include "core/pipeline_ng/pipeline_context.h"
69
70 namespace OHOS::Ace::NG {
71 namespace {
72 constexpr int32_t INVLID_VALUE = -1;
73
WriteStringToBuffer(const std::string & src,char * buffer,int32_t bufferSize,int32_t * writeLen)74 int32_t WriteStringToBuffer(const std::string& src, char* buffer, int32_t bufferSize, int32_t* writeLen)
75 {
76 CHECK_NULL_RETURN(buffer, ERROR_CODE_PARAM_INVALID);
77 CHECK_NULL_RETURN(writeLen, ERROR_CODE_PARAM_INVALID);
78 if (src.empty()) {
79 return ERROR_CODE_NO_ERROR;
80 }
81 int32_t srcLength = static_cast<int32_t>(src.length());
82 if (bufferSize - 1 < srcLength) {
83 *writeLen = srcLength == INT32_MAX ? INT32_MAX : srcLength + 1;
84 return ERROR_CODE_NATIVE_IMPL_BUFFER_SIZE_ERROR;
85 }
86 src.copy(buffer, srcLength);
87 buffer[srcLength] = '\0';
88 *writeLen = srcLength;
89 return ERROR_CODE_NO_ERROR;
90 }
91
GetNavDestinationInfoByNode(ArkUINodeHandle node)92 std::shared_ptr<NavDestinationInfo> GetNavDestinationInfoByNode(ArkUINodeHandle node)
93 {
94 FrameNode* currentNode = reinterpret_cast<FrameNode*>(node);
95 CHECK_NULL_RETURN(currentNode, nullptr);
96 return NG::UIObserverHandler::GetInstance().GetNavigationState(Ace::AceType::Claim<FrameNode>(currentNode));
97 }
98
GetRouterPageInfoByNode(ArkUINodeHandle node)99 std::shared_ptr<RouterPageInfoNG> GetRouterPageInfoByNode(ArkUINodeHandle node)
100 {
101 FrameNode* currentNode = reinterpret_cast<FrameNode*>(node);
102 CHECK_NULL_RETURN(currentNode, nullptr);
103 return NG::UIObserverHandler::GetInstance().GetRouterPageState(Ace::AceType::Claim<FrameNode>(currentNode));
104 }
105
GetNavigationStackByNode(ArkUINodeHandle node)106 RefPtr<NavigationStack> GetNavigationStackByNode(ArkUINodeHandle node)
107 {
108 FrameNode* currentNode = reinterpret_cast<FrameNode*>(node);
109 CHECK_NULL_RETURN(currentNode, nullptr);
110 auto pipeline = currentNode->GetContext();
111 CHECK_NULL_RETURN(pipeline, nullptr);
112 auto navigationMgr = pipeline->GetNavigationManager();
113 CHECK_NULL_RETURN(navigationMgr, nullptr);
114 auto result = navigationMgr->GetNavigationInfo(Ace::AceType::Claim<FrameNode>(currentNode));
115 CHECK_NULL_RETURN(result, nullptr);
116 return result->pathStack.Upgrade();
117 }
118 } // namespace
119
GetUIState(ArkUINodeHandle node)120 ArkUI_Int64 GetUIState(ArkUINodeHandle node)
121 {
122 auto* frameNode = reinterpret_cast<FrameNode*>(node);
123 CHECK_NULL_RETURN(frameNode, 0);
124 auto eventHub = frameNode->GetEventHub<EventHub>();
125 CHECK_NULL_RETURN(eventHub, 0);
126 return eventHub->GetCurrentUIState();
127 }
128
SetSupportedUIState(ArkUINodeHandle node,ArkUI_Int64 state)129 void SetSupportedUIState(ArkUINodeHandle node, ArkUI_Int64 state)
130 {
131 auto* frameNode = reinterpret_cast<FrameNode*>(node);
132 CHECK_NULL_VOID(frameNode);
133 auto eventHub = frameNode->GetEventHub<EventHub>();
134 CHECK_NULL_VOID(eventHub);
135 eventHub->AddSupportedState(static_cast<uint64_t>(state));
136 }
137
138 namespace NodeModifier {
GetUIStateModifier()139 const ArkUIStateModifier* GetUIStateModifier()
140 {
141 static const ArkUIStateModifier modifier = { GetUIState, SetSupportedUIState };
142 return &modifier;
143 }
144
GetCJUIStateModifier()145 const CJUIStateModifier* GetCJUIStateModifier()
146 {
147 static const CJUIStateModifier modifier = {
148 GetUIState,
149 SetSupportedUIState
150 };
151 return &modifier;
152 }
153 } // namespace NodeModifier
154
155 namespace NodeEvent {
156 std::deque<ArkUINodeEvent> g_eventQueue;
CheckEvent(ArkUINodeEvent * event)157 int CheckEvent(ArkUINodeEvent* event)
158 {
159 if (!g_eventQueue.empty()) {
160 *event = g_eventQueue.front();
161 g_eventQueue.pop_front();
162 return 1;
163 }
164 return 0;
165 }
166
167 static EventReceiver globalEventReceiver = nullptr;
168
SendArkUIAsyncEvent(ArkUINodeEvent * event)169 void SendArkUIAsyncEvent(ArkUINodeEvent* event)
170 {
171 if (globalEventReceiver) {
172 globalEventReceiver(event);
173 } else {
174 g_eventQueue.push_back(*event);
175 }
176 }
177 } // namespace NodeEvent
178
179 namespace CustomNodeEvent {
180 std::deque<ArkUICustomNodeEvent> g_eventQueue;
CheckEvent(ArkUICustomNodeEvent * event)181 int CheckEvent(ArkUICustomNodeEvent* event)
182 {
183 if (!g_eventQueue.empty()) {
184 *event = g_eventQueue.front();
185 g_eventQueue.pop_front();
186 return 1;
187 }
188 return 0;
189 }
190
191 void (*g_fliter)(ArkUICustomNodeEvent* event) = nullptr;
SendArkUIAsyncEvent(ArkUICustomNodeEvent * event)192 void SendArkUIAsyncEvent(ArkUICustomNodeEvent* event)
193 {
194 if (g_fliter) {
195 g_fliter(event);
196 } else {
197 g_eventQueue.push_back(*event);
198 }
199 }
200 } // namespace CustomNodeEvent
201
202 namespace {
203
SetCustomCallback(ArkUIVMContext context,ArkUINodeHandle node,ArkUI_Int32 callback)204 void SetCustomCallback(ArkUIVMContext context, ArkUINodeHandle node, ArkUI_Int32 callback)
205 {
206 ViewModel::SetCustomCallback(context, node, callback);
207 }
208
CreateNode(ArkUINodeType type,int peerId,ArkUI_Int32 flags)209 ArkUINodeHandle CreateNode(ArkUINodeType type, int peerId, ArkUI_Int32 flags)
210 {
211 ArkUINodeHandle node = nullptr;
212 if (flags == ARKUI_NODE_FLAG_C) {
213 ContainerScope Scope(Container::CurrentIdSafelyWithCheck());
214 node = reinterpret_cast<ArkUINodeHandle>(ViewModel::CreateNode(type, peerId));
215 auto* uiNode = reinterpret_cast<UINode*>(node);
216 if (uiNode) {
217 uiNode->setIsCNode(true);
218 }
219 } else {
220 node = reinterpret_cast<ArkUINodeHandle>(ViewModel::CreateNode(type, peerId));
221 }
222 return node;
223 }
224
CreateNodeWithParams(ArkUINodeType type,int peerId,ArkUI_Int32 flags,const ArkUI_Params & params)225 ArkUINodeHandle CreateNodeWithParams(ArkUINodeType type, int peerId, ArkUI_Int32 flags, const ArkUI_Params& params)
226 {
227 auto* node = reinterpret_cast<ArkUINodeHandle>(ViewModel::CreateNodeWithParams(type, peerId, params));
228 return node;
229 }
230
GetNodeByViewStack()231 ArkUINodeHandle GetNodeByViewStack()
232 {
233 auto node = ViewStackProcessor::GetInstance()->Finish();
234 node->IncRefCount();
235 return reinterpret_cast<ArkUINodeHandle>(AceType::RawPtr(node));
236 }
237
DisposeNode(ArkUINodeHandle node)238 void DisposeNode(ArkUINodeHandle node)
239 {
240 ViewModel::DisposeNode(node);
241 }
242
GetName(ArkUINodeHandle node)243 ArkUI_CharPtr GetName(ArkUINodeHandle node)
244 {
245 return ViewModel::GetName(node);
246 }
247
DumpTree(ArkUINodeHandle node,int indent)248 static void DumpTree(ArkUINodeHandle node, int indent)
249 {
250 TAG_LOGI(AceLogTag::ACE_NATIVE_NODE, "dumpTree %{public}p", node);
251 }
252
DumpTreeNode(ArkUINodeHandle node)253 void DumpTreeNode(ArkUINodeHandle node)
254 {
255 DumpTree(node, 0);
256 }
257
AddChild(ArkUINodeHandle parent,ArkUINodeHandle child)258 ArkUI_Int32 AddChild(ArkUINodeHandle parent, ArkUINodeHandle child)
259 {
260 auto* nodeAdapter = NodeAdapter::GetNodeAdapterAPI()->getNodeAdapter(parent);
261 if (nodeAdapter) {
262 return ERROR_CODE_NATIVE_IMPL_NODE_ADAPTER_EXIST;
263 }
264 ViewModel::AddChild(parent, child);
265 return ERROR_CODE_NO_ERROR;
266 }
267
InsertChildAt(ArkUINodeHandle parent,ArkUINodeHandle child,int32_t position)268 ArkUI_Int32 InsertChildAt(ArkUINodeHandle parent, ArkUINodeHandle child, int32_t position)
269 {
270 auto* nodeAdapter = NodeAdapter::GetNodeAdapterAPI()->getNodeAdapter(parent);
271 if (nodeAdapter) {
272 return ERROR_CODE_NATIVE_IMPL_NODE_ADAPTER_EXIST;
273 }
274 ViewModel::InsertChildAt(parent, child, position);
275 return ERROR_CODE_NO_ERROR;
276 }
277
RemoveChild(ArkUINodeHandle parent,ArkUINodeHandle child)278 void RemoveChild(ArkUINodeHandle parent, ArkUINodeHandle child)
279 {
280 ViewModel::RemoveChild(parent, child);
281 }
282
InsertChildAfter(ArkUINodeHandle parent,ArkUINodeHandle child,ArkUINodeHandle sibling)283 ArkUI_Int32 InsertChildAfter(ArkUINodeHandle parent, ArkUINodeHandle child, ArkUINodeHandle sibling)
284 {
285 auto* nodeAdapter = NodeAdapter::GetNodeAdapterAPI()->getNodeAdapter(parent);
286 if (nodeAdapter) {
287 return ERROR_CODE_NATIVE_IMPL_NODE_ADAPTER_EXIST;
288 }
289 ViewModel::InsertChildAfter(parent, child, sibling);
290 return ERROR_CODE_NO_ERROR;
291 }
292
IsBuilderNode(ArkUINodeHandle node)293 ArkUI_Bool IsBuilderNode(ArkUINodeHandle node)
294 {
295 return ViewModel::IsBuilderNode(node);
296 }
297
ConvertLengthMetricsUnit(ArkUI_Float64 value,ArkUI_Int32 originUnit,ArkUI_Int32 targetUnit)298 ArkUI_Float64 ConvertLengthMetricsUnit(ArkUI_Float64 value, ArkUI_Int32 originUnit, ArkUI_Int32 targetUnit)
299 {
300 Dimension lengthMetric(value, static_cast<DimensionUnit>(originUnit));
301 return lengthMetric.GetNativeValue(static_cast<DimensionUnit>(targetUnit));
302 }
303
InsertChildBefore(ArkUINodeHandle parent,ArkUINodeHandle child,ArkUINodeHandle sibling)304 ArkUI_Int32 InsertChildBefore(ArkUINodeHandle parent, ArkUINodeHandle child, ArkUINodeHandle sibling)
305 {
306 auto* nodeAdapter = NodeAdapter::GetNodeAdapterAPI()->getNodeAdapter(parent);
307 if (nodeAdapter) {
308 return ERROR_CODE_NATIVE_IMPL_NODE_ADAPTER_EXIST;
309 }
310 ViewModel::InsertChildBefore(parent, child, sibling);
311 return ERROR_CODE_NO_ERROR;
312 }
313
SetAttribute(ArkUINodeHandle node,ArkUI_CharPtr attribute,ArkUI_CharPtr value)314 void SetAttribute(ArkUINodeHandle node, ArkUI_CharPtr attribute, ArkUI_CharPtr value)
315 {
316 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "%{public}p SetAttribute %{public}s, %{public}s", node, attribute, value);
317 }
318
GetAttribute(ArkUINodeHandle node,ArkUI_CharPtr attribute)319 ArkUI_CharPtr GetAttribute(ArkUINodeHandle node, ArkUI_CharPtr attribute)
320 {
321 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "%{public}p GetAttribute %{public}s", node, attribute);
322 return "";
323 }
324
ResetAttribute(ArkUINodeHandle nodePtr,ArkUI_CharPtr attribute)325 void ResetAttribute(ArkUINodeHandle nodePtr, ArkUI_CharPtr attribute)
326 {
327 TAG_LOGI(AceLogTag::ACE_NATIVE_NODE, "Reset attribute %{public}s", attribute);
328 }
329
330 typedef void (*ComponentAsyncEventHandler)(ArkUINodeHandle node, void* extraParam);
331
332 typedef void (*ResetComponentAsyncEventHandler)(ArkUINodeHandle node);
333
334 /**
335 * IMPORTANT!!!
336 * the order of declaring the handler must be same as the in the ArkUIEventSubKind enum
337 */
338 /* clang-format off */
339 const ComponentAsyncEventHandler commonNodeAsyncEventHandlers[] = {
340 NodeModifier::SetOnAppear,
341 NodeModifier::SetOnDisappear,
342 NodeModifier::SetOnTouch,
343 NodeModifier::SetOnClick,
344 NodeModifier::SetOnHover,
345 NodeModifier::SetOnBlur,
346 nullptr,
347 NodeModifier::SetOnMouse,
348 NodeModifier::SetOnAreaChange,
349 nullptr,
350 nullptr,
351 NodeModifier::SetOnFocus,
352 NodeModifier::SetOnTouchIntercept,
353 NodeModifier::SetOnAttach,
354 NodeModifier::SetOnDetach,
355 NodeModifier::SetOnAccessibilityActions,
356 NodeModifier::SetOnDragStart,
357 NodeModifier::SetOnDragEnter,
358 NodeModifier::SetOnDragDrop,
359 NodeModifier::SetOnDragMove,
360 NodeModifier::SetOnDragLeave,
361 NodeModifier::SetOnDragEnd,
362 NodeModifier::SetOnPreDrag,
363 };
364
365 const ComponentAsyncEventHandler scrollNodeAsyncEventHandlers[] = {
366 NodeModifier::SetOnScroll,
367 NodeModifier::SetOnScrollFrameBegin,
368 NodeModifier::SetScrollOnWillScroll,
369 NodeModifier::SetScrollOnDidScroll,
370 NodeModifier::SetOnScrollStart,
371 NodeModifier::SetOnScrollStop,
372 NodeModifier::SetOnScrollEdge,
373 NodeModifier::SetOnScrollReachStart,
374 NodeModifier::SetOnScrollReachEnd,
375 };
376
377 const ComponentAsyncEventHandler TEXT_NODE_ASYNC_EVENT_HANDLERS[] = {
378 NodeModifier::SetOnDetectResultUpdate,
379 };
380
381 const ComponentAsyncEventHandler textInputNodeAsyncEventHandlers[] = {
382 NodeModifier::SetOnTextInputEditChange,
383 NodeModifier::SetTextInputOnSubmit,
384 NodeModifier::SetOnTextInputChange,
385 NodeModifier::SetOnTextInputCut,
386 NodeModifier::SetOnTextInputPaste,
387 NodeModifier::SetOnTextInputSelectionChange,
388 NodeModifier::SetOnTextInputContentSizeChange,
389 NodeModifier::SetOnTextInputInputFilterError,
390 NodeModifier::SetTextInputOnTextContentScroll,
391 NodeModifier::SetTextInputOnWillInsert,
392 NodeModifier::SetTextInputOnDidInsert,
393 NodeModifier::SetTextInputOnWillDelete,
394 NodeModifier::SetTextInputOnDidDelete,
395 };
396
397 const ComponentAsyncEventHandler textAreaNodeAsyncEventHandlers[] = {
398 NodeModifier::SetOnTextAreaEditChange,
399 nullptr,
400 NodeModifier::SetOnTextAreaChange,
401 NodeModifier::SetOnTextAreaPaste,
402 NodeModifier::SetOnTextAreaSelectionChange,
403 NodeModifier::SetTextAreaOnSubmit,
404 NodeModifier::SetOnTextAreaContentSizeChange,
405 NodeModifier::SetOnTextAreaInputFilterError,
406 NodeModifier::SetTextAreaOnTextContentScroll,
407 NodeModifier::SetTextAreaOnWillInsertValue,
408 NodeModifier::SetTextAreaOnDidInsertValue,
409 NodeModifier::SetTextAreaOnWillDeleteValue,
410 NodeModifier::SetTextAreaOnDidDeleteValue,
411 };
412
413 const ComponentAsyncEventHandler refreshNodeAsyncEventHandlers[] = {
414 NodeModifier::SetRefreshOnStateChange,
415 NodeModifier::SetOnRefreshing,
416 NodeModifier::SetRefreshOnOffsetChange,
417 NodeModifier::SetRefreshChangeEvent,
418 };
419
420 const ComponentAsyncEventHandler TOGGLE_NODE_ASYNC_EVENT_HANDLERS[] = {
421 NodeModifier::SetOnToggleChange,
422 };
423
424 const ComponentAsyncEventHandler imageNodeAsyncEventHandlers[] = {
425 NodeModifier::SetImageOnComplete,
426 NodeModifier::SetImageOnError,
427 NodeModifier::SetImageOnSvgPlayFinish,
428 NodeModifier::SetImageOnDownloadProgress,
429 };
430
431 const ComponentAsyncEventHandler DATE_PICKER_NODE_ASYNC_EVENT_HANDLERS[] = {
432 NodeModifier::SetDatePickerOnDateChange,
433 };
434
435 const ComponentAsyncEventHandler TIME_PICKER_NODE_ASYNC_EVENT_HANDLERS[] = {
436 NodeModifier::SetTimePickerOnChange,
437 };
438
439 const ComponentAsyncEventHandler TEXT_PICKER_NODE_ASYNC_EVENT_HANDLERS[] = {
440 NodeModifier::SetTextPickerOnChange,
441 };
442
443 const ComponentAsyncEventHandler CALENDAR_PICKER_NODE_ASYNC_EVENT_HANDLERS[] = {
444 NodeModifier::SetCalendarPickerOnChange,
445 };
446
447 const ComponentAsyncEventHandler CHECKBOX_NODE_ASYNC_EVENT_HANDLERS[] = {
448 NodeModifier::SetCheckboxChange,
449 };
450
451 const ComponentAsyncEventHandler SLIDER_NODE_ASYNC_EVENT_HANDLERS[] = {
452 NodeModifier::SetSliderChange,
453 };
454
455 const ComponentAsyncEventHandler SWIPER_NODE_ASYNC_EVENT_HANDLERS[] = {
456 NodeModifier::SetSwiperChange,
457 NodeModifier::SetSwiperAnimationStart,
458 NodeModifier::SetSwiperAnimationEnd,
459 NodeModifier::SetSwiperGestureSwipe,
460 NodeModifier::SetSwiperOnContentDidScroll,
461 };
462
463 const ComponentAsyncEventHandler CANVAS_NODE_ASYNC_EVENT_HANDLERS[] = {
464 NodeModifier::SetCanvasOnReady,
465 };
466
467 const ComponentAsyncEventHandler listNodeAsyncEventHandlers[] = {
468 NodeModifier::SetOnListScroll,
469 NodeModifier::SetOnListScrollIndex,
470 NodeModifier::SetOnListScrollStart,
471 NodeModifier::SetOnListScrollStop,
472 NodeModifier::SetOnListScrollFrameBegin,
473 NodeModifier::SetOnListWillScroll,
474 NodeModifier::SetOnListDidScroll,
475 NodeModifier::SetOnListReachStart,
476 NodeModifier::SetOnListReachEnd,
477 };
478
479 const ComponentAsyncEventHandler LIST_ITEM_NODE_ASYNC_EVENT_HANDLERS[] = {
480 NodeModifier::SetListItemOnSelect,
481 };
482
483 const ComponentAsyncEventHandler WATER_FLOW_NODE_ASYNC_EVENT_HANDLERS[] = {
484 NodeModifier::SetOnWillScroll,
485 NodeModifier::SetOnWaterFlowReachEnd,
486 NodeModifier::SetOnDidScroll,
487 NodeModifier::SetOnWaterFlowScrollStart,
488 NodeModifier::SetOnWaterFlowScrollStop,
489 NodeModifier::SetOnWaterFlowScrollFrameBegin,
490 NodeModifier::SetOnWaterFlowScrollIndex,
491 NodeModifier::SetOnWaterFlowReachStart,
492 };
493
494 const ComponentAsyncEventHandler GRID_NODE_ASYNC_EVENT_HANDLERS[] = {
495 nullptr,
496 nullptr,
497 nullptr,
498 NodeModifier::SetOnGridScrollIndex,
499 };
500
501 const ComponentAsyncEventHandler ALPHABET_INDEXER_NODE_ASYNC_EVENT_HANDLERS[] = {
502 NodeModifier::SetOnIndexerSelected,
503 NodeModifier::SetOnIndexerRequestPopupData,
504 NodeModifier::SetOnIndexerPopupSelected,
505 NodeModifier::SetIndexerChangeEvent,
506 NodeModifier::SetIndexerCreatChangeEvent,
507 };
508
509 const ComponentAsyncEventHandler SEARCH_NODE_ASYNC_EVENT_HANDLERS[] = {
510 NodeModifier::SetOnSearchSubmit,
511 NodeModifier::SetOnSearchChange,
512 NodeModifier::SetOnSearchCopy,
513 NodeModifier::SetOnSearchCut,
514 NodeModifier::SetOnSearchPaste,
515 };
516
517 const ComponentAsyncEventHandler RADIO_NODE_ASYNC_EVENT_HANDLERS[] = {
518 NodeModifier::SetOnRadioChange,
519 };
520
521 const ComponentAsyncEventHandler SELECT_NODE_ASYNC_EVENT_HANDLERS[] = {
522 NodeModifier::SetOnSelectSelect,
523 };
524
525 const ComponentAsyncEventHandler IMAGE_ANIMATOR_NODE_ASYNC_EVENT_HANDLERS[] = {
526 NodeModifier::SetImageAnimatorOnStart,
527 NodeModifier::SetImageAnimatorOnPause,
528 NodeModifier::SetImageAnimatorOnRepeat,
529 NodeModifier::SetImageAnimatorOnCancel,
530 NodeModifier::SetImageAnimatorOnFinish,
531 };
532
533 const ResetComponentAsyncEventHandler COMMON_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
534 NodeModifier::ResetOnAppear,
535 NodeModifier::ResetOnDisappear,
536 NodeModifier::ResetOnTouch,
537 NodeModifier::ResetOnClick,
538 NodeModifier::ResetOnHover,
539 NodeModifier::ResetOnBlur,
540 nullptr,
541 NodeModifier::ResetOnMouse,
542 NodeModifier::ResetOnAreaChange,
543 NodeModifier::ResetOnVisibleAreaChange,
544 nullptr,
545 NodeModifier::ResetOnFocus,
546 NodeModifier::ResetOnTouchIntercept,
547 NodeModifier::ResetOnAttach,
548 NodeModifier::ResetOnDetach,
549 nullptr,
550 };
551
552 const ResetComponentAsyncEventHandler SCROLL_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
553 NodeModifier::ResetOnScroll,
554 NodeModifier::ResetOnScrollFrameBegin,
555 NodeModifier::ResetScrollOnWillScroll,
556 NodeModifier::ResetScrollOnDidScroll,
557 NodeModifier::ResetOnScrollStart,
558 NodeModifier::ResetOnScrollStop,
559 NodeModifier::ResetOnScrollEdge,
560 NodeModifier::ResetOnScrollReachStart,
561 NodeModifier::ResetOnScrollReachEnd,
562 };
563
564 const ResetComponentAsyncEventHandler TEXT_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
565 NodeModifier::ResetOnDetectResultUpdate,
566 };
567
568 const ResetComponentAsyncEventHandler TEXT_INPUT_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
569 NodeModifier::ResetOnTextInputEditChange,
570 NodeModifier::ResetTextInputOnSubmit,
571 NodeModifier::ResetOnTextInputChange,
572 NodeModifier::ResetOnTextInputCut,
573 NodeModifier::ResetOnTextInputPaste,
574 NodeModifier::ResetOnTextInputSelectionChange,
575 NodeModifier::ResetOnTextInputContentSizeChange,
576 NodeModifier::ResetOnTextInputInputFilterError,
577 NodeModifier::ResetTextInputOnTextContentScroll,
578 };
579
580 const ResetComponentAsyncEventHandler TEXT_AREA_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
581 NodeModifier::ResetOnTextAreaEditChange,
582 nullptr,
583 NodeModifier::ResetOnTextAreaChange,
584 NodeModifier::ResetOnTextAreaPaste,
585 NodeModifier::ResetOnTextAreaSelectionChange,
586 NodeModifier::ResetTextAreaOnSubmit,
587 NodeModifier::ResetOnTextAreaContentSizeChange,
588 NodeModifier::ResetOnTextAreaInputFilterError,
589 NodeModifier::ResetTextAreaOnTextContentScroll,
590 };
591
592 const ResetComponentAsyncEventHandler REFRESH_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
593 NodeModifier::ResetRefreshOnStateChange,
594 NodeModifier::ResetOnRefreshing,
595 NodeModifier::ResetRefreshOnOffsetChange,
596 NodeModifier::ResetRefreshChangeEvent,
597 };
598
599 const ResetComponentAsyncEventHandler TOGGLE_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
600 NodeModifier::ResetOnToggleChange,
601 };
602
603 const ResetComponentAsyncEventHandler IMAGE_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
604 NodeModifier::ResetImageOnComplete,
605 NodeModifier::ResetImageOnError,
606 NodeModifier::ResetImageOnSvgPlayFinish,
607 NodeModifier::ResetImageOnDownloadProgress,
608 };
609
610 const ResetComponentAsyncEventHandler DATE_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
611 nullptr,
612 };
613
614 const ResetComponentAsyncEventHandler TIME_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
615 nullptr,
616 };
617
618 const ResetComponentAsyncEventHandler TEXT_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
619 nullptr,
620 };
621
622 const ResetComponentAsyncEventHandler CALENDAR_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
623 nullptr,
624 };
625
626 const ResetComponentAsyncEventHandler CHECKBOX_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
627 nullptr,
628 };
629
630 const ResetComponentAsyncEventHandler SLIDER_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
631 nullptr,
632 };
633
634 const ResetComponentAsyncEventHandler SWIPER_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
635 nullptr,
636 nullptr,
637 nullptr,
638 nullptr,
639 nullptr,
640 };
641
642 const ResetComponentAsyncEventHandler CANVAS_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
643 nullptr,
644 };
645
646 const ResetComponentAsyncEventHandler LIST_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
647 NodeModifier::ResetOnListScroll,
648 NodeModifier::ResetOnListScrollIndex,
649 NodeModifier::ResetOnListScrollStart,
650 NodeModifier::ResetOnListScrollStop,
651 NodeModifier::ResetOnListScrollFrameBegin,
652 NodeModifier::ResetOnListWillScroll,
653 NodeModifier::ResetOnListDidScroll,
654 NodeModifier::ResetOnListReachStart,
655 NodeModifier::ResetOnListReachEnd,
656 };
657
658 const ResetComponentAsyncEventHandler LIST_ITEM_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
659 NodeModifier::ResetListItemOnSelect,
660 };
661
662 const ResetComponentAsyncEventHandler WATERFLOW_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
663 NodeModifier::ResetOnWillScroll,
664 NodeModifier::ResetOnWaterFlowReachEnd,
665 NodeModifier::ResetOnDidScroll,
666 NodeModifier::ResetOnWaterFlowScrollStart,
667 NodeModifier::ResetOnWaterFlowScrollStop,
668 NodeModifier::ResetOnWaterFlowScrollFrameBegin,
669 NodeModifier::ResetOnWaterFlowScrollIndex,
670 NodeModifier::ResetOnWaterFlowReachStart,
671 };
672
673 const ResetComponentAsyncEventHandler GRID_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
674 nullptr,
675 nullptr,
676 nullptr,
677 NodeModifier::ResetOnGridScrollIndex,
678 };
679
680 const ResetComponentAsyncEventHandler ALPHABET_INDEXER_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
681 nullptr,
682 nullptr,
683 nullptr,
684 nullptr,
685 nullptr,
686 };
687
688 const ResetComponentAsyncEventHandler SEARCH_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
689 nullptr,
690 nullptr,
691 nullptr,
692 nullptr,
693 nullptr,
694 };
695
696 const ResetComponentAsyncEventHandler RADIO_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
697 nullptr,
698 };
699
700 const ResetComponentAsyncEventHandler SELECT_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
701 nullptr,
702 };
703
704 const ResetComponentAsyncEventHandler IMAGE_ANIMATOR_NODE_RESET_ASYNC_EVENT_HANDLERS[] = {
705 NodeModifier::ResetImageAnimatorOnStart,
706 NodeModifier::ResetImageAnimatorOnPause,
707 NodeModifier::ResetImageAnimatorOnRepeat,
708 NodeModifier::ResetImageAnimatorOnCancel,
709 NodeModifier::ResetImageAnimatorOnFinish,
710 };
711
712 /* clang-format on */
NotifyComponentAsyncEvent(ArkUINodeHandle node,ArkUIEventSubKind kind,ArkUI_Int64 extraParam)713 void NotifyComponentAsyncEvent(ArkUINodeHandle node, ArkUIEventSubKind kind, ArkUI_Int64 extraParam)
714 {
715 unsigned int subClassType = kind / ARKUI_MAX_EVENT_NUM;
716 unsigned int subKind = kind % ARKUI_MAX_EVENT_NUM;
717 ComponentAsyncEventHandler eventHandle = nullptr;
718 switch (subClassType) {
719 case 0: {
720 // common event type.
721 if (subKind >= sizeof(commonNodeAsyncEventHandlers) / sizeof(ComponentAsyncEventHandler)) {
722 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
723 return;
724 }
725 eventHandle = commonNodeAsyncEventHandlers[subKind];
726 break;
727 }
728 case ARKUI_IMAGE: {
729 if (subKind >= sizeof(imageNodeAsyncEventHandlers) / sizeof(ComponentAsyncEventHandler)) {
730 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
731 return;
732 }
733 eventHandle = imageNodeAsyncEventHandlers[subKind];
734 break;
735 }
736 case ARKUI_SCROLL: {
737 // scroll event type.
738 if (subKind >= sizeof(scrollNodeAsyncEventHandlers) / sizeof(ComponentAsyncEventHandler)) {
739 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
740 return;
741 }
742 eventHandle = scrollNodeAsyncEventHandlers[subKind];
743 break;
744 }
745 case ARKUI_TEXT: {
746 // text event type.
747 if (subKind >= sizeof(TEXT_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
748 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
749 return;
750 }
751 eventHandle = TEXT_NODE_ASYNC_EVENT_HANDLERS[subKind];
752 break;
753 }
754 case ARKUI_TEXT_INPUT: {
755 // text input event type.
756 if (subKind >= sizeof(textInputNodeAsyncEventHandlers) / sizeof(ComponentAsyncEventHandler)) {
757 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
758 return;
759 }
760 eventHandle = textInputNodeAsyncEventHandlers[subKind];
761 break;
762 }
763 case ARKUI_TEXTAREA: {
764 // textarea event type.
765 if (subKind >= sizeof(textAreaNodeAsyncEventHandlers) / sizeof(ComponentAsyncEventHandler)) {
766 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
767 return;
768 }
769 eventHandle = textAreaNodeAsyncEventHandlers[subKind];
770 break;
771 }
772 case ARKUI_REFRESH: {
773 // refresh event type.
774 if (subKind >= sizeof(refreshNodeAsyncEventHandlers) / sizeof(ComponentAsyncEventHandler)) {
775 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
776 return;
777 }
778 eventHandle = refreshNodeAsyncEventHandlers[subKind];
779 break;
780 }
781 case ARKUI_TOGGLE: {
782 // toggle event type.
783 if (subKind >= sizeof(TOGGLE_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
784 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
785 return;
786 }
787 eventHandle = TOGGLE_NODE_ASYNC_EVENT_HANDLERS[subKind];
788 break;
789 }
790 case ARKUI_DATE_PICKER: {
791 // datepicker event type.
792 if (subKind >= sizeof(DATE_PICKER_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
793 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
794 return;
795 }
796 eventHandle = DATE_PICKER_NODE_ASYNC_EVENT_HANDLERS[subKind];
797 break;
798 }
799 case ARKUI_TIME_PICKER: {
800 // timepicker event type.
801 if (subKind >= sizeof(TIME_PICKER_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
802 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
803 return;
804 }
805 eventHandle = TIME_PICKER_NODE_ASYNC_EVENT_HANDLERS[subKind];
806 break;
807 }
808 case ARKUI_TEXT_PICKER: {
809 if (subKind >= sizeof(TEXT_PICKER_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
810 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
811 return;
812 }
813 eventHandle = TEXT_PICKER_NODE_ASYNC_EVENT_HANDLERS[subKind];
814 break;
815 }
816 case ARKUI_CALENDAR_PICKER: {
817 // calendar picker event type.
818 if (subKind >= sizeof(CALENDAR_PICKER_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
819 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
820 return;
821 }
822 eventHandle = CALENDAR_PICKER_NODE_ASYNC_EVENT_HANDLERS[subKind];
823 break;
824 }
825 case ARKUI_CHECKBOX: {
826 // timepicker event type.
827 if (subKind >= sizeof(CHECKBOX_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
828 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
829 return;
830 }
831 eventHandle = CHECKBOX_NODE_ASYNC_EVENT_HANDLERS[subKind];
832 break;
833 }
834 case ARKUI_SLIDER: {
835 // timepicker event type.
836 if (subKind >= sizeof(SLIDER_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
837 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
838 return;
839 }
840 eventHandle = SLIDER_NODE_ASYNC_EVENT_HANDLERS[subKind];
841 break;
842 }
843 case ARKUI_SWIPER: {
844 // swiper event type.
845 if (subKind >= sizeof(SWIPER_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
846 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
847 return;
848 }
849 eventHandle = SWIPER_NODE_ASYNC_EVENT_HANDLERS[subKind];
850 break;
851 }
852 case ARKUI_CANVAS: {
853 if (subKind >= sizeof(CANVAS_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
854 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
855 return;
856 }
857 eventHandle = CANVAS_NODE_ASYNC_EVENT_HANDLERS[subKind];
858 break;
859 }
860 case ARKUI_LIST: {
861 // list event type.
862 if (subKind >= sizeof(listNodeAsyncEventHandlers) / sizeof(ComponentAsyncEventHandler)) {
863 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
864 return;
865 }
866 eventHandle = listNodeAsyncEventHandlers[subKind];
867 break;
868 }
869 case ARKUI_LIST_ITEM: {
870 // list item event type.
871 if (subKind >= sizeof(LIST_ITEM_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
872 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
873 return;
874 }
875 eventHandle = LIST_ITEM_NODE_ASYNC_EVENT_HANDLERS[subKind];
876 break;
877 }
878 case ARKUI_WATER_FLOW: {
879 // swiper event type.
880 if (subKind >= sizeof(WATER_FLOW_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
881 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
882 return;
883 }
884 eventHandle = WATER_FLOW_NODE_ASYNC_EVENT_HANDLERS[subKind];
885 break;
886 }
887 case ARKUI_GRID: {
888 // grid event type.
889 if (subKind >= sizeof(GRID_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
890 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
891 return;
892 }
893 eventHandle = GRID_NODE_ASYNC_EVENT_HANDLERS[subKind];
894 break;
895 }
896 case ARKUI_ALPHABET_INDEXER: {
897 // alphabet indexer event type.
898 if (subKind >= sizeof(ALPHABET_INDEXER_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
899 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
900 return;
901 }
902 eventHandle = ALPHABET_INDEXER_NODE_ASYNC_EVENT_HANDLERS[subKind];
903 break;
904 }
905 case ARKUI_SEARCH: {
906 // search event type.
907 if (subKind >= sizeof(SEARCH_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
908 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
909 return;
910 }
911 eventHandle = SEARCH_NODE_ASYNC_EVENT_HANDLERS[subKind];
912 break;
913 }
914 case ARKUI_RADIO: {
915 // search event type.
916 if (subKind >= sizeof(RADIO_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
917 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
918 return;
919 }
920 eventHandle = RADIO_NODE_ASYNC_EVENT_HANDLERS[subKind];
921 break;
922 }
923 case ARKUI_SELECT: {
924 // select event type.
925 if (subKind >= sizeof(SELECT_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
926 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
927 return;
928 }
929 eventHandle = SELECT_NODE_ASYNC_EVENT_HANDLERS[subKind];
930 break;
931 }
932 case ARKUI_IMAGE_ANIMATOR: {
933 // imageAnimator event type.
934 if (subKind >= sizeof(IMAGE_ANIMATOR_NODE_ASYNC_EVENT_HANDLERS) / sizeof(ComponentAsyncEventHandler)) {
935 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
936 return;
937 }
938 eventHandle = IMAGE_ANIMATOR_NODE_ASYNC_EVENT_HANDLERS[subKind];
939 break;
940 }
941 default: {
942 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
943 }
944 }
945 if (eventHandle) {
946 // TODO: fix handlers.
947 eventHandle(node, reinterpret_cast<void*>(static_cast<intptr_t>(extraParam)));
948 } else {
949 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyComponentAsyncEvent kind:%{public}d EMPTY IMPLEMENT", kind);
950 }
951 }
952
NotifyResetComponentAsyncEvent(ArkUINodeHandle node,ArkUIEventSubKind kind)953 void NotifyResetComponentAsyncEvent(ArkUINodeHandle node, ArkUIEventSubKind kind)
954 {
955 unsigned int subClassType = kind / ARKUI_MAX_EVENT_NUM;
956 unsigned int subKind = kind % ARKUI_MAX_EVENT_NUM;
957 ResetComponentAsyncEventHandler eventHandle = nullptr;
958 switch (subClassType) {
959 case 0: {
960 // common event type.
961 if (subKind >= sizeof(COMMON_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
962 TAG_LOGE(
963 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
964 return;
965 }
966 eventHandle = COMMON_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
967 break;
968 }
969 case ARKUI_IMAGE: {
970 if (subKind >= sizeof(IMAGE_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
971 TAG_LOGE(
972 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
973 return;
974 }
975 eventHandle = IMAGE_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
976 break;
977 }
978 case ARKUI_SCROLL: {
979 // scroll event type.
980 if (subKind >= sizeof(SCROLL_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
981 TAG_LOGE(
982 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
983 return;
984 }
985 eventHandle = SCROLL_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
986 break;
987 }
988 case ARKUI_TEXT: {
989 // text event type.
990 if (subKind >= sizeof(TEXT_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
991 TAG_LOGE(
992 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
993 return;
994 }
995 eventHandle = TEXT_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
996 break;
997 }
998 case ARKUI_TEXT_INPUT: {
999 // text input event type.
1000 if (subKind >=
1001 sizeof(TEXT_INPUT_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1002 TAG_LOGE(
1003 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1004 return;
1005 }
1006 eventHandle = TEXT_INPUT_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1007 break;
1008 }
1009 case ARKUI_TEXTAREA: {
1010 // textarea event type.
1011 if (subKind >=
1012 sizeof(TEXT_AREA_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1013 TAG_LOGE(
1014 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1015 return;
1016 }
1017 eventHandle = TEXT_AREA_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1018 break;
1019 }
1020 case ARKUI_REFRESH: {
1021 // refresh event type.
1022 if (subKind >= sizeof(REFRESH_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1023 TAG_LOGE(
1024 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1025 return;
1026 }
1027 eventHandle = REFRESH_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1028 break;
1029 }
1030 case ARKUI_TOGGLE: {
1031 // toggle event type.
1032 if (subKind >= sizeof(TOGGLE_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1033 TAG_LOGE(
1034 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1035 return;
1036 }
1037 eventHandle = TOGGLE_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1038 break;
1039 }
1040 case ARKUI_DATE_PICKER: {
1041 // datepicker event type.
1042 if (subKind >=
1043 sizeof(DATE_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1044 TAG_LOGE(
1045 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1046 return;
1047 }
1048 eventHandle = DATE_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1049 break;
1050 }
1051 case ARKUI_TIME_PICKER: {
1052 // timepicker event type.
1053 if (subKind >=
1054 sizeof(TIME_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1055 TAG_LOGE(
1056 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1057 return;
1058 }
1059 eventHandle = TIME_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1060 break;
1061 }
1062 case ARKUI_TEXT_PICKER: {
1063 if (subKind >=
1064 sizeof(TEXT_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1065 TAG_LOGE(
1066 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1067 return;
1068 }
1069 eventHandle = TEXT_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1070 break;
1071 }
1072 case ARKUI_CALENDAR_PICKER: {
1073 // calendar picker event type.
1074 if (subKind >= sizeof(CALENDAR_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(
1075 ResetComponentAsyncEventHandler)) {
1076 TAG_LOGE(
1077 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1078 return;
1079 }
1080 eventHandle = CALENDAR_PICKER_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1081 break;
1082 }
1083 case ARKUI_CHECKBOX: {
1084 // timepicker event type.
1085 if (subKind >= sizeof(CHECKBOX_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1086 TAG_LOGE(
1087 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1088 return;
1089 }
1090 eventHandle = CHECKBOX_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1091 break;
1092 }
1093 case ARKUI_SLIDER: {
1094 // timepicker event type.
1095 if (subKind >= sizeof(SLIDER_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1096 TAG_LOGE(
1097 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1098 return;
1099 }
1100 eventHandle = SLIDER_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1101 break;
1102 }
1103 case ARKUI_SWIPER: {
1104 // swiper event type.
1105 if (subKind >= sizeof(SWIPER_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1106 TAG_LOGE(
1107 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1108 return;
1109 }
1110 eventHandle = SWIPER_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1111 break;
1112 }
1113 case ARKUI_CANVAS: {
1114 if (subKind >= sizeof(CANVAS_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1115 TAG_LOGE(
1116 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1117 return;
1118 }
1119 eventHandle = CANVAS_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1120 break;
1121 }
1122 case ARKUI_LIST: {
1123 // list event type.
1124 if (subKind >= sizeof(LIST_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1125 TAG_LOGE(
1126 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1127 return;
1128 }
1129 eventHandle = LIST_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1130 break;
1131 }
1132 case ARKUI_LIST_ITEM: {
1133 // list item event type.
1134 if (subKind >=
1135 sizeof(LIST_ITEM_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1136 TAG_LOGE(
1137 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1138 return;
1139 }
1140 eventHandle = LIST_ITEM_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1141 break;
1142 }
1143 case ARKUI_WATER_FLOW: {
1144 // swiper event type.
1145 if (subKind >=
1146 sizeof(WATERFLOW_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1147 TAG_LOGE(
1148 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1149 return;
1150 }
1151 eventHandle = WATERFLOW_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1152 break;
1153 }
1154 case ARKUI_GRID: {
1155 // grid event type.
1156 if (subKind >= sizeof(GRID_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1157 TAG_LOGE(
1158 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1159 return;
1160 }
1161 eventHandle = GRID_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1162 break;
1163 }
1164 case ARKUI_ALPHABET_INDEXER: {
1165 // alphabet indexer event type.
1166 if (subKind >= sizeof(ALPHABET_INDEXER_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(
1167 ResetComponentAsyncEventHandler)) {
1168 TAG_LOGE(
1169 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1170 return;
1171 }
1172 eventHandle = ALPHABET_INDEXER_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1173 break;
1174 }
1175 case ARKUI_SEARCH: {
1176 // search event type.
1177 if (subKind >= sizeof(SEARCH_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1178 TAG_LOGE(
1179 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1180 return;
1181 }
1182 eventHandle = SEARCH_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1183 break;
1184 }
1185 case ARKUI_RADIO: {
1186 // search event type.
1187 if (subKind >= sizeof(RADIO_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1188 TAG_LOGE(
1189 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1190 return;
1191 }
1192 eventHandle = RADIO_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1193 break;
1194 }
1195 case ARKUI_SELECT: {
1196 // select event type.
1197 if (subKind >= sizeof(SELECT_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1198 TAG_LOGE(
1199 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1200 return;
1201 }
1202 eventHandle = SELECT_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1203 break;
1204 }
1205 case ARKUI_IMAGE_ANIMATOR: {
1206 // imageAnimator event type.
1207 if (subKind >=
1208 sizeof(IMAGE_ANIMATOR_NODE_RESET_ASYNC_EVENT_HANDLERS) / sizeof(ResetComponentAsyncEventHandler)) {
1209 TAG_LOGE(
1210 AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1211 return;
1212 }
1213 eventHandle = IMAGE_ANIMATOR_NODE_RESET_ASYNC_EVENT_HANDLERS[subKind];
1214 break;
1215 }
1216 default: {
1217 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d NOT IMPLEMENT", kind);
1218 }
1219 }
1220 if (eventHandle) {
1221 eventHandle(node);
1222 } else {
1223 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "NotifyResetComponentAsyncEvent kind:%{public}d EMPTY IMPLEMENT", kind);
1224 }
1225 }
1226
RegisterNodeAsyncEventReceiver(EventReceiver eventReceiver)1227 void RegisterNodeAsyncEventReceiver(EventReceiver eventReceiver)
1228 {
1229 NodeEvent::globalEventReceiver = eventReceiver;
1230 }
1231
UnregisterNodeAsyncEventReceiver()1232 void UnregisterNodeAsyncEventReceiver()
1233 {
1234 NodeEvent::globalEventReceiver = nullptr;
1235 }
1236
ApplyModifierFinish(ArkUINodeHandle nodePtr)1237 void ApplyModifierFinish(ArkUINodeHandle nodePtr)
1238 {
1239 auto* uiNode = reinterpret_cast<UINode*>(nodePtr);
1240 auto* frameNode = AceType::DynamicCast<FrameNode>(uiNode);
1241 if (frameNode) {
1242 frameNode->MarkModifyDone();
1243 }
1244 }
1245
MarkDirty(ArkUINodeHandle nodePtr,ArkUI_Uint32 flag)1246 void MarkDirty(ArkUINodeHandle nodePtr, ArkUI_Uint32 flag)
1247 {
1248 auto* uiNode = reinterpret_cast<UINode*>(nodePtr);
1249 if (uiNode) {
1250 uiNode->MarkDirtyNode(flag);
1251 }
1252 }
1253
SetCallbackMethod(ArkUIAPICallbackMethod * method)1254 static void SetCallbackMethod(ArkUIAPICallbackMethod* method)
1255 {
1256 ViewModel::SetCallbackMethod(method);
1257 }
1258
GetArkUIAPICallbackMethod()1259 ArkUIAPICallbackMethod* GetArkUIAPICallbackMethod()
1260 {
1261 return ViewModel::GetCallbackMethod();
1262 }
1263
GetPipelineContext(ArkUINodeHandle node)1264 ArkUIPipelineContext GetPipelineContext(ArkUINodeHandle node)
1265 {
1266 auto frameNode = reinterpret_cast<FrameNode*>(node);
1267 return reinterpret_cast<ArkUIPipelineContext>(frameNode->GetContext());
1268 }
1269
SetVsyncCallback(ArkUIVMContext vmContext,ArkUIPipelineContext pipelineContext,ArkUI_Int32 callbackId)1270 void SetVsyncCallback(ArkUIVMContext vmContext, ArkUIPipelineContext pipelineContext, ArkUI_Int32 callbackId)
1271 {
1272 static int vsyncCount = 1;
1273 auto vsync = [vmContext, callbackId]() {
1274 ArkUIEventCallbackArg args[] = { {.i32 =vsyncCount++ } };
1275 ArkUIAPICallbackMethod* cbs = GetArkUIAPICallbackMethod();
1276 CHECK_NULL_VOID(vmContext);
1277 CHECK_NULL_VOID(cbs);
1278 cbs->CallInt(vmContext, callbackId, 1, &args[0]);
1279 };
1280
1281 reinterpret_cast<PipelineContext*>(pipelineContext)->SetVsyncListener(vsync);
1282 }
1283
UnblockVsyncWait(ArkUIVMContext vmContext,ArkUIPipelineContext pipelineContext)1284 void UnblockVsyncWait(ArkUIVMContext vmContext, ArkUIPipelineContext pipelineContext)
1285 {
1286 reinterpret_cast<PipelineContext*>(pipelineContext)->RequestFrame();
1287 }
1288
MeasureNode(ArkUIVMContext vmContext,ArkUINodeHandle node,ArkUI_Float32 * data)1289 ArkUI_Int32 MeasureNode(ArkUIVMContext vmContext, ArkUINodeHandle node, ArkUI_Float32* data)
1290 {
1291 return ViewModel::MeasureNode(vmContext, node, data);
1292 }
1293
LayoutNode(ArkUIVMContext vmContext,ArkUINodeHandle node,ArkUI_Float32 (* data)[2])1294 ArkUI_Int32 LayoutNode(ArkUIVMContext vmContext, ArkUINodeHandle node, ArkUI_Float32 (*data)[2])
1295 {
1296 return ViewModel::LayoutNode(vmContext, node, data);
1297 }
1298
DrawNode(ArkUIVMContext vmContext,ArkUINodeHandle node,ArkUI_Float32 * data)1299 ArkUI_Int32 DrawNode(ArkUIVMContext vmContext, ArkUINodeHandle node, ArkUI_Float32* data)
1300 {
1301 return ViewModel::DrawNode(vmContext, node, data);
1302 }
1303
SetAttachNodePtr(ArkUINodeHandle node,void * value)1304 void SetAttachNodePtr(ArkUINodeHandle node, void* value)
1305 {
1306 return ViewModel::SetAttachNodePtr(node, value);
1307 }
1308
GetAttachNodePtr(ArkUINodeHandle node)1309 void* GetAttachNodePtr(ArkUINodeHandle node)
1310 {
1311 return ViewModel::GetAttachNodePtr(node);
1312 }
1313
MeasureLayoutAndDraw(ArkUIVMContext vmContext,ArkUINodeHandle rootPtr)1314 ArkUI_Int32 MeasureLayoutAndDraw(ArkUIVMContext vmContext, ArkUINodeHandle rootPtr)
1315 {
1316 auto* root = reinterpret_cast<FrameNode*>(rootPtr);
1317 float width = root->GetGeometryNode()->GetFrameSize().Width();
1318 float height = root->GetGeometryNode()->GetFrameSize().Height();
1319 // measure
1320 ArkUI_Float32 measureData[] = { width, height, width, height, width, height };
1321 MeasureNode(vmContext, rootPtr, &measureData[0]);
1322 // layout
1323 ArkUI_Float32 layoutData[] = { 0, 0 };
1324 LayoutNode(vmContext, rootPtr, &layoutData);
1325 // draw
1326 ArkUI_Float32 drawData[] = { 0, 0, 0, 0 };
1327 DrawNode(vmContext, rootPtr, &drawData[0]);
1328
1329 return 0;
1330 }
1331
RegisterCustomNodeAsyncEvent(ArkUINodeHandle node,int32_t eventType,void * extraParam)1332 void RegisterCustomNodeAsyncEvent(ArkUINodeHandle node, int32_t eventType, void* extraParam)
1333 {
1334 auto companion = ViewModel::GetCompanion(node);
1335 if (!companion) {
1336 ViewModel::RegisterCompanion(node, -1, eventType);
1337 auto companion = ViewModel::GetCompanion(node);
1338 CHECK_NULL_VOID(companion);
1339 companion->SetExtraParam(eventType, extraParam);
1340 } else {
1341 auto originEventType = companion->GetFlags();
1342 companion->SetFlags(static_cast<uint32_t>(originEventType) | static_cast<uint32_t>(eventType));
1343 companion->SetExtraParam(eventType, extraParam);
1344 }
1345 }
1346
RegisterCustomSpanAsyncEvent(ArkUINodeHandle node,int32_t eventType,void * extraParam)1347 void RegisterCustomSpanAsyncEvent(ArkUINodeHandle node, int32_t eventType, void* extraParam)
1348 {
1349 switch (eventType) {
1350 case ArkUIAPINodeFlags::CUSTOM_MEASURE:
1351 NodeModifier::SetCustomSpanOnMeasure(node, extraParam);
1352 break;
1353 case ArkUIAPINodeFlags::CUSTOM_DRAW:
1354 NodeModifier::SetCustomSpanOnDraw(node, extraParam);
1355 break;
1356 default:
1357 break;
1358 }
1359 }
1360
UnregisterCustomNodeEvent(ArkUINodeHandle node,ArkUI_Int32 eventType)1361 ArkUI_Int32 UnregisterCustomNodeEvent(ArkUINodeHandle node, ArkUI_Int32 eventType)
1362 {
1363 auto companion = ViewModel::GetCompanion(node);
1364 CHECK_NULL_RETURN(companion, -1);
1365 auto originEventType = static_cast<uint32_t>(companion->GetFlags());
1366 //check is Contains
1367 if ((originEventType & static_cast<uint32_t>(eventType)) != static_cast<uint32_t>(eventType)) {
1368 return -1;
1369 }
1370 companion->SetFlags(static_cast<uint32_t>(originEventType) ^ static_cast<uint32_t>(eventType));
1371 companion->EraseExtraParam(eventType);
1372 return 0;
1373 }
1374
RegisterCustomNodeEventReceiver(void (* eventReceiver)(ArkUICustomNodeEvent * event))1375 void RegisterCustomNodeEventReceiver(void (*eventReceiver)(ArkUICustomNodeEvent* event))
1376 {
1377 CustomNodeEvent::g_fliter = eventReceiver;
1378 }
1379
SetMeasureWidth(ArkUINodeHandle node,ArkUI_Int32 value)1380 void SetMeasureWidth(ArkUINodeHandle node, ArkUI_Int32 value)
1381 {
1382 // directly set frameNode measure width.
1383 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1384 if (!frameNode) {
1385 return;
1386 }
1387 frameNode->GetGeometryNode()->SetFrameWidth(value);
1388 }
1389
GetMeasureWidth(ArkUINodeHandle node)1390 ArkUI_Int32 GetMeasureWidth(ArkUINodeHandle node)
1391 {
1392 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1393 if (!frameNode) {
1394 return 0;
1395 }
1396 return frameNode->GetGeometryNode()->GetFrameSize().Width();
1397 }
1398
SetMeasureHeight(ArkUINodeHandle node,ArkUI_Int32 value)1399 void SetMeasureHeight(ArkUINodeHandle node, ArkUI_Int32 value)
1400 {
1401 // directly set frameNode measure height.
1402 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1403 if (!frameNode) {
1404 return;
1405 }
1406 frameNode->GetGeometryNode()->SetFrameHeight(value);
1407 }
1408
GetMeasureHeight(ArkUINodeHandle node)1409 ArkUI_Int32 GetMeasureHeight(ArkUINodeHandle node)
1410 {
1411 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1412 if (!frameNode) {
1413 return 0;
1414 }
1415 return frameNode->GetGeometryNode()->GetFrameSize().Height();
1416 }
1417
SetX(ArkUINodeHandle node,ArkUI_Int32 value)1418 void SetX(ArkUINodeHandle node, ArkUI_Int32 value)
1419 {
1420 // directly set frameNode measure postionX.
1421 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1422 if (!frameNode) {
1423 return;
1424 }
1425 frameNode->GetGeometryNode()->SetMarginFrameOffsetX(value);
1426 }
1427
SetY(ArkUINodeHandle node,ArkUI_Int32 value)1428 void SetY(ArkUINodeHandle node, ArkUI_Int32 value)
1429 {
1430 // directly set frameNode measure postionY.
1431 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1432 if (!frameNode) {
1433 return;
1434 }
1435 frameNode->GetGeometryNode()->SetMarginFrameOffsetY(value);
1436 }
1437
GetX(ArkUINodeHandle node)1438 ArkUI_Int32 GetX(ArkUINodeHandle node)
1439 {
1440 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1441 if (!frameNode) {
1442 return 0;
1443 }
1444 return frameNode->GetGeometryNode()->GetMarginFrameOffset().GetX();
1445 }
1446
GetY(ArkUINodeHandle node)1447 ArkUI_Int32 GetY(ArkUINodeHandle node)
1448 {
1449 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1450 if (!frameNode) {
1451 return 0;
1452 }
1453 return frameNode->GetGeometryNode()->GetMarginFrameOffset().GetY();
1454 }
1455
SetCustomMethodFlag(ArkUINodeHandle node,ArkUI_Int32 flag)1456 void SetCustomMethodFlag(ArkUINodeHandle node, ArkUI_Int32 flag)
1457 {
1458 auto* companion = ViewModel::GetCompanion(node);
1459 CHECK_NULL_VOID(companion);
1460 companion->SetFlags(flag);
1461 }
1462
GetCustomMethodFlag(ArkUINodeHandle node)1463 ArkUI_Int32 GetCustomMethodFlag(ArkUINodeHandle node)
1464 {
1465 auto* companion = ViewModel::GetCompanion(node);
1466 CHECK_NULL_RETURN(companion, 0);
1467 return companion->GetFlags();
1468 }
1469
SetAlignment(ArkUINodeHandle node,ArkUI_Int32 value)1470 void SetAlignment(ArkUINodeHandle node, ArkUI_Int32 value)
1471 {
1472 auto* companion = ViewModel::GetCompanion(node);
1473 CHECK_NULL_VOID(companion);
1474 companion->SetAlignmentValue(value);
1475 }
1476
GetAlignment(ArkUINodeHandle node)1477 ArkUI_Int32 GetAlignment(ArkUINodeHandle node)
1478 {
1479 auto* companion = ViewModel::GetCompanion(node);
1480 CHECK_NULL_RETURN(companion, 0);
1481 return companion->GetAlignmentValue();
1482 }
1483
GetLayoutConstraint(ArkUINodeHandle node,ArkUI_Int32 * value)1484 void GetLayoutConstraint(ArkUINodeHandle node, ArkUI_Int32* value)
1485 {
1486 auto* frameNode = AceType::DynamicCast<FrameNode>(reinterpret_cast<UINode*>(node));
1487 CHECK_NULL_VOID(frameNode);
1488 auto layoutConstraint = frameNode->GetLayoutProperty()->GetContentLayoutConstraint();
1489 if (layoutConstraint.has_value()) {
1490 //min
1491 value[0] = static_cast<ArkUI_Int32>(layoutConstraint.value().minSize.Width());
1492 //min
1493 value[1] = static_cast<ArkUI_Int32>(layoutConstraint.value().minSize.Height());
1494 //.max
1495 value[2] = static_cast<ArkUI_Int32>(layoutConstraint.value().maxSize.Width());
1496 //.max
1497 value[3] = static_cast<ArkUI_Int32>(layoutConstraint.value().maxSize.Height());
1498 //percentReference
1499 value[4] = static_cast<ArkUI_Int32>(layoutConstraint.value().percentReference.Width());
1500 //percentReference
1501 value[5] = static_cast<ArkUI_Int32>(layoutConstraint.value().percentReference.Height());
1502 }
1503 }
1504
1505
1506
GetNavigationId(ArkUINodeHandle node,char * buffer,ArkUI_Int32 bufferSize,ArkUI_Int32 * writeLen)1507 ArkUI_Int32 GetNavigationId(
1508 ArkUINodeHandle node, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* writeLen)
1509 {
1510 auto navDesInfo = GetNavDestinationInfoByNode(node);
1511 CHECK_NULL_RETURN(navDesInfo, ERROR_CODE_NATIVE_IMPL_GET_INFO_FAILED);
1512 std::string navigationId = navDesInfo->navigationId;
1513 return WriteStringToBuffer(navigationId, buffer, bufferSize, writeLen);
1514 }
1515
GetNavDestinationName(ArkUINodeHandle node,char * buffer,ArkUI_Int32 bufferSize,ArkUI_Int32 * writeLen)1516 ArkUI_Int32 GetNavDestinationName(
1517 ArkUINodeHandle node, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* writeLen)
1518 {
1519 auto navDesInfo = GetNavDestinationInfoByNode(node);
1520 CHECK_NULL_RETURN(navDesInfo, ERROR_CODE_NATIVE_IMPL_GET_INFO_FAILED);
1521 std::string name = navDesInfo->name;
1522 return WriteStringToBuffer(name, buffer, bufferSize, writeLen);
1523 }
1524
GetStackLength(ArkUINodeHandle node)1525 ArkUI_Int32 GetStackLength(ArkUINodeHandle node)
1526 {
1527 auto navigationStack = GetNavigationStackByNode(node);
1528 CHECK_NULL_RETURN(navigationStack, INVLID_VALUE);
1529 return navigationStack->Size();
1530 }
1531
GetNavDesNameByIndex(ArkUINodeHandle node,ArkUI_Int32 index,char * buffer,ArkUI_Int32 bufferSize,ArkUI_Int32 * writeLen)1532 ArkUI_Int32 GetNavDesNameByIndex(
1533 ArkUINodeHandle node, ArkUI_Int32 index, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* writeLen)
1534 {
1535 auto navigationStack = GetNavigationStackByNode(node);
1536 CHECK_NULL_RETURN(navigationStack, ERROR_CODE_NATIVE_IMPL_GET_INFO_FAILED);
1537 if (index < 0 || index >= navigationStack->Size()) {
1538 return ERROR_CODE_NATIVE_IMPL_NODE_INDEX_INVALID;
1539 }
1540
1541 std::string name = navigationStack->GetNavDesNameByIndex(index);
1542 return WriteStringToBuffer(name, buffer, bufferSize, writeLen);
1543 }
1544
GetNavDestinationId(ArkUINodeHandle node,char * buffer,ArkUI_Int32 bufferSize,ArkUI_Int32 * writeLen)1545 ArkUI_Int32 GetNavDestinationId(
1546 ArkUINodeHandle node, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* writeLen)
1547 {
1548 auto navDesInfo = GetNavDestinationInfoByNode(node);
1549 CHECK_NULL_RETURN(navDesInfo, ERROR_CODE_NATIVE_IMPL_GET_INFO_FAILED);
1550 std::string navDestinationId = navDesInfo->navDestinationId;
1551 return WriteStringToBuffer(navDestinationId, buffer, bufferSize, writeLen);
1552 }
1553
GetNavDestinationState(ArkUINodeHandle node)1554 ArkUI_Int32 GetNavDestinationState(ArkUINodeHandle node)
1555 {
1556 auto navDesInfo = GetNavDestinationInfoByNode(node);
1557 CHECK_NULL_RETURN(navDesInfo, INVLID_VALUE);
1558 return static_cast<int32_t>(navDesInfo->state);
1559 }
1560
GetNavDestinationIndex(ArkUINodeHandle node)1561 ArkUI_Int32 GetNavDestinationIndex(ArkUINodeHandle node)
1562 {
1563 auto navDesInfo = GetNavDestinationInfoByNode(node);
1564 CHECK_NULL_RETURN(navDesInfo, INVLID_VALUE);
1565 return navDesInfo->index;
1566 }
1567
GetNavDestinationParam(ArkUINodeHandle node)1568 void* GetNavDestinationParam(ArkUINodeHandle node)
1569 {
1570 auto navDesInfo = GetNavDestinationInfoByNode(node);
1571 CHECK_NULL_RETURN(navDesInfo, nullptr);
1572 return reinterpret_cast<void*>(navDesInfo->param);
1573 }
1574
GetRouterPageIndex(ArkUINodeHandle node)1575 ArkUI_Int32 GetRouterPageIndex(ArkUINodeHandle node)
1576 {
1577 auto routerInfo = GetRouterPageInfoByNode(node);
1578 CHECK_NULL_RETURN(routerInfo, INVLID_VALUE);
1579 return routerInfo->index;
1580 }
1581
GetRouterPageName(ArkUINodeHandle node,char * buffer,ArkUI_Int32 bufferSize,ArkUI_Int32 * writeLen)1582 ArkUI_Int32 GetRouterPageName(
1583 ArkUINodeHandle node, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* writeLen)
1584 {
1585 auto routerInfo = GetRouterPageInfoByNode(node);
1586 CHECK_NULL_RETURN(routerInfo, ERROR_CODE_NATIVE_IMPL_GET_INFO_FAILED);
1587 std::string name = routerInfo->name;
1588 return WriteStringToBuffer(name, buffer, bufferSize, writeLen);
1589 }
1590
GetRouterPagePath(ArkUINodeHandle node,char * buffer,ArkUI_Int32 bufferSize,ArkUI_Int32 * writeLen)1591 ArkUI_Int32 GetRouterPagePath(
1592 ArkUINodeHandle node, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* writeLen)
1593 {
1594 auto routerInfo = GetRouterPageInfoByNode(node);
1595 CHECK_NULL_RETURN(routerInfo, ERROR_CODE_NATIVE_IMPL_GET_INFO_FAILED);
1596 std::string path = routerInfo->path;
1597 return WriteStringToBuffer(path, buffer, bufferSize, writeLen);
1598 }
1599
GetRouterPageState(ArkUINodeHandle node)1600 ArkUI_Int32 GetRouterPageState(ArkUINodeHandle node)
1601 {
1602 auto routerInfo = GetRouterPageInfoByNode(node);
1603 CHECK_NULL_RETURN(routerInfo, INVLID_VALUE);
1604 return static_cast<int32_t>(routerInfo->state);
1605 }
1606
GetRouterPageId(ArkUINodeHandle node,char * buffer,ArkUI_Int32 bufferSize,ArkUI_Int32 * writeLen)1607 ArkUI_Int32 GetRouterPageId(
1608 ArkUINodeHandle node, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* writeLen)
1609 {
1610 auto routerInfo = GetRouterPageInfoByNode(node);
1611 CHECK_NULL_RETURN(routerInfo, ERROR_CODE_NATIVE_IMPL_GET_INFO_FAILED);
1612 std::string pageId = routerInfo->pageId;
1613 return WriteStringToBuffer(pageId, buffer, bufferSize, writeLen);
1614 }
1615
GetContextByNode(ArkUINodeHandle node)1616 int32_t GetContextByNode(ArkUINodeHandle node)
1617 {
1618 int32_t instanceId = -1;
1619 FrameNode* currentNode = reinterpret_cast<FrameNode*>(node);
1620 CHECK_NULL_RETURN(currentNode, instanceId);
1621 auto pipeline = currentNode->GetContext();
1622 CHECK_NULL_RETURN(pipeline, instanceId);
1623 instanceId = pipeline->GetInstanceId();
1624 return instanceId;
1625 }
1626
GetBasicAPI()1627 const ArkUIBasicAPI* GetBasicAPI()
1628 {
1629 /* clang-format off */
1630 static const ArkUIBasicAPI basicImpl = {
1631 CreateNode,
1632 CreateNodeWithParams,
1633 GetNodeByViewStack,
1634 DisposeNode,
1635 GetName,
1636 DumpTreeNode,
1637
1638 AddChild,
1639 RemoveChild,
1640 InsertChildAfter,
1641 InsertChildBefore,
1642 InsertChildAt,
1643 GetAttribute,
1644 SetAttribute,
1645 ResetAttribute,
1646
1647 NotifyComponentAsyncEvent,
1648 NotifyResetComponentAsyncEvent,
1649 RegisterNodeAsyncEventReceiver,
1650 UnregisterNodeAsyncEventReceiver,
1651
1652 nullptr,
1653
1654 ApplyModifierFinish,
1655 MarkDirty,
1656 IsBuilderNode,
1657 ConvertLengthMetricsUnit,
1658
1659 GetContextByNode,
1660 };
1661 /* clang-format on */
1662
1663 return &basicImpl;
1664 }
1665
GetCJUIBasicAPI()1666 const CJUIBasicAPI* GetCJUIBasicAPI()
1667 {
1668 /* clang-format off */
1669 static const CJUIBasicAPI basicImpl = {
1670 CreateNode,
1671 DisposeNode,
1672 GetName,
1673 DumpTreeNode,
1674
1675 AddChild,
1676 RemoveChild,
1677 InsertChildAfter,
1678 InsertChildBefore,
1679 InsertChildAt,
1680 GetAttribute,
1681 SetAttribute,
1682 ResetAttribute,
1683
1684 NotifyComponentAsyncEvent,
1685 NotifyResetComponentAsyncEvent,
1686 RegisterNodeAsyncEventReceiver,
1687 UnregisterNodeAsyncEventReceiver,
1688
1689 nullptr,
1690
1691 ApplyModifierFinish,
1692 MarkDirty,
1693 IsBuilderNode,
1694 ConvertLengthMetricsUnit,
1695
1696 GetContextByNode,
1697 };
1698 /* clang-format on */
1699
1700 return &basicImpl;
1701 }
1702
CreateDialog()1703 ArkUIDialogHandle CreateDialog()
1704 {
1705 return CustomDialog::CreateDialog();
1706 }
1707
DisposeDialog(ArkUIDialogHandle handle)1708 void DisposeDialog(ArkUIDialogHandle handle)
1709 {
1710 CustomDialog::DisposeDialog(handle);
1711 }
1712
SetDialogContent(ArkUIDialogHandle handle,ArkUINodeHandle contentNode)1713 ArkUI_Int32 SetDialogContent(ArkUIDialogHandle handle, ArkUINodeHandle contentNode)
1714 {
1715 return CustomDialog::SetDialogContent(handle, contentNode);
1716 }
1717
RemoveDialogContent(ArkUIDialogHandle handle)1718 ArkUI_Int32 RemoveDialogContent(ArkUIDialogHandle handle)
1719 {
1720 return CustomDialog::RemoveDialogContent(handle);
1721 }
1722
SetDialogContentAlignment(ArkUIDialogHandle handle,ArkUI_Int32 alignment,ArkUI_Float32 offsetX,ArkUI_Float32 offsetY)1723 ArkUI_Int32 SetDialogContentAlignment(
1724 ArkUIDialogHandle handle, ArkUI_Int32 alignment, ArkUI_Float32 offsetX, ArkUI_Float32 offsetY)
1725 {
1726 return CustomDialog::SetDialogContentAlignment(handle, alignment, offsetX, offsetY);
1727 }
1728
ResetDialogContentAlignment(ArkUIDialogHandle handle)1729 ArkUI_Int32 ResetDialogContentAlignment(ArkUIDialogHandle handle)
1730 {
1731 return CustomDialog::ResetDialogContentAlignment(handle);
1732 }
1733
SetDialogModalMode(ArkUIDialogHandle handle,ArkUI_Bool isModal)1734 ArkUI_Int32 SetDialogModalMode(ArkUIDialogHandle handle, ArkUI_Bool isModal)
1735 {
1736 return CustomDialog::SetDialogModalMode(handle, isModal);
1737 }
1738
SetDialogAutoCancel(ArkUIDialogHandle handle,ArkUI_Bool autoCancel)1739 ArkUI_Int32 SetDialogAutoCancel(ArkUIDialogHandle handle, ArkUI_Bool autoCancel)
1740 {
1741 return CustomDialog::SetDialogAutoCancel(handle, autoCancel);
1742 }
1743
SetDialogMask(ArkUIDialogHandle handle,ArkUI_Uint32 maskColor,ArkUIRect * rect)1744 ArkUI_Int32 SetDialogMask(ArkUIDialogHandle handle, ArkUI_Uint32 maskColor, ArkUIRect* rect)
1745 {
1746 return CustomDialog::SetDialogMask(handle, maskColor, rect);
1747 }
1748
SetDialogBackgroundColor(ArkUIDialogHandle handle,uint32_t backgroundColor)1749 ArkUI_Int32 SetDialogBackgroundColor(ArkUIDialogHandle handle, uint32_t backgroundColor)
1750 {
1751 return CustomDialog::SetDialogBackgroundColor(handle, backgroundColor);
1752 }
1753
SetDialogCornerRadius(ArkUIDialogHandle handle,float topLeft,float topRight,float bottomLeft,float bottomRight)1754 ArkUI_Int32 SetDialogCornerRadius(
1755 ArkUIDialogHandle handle, float topLeft, float topRight, float bottomLeft, float bottomRight)
1756 {
1757 return CustomDialog::SetDialogCornerRadius(handle, topLeft, topRight, bottomLeft, bottomRight);
1758 }
1759
SetDialogGridColumnCount(ArkUIDialogHandle handle,int32_t gridCount)1760 ArkUI_Int32 SetDialogGridColumnCount(ArkUIDialogHandle handle, int32_t gridCount)
1761 {
1762 return CustomDialog::SetDialogGridColumnCount(handle, gridCount);
1763 }
1764
EnableDialogCustomStyle(ArkUIDialogHandle handle,ArkUI_Bool enableCustomStyle)1765 ArkUI_Int32 EnableDialogCustomStyle(ArkUIDialogHandle handle, ArkUI_Bool enableCustomStyle)
1766 {
1767 return CustomDialog::EnableDialogCustomStyle(handle, enableCustomStyle);
1768 }
1769
EnableDialogCustomAnimation(ArkUIDialogHandle handle,ArkUI_Bool enableCustomAnimation)1770 ArkUI_Int32 EnableDialogCustomAnimation(ArkUIDialogHandle handle, ArkUI_Bool enableCustomAnimation)
1771 {
1772 return CustomDialog::EnableDialogCustomAnimation(handle, enableCustomAnimation);
1773 }
1774
ShowDialog(ArkUIDialogHandle handle,ArkUI_Bool showInSubWindow)1775 ArkUI_Int32 ShowDialog(ArkUIDialogHandle handle, ArkUI_Bool showInSubWindow)
1776 {
1777 return CustomDialog::ShowDialog(handle, showInSubWindow);
1778 }
1779
CloseDialog(ArkUIDialogHandle handle)1780 ArkUI_Int32 CloseDialog(ArkUIDialogHandle handle)
1781 {
1782 return CustomDialog::CloseDialog(handle);
1783 }
1784
1785 // Register closing event
RegisterOnWillDialogDismiss(ArkUIDialogHandle handle,bool (* eventHandler)(ArkUI_Int32))1786 ArkUI_Int32 RegisterOnWillDialogDismiss(ArkUIDialogHandle handle, bool (*eventHandler)(ArkUI_Int32))
1787 {
1788 return CustomDialog::RegisterOnWillDialogDismiss(handle, eventHandler);
1789 }
1790
1791 // Register closing event
RegisterOnWillDismissWithUserData(ArkUIDialogHandle handler,void * userData,void (* callback)(ArkUI_DialogDismissEvent * event))1792 ArkUI_Int32 RegisterOnWillDismissWithUserData(
1793 ArkUIDialogHandle handler, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event))
1794 {
1795 return CustomDialog::RegisterOnWillDialogDismissWithUserData(handler, userData, callback);
1796 }
1797
GetDialogAPI()1798 const ArkUIDialogAPI* GetDialogAPI()
1799 {
1800 static const ArkUIDialogAPI dialogImpl = {
1801 CreateDialog,
1802 DisposeDialog,
1803 SetDialogContent,
1804 RemoveDialogContent,
1805 SetDialogContentAlignment,
1806 ResetDialogContentAlignment,
1807 SetDialogModalMode,
1808 SetDialogAutoCancel,
1809 SetDialogMask,
1810 SetDialogBackgroundColor,
1811 SetDialogCornerRadius,
1812 SetDialogGridColumnCount,
1813 EnableDialogCustomStyle,
1814 EnableDialogCustomAnimation,
1815 ShowDialog,
1816 CloseDialog,
1817 RegisterOnWillDialogDismiss,
1818 RegisterOnWillDismissWithUserData
1819 };
1820 return &dialogImpl;
1821 }
1822
ShowCrash(ArkUI_CharPtr message)1823 void ShowCrash(ArkUI_CharPtr message)
1824 {
1825 TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "Arkoala crash: %{public}s", message);
1826 }
1827
1828 /* clang-format off */
1829 ArkUIExtendedNodeAPI impl_extended = {
1830 ARKUI_EXTENDED_API_VERSION,
1831
1832 NodeModifier::GetUtilsModifier, // getUtilsModifier
1833 NodeModifier::GetCanvasRenderingContext2DModifier,
1834
1835 SetCallbackMethod,
1836 SetCustomMethodFlag,
1837 GetCustomMethodFlag,
1838 RegisterCustomNodeAsyncEvent,
1839 RegisterCustomSpanAsyncEvent,
1840 UnregisterCustomNodeEvent,
1841 RegisterCustomNodeEventReceiver,
1842 SetCustomCallback, // setCustomCallback
1843 MeasureLayoutAndDraw,
1844 MeasureNode,
1845 LayoutNode,
1846 DrawNode,
1847 SetAttachNodePtr,
1848 GetAttachNodePtr,
1849 SetMeasureWidth, // setMeasureWidth
1850 GetMeasureWidth, // getMeasureWidth
1851 SetMeasureHeight, // setMeasureHeight
1852 GetMeasureHeight, // getMeasureHeight
1853 SetX, // setX
1854 SetY, // setY
1855 GetX, // getX
1856 GetY, // getY
1857 GetLayoutConstraint,
1858 SetAlignment,
1859 GetAlignment,
1860 nullptr, // indexerChecker
1861 nullptr, // setRangeUpdater
1862 nullptr, // setLazyItemIndexer
1863 GetPipelineContext,
1864 SetVsyncCallback,
1865 UnblockVsyncWait,
1866 NodeEvent::CheckEvent,
1867 NodeEvent::SendArkUIAsyncEvent, // sendEvent
1868 nullptr, // callContinuation
1869 nullptr, // setChildTotalCount
1870 ShowCrash,
1871 };
1872 /* clang-format on */
1873
CanvasDrawRect(ArkUICanvasHandle canvas,ArkUI_Float32 left,ArkUI_Float32 top,ArkUI_Float32 right,ArkUI_Float32 bottom,ArkUIPaintHandle paint)1874 void CanvasDrawRect(ArkUICanvasHandle canvas, ArkUI_Float32 left, ArkUI_Float32 top, ArkUI_Float32 right,
1875 ArkUI_Float32 bottom, ArkUIPaintHandle paint)
1876 {
1877 TAG_LOGI(AceLogTag::ACE_NATIVE_NODE,
1878 "DrawRect canvas=%{public}p [%{public}f, %{public}f, %{public}f, %{public}f]\n", canvas, left, top, right,
1879 bottom);
1880 }
1881
GetCanvasAPI()1882 const ArkUIGraphicsCanvas* GetCanvasAPI()
1883 {
1884 static const ArkUIGraphicsCanvas modifier = { nullptr, nullptr, nullptr, nullptr, nullptr, CanvasDrawRect,
1885 nullptr };
1886 return &modifier;
1887 }
1888
1889 struct DummyPaint {
1890 ArkUI_Int32 color;
1891 };
1892
PaintMake()1893 ArkUIPaintHandle PaintMake()
1894 {
1895 return reinterpret_cast<ArkUIPaintHandle>(new DummyPaint());
1896 }
1897
PaintFinalize(ArkUIPaintHandle paintPtr)1898 void PaintFinalize(ArkUIPaintHandle paintPtr)
1899 {
1900 auto* paint = reinterpret_cast<DummyPaint*>(paintPtr);
1901 delete paint;
1902 }
1903
GetPaintAPI()1904 const ArkUIGraphicsPaint* GetPaintAPI()
1905 {
1906 static const ArkUIGraphicsPaint modifier = { PaintMake, PaintFinalize, nullptr, nullptr, nullptr, nullptr };
1907 return &modifier;
1908 }
1909
GetFontAPI()1910 const ArkUIGraphicsFont* GetFontAPI()
1911 {
1912 static const ArkUIGraphicsFont modifier = {
1913 nullptr,
1914 };
1915 return &modifier;
1916 }
1917
GetGraphicsAPI()1918 const ArkUIGraphicsAPI* GetGraphicsAPI()
1919 {
1920 static const ArkUIGraphicsAPI api = { ARKUI_NODE_GRAPHICS_API_VERSION, SetCallbackMethod, GetCanvasAPI, GetPaintAPI,
1921 GetFontAPI };
1922 return &api;
1923 }
1924
AnimateTo(ArkUIContext * context,ArkUIAnimateOption option,void * event,void * user)1925 void AnimateTo(ArkUIContext* context, ArkUIAnimateOption option, void* event, void* user)
1926 {
1927 ViewAnimate::AnimateTo(context, option, reinterpret_cast<void (*)(void*)>(event), user);
1928 }
1929
KeyframeAnimateTo(ArkUIContext * context,ArkUIKeyframeAnimateOption * animateOption)1930 void KeyframeAnimateTo(ArkUIContext* context, ArkUIKeyframeAnimateOption* animateOption)
1931 {
1932 ViewAnimate::KeyframeAnimateTo(context, animateOption);
1933 }
1934
CreateAnimator(ArkUIContext * context,ArkUIAnimatorOption * animateOption)1935 ArkUIAnimatorHandle CreateAnimator(ArkUIContext* context, ArkUIAnimatorOption* animateOption)
1936 {
1937 return ViewAnimate::CreateAnimator(context, animateOption);
1938 }
1939
DisposeAnimator(ArkUIAnimatorHandle animator)1940 void DisposeAnimator(ArkUIAnimatorHandle animator)
1941 {
1942 ViewAnimate::DisposeAnimator(animator);
1943 }
1944
AnimatorReset(ArkUIAnimatorHandle animator,ArkUIAnimatorOption * option)1945 ArkUI_Int32 AnimatorReset(ArkUIAnimatorHandle animator, ArkUIAnimatorOption* option)
1946 {
1947 return ViewAnimate::AnimatorReset(animator, option);
1948 }
1949
AnimatorPlay(ArkUIAnimatorHandle animator)1950 ArkUI_Int32 AnimatorPlay(ArkUIAnimatorHandle animator)
1951 {
1952 return ViewAnimate::AnimatorPlay(animator);
1953 }
1954
AnimatorFinish(ArkUIAnimatorHandle animator)1955 ArkUI_Int32 AnimatorFinish(ArkUIAnimatorHandle animator)
1956 {
1957 return ViewAnimate::AnimatorFinish(animator);
1958 }
1959
AnimatorPause(ArkUIAnimatorHandle animator)1960 ArkUI_Int32 AnimatorPause(ArkUIAnimatorHandle animator)
1961 {
1962 return ViewAnimate::AnimatorPause(animator);
1963 }
1964
AnimatorCancel(ArkUIAnimatorHandle animator)1965 ArkUI_Int32 AnimatorCancel(ArkUIAnimatorHandle animator)
1966 {
1967 return ViewAnimate::AnimatorCancel(animator);
1968 }
1969
AnimatorReverse(ArkUIAnimatorHandle animator)1970 ArkUI_Int32 AnimatorReverse(ArkUIAnimatorHandle animator)
1971 {
1972 return ViewAnimate::AnimatorReverse(animator);
1973 }
1974
CreateCurve(ArkUI_Int32 curve)1975 ArkUICurveHandle CreateCurve(ArkUI_Int32 curve)
1976 {
1977 return ViewAnimate::CreateCurve(curve);
1978 }
1979
CreateStepsCurve(ArkUI_Int32 count,ArkUI_Bool end)1980 ArkUICurveHandle CreateStepsCurve(ArkUI_Int32 count, ArkUI_Bool end)
1981 {
1982 return ViewAnimate::CreateStepsCurve(count, end);
1983 }
1984
CreateCubicBezierCurve(ArkUI_Float32 x1,ArkUI_Float32 y1,ArkUI_Float32 x2,ArkUI_Float32 y2)1985 ArkUICurveHandle CreateCubicBezierCurve(ArkUI_Float32 x1, ArkUI_Float32 y1, ArkUI_Float32 x2, ArkUI_Float32 y2)
1986 {
1987 return ViewAnimate::CreateCubicBezierCurve(x1, y1, x2, y2);
1988 }
1989
CreateSpringCurve(ArkUI_Float32 velocity,ArkUI_Float32 mass,ArkUI_Float32 stiffness,ArkUI_Float32 damping)1990 ArkUICurveHandle CreateSpringCurve(
1991 ArkUI_Float32 velocity, ArkUI_Float32 mass, ArkUI_Float32 stiffness, ArkUI_Float32 damping)
1992 {
1993 return ViewAnimate::CreateSpringCurve(velocity, mass, stiffness, damping);
1994 }
1995
CreateSpringMotion(ArkUI_Float32 response,ArkUI_Float32 dampingFraction,ArkUI_Float32 overlapDuration)1996 ArkUICurveHandle CreateSpringMotion(
1997 ArkUI_Float32 response, ArkUI_Float32 dampingFraction, ArkUI_Float32 overlapDuration)
1998 {
1999 return ViewAnimate::CreateSpringMotion(response, dampingFraction, overlapDuration);
2000 }
2001
CreateResponsiveSpringMotion(ArkUI_Float32 response,ArkUI_Float32 dampingFraction,ArkUI_Float32 overlapDuration)2002 ArkUICurveHandle CreateResponsiveSpringMotion(
2003 ArkUI_Float32 response, ArkUI_Float32 dampingFraction, ArkUI_Float32 overlapDuration)
2004 {
2005 return ViewAnimate::CreateResponsiveSpringMotion(response, dampingFraction, overlapDuration);
2006 }
2007
CreateInterpolatingSpring(ArkUI_Float32 velocity,ArkUI_Float32 mass,ArkUI_Float32 stiffness,ArkUI_Float32 damping)2008 ArkUICurveHandle CreateInterpolatingSpring(
2009 ArkUI_Float32 velocity, ArkUI_Float32 mass, ArkUI_Float32 stiffness, ArkUI_Float32 damping)
2010 {
2011 return ViewAnimate::CreateInterpolatingSpring(velocity, mass, stiffness, damping);
2012 }
2013
CreateCustomCurve(ArkUI_Float32 (* interpolate)(ArkUI_Float32 fraction,void * userData),void * userData)2014 ArkUICurveHandle CreateCustomCurve(ArkUI_Float32 (*interpolate)(ArkUI_Float32 fraction, void* userData), void* userData)
2015 {
2016 return ViewAnimate::CreateCustomCurve(interpolate, userData);
2017 }
2018
DisposeCurve(ArkUICurveHandle curve)2019 void DisposeCurve(ArkUICurveHandle curve)
2020 {
2021 return ViewAnimate::DisposeCurve(curve);
2022 }
2023
GetAnimationAPI()2024 const ArkUIAnimation* GetAnimationAPI()
2025 {
2026 static const ArkUIAnimation modifier = {
2027 nullptr,
2028 nullptr,
2029 nullptr,
2030 AnimateTo,
2031 KeyframeAnimateTo,
2032 CreateAnimator,
2033 DisposeAnimator,
2034 AnimatorReset,
2035 AnimatorPlay,
2036 AnimatorFinish,
2037 AnimatorPause,
2038 AnimatorCancel,
2039 AnimatorReverse,
2040 CreateCurve,
2041 CreateStepsCurve,
2042 CreateCubicBezierCurve,
2043 CreateSpringCurve,
2044 CreateSpringMotion,
2045 CreateResponsiveSpringMotion,
2046 CreateInterpolatingSpring,
2047 CreateCustomCurve,
2048 DisposeCurve,
2049 };
2050 return &modifier;
2051 }
2052
GetNavigationAPI()2053 const ArkUINavigation* GetNavigationAPI()
2054 {
2055 static const ArkUINavigation modifier = {
2056 nullptr,
2057 nullptr,
2058 GetNavigationId,
2059 GetNavDestinationName,
2060 GetStackLength,
2061 GetNavDesNameByIndex,
2062 GetNavDestinationId,
2063 GetNavDestinationState,
2064 GetNavDestinationIndex,
2065 GetNavDestinationParam,
2066 GetRouterPageIndex,
2067 GetRouterPageName,
2068 GetRouterPagePath,
2069 GetRouterPageState,
2070 GetRouterPageId,
2071 };
2072 return &modifier;
2073 }
2074
GetExtendedAPI()2075 const ArkUIExtendedNodeAPI* GetExtendedAPI()
2076 {
2077 return &impl_extended;
2078 }
2079
2080 /* clang-format off */
2081 ArkUIFullNodeAPI impl_full = {
2082 ARKUI_NODE_API_VERSION,
2083 SetCallbackMethod, // CallbackMethod
2084 GetBasicAPI, // BasicAPI
2085 GetArkUINodeModifiers, // NodeModifiers
2086 GetAnimationAPI, // Animation
2087 GetNavigationAPI, // Navigation
2088 GetGraphicsAPI, // Graphics
2089 GetDialogAPI,
2090 GetExtendedAPI, // Extended
2091 NodeAdapter::GetNodeAdapterAPI, // adapter.
2092 DragAdapter::GetDragAdapterAPI, // drag adapter.
2093 };
2094 /* clang-format on */
2095
GetCJUIAnimationAPI()2096 const CJUIAnimation* GetCJUIAnimationAPI()
2097 {
2098 static const CJUIAnimation modifier = {
2099 nullptr,
2100 nullptr,
2101 nullptr,
2102 AnimateTo,
2103 KeyframeAnimateTo,
2104 CreateAnimator,
2105 DisposeAnimator,
2106 AnimatorReset,
2107 AnimatorPlay,
2108 AnimatorFinish,
2109 AnimatorPause,
2110 AnimatorCancel,
2111 AnimatorReverse,
2112 CreateCurve,
2113 CreateStepsCurve,
2114 CreateCubicBezierCurve,
2115 CreateSpringCurve,
2116 CreateSpringMotion,
2117 CreateResponsiveSpringMotion,
2118 CreateInterpolatingSpring,
2119 CreateCustomCurve,
2120 DisposeCurve,
2121 };
2122 return &modifier;
2123 }
2124
GetCJUINavigationAPI()2125 const CJUINavigation* GetCJUINavigationAPI()
2126 {
2127 static const CJUINavigation modifier = {
2128 nullptr,
2129 nullptr,
2130 GetNavigationId,
2131 GetNavDestinationName,
2132 GetStackLength,
2133 GetNavDesNameByIndex,
2134 GetNavDestinationId,
2135 GetNavDestinationState,
2136 GetNavDestinationIndex,
2137 GetNavDestinationParam,
2138 GetRouterPageIndex,
2139 GetRouterPageName,
2140 GetRouterPagePath,
2141 GetRouterPageState,
2142 GetRouterPageId,
2143 };
2144 return &modifier;
2145 }
2146
GetCJUIGraphicsAPI()2147 const CJUIGraphicsAPI* GetCJUIGraphicsAPI()
2148 {
2149 static const CJUIGraphicsAPI api = {
2150 ARKUI_NODE_GRAPHICS_API_VERSION, SetCallbackMethod, GetCanvasAPI, GetPaintAPI, GetFontAPI
2151 };
2152 return &api;
2153 }
2154
GetCJUIDialogAPI()2155 const CJUIDialogAPI* GetCJUIDialogAPI()
2156 {
2157 static const CJUIDialogAPI dialogImpl = {
2158 CreateDialog,
2159 DisposeDialog,
2160 SetDialogContent,
2161 RemoveDialogContent,
2162 SetDialogContentAlignment,
2163 ResetDialogContentAlignment,
2164 SetDialogModalMode,
2165 SetDialogAutoCancel,
2166 SetDialogMask,
2167 SetDialogBackgroundColor,
2168 SetDialogCornerRadius,
2169 SetDialogGridColumnCount,
2170 EnableDialogCustomStyle,
2171 EnableDialogCustomAnimation,
2172 ShowDialog,
2173 CloseDialog,
2174 RegisterOnWillDialogDismiss,
2175 };
2176 return &dialogImpl;
2177 }
2178
GetCJUIExtendedAPI()2179 const CJUIExtendedNodeAPI* GetCJUIExtendedAPI()
2180 {
2181 static CJUIExtendedNodeAPI impl_extended = {
2182 ARKUI_EXTENDED_API_VERSION,
2183
2184 NodeModifier::GetUtilsModifier,
2185 NodeModifier::GetCanvasRenderingContext2DModifier,
2186
2187 SetCallbackMethod,
2188 SetCustomMethodFlag,
2189 GetCustomMethodFlag,
2190 RegisterCustomNodeAsyncEvent,
2191 UnregisterCustomNodeEvent,
2192 RegisterCustomNodeEventReceiver,
2193 SetCustomCallback, // setCustomCallback
2194 MeasureLayoutAndDraw,
2195 MeasureNode,
2196 LayoutNode,
2197 DrawNode,
2198 SetAttachNodePtr,
2199 GetAttachNodePtr,
2200 SetMeasureWidth, // setMeasureWidth
2201 GetMeasureWidth, // getMeasureWidth
2202 SetMeasureHeight, // setMeasureHeight
2203 GetMeasureHeight, // getMeasureHeight
2204 SetX, // setX
2205 SetY, // setY
2206 GetX, // getX
2207 GetY, // getY
2208 GetLayoutConstraint,
2209 SetAlignment,
2210 GetAlignment,
2211 nullptr, // indexerChecker
2212 nullptr, // setRangeUpdater
2213 nullptr, // setLazyItemIndexer
2214 GetPipelineContext,
2215 SetVsyncCallback,
2216 UnblockVsyncWait,
2217 NodeEvent::CheckEvent,
2218 NodeEvent::SendArkUIAsyncEvent,
2219 nullptr, // callContinuation
2220 nullptr, // setChildTotalCount
2221 ShowCrash,
2222 };
2223 return &impl_extended;
2224 }
2225
2226 CJUIFullNodeAPI fullCJUIApi {
2227 SetCallbackMethod,
2228 GetCJUIBasicAPI, // BasicAPI
2229 GetCJUINodeModifiers, // NodeModifiers
2230 GetCJUIAnimationAPI, // Animation
2231 GetCJUINavigationAPI, // Navigation
2232 GetCJUIGraphicsAPI, // Graphics
2233 GetCJUIDialogAPI,
2234 GetCJUIExtendedAPI, // Extended
2235 NodeAdapter::GetCJUINodeAdapterAPI, // adapter.
2236 };
2237 } // namespace
2238
2239 } // namespace OHOS::Ace::NG
2240
2241 extern "C" {
2242
GetCJUIFullNodeAPI()2243 ACE_FORCE_EXPORT CJUIFullNodeAPI* GetCJUIFullNodeAPI()
2244 {
2245 return &OHOS::Ace::NG::fullCJUIApi;
2246 }
2247
GetArkUIAnyFullNodeAPI(int version)2248 ACE_FORCE_EXPORT ArkUIAnyAPI* GetArkUIAnyFullNodeAPI(int version)
2249 {
2250 switch (version) {
2251 case ARKUI_NODE_API_VERSION:
2252 return reinterpret_cast<ArkUIAnyAPI*>(&OHOS::Ace::NG::impl_full);
2253 default: {
2254 TAG_LOGE(OHOS::Ace::AceLogTag::ACE_NATIVE_NODE,
2255 "Requested version %{public}d is not supported, we're version %{public}d", version,
2256 ARKUI_NODE_API_VERSION);
2257 return nullptr;
2258 }
2259 }
2260 }
2261
GetArkUIFullNodeAPI()2262 const ArkUIFullNodeAPI* GetArkUIFullNodeAPI()
2263 {
2264 return &OHOS::Ace::NG::impl_full;
2265 }
2266
SendArkUIAsyncEvent(ArkUINodeEvent * event)2267 void SendArkUIAsyncEvent(ArkUINodeEvent* event)
2268 {
2269 OHOS::Ace::NG::NodeEvent::SendArkUIAsyncEvent(event);
2270 }
2271
SendArkUIAsyncCustomEvent(ArkUICustomNodeEvent * event)2272 void SendArkUIAsyncCustomEvent(ArkUICustomNodeEvent* event)
2273 {
2274 OHOS::Ace::NG::CustomNodeEvent::SendArkUIAsyncEvent(event);
2275 }
2276
GetArkUIAPI(ArkUIAPIVariantKind kind,ArkUI_Int32 version)2277 ACE_FORCE_EXPORT const ArkUIAnyAPI* GetArkUIAPI(ArkUIAPIVariantKind kind, ArkUI_Int32 version)
2278 {
2279 switch (kind) {
2280 case ArkUIAPIVariantKind::BASIC: {
2281 switch (version) {
2282 case ARKUI_BASIC_API_VERSION:
2283 return reinterpret_cast<const ArkUIAnyAPI*>(OHOS::Ace::NG::GetBasicAPI());
2284 default: {
2285 TAG_LOGE(OHOS::Ace::AceLogTag::ACE_NATIVE_NODE,
2286 "Requested basic version %{public}d is not supported, we're version %{public}d\n", version,
2287 ARKUI_BASIC_API_VERSION);
2288
2289 return nullptr;
2290 }
2291 }
2292 }
2293 case ArkUIAPIVariantKind::FULL: {
2294 switch (version) {
2295 case ARKUI_FULL_API_VERSION:
2296 return reinterpret_cast<const ArkUIAnyAPI*>(&OHOS::Ace::NG::impl_full);
2297 default: {
2298 TAG_LOGE(OHOS::Ace::AceLogTag::ACE_NATIVE_NODE,
2299 "Requested full version %{public}d is not supported, we're version %{public}d\n", version,
2300 ARKUI_FULL_API_VERSION);
2301
2302 return nullptr;
2303 }
2304 }
2305 }
2306 case ArkUIAPIVariantKind::GRAPHICS: {
2307 switch (version) {
2308 case ARKUI_NODE_GRAPHICS_API_VERSION:
2309 return reinterpret_cast<const ArkUIAnyAPI*>(OHOS::Ace::NG::GetGraphicsAPI());
2310 default: {
2311 TAG_LOGE(OHOS::Ace::AceLogTag::ACE_NATIVE_NODE,
2312 "Requested graphics version %{public}d is not supported, we're version %{public}d\n", version,
2313 ARKUI_NODE_GRAPHICS_API_VERSION);
2314
2315 return nullptr;
2316 }
2317 }
2318 }
2319 case ArkUIAPIVariantKind::EXTENDED: {
2320 switch (version) {
2321 case ARKUI_EXTENDED_API_VERSION:
2322 return reinterpret_cast<const ArkUIAnyAPI*>(&OHOS::Ace::NG::impl_extended);
2323 default: {
2324 TAG_LOGE(OHOS::Ace::AceLogTag::ACE_NATIVE_NODE,
2325 "Requested extended version %{public}d is not supported, we're version %{public}d\n", version,
2326 ARKUI_EXTENDED_API_VERSION);
2327
2328 return nullptr;
2329 }
2330 }
2331 }
2332 default: {
2333 TAG_LOGE(OHOS::Ace::AceLogTag::ACE_NATIVE_NODE, "API kind %{public}d is not supported\n",
2334 static_cast<int>(kind));
2335
2336 return nullptr;
2337 }
2338 }
2339 }
2340
provideEntryPoint(void)2341 __attribute__((constructor)) static void provideEntryPoint(void)
2342 {
2343 #ifdef WINDOWS_PLATFORM
2344 // mingw has no setenv :(.
2345 static char entryPointString[64];
2346 if (snprintf_s(entryPointString, sizeof entryPointString, sizeof entryPointString - 1,
2347 "__LIBACE_ENTRY_POINT=%llx", static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(&GetArkUIAPI))) < 0) {
2348 return;
2349 }
2350 putenv(entryPointString);
2351 #else
2352 char entryPointString[64];
2353 if (snprintf_s(entryPointString, sizeof entryPointString, sizeof entryPointString - 1,
2354 "%llx", static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(&GetArkUIAPI))) < 0) {
2355 return;
2356 }
2357 setenv("__LIBACE_ENTRY_POINT", entryPointString, 1);
2358 #endif
2359 }
2360 }
2361