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