• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
16 #include <utility>
17 
18 #include "ark_native_engine.h"
19 #include "jsnapi_expo.h"
20 
21 #include "base/memory/ace_type.h"
22 #include "base/utils/string_utils.h"
23 #include "base/utils/utils.h"
24 #include "bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h"
25 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
26 #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h"
27 #include "bridge/declarative_frontend/engine/jsi/jsi_types.h"
28 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.h"
29 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
30 #include "bridge/declarative_frontend/jsview/js_view_context.h"
31 #include "bridge/js_frontend/engine/jsi/ark_js_runtime.h"
32 #include "core/components/common/properties/blend_mode.h"
33 #include "core/components_ng/base/view_abstract_model_ng.h"
34 #include "core/components_ng/property/safe_area_insets.h"
35 #include "core/pipeline/pipeline_base.h"
36 #include "core/pipeline_ng/pipeline_context.h"
37 #include "frameworks/base/geometry/calc_dimension.h"
38 #include "frameworks/base/geometry/dimension.h"
39 #include "frameworks/bridge/declarative_frontend/engine/js_types.h"
40 #include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_value_conversions.h"
41 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
42 #include "frameworks/bridge/declarative_frontend/jsview/js_shape_abstract.h"
43 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
44 using namespace OHOS::Ace::Framework;
45 
46 namespace OHOS::Ace::NG {
47 namespace {
48 constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000;
49 constexpr uint32_t ALIGNMENT_TOP_LEFT = 0;
50 constexpr float DEFAULT_PROGRESS_TOTAL = 100.0f;
51 constexpr int NUM_0 = 0;
52 constexpr int NUM_1 = 1;
53 constexpr int NUM_2 = 2;
54 constexpr int NUM_3 = 3;
55 constexpr int NUM_4 = 4;
56 constexpr int NUM_5 = 5;
57 constexpr int NUM_6 = 6;
58 constexpr int NUM_7 = 7;
59 constexpr int NUM_8 = 8;
60 constexpr int NUM_9 = 9;
61 constexpr int NUM_10 = 10;
62 constexpr int NUM_13 = 13;
63 constexpr int SIZE_OF_TWO = 2;
64 constexpr int SIZE_OF_THREE = 3;
65 constexpr int SIZE_OF_FOUR = 4;
66 constexpr int SIZE_OF_FIVE = 5;
67 constexpr int SIZE_OF_EIGHT = 8;
68 constexpr int32_t ALIGN_RULES_NUM = 6;
69 constexpr int32_t ALIGN_DIRECTION_DEFAULT = 2;
70 constexpr double FULL_DIMENSION = 100.0;
71 constexpr double HALF_DIMENSION = 50.0;
72 constexpr uint32_t DEFAULT_DURATION = 1000;
73 constexpr int64_t MICROSEC_TO_MILLISEC = 1000;
74 constexpr int32_t MAX_ALIGN_VALUE = 8;
75 constexpr int32_t BACKWARD_COMPAT_MAGIC_NUMBER_OFFSCREEN = 1000;
76 constexpr SharedTransitionEffectType DEFAULT_SHARED_EFFECT = SharedTransitionEffectType::SHARED_EFFECT_EXCHANGE;
77 constexpr int32_t DEFAULT_TAP_FINGER = 1;
78 constexpr int32_t DEFAULT_TAP_COUNT = 1;
79 constexpr double DEFAULT_TAP_DISTANCE = std::numeric_limits<double>::infinity();
80 constexpr int32_t DEFAULT_LONG_PRESS_FINGER = 1;
81 constexpr int32_t DEFAULT_LONG_PRESS_DURATION = 500;
82 constexpr int32_t DEFAULT_PINCH_FINGER = 2;
83 constexpr int32_t DEFAULT_MAX_PINCH_FINGER = 5;
84 constexpr double DEFAULT_PINCH_DISTANCE = 5.0;
85 constexpr int32_t DEFAULT_PAN_FINGER = 1;
86 constexpr int32_t DEFAULT_MAX_FINGERS = 10;
87 constexpr OHOS::Ace::Dimension DEFAULT_PAN_DISTANCE = 5.0_vp;
88 constexpr int32_t DEFAULT_SLIDE_FINGER = DEFAULT_PAN_FINGER;
89 constexpr double DEFAULT_SLIDE_SPEED = 100.0;
90 constexpr int32_t DEFAULT_ROTATION_FINGER = 2;
91 constexpr int32_t DEFAULT_MAX_ROTATION_FINGER = 5;
92 constexpr double DEFAULT_ROTATION_ANGLE = 1.0;
93 constexpr double DEFAULT_MAX_ROTATION_ANGLE = 360.0;
94 const std::string BLOOM_RADIUS_SYS_RES_NAME = "sys.float.ohos_id_point_light_bloom_radius";
95 const std::string BLOOM_COLOR_SYS_RES_NAME = "sys.color.ohos_id_point_light_bloom_color";
96 const std::string ILLUMINATED_BORDER_WIDTH_SYS_RES_NAME = "sys.float.ohos_id_point_light_illuminated_border_width";
97 constexpr double WIDTH_BREAKPOINT_320VP = 320.0; // window width threshold
98 constexpr double WIDTH_BREAKPOINT_600VP = 600.0;
99 constexpr double WIDTH_BREAKPOINT_840VP = 840.0;
100 constexpr double WIDTH_BREAKPOINT_1440VP = 1440.0;
101 constexpr double HEIGHT_ASPECTRATIO_THRESHOLD1 = 0.8; // window height/width = 0.8
102 constexpr double HEIGHT_ASPECTRATIO_THRESHOLD2 = 1.2;
103 
104 enum class WidthBreakpoint {WIDTH_XS, WIDTH_SM, WIDTH_MD, WIDTH_LG, WIDTH_XL};
105 enum class HeightBreakpoint {HEIGHT_SM, HEIGHT_MD, HEIGHT_LG};
106 enum ParseResult { LENGTHMETRICS_SUCCESS, DIMENSION_SUCCESS, FAIL };
107 
ConvertBorderStyle(int32_t value)108 BorderStyle ConvertBorderStyle(int32_t value)
109 {
110     auto style = static_cast<BorderStyle>(value);
111     if (style < BorderStyle::SOLID || style > BorderStyle::NONE) {
112         style = BorderStyle::SOLID;
113     }
114     return style;
115 }
116 
ParseJsDouble(const EcmaVM * vm,const Local<JSValueRef> & value,double & result)117 bool ParseJsDouble(const EcmaVM *vm, const Local<JSValueRef> &value, double &result)
118 {
119     if (value->IsNumber()) {
120         result = value->ToNumber(vm)->Value();
121         return true;
122     }
123     if (value->IsString(vm)) {
124         return StringUtils::StringToDouble(value->ToString(vm)->ToString(vm), result);
125     }
126 
127     return false;
128 }
129 
ParseJsInt32(const EcmaVM * vm,const Local<JSValueRef> & value,int32_t & result)130 bool ParseJsInt32(const EcmaVM *vm, const Local<JSValueRef> &value, int32_t &result)
131 {
132     if (value->IsNumber()) {
133         result = value->Int32Value(vm);
134         return true;
135     }
136     if (value->IsString(vm)) {
137         result = StringUtils::StringToInt(value->ToString(vm)->ToString(vm));
138         return true;
139     }
140 
141     return false;
142 }
143 
ParseJsAngle(const EcmaVM * vm,const Local<JSValueRef> & value,std::optional<float> & angle)144 void ParseJsAngle(const EcmaVM *vm, const Local<JSValueRef> &value, std::optional<float> &angle)
145 {
146     if (value->IsNumber()) {
147         angle = static_cast<float>(value->ToNumber(vm)->Value());
148         return;
149     }
150     if (value->IsString(vm)) {
151         angle = static_cast<float>(StringUtils::StringToDegree(value->ToString(vm)->ToString(vm)));
152         return;
153     }
154     return;
155 }
156 
ParseGradientAngle(const EcmaVM * vm,const Local<JSValueRef> & value,std::vector<ArkUIInt32orFloat32> & values)157 void ParseGradientAngle(const EcmaVM *vm, const Local<JSValueRef> &value, std::vector<ArkUIInt32orFloat32> &values)
158 {
159     std::optional<float> degree;
160     ParseJsAngle(vm, value, degree);
161     auto angleHasValue = degree.has_value();
162     auto angleValue = angleHasValue ? degree.value() : 0.0f;
163     degree.reset();
164     values.push_back({.i32 = static_cast<ArkUI_Int32>(angleHasValue)});
165     values.push_back({.f32 = static_cast<ArkUI_Float32>(angleValue)});
166 }
167 
ParseGradientColorStops(const EcmaVM * vm,const Local<JSValueRef> & value,std::vector<ArkUIInt32orFloat32> & colors)168 void ParseGradientColorStops(const EcmaVM *vm, const Local<JSValueRef> &value, std::vector<ArkUIInt32orFloat32> &colors)
169 {
170     if (!value->IsArray(vm)) {
171         return;
172     }
173     auto array = panda::Local<panda::ArrayRef>(value);
174     auto length = array->Length(vm);
175     for (uint32_t index = 0; index < length; index++) {
176         auto item = panda::ArrayRef::GetValueAt(vm, array, index);
177         if (!item->IsArray(vm)) {
178             continue;
179         }
180         auto itemArray = panda::Local<panda::ArrayRef>(item);
181         auto itemLength = itemArray->Length(vm);
182         if (itemLength < NUM_1) {
183             continue;
184         }
185         Color color;
186         auto colorParams = panda::ArrayRef::GetValueAt(vm, itemArray, NUM_0);
187         if (!ArkTSUtils::ParseJsColorAlpha(vm, colorParams, color)) {
188             continue;
189         }
190         bool hasDimension = false;
191         double dimension = 0.0;
192         if (itemLength > NUM_1) {
193             auto stopDimension = panda::ArrayRef::GetValueAt(vm, itemArray, NUM_1);
194             if (ArkTSUtils::ParseJsDouble(vm, stopDimension, dimension)) {
195                 hasDimension = true;
196             }
197         }
198         colors.push_back({.u32 = static_cast<ArkUI_Uint32>(color.GetValue())});
199         colors.push_back({.i32 = static_cast<ArkUI_Int32>(hasDimension)});
200         colors.push_back({.f32 = static_cast<ArkUI_Float32>(dimension)});
201     }
202 }
203 
ParseJsShadowColorStrategy(const EcmaVM * vm,const Local<JSValueRef> & value,ShadowColorStrategy & strategy)204 bool ParseJsShadowColorStrategy(const EcmaVM *vm, const Local<JSValueRef> &value, ShadowColorStrategy& strategy)
205 {
206     if (value->IsString(vm)) {
207         std::string colorStr = value->ToString(vm)->ToString(vm);
208         if (colorStr.compare("average") == 0) {
209             strategy = ShadowColorStrategy::AVERAGE;
210             return true;
211         } else if (colorStr.compare("primary") == 0) {
212             strategy = ShadowColorStrategy::PRIMARY;
213             return true;
214         }
215     }
216     return false;
217 }
218 
ParseJsShadowDimension(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimension)219 bool ParseJsShadowDimension(const EcmaVM *vm, const Local<JSValueRef> &value, CalcDimension& dimension)
220 {
221     if (ArkTSUtils::ParseJsResource(vm, value, dimension)) {
222         return true;
223     } else {
224         if (ArkTSUtils::ParseJsDimensionVp(vm, value, dimension)) {
225             return true;
226         }
227     }
228     return false;
229 }
230 
ParseJsShadowColor(const EcmaVM * vm,const Local<JSValueRef> & colorArg,int32_t & type,uint32_t & colorValue)231 bool ParseJsShadowColor(const EcmaVM *vm, const Local<JSValueRef> &colorArg,
232     int32_t& type, uint32_t& colorValue)
233 {
234     Color color;
235     ShadowColorStrategy shadowColorStrategy;
236     if (ParseJsShadowColorStrategy(vm, colorArg, shadowColorStrategy)) {
237         type = 1; // 1: has shadowColorStrategy
238         colorValue = static_cast<uint32_t>(shadowColorStrategy);
239         return true;
240     } else if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
241         type = 2; // 2: has shadowColor
242         colorValue = color.GetValue();
243         return true;
244     }
245     return false;
246 }
247 
ParseCalcDimensions(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count,std::vector<std::optional<CalcDimension>> & results,const CalcDimension & defValue)248 bool ParseCalcDimensions(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count,
249     std::vector<std::optional<CalcDimension>>& results, const CalcDimension& defValue)
250 {
251     auto end = offset + count;
252     auto argsNumber = runtimeCallInfo->GetArgsNumber();
253     if (end > argsNumber) {
254         return false;
255     }
256     bool hasValue = false;
257     EcmaVM* vm = runtimeCallInfo->GetVM();
258     for (uint32_t index = offset; index < end; index++) {
259         auto arg = runtimeCallInfo->GetCallArgRef(index);
260         std::optional<CalcDimension> optCalcDimension;
261         CalcDimension dimension(defValue);
262         if (ArkTSUtils::ParseJsDimensionVp(vm, arg, dimension, false)) {
263             optCalcDimension = dimension;
264             hasValue = true;
265         }
266         results.push_back(optCalcDimension);
267     }
268     return hasValue;
269 }
270 
ParseCalcDimensionsNG(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count,std::vector<std::optional<CalcDimension>> & results,const CalcDimension & defValue)271 ParseResult ParseCalcDimensionsNG(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count,
272     std::vector<std::optional<CalcDimension>>& results, const CalcDimension& defValue)
273 {
274     auto end = offset + count;
275     auto argsNumber = runtimeCallInfo->GetArgsNumber();
276     if (end > argsNumber) {
277         return ParseResult::FAIL;
278     }
279     ParseResult res = ParseResult::FAIL;
280     EcmaVM* vm = runtimeCallInfo->GetVM();
281     for (uint32_t index = offset; index < end; index++) {
282         auto arg = runtimeCallInfo->GetCallArgRef(index);
283         std::optional<CalcDimension> optCalcDimension;
284         CalcDimension dimension(defValue);
285         // Parse string, '10abc' return false
286         if (ArkTSUtils::ParseJsDimensionVpNG(vm, arg, dimension, true)) {
287             optCalcDimension = dimension;
288             res = ParseResult::DIMENSION_SUCCESS;
289         } else if (ArkTSUtils::ParseJsLengthMetrics(vm, arg, dimension)) {
290             optCalcDimension = dimension;
291             res = ParseResult::LENGTHMETRICS_SUCCESS;
292         }
293         results.push_back(optCalcDimension);
294     }
295     return res;
296 }
297 
ResetCalcDimensions(std::vector<std::optional<CalcDimension>> & optDimensions)298 void ResetCalcDimensions(std::vector<std::optional<CalcDimension>>& optDimensions)
299 {
300     for (uint32_t index = 0; index < optDimensions.size(); index++) {
301         auto optDimension = optDimensions[index];
302         optDimension.reset();
303     }
304 }
305 
PushDimensionsToVector(std::vector<ArkUIStringAndFloat> & results,const std::vector<std::optional<CalcDimension>> & optDimensions)306 void PushDimensionsToVector(std::vector<ArkUIStringAndFloat>& results,
307     const std::vector<std::optional<CalcDimension>>& optDimensions)
308 {
309     for (uint32_t index = 0; index < optDimensions.size(); index++) {
310         auto optDimension = optDimensions[index];
311         auto hasValue = optDimension.has_value();
312         DimensionUnit unit = DimensionUnit::PX;
313         ArkUIStringAndFloat value = { 0.0, nullptr };
314         if (hasValue) {
315             unit = optDimension.value().Unit();
316             if (unit == DimensionUnit::CALC) {
317                 value.valueStr = optDimension.value().CalcValue().c_str();
318             } else {
319                 value.value = optDimension.value().Value();
320             }
321         }
322         results.push_back(ArkUIStringAndFloat { static_cast<double>(hasValue), nullptr });
323         results.push_back(value);
324         results.push_back(ArkUIStringAndFloat { static_cast<double>(unit), nullptr });
325     }
326 }
327 
ParseBorderImageSlice(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<std::optional<CalcDimension>> & optDimensions,uint8_t & bitsets)328 void ParseBorderImageSlice(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
329     std::vector<std::optional<CalcDimension>>& optDimensions, uint8_t& bitsets)
330 {
331     if (ParseCalcDimensions(runtimeCallInfo, offset, NUM_4, optDimensions, CalcDimension(0.0))) {
332         bitsets |= BorderImage::SLICE_BIT;
333     }
334     offset += NUM_4;
335 }
336 
ParseBorderImageWidth(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<std::optional<CalcDimension>> & optDimensions,uint8_t & bitsets)337 void ParseBorderImageWidth(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
338     std::vector<std::optional<CalcDimension>>& optDimensions, uint8_t& bitsets)
339 {
340     if (ParseCalcDimensions(runtimeCallInfo, offset, NUM_4, optDimensions, CalcDimension(0.0))) {
341         bitsets |= BorderImage::WIDTH_BIT;
342     }
343     offset += NUM_4;
344 }
345 
ParseBorderImageOutset(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<std::optional<CalcDimension>> & optDimensions,uint8_t & bitsets)346 void ParseBorderImageOutset(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
347     std::vector<std::optional<CalcDimension>>& optDimensions, uint8_t& bitsets)
348 {
349     if (ParseCalcDimensions(runtimeCallInfo, offset, NUM_4, optDimensions, CalcDimension(0.0))) {
350         bitsets |= BorderImage::OUTSET_BIT;
351     }
352     offset += NUM_4;
353 }
354 
ParseBorderImageRepeat(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<ArkUIStringAndFloat> & options,uint8_t & bitsets)355 bool ParseBorderImageRepeat(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
356     std::vector<ArkUIStringAndFloat>& options, uint8_t& bitsets)
357 {
358     auto argsNumber = runtimeCallInfo->GetArgsNumber();
359     if ((offset + NUM_1) > argsNumber) {
360         return false;
361     }
362     auto vm = runtimeCallInfo->GetVM();
363     auto repeatArg = runtimeCallInfo->GetCallArgRef(offset);
364     auto repeatHasValue = repeatArg->IsString(vm);
365     auto repeatValue = BorderImageRepeat::STRETCH;
366     if (repeatHasValue) {
367         auto repeatStr = repeatArg->ToString(vm)->ToString(vm);
368         if (repeatStr == "Repeat") {
369             repeatValue = BorderImageRepeat::REPEAT;
370         } else if (repeatStr == "Round") {
371             repeatValue = BorderImageRepeat::ROUND;
372         } else if (repeatStr == "Space") {
373             repeatValue = BorderImageRepeat::SPACE;
374         } else {
375             repeatValue = BorderImageRepeat::STRETCH;
376         }
377     }
378     options.push_back(ArkUIStringAndFloat { static_cast<double>(repeatHasValue), nullptr });
379     options.push_back(ArkUIStringAndFloat { static_cast<double>(repeatValue), nullptr });
380     if (repeatHasValue) {
381         bitsets |= BorderImage::REPEAT_BIT;
382     }
383     offset += NUM_1;
384     return true;
385 }
386 
ParseBorderImageFill(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<ArkUIStringAndFloat> & options)387 bool ParseBorderImageFill(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
388     std::vector<ArkUIStringAndFloat>& options)
389 {
390     auto argsNumber = runtimeCallInfo->GetArgsNumber();
391     if ((offset + NUM_1) > argsNumber) {
392         return false;
393     }
394     auto fillArg = runtimeCallInfo->GetCallArgRef(offset);
395     auto hasValue = fillArg->IsBoolean();
396     auto fill = (hasValue) ? fillArg->BooleaValue(runtimeCallInfo->GetVM()) : false;
397     options.push_back(ArkUIStringAndFloat {static_cast<double>(hasValue), nullptr });
398     options.push_back(ArkUIStringAndFloat {static_cast<double>(fill), nullptr });
399     offset += NUM_1;
400     return true;
401 }
402 
IsArgsUndefined(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count)403 bool IsArgsUndefined(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count)
404 {
405     auto argsNumber = runtimeCallInfo->GetArgsNumber();
406     auto end = offset + count;
407     end = (end > argsNumber) ? argsNumber : end;
408     for (uint32_t index = offset; index < end; index++) {
409         auto jsArg = runtimeCallInfo->GetCallArgRef(index);
410         if (jsArg->IsUndefined()) {
411             continue;
412         }
413         return false;
414     }
415     return true;
416 }
417 
ParseBorderImageLinearGradient(ArkUINodeHandle node,ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint8_t & bitsets)418 void ParseBorderImageLinearGradient(ArkUINodeHandle node,
419     ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset,
420     uint8_t& bitsets)
421 {
422     auto argsNumber = runtimeCallInfo->GetArgsNumber();
423     if ((offset + NUM_4) > argsNumber) {
424         return;
425     }
426     auto angleArg = runtimeCallInfo->GetCallArgRef(offset);
427     auto directionArg = runtimeCallInfo->GetCallArgRef(offset + NUM_1);
428     auto colorsArg = runtimeCallInfo->GetCallArgRef(offset + NUM_2);
429     auto repeatingArg = runtimeCallInfo->GetCallArgRef(offset + NUM_3);
430     if (angleArg->IsUndefined() && directionArg->IsUndefined() &&
431         colorsArg->IsUndefined() && repeatingArg->IsUndefined()) {
432         return;
433     }
434     auto vm = runtimeCallInfo->GetVM();
435     std::vector<ArkUIInt32orFloat32> options;
436     ParseGradientAngle(vm, angleArg, options);
437     int32_t direction = static_cast<int32_t>(GradientDirection::NONE);
438     ParseJsInt32(vm, directionArg, direction);
439     options.push_back({.i32 = static_cast<ArkUI_Int32>(direction)});
440 
441     std::vector<ArkUIInt32orFloat32> colors;
442     ParseGradientColorStops(vm, colorsArg, colors);
443     auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(runtimeCallInfo->GetVM()) : false;
444     options.push_back({.i32 = static_cast<ArkUI_Int32>(repeating)});
445     GetArkUINodeModifiers()->getCommonModifier()->setBorderImageGradient(node,
446         options.data(), options.size(), colors.data(), colors.size());
447 }
448 
ParseBorderImageSource(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,ArkUINodeHandle node,std::string & src,uint8_t & bitsets)449 bool ParseBorderImageSource(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
450     ArkUINodeHandle node, std::string& src, uint8_t& bitsets)
451 {
452     auto argsNumber = runtimeCallInfo->GetArgsNumber();
453     if ((offset + NUM_5) > argsNumber) {
454         return false;
455     }
456     if (IsArgsUndefined(runtimeCallInfo, offset, NUM_5)) {
457         return false;
458     }
459     auto sourceArg = runtimeCallInfo->GetCallArgRef(offset); // use 1 args
460     offset += NUM_1;
461     auto vm = runtimeCallInfo->GetVM();
462     if (sourceArg->IsString(vm)) {
463         src = sourceArg->ToString(vm)->ToString(vm);
464         bitsets |= BorderImage::SOURCE_BIT;
465     } else {
466         if (ArkTSUtils::ParseJsMedia(vm, sourceArg, src)) {
467             bitsets |= BorderImage::SOURCE_BIT;
468         } else {
469             ParseBorderImageLinearGradient(node, runtimeCallInfo, offset, bitsets);
470         }
471     }
472     offset += NUM_4; // skip 4 args
473     return true;
474 }
475 
ParseChainedMoveTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)476 RefPtr<NG::ChainedTransitionEffect> ParseChainedMoveTransition(
477     const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
478 {
479     int32_t edge = 0;
480     if (JSViewAbstract::ParseJsInt32(effectOption, edge)) {
481         if (edge < static_cast<int32_t>(NG::TransitionEdge::TOP) ||
482             edge > static_cast<int32_t>(NG::TransitionEdge::END)) {
483             edge = static_cast<int32_t>(NG::TransitionEdge::START);
484         }
485         return AceType::MakeRefPtr<NG::ChainedMoveEffect>(static_cast<NG::TransitionEdge>(edge));
486     }
487     return nullptr;
488 }
489 
ParseChainedOpacityTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)490 RefPtr<NG::ChainedTransitionEffect> ParseChainedOpacityTransition(
491     const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
492 {
493     double opacity = 1.0;
494     if (Framework::JSViewAbstract::ParseJsDouble(effectOption, opacity)) {
495         if ((LessNotEqual(opacity, 0.0)) || opacity > 1.0) {
496             opacity = 1.0;
497         }
498         return AceType::MakeRefPtr<NG::ChainedOpacityEffect>(opacity);
499     }
500     return nullptr;
501 }
502 
ParseJsTranslate(const Framework::JSRef<Framework::JSVal> & jsValue,CalcDimension & translateX,CalcDimension & translateY,CalcDimension & translateZ)503 void ParseJsTranslate(const Framework::JSRef<Framework::JSVal>& jsValue, CalcDimension& translateX,
504     CalcDimension& translateY, CalcDimension& translateZ)
505 {
506     if (!jsValue->IsObject()) {
507         return;
508     }
509     Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
510     Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("x"), translateX);
511     Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("y"), translateY);
512     Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("z"), translateZ);
513 }
514 
ParseStrToUint(std::string safeAreaTypeStr)515 uint32_t ParseStrToUint(std::string safeAreaTypeStr)
516 {
517     uint32_t uintType = NG::SAFE_AREA_TYPE_NONE;
518     std::string delimiter = "|";
519     std::string type;
520     size_t pos = 0;
521     while ((pos = safeAreaTypeStr.find(delimiter)) != std::string::npos) {
522         type = safeAreaTypeStr.substr(0, pos);
523         uintType |= (1 << StringUtils::StringToUint(type));
524         safeAreaTypeStr.erase(0, pos + delimiter.length());
525     }
526     uintType |= (1 << StringUtils::StringToUint(safeAreaTypeStr));
527     return uintType;
528 }
529 
ParseChainedTranslateTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)530 RefPtr<NG::ChainedTransitionEffect> ParseChainedTranslateTransition(
531     const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
532 {
533     if (effectOption->IsObject()) {
534         // default: x, y, z (0.0, 0.0, 0.0)
535         NG::TranslateOptions translate;
536         ParseJsTranslate(effectOption, translate.x, translate.y, translate.z);
537         return AceType::MakeRefPtr<NG::ChainedTranslateEffect>(translate);
538     }
539     return nullptr;
540 }
541 
GetDefaultRotateVector(double & dx,double & dy,double & dz)542 void GetDefaultRotateVector(double& dx, double& dy, double& dz)
543 {
544     dx = 0.0;
545     dy = 0.0;
546     dz = 0.0;
547     if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_NINE)) {
548         dz = 1.0;
549     }
550 }
551 
ParseJsRotate(const Framework::JSRef<Framework::JSVal> & jsValue,NG::RotateOptions & rotate,std::optional<float> & angle)552 void ParseJsRotate(
553     const Framework::JSRef<Framework::JSVal>& jsValue, NG::RotateOptions& rotate, std::optional<float>& angle)
554 {
555     if (!jsValue->IsObject()) {
556         return;
557     }
558     // default: dx, dy, dz (0.0, 0.0, 0.0)
559     double dxVal = 0.0;
560     double dyVal = 0.0;
561     double dzVal = 0.0;
562     Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
563     if (!jsObj->HasProperty("x") && !jsObj->HasProperty("y") && !jsObj->HasProperty("z")) {
564         GetDefaultRotateVector(dxVal, dyVal, dzVal);
565     } else {
566         Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("x"), dxVal);
567         Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("y"), dyVal);
568         Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("z"), dzVal);
569     }
570     rotate.xDirection = static_cast<float>(dxVal);
571     rotate.yDirection = static_cast<float>(dyVal);
572     rotate.zDirection = static_cast<float>(dzVal);
573     // if specify centerX
574     if (!Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerX"), rotate.centerX)) {
575         rotate.centerX = Dimension(0.5f, DimensionUnit::PERCENT);
576     }
577     // if specify centerY
578     if (!Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerY"), rotate.centerY)) {
579         rotate.centerY = Dimension(0.5f, DimensionUnit::PERCENT);
580     }
581     // if specify centerZ
582     if (!Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerZ"), rotate.centerZ)) {
583         rotate.centerZ = Dimension(0.5f, DimensionUnit::PERCENT);
584     }
585     // if specify angle
586     Framework::JSViewAbstract::GetJsAngle(static_cast<int32_t>(ArkUIIndex::ANGLE), jsObj, angle);
587     rotate.perspective = 0.0f;
588     Framework::JSViewAbstract::GetJsPerspective(static_cast<int32_t>(ArkUIIndex::PERSPECTIVE), jsObj,
589         rotate.perspective);
590 }
591 
ParseChainedRotateTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)592 RefPtr<NG::ChainedTransitionEffect> ParseChainedRotateTransition(
593     const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
594 {
595     RefPtr<NG::ChainedTransitionEffect> effect;
596     if (effectOption->IsObject()) {
597         NG::RotateOptions rotate(0.0f, 0.0f, 0.0f, 0.0f, 0.5_pct, 0.5_pct);
598         std::optional<float> angle;
599         ParseJsRotate(effectOption, rotate, angle);
600         if (angle.has_value()) {
601             rotate.angle = angle.value();
602             return AceType::MakeRefPtr<NG::ChainedRotateEffect>(rotate);
603         }
604     }
605     return nullptr;
606 }
607 
ParseJsScale(const Framework::JSRef<Framework::JSVal> & jsValue,float & scaleX,float & scaleY,float & scaleZ,CalcDimension & centerX,CalcDimension & centerY)608 void ParseJsScale(const Framework::JSRef<Framework::JSVal>& jsValue, float& scaleX, float& scaleY, float& scaleZ,
609     CalcDimension& centerX, CalcDimension& centerY)
610 {
611     double xVal = 1.0;
612     double yVal = 1.0;
613     double zVal = 1.0;
614     if (!jsValue->IsObject()) {
615         scaleX = static_cast<float>(xVal);
616         scaleY = static_cast<float>(yVal);
617         scaleZ = static_cast<float>(zVal);
618         CalcDimension length;
619         centerX = length;
620         centerY = length;
621         return;
622     }
623     Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
624     Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("x"), xVal);
625     Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("y"), yVal);
626     Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("z"), zVal);
627     scaleX = static_cast<float>(xVal);
628     scaleY = static_cast<float>(yVal);
629     scaleZ = static_cast<float>(zVal);
630     // if specify centerX
631     Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerX"), centerX);
632     // if specify centerY
633     Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerY"), centerY);
634 }
635 
ParseChainedScaleTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)636 RefPtr<NG::ChainedTransitionEffect> ParseChainedScaleTransition(
637     const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
638 {
639     if (effectOption->IsObject()) {
640         // default: x, y, z (1.0, 1.0, 1.0), centerX, centerY 50% 50%;
641         NG::ScaleOptions scale(1.0f, 1.0f, 1.0f, 0.5_pct, 0.5_pct);
642         ParseJsScale(effectOption, scale.xScale, scale.yScale, scale.zScale, scale.centerX, scale.centerY);
643         return AceType::MakeRefPtr<NG::ChainedScaleEffect>(scale);
644     }
645     return nullptr;
646 }
647 
648 RefPtr<NG::ChainedTransitionEffect> ParseChainedTransition(
649     const JSRef<JSObject>& object, const JSExecutionContext& context);
650 
ParseChainedAsymmetricTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)651 RefPtr<NG::ChainedTransitionEffect> ParseChainedAsymmetricTransition(
652     const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
653 {
654     if (effectOption->IsObject()) {
655         auto effectObj = Framework::JSRef<Framework::JSObject>::Cast(effectOption);
656         auto appearJsVal = effectObj->GetProperty("appear");
657         auto disappearJsVal = effectObj->GetProperty("disappear");
658         RefPtr<NG::ChainedTransitionEffect> appearEffect;
659         RefPtr<NG::ChainedTransitionEffect> disappearEffect;
660         if (appearJsVal->IsObject()) {
661             auto appearObj = Framework::JSRef<Framework::JSObject>::Cast(appearJsVal);
662             appearEffect = ParseChainedTransition(appearObj, context);
663         }
664         if (disappearJsVal->IsObject()) {
665             auto disappearObj = Framework::JSRef<Framework::JSObject>::Cast(disappearJsVal);
666             disappearEffect = ParseChainedTransition(disappearObj, context);
667         }
668         return AceType::MakeRefPtr<NG::ChainedAsymmetricEffect>(appearEffect, disappearEffect);
669     }
670     return nullptr;
671 }
672 
GetFormAnimationTimeInterval(const RefPtr<PipelineBase> & pipelineContext)673 int64_t GetFormAnimationTimeInterval(const RefPtr<PipelineBase>& pipelineContext)
674 {
675     CHECK_NULL_RETURN(pipelineContext, 0);
676     return (GetMicroTickCount() - pipelineContext->GetFormAnimationStartTime()) / MICROSEC_TO_MILLISEC;
677 }
678 
679 using ChainedTransitionEffectCreator = RefPtr<NG::ChainedTransitionEffect> (*)(
680     const Framework::JSRef<Framework::JSVal>&, const JSExecutionContext&);
681 
GetAnimationOptionResult(shared_ptr<AnimationOption> & animationOptionResult,const JSRef<JSObject> & propAnimationOption,const RefPtr<PipelineBase> & pipelineContext,const JSExecutionContext & context)682 void GetAnimationOptionResult(shared_ptr<AnimationOption>& animationOptionResult,
683     const JSRef<JSObject>& propAnimationOption, const RefPtr<PipelineBase>& pipelineContext,
684     const JSExecutionContext& context)
685 {
686     // The maximum of the form-animation-playback duration value is 1000 ms.
687     if (pipelineContext->IsFormRender() && pipelineContext->IsFormAnimation()) {
688         auto formAnimationTimeInterval = GetFormAnimationTimeInterval(pipelineContext);
689         // If the duration exceeds 1000ms, init it to 0 ms.
690         if (formAnimationTimeInterval > DEFAULT_DURATION) {
691             animationOptionResult->SetDuration(0);
692         } else if (animationOptionResult->GetDuration() > (DEFAULT_DURATION - formAnimationTimeInterval)) {
693             // If remaining time is less than 1000ms, check for update duration.
694             animationOptionResult->SetDuration(DEFAULT_DURATION - formAnimationTimeInterval);
695             TAG_LOGI(AceLogTag::ACE_FORM, "[Form animation]  Form Transition SetDuration: %{public}lld ms",
696                 static_cast<long long>(DEFAULT_DURATION - formAnimationTimeInterval));
697         }
698     }
699     auto animationOptionObj = Framework::JSRef<Framework::JSObject>::Cast(propAnimationOption);
700     Framework::JSRef<Framework::JSVal> onFinish = animationOptionObj->GetProperty("onFinish");
701     if (onFinish->IsFunction()) {
702         RefPtr<JsFunction> jsFunc =
703             AceType::MakeRefPtr<JsFunction>(Framework::JSRef<Framework::JSObject>(), JSRef<JSFunc>::Cast(onFinish));
704         std::function<void()> onFinishEvent = [execCtx = context, func = std::move(jsFunc),
705                                                   id = Container::CurrentId()]() {
706             ContainerScope scope(id);
707             JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
708             func->Execute();
709         };
710         animationOptionResult->SetOnFinishEvent(onFinishEvent);
711     }
712 }
713 
ParseChainedTransition(const Framework::JSRef<Framework::JSObject> & object,const JSExecutionContext & context)714 RefPtr<NG::ChainedTransitionEffect> ParseChainedTransition(
715     const Framework::JSRef<Framework::JSObject>& object, const JSExecutionContext& context)
716 {
717     auto propType = object->GetProperty("type_");
718     if (!propType->IsString()) {
719         return nullptr;
720     }
721     std::string type = propType->ToString();
722     auto propEffectOption = object->GetProperty("effect_");
723     auto propAnimationOption = object->GetProperty("animation_");
724     auto propSuccessor = object->GetProperty("successor_");
725     static const LinearMapNode<ChainedTransitionEffectCreator> creatorMap[] = {
726         { "asymmetric", ParseChainedAsymmetricTransition },
727         { "identity",
728             [](const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
729                 -> RefPtr<NG::ChainedTransitionEffect> { return AceType::MakeRefPtr<NG::ChainedIdentityEffect>(); } },
730         { "move", ParseChainedMoveTransition },
731         { "opacity", ParseChainedOpacityTransition },
732         { "rotate", ParseChainedRotateTransition },
733         { "scale", ParseChainedScaleTransition },
734         { "slideSwitch",
735             [](const Framework::JSRef<Framework::JSVal>& effectOption,
736                 const JSExecutionContext& context) -> RefPtr<NG::ChainedTransitionEffect> {
737                 return AceType::MakeRefPtr<NG::ChainedSlideSwitchEffect>();
738             } },
739         { "translate", ParseChainedTranslateTransition },
740     };
741     int64_t index = BinarySearchFindIndex(creatorMap, ArraySize(creatorMap), type.c_str());
742     if (index < 0) {
743         return nullptr;
744     }
745     RefPtr<NG::ChainedTransitionEffect> result = creatorMap[index].value(propEffectOption, context);
746     if (!result) {
747         return nullptr;
748     }
749     if (propAnimationOption->IsObject()) {
750         auto container = Container::Current();
751         CHECK_NULL_RETURN(container, nullptr);
752         auto pipelineContext = container->GetPipelineContext();
753         CHECK_NULL_RETURN(pipelineContext, nullptr);
754         auto animationOptionResult = std::make_shared<AnimationOption>(
755             JSViewContext::CreateAnimation(propAnimationOption, pipelineContext->IsFormRender()));
756         GetAnimationOptionResult(animationOptionResult, propAnimationOption, pipelineContext, context);
757         result->SetAnimationOption(animationOptionResult);
758     }
759     if (propSuccessor->IsObject()) {
760         result->SetNext(ParseChainedTransition(Framework::JSRef<Framework::JSObject>::Cast(propSuccessor), context));
761     }
762     return result;
763 }
764 
ParseJsTransition(const Framework::JSRef<Framework::JSVal> & transitionArgs)765 NG::TransitionOptions ParseJsTransition(const Framework::JSRef<Framework::JSVal>& transitionArgs)
766 {
767     NG::TransitionOptions transitionOption;
768     if (!transitionArgs->IsObject()) {
769         return transitionOption;
770     }
771     Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(transitionArgs);
772     bool hasEffect = false;
773     transitionOption.Type = ParseTransitionType(jsObj->GetPropertyValue<std::string>("type", "All"));
774     if (jsObj->HasProperty("opacity")) {
775         double opacity = 1.0;
776         Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("opacity"), opacity);
777         opacity = std::clamp(opacity, 0.0, 1.0);
778         transitionOption.UpdateOpacity(static_cast<float>(opacity));
779         hasEffect = true;
780     }
781     if (jsObj->HasProperty("translate")) {
782         // default: x, y, z (0.0, 0.0, 0.0)
783         NG::TranslateOptions translate;
784         ParseJsTranslate(jsObj->GetProperty("translate"), translate.x, translate.y, translate.z);
785         transitionOption.UpdateTranslate(translate);
786         hasEffect = true;
787     }
788     if (jsObj->HasProperty("scale")) {
789         // default: x, y, z (1.0, 1.0, 1.0), centerX, centerY 50% 50%;
790         NG::ScaleOptions scale(1.0f, 1.0f, 1.0f, 0.5_pct, 0.5_pct);
791         ParseJsScale(
792             jsObj->GetProperty("scale"), scale.xScale, scale.yScale, scale.zScale, scale.centerX, scale.centerY);
793         transitionOption.UpdateScale(scale);
794         hasEffect = true;
795     }
796     if (jsObj->HasProperty("rotate")) {
797         // default: dx, dy, dz (0.0, 0.0, 0.0), angle 0, centerX, centerY 50% 50%;
798         NG::RotateOptions rotate(0.0f, 0.0f, 0.0f, 0.0f, 0.5_pct, 0.5_pct);
799         std::optional<float> angle;
800         ParseJsRotate(jsObj->GetProperty("rotate"), rotate, angle);
801         if (angle.has_value()) {
802             rotate.angle = angle.value();
803             transitionOption.UpdateRotate(rotate);
804             hasEffect = true;
805         }
806     }
807     if (!hasEffect) {
808         // default transition
809         transitionOption = NG::TransitionOptions::GetDefaultTransition(transitionOption.Type);
810     }
811     return transitionOption;
812 }
813 
ParseMotionPath(const Framework::JSRef<Framework::JSVal> & jsValue,MotionPathOption & option)814 bool ParseMotionPath(const Framework::JSRef<Framework::JSVal>& jsValue, MotionPathOption& option)
815 {
816     if (!jsValue->IsObject()) {
817         return false;
818     }
819 
820     Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
821     auto path = jsObj->GetPropertyValue<std::string>("path", "");
822     if (path.empty()) {
823         return false;
824     }
825     option.SetPath(path);
826     double from = 0.0;
827     double to = 1.0;
828     Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("from"), from);
829     Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("to"), to);
830     if (GreatNotEqual(from, 1.0) || LessNotEqual(from, 0.0)) {
831         from = 0.0;
832     }
833     if (GreatNotEqual(to, 1.0) || LessNotEqual(to, 0.0)) {
834         to = 1.0;
835     } else if (to < from) {
836         to = from;
837     }
838     option.SetBegin(static_cast<float>(from));
839     option.SetEnd(static_cast<float>(to));
840     option.SetRotate(jsObj->GetPropertyValue<bool>("rotatable", false));
841     return true;
842 }
843 
ParseJsDoublePair(const EcmaVM * vm,const Local<JSValueRef> & value,ArkUI_Float32 & first,ArkUI_Float32 & second)844 bool ParseJsDoublePair(const EcmaVM *vm, const Local<JSValueRef> &value, ArkUI_Float32 &first, ArkUI_Float32 &second)
845 {
846     if (!value->IsArray(vm)) {
847         return false;
848     }
849     auto array = panda::Local<panda::ArrayRef>(value);
850     if (array->Length(vm) != NUM_2) {
851         return false;
852     }
853     auto firstArg = panda::ArrayRef::GetValueAt(vm, array, NUM_0);
854     if (!firstArg->IsNumber()) {
855         return false;
856     }
857     auto secondArg = panda::ArrayRef::GetValueAt(vm, array, NUM_1);
858     if (!secondArg->IsNumber()) {
859         return false;
860     }
861     first = static_cast<ArkUI_Float32>(firstArg->ToNumber(vm)->Value());
862     second = static_cast<ArkUI_Float32>(secondArg->ToNumber(vm)->Value());
863     return true;
864 }
865 
ParseGradientCenter(const EcmaVM * vm,const Local<JSValueRef> & value,std::vector<ArkUIInt32orFloat32> & values)866 void ParseGradientCenter(const EcmaVM* vm, const Local<JSValueRef>& value, std::vector<ArkUIInt32orFloat32>& values)
867 {
868     bool hasValueX = false;
869     bool hasValueY = false;
870     CalcDimension valueX;
871     CalcDimension valueY;
872     if (value->IsArray(vm)) {
873         auto array = panda::Local<panda::ArrayRef>(value);
874         auto length = array->Length(vm);
875         if (length == NUM_2) {
876             hasValueX =
877                 ArkTSUtils::ParseJsDimensionVp(vm, panda::ArrayRef::GetValueAt(vm, array, NUM_0), valueX, false);
878             hasValueY =
879                 ArkTSUtils::ParseJsDimensionVp(vm, panda::ArrayRef::GetValueAt(vm, array, NUM_1), valueY, false);
880         }
881     }
882     values.push_back({.i32 = static_cast<ArkUI_Int32>(hasValueX)});
883     values.push_back({.f32 = static_cast<ArkUI_Float32>(valueX.Value())});
884     values.push_back({.i32 = static_cast<ArkUI_Int32>(valueX.Unit())});
885     values.push_back({.i32 = static_cast<ArkUI_Int32>(hasValueY)});
886     values.push_back({.f32 = static_cast<ArkUI_Float32>(valueY.Value())});
887     values.push_back({.i32 = static_cast<ArkUI_Int32>(valueY.Unit())});
888 }
889 
PushOuterBorderDimensionVector(const std::optional<CalcDimension> & valueDim,std::vector<ArkUI_Float32> & options)890 void PushOuterBorderDimensionVector(const std::optional<CalcDimension>& valueDim, std::vector<ArkUI_Float32> &options)
891 {
892     options.push_back(static_cast<ArkUI_Float32>(valueDim.has_value()));
893     if (valueDim.has_value()) {
894         options.push_back(static_cast<ArkUI_Float32>(valueDim.value().Value()));
895         options.push_back(static_cast<ArkUI_Float32>(valueDim.value().Unit()));
896     } else {
897         options.push_back(0);
898         options.push_back(0);
899     }
900 }
901 
ParseOuterBorderWidth(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values,bool needLocalized=false)902 void ParseOuterBorderWidth(
903     ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<ArkUI_Float32>& values, bool needLocalized = false)
904 {
905     Local<JSValueRef> leftArgs = runtimeCallInfo->GetCallArgRef(NUM_1);
906     Local<JSValueRef> rightArgs = runtimeCallInfo->GetCallArgRef(NUM_2);
907     Local<JSValueRef> topArgs = runtimeCallInfo->GetCallArgRef(NUM_3);
908     Local<JSValueRef> bottomArgs = runtimeCallInfo->GetCallArgRef(NUM_4);
909 
910     std::optional<CalcDimension> leftDim;
911     std::optional<CalcDimension> rightDim;
912     std::optional<CalcDimension> topDim;
913     std::optional<CalcDimension> bottomDim;
914     std::optional<CalcDimension> startDim;
915     std::optional<CalcDimension> endDim;
916 
917     ArkTSUtils::ParseOuterBorder(vm, leftArgs, leftDim);
918     ArkTSUtils::ParseOuterBorder(vm, rightArgs, rightDim);
919     if (needLocalized) {
920         Local<JSValueRef> startArgs = runtimeCallInfo->GetCallArgRef(25); // 25: index of BorderWidth.start
921         Local<JSValueRef> endArgs = runtimeCallInfo->GetCallArgRef(26);   // 26: index of BorderWidth.end
922         ArkTSUtils::ParseOuterBorderForDashParams(vm, startArgs, startDim);
923         ArkTSUtils::ParseOuterBorderForDashParams(vm, endArgs, endDim);
924         ArkTSUtils::ParseOuterBorderForDashParams(vm, topArgs, topDim);
925         ArkTSUtils::ParseOuterBorderForDashParams(vm, bottomArgs, bottomDim);
926     } else {
927         ArkTSUtils::ParseOuterBorder(vm, topArgs, topDim);
928         ArkTSUtils::ParseOuterBorder(vm, bottomArgs, bottomDim);
929     }
930 
931     if (startDim.has_value() || endDim.has_value()) {
932         PushOuterBorderDimensionVector(startDim, values);
933         PushOuterBorderDimensionVector(endDim, values);
934     } else {
935         PushOuterBorderDimensionVector(leftDim, values);
936         PushOuterBorderDimensionVector(rightDim, values);
937     }
938     PushOuterBorderDimensionVector(topDim, values);
939     PushOuterBorderDimensionVector(bottomDim, values);
940 }
941 
PushOuterBorderColorVector(const std::optional<Color> & valueColor,std::vector<uint32_t> & options)942 void PushOuterBorderColorVector(const std::optional<Color>& valueColor, std::vector<uint32_t> &options)
943 {
944     options.push_back(static_cast<uint32_t>(valueColor.has_value()));
945     if (valueColor.has_value()) {
946         options.push_back(static_cast<uint32_t>(valueColor.value().GetValue()));
947     } else {
948         options.push_back(0);
949     }
950 }
ParseOuterBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<uint32_t> & values,int32_t argsIndex,bool needLocalized=false)951 void ParseOuterBorderColor(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<uint32_t>& values,
952     int32_t argsIndex, bool needLocalized = false)
953 {
954     Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(argsIndex);
955     Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
956     Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
957     Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
958 
959     std::optional<Color> leftColor;
960     std::optional<Color> rightColor;
961     std::optional<Color> topColor;
962     std::optional<Color> bottomColor;
963     std::optional<Color> startColor;
964     std::optional<Color> endColor;
965 
966     Color left;
967     if (!leftArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, leftArg, left)) {
968         leftColor = left;
969     }
970     Color right;
971     if (!rightArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, rightArg, right)) {
972         rightColor = right;
973     }
974     Color top;
975     if (!topArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, topArg, top)) {
976         topColor = top;
977     }
978     Color bottom;
979     if (!bottomArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, bottomArg, bottom)) {
980         bottomColor = bottom;
981     }
982     if (needLocalized) {
983         Local<JSValueRef> startArgs = runtimeCallInfo->GetCallArgRef(27); // 27: index of BorderColor.startColor
984         Local<JSValueRef> endArgs = runtimeCallInfo->GetCallArgRef(28);   // 28: index of BorderColor.endColor
985         Color start;
986         if (!startArgs->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, startArgs, start)) {
987             startColor = start;
988         }
989         Color end;
990         if (!endArgs->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, endArgs, end)) {
991             endColor = end;
992         }
993     }
994     if (startColor.has_value() || endColor.has_value()) {
995         PushOuterBorderColorVector(startColor, values);
996         PushOuterBorderColorVector(endColor, values);
997     } else {
998         PushOuterBorderColorVector(leftColor, values);
999         PushOuterBorderColorVector(rightColor, values);
1000     }
1001     PushOuterBorderColorVector(topColor, values);
1002     PushOuterBorderColorVector(bottomColor, values);
1003 }
1004 
ParseLocalizedBorderRadius(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & result)1005 bool ParseLocalizedBorderRadius(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& result)
1006 {
1007     if (ArkTSUtils::ParseJsLengthMetrics(vm, value, result)) {
1008         if (result.IsNegative()) {
1009             result.Reset();
1010         }
1011         return true;
1012     }
1013     return false;
1014 }
1015 
ParseOuterBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values,int32_t argsIndex,bool needLocalized=false)1016 void ParseOuterBorderRadius(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<ArkUI_Float32>& values,
1017     int32_t argsIndex, bool needLocalized = false)
1018 {
1019     Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(argsIndex);
1020     Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
1021     Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
1022     Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
1023     if (needLocalized) {
1024         Local<JSValueRef> topStartArgs = runtimeCallInfo->GetCallArgRef(29);    // 29: index of BorderRadius.topStart
1025         Local<JSValueRef> topEndArgs = runtimeCallInfo->GetCallArgRef(30);      // 30: index of BorderRadius.topEnd
1026         Local<JSValueRef> bottomStartArgs = runtimeCallInfo->GetCallArgRef(31); // 31: index of BorderRadius.bottomStart
1027         Local<JSValueRef> bottomEndArgs = runtimeCallInfo->GetCallArgRef(32);   // 32: index of BorderRadius.bottomEnd
1028         // 35: index of is LocalizedBorderRadius or not
1029         Local<JSValueRef> isLocalizedBorderRadiusArg = runtimeCallInfo->GetCallArgRef(35);
1030         bool isLocalizedBorderRadius =
1031             (isLocalizedBorderRadiusArg->IsBoolean()) ? isLocalizedBorderRadiusArg->ToBoolean(vm)->Value() : false;
1032         if (isLocalizedBorderRadius) {
1033             CalcDimension topStartOptional;
1034             CalcDimension topEndOptional;
1035             CalcDimension bottomStartOptional;
1036             CalcDimension bottomEndOptional;
1037             ParseLocalizedBorderRadius(vm, topStartArgs, topStartOptional);
1038             ParseLocalizedBorderRadius(vm, topEndArgs, topEndOptional);
1039             ParseLocalizedBorderRadius(vm, bottomStartArgs, bottomStartOptional);
1040             ParseLocalizedBorderRadius(vm, bottomEndArgs, bottomEndOptional);
1041             PushOuterBorderDimensionVector(topStartOptional, values);
1042             PushOuterBorderDimensionVector(topEndOptional, values);
1043             PushOuterBorderDimensionVector(bottomStartOptional, values);
1044             PushOuterBorderDimensionVector(bottomEndOptional, values);
1045             return;
1046         }
1047     }
1048 
1049     std::optional<CalcDimension> topLeftOptional;
1050     std::optional<CalcDimension> topRightOptional;
1051     std::optional<CalcDimension> bottomLeftOptional;
1052     std::optional<CalcDimension> bottomRightOptional;
1053 
1054     ArkTSUtils::ParseOuterBorder(vm, topLeftArgs, topLeftOptional);
1055     ArkTSUtils::ParseOuterBorder(vm, topRightArgs, topRightOptional);
1056     ArkTSUtils::ParseOuterBorder(vm, bottomLeftArgs, bottomLeftOptional);
1057     ArkTSUtils::ParseOuterBorder(vm, bottomRightArgs, bottomRightOptional);
1058 
1059     PushOuterBorderDimensionVector(topLeftOptional, values);
1060     PushOuterBorderDimensionVector(topRightOptional, values);
1061     PushOuterBorderDimensionVector(bottomLeftOptional, values);
1062     PushOuterBorderDimensionVector(bottomRightOptional, values);
1063 }
1064 
PushOuterBorderStyleVector(const std::optional<BorderStyle> & value,std::vector<uint32_t> & options)1065 void PushOuterBorderStyleVector(const std::optional<BorderStyle>& value, std::vector<uint32_t> &options)
1066 {
1067     options.push_back(static_cast<uint32_t>(value.has_value()));
1068     if (value.has_value()) {
1069         options.push_back(static_cast<uint32_t>(value.value()));
1070     } else {
1071         options.push_back(0);
1072     }
1073 }
1074 
ParseOuterBorderStyle(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<uint32_t> & values,int32_t argsIndex)1075 void ParseOuterBorderStyle(
1076     ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<uint32_t>& values, int32_t argsIndex)
1077 {
1078     std::optional<BorderStyle> styleLeft;
1079     std::optional<BorderStyle> styleRight;
1080     std::optional<BorderStyle> styleTop;
1081     std::optional<BorderStyle> styleBottom;
1082 
1083     auto topArg = runtimeCallInfo->GetCallArgRef(argsIndex);
1084     auto rightArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
1085     auto bottomArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
1086     auto leftArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
1087 
1088     if (!topArg->IsUndefined() && topArg->IsNumber()) {
1089         styleTop = ConvertBorderStyle(topArg->Int32Value(vm));
1090     }
1091     if (!rightArg->IsUndefined() && rightArg->IsNumber()) {
1092         styleRight = ConvertBorderStyle(rightArg->Int32Value(vm));
1093     }
1094     if (!bottomArg->IsUndefined() && bottomArg->IsNumber()) {
1095         styleBottom = ConvertBorderStyle(bottomArg->Int32Value(vm));
1096     }
1097     if (!leftArg->IsUndefined() && leftArg->IsNumber()) {
1098         styleLeft = ConvertBorderStyle(leftArg->Int32Value(vm));
1099     }
1100 
1101     PushOuterBorderStyleVector(styleLeft, values);
1102     PushOuterBorderStyleVector(styleRight, values);
1103     PushOuterBorderStyleVector(styleTop, values);
1104     PushOuterBorderStyleVector(styleBottom, values);
1105 }
1106 
ParseOuterBorderDashParam(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values,int32_t argsIndex)1107 void ParseOuterBorderDashParam(ArkUIRuntimeCallInfo *runtimeCallInfo, EcmaVM *vm, std::vector<ArkUI_Float32> &values,
1108     int32_t argsIndex)
1109 {
1110     Local<JSValueRef> leftArgs = runtimeCallInfo->GetCallArgRef(argsIndex);
1111     Local<JSValueRef> rightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
1112     Local<JSValueRef> topArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
1113     Local<JSValueRef> bottomArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
1114     std::optional<CalcDimension> leftDim;
1115     std::optional<CalcDimension> rightDim;
1116     std::optional<CalcDimension> topDim;
1117     std::optional<CalcDimension> bottomDim;
1118 
1119     ArkTSUtils::ParseOuterBorderForDashParams(vm, leftArgs, leftDim);
1120     ArkTSUtils::ParseOuterBorderForDashParams(vm, rightArgs, rightDim);
1121     ArkTSUtils::ParseOuterBorderForDashParams(vm, topArgs, topDim);
1122     ArkTSUtils::ParseOuterBorderForDashParams(vm, bottomArgs, bottomDim);
1123 
1124     PushOuterBorderDimensionVector(leftDim, values);
1125     PushOuterBorderDimensionVector(rightDim, values);
1126     PushOuterBorderDimensionVector(topDim, values);
1127     PushOuterBorderDimensionVector(bottomDim, values);
1128 }
1129 
SetBackgroundImagePositionAlign(double & value,DimensionUnit & type,double valueContent,const DimensionUnit & typeContent)1130 void SetBackgroundImagePositionAlign(double &value, DimensionUnit &type, double valueContent,
1131     const DimensionUnit &typeContent)
1132 {
1133     value = valueContent;
1134     type = typeContent;
1135 }
1136 
ParseBackgroundImagePositionAlign(const int32_t align,double & valueX,double & valueY,DimensionUnit & typeX,DimensionUnit & typeY)1137 void ParseBackgroundImagePositionAlign(const int32_t align, double &valueX, double &valueY, DimensionUnit &typeX,
1138     DimensionUnit &typeY)
1139 {
1140     switch (align) {
1141         case NUM_0:
1142             SetBackgroundImagePositionAlign(valueX, typeX, 0.0, DimensionUnit::PERCENT);
1143             SetBackgroundImagePositionAlign(valueY, typeY, 0.0, DimensionUnit::PERCENT);
1144             break;
1145         case NUM_1:
1146             SetBackgroundImagePositionAlign(valueX, typeX, HALF_DIMENSION, DimensionUnit::PERCENT);
1147             SetBackgroundImagePositionAlign(valueY, typeY, 0.0, DimensionUnit::PERCENT);
1148             break;
1149         case NUM_2:
1150             SetBackgroundImagePositionAlign(valueX, typeX, FULL_DIMENSION, DimensionUnit::PERCENT);
1151             SetBackgroundImagePositionAlign(valueY, typeY, 0.0, DimensionUnit::PERCENT);
1152             break;
1153         case NUM_3:
1154             SetBackgroundImagePositionAlign(valueX, typeX, 0.0, DimensionUnit::PERCENT);
1155             SetBackgroundImagePositionAlign(valueY, typeY, HALF_DIMENSION, DimensionUnit::PERCENT);
1156             break;
1157         case NUM_4:
1158             SetBackgroundImagePositionAlign(valueX, typeX, HALF_DIMENSION, DimensionUnit::PERCENT);
1159             SetBackgroundImagePositionAlign(valueY, typeY, HALF_DIMENSION, DimensionUnit::PERCENT);
1160             break;
1161         case NUM_5:
1162             SetBackgroundImagePositionAlign(valueX, typeX, FULL_DIMENSION, DimensionUnit::PERCENT);
1163             SetBackgroundImagePositionAlign(valueY, typeY, HALF_DIMENSION, DimensionUnit::PERCENT);
1164             break;
1165         case NUM_6:
1166             SetBackgroundImagePositionAlign(valueX, typeX, 0.0, DimensionUnit::PERCENT);
1167             SetBackgroundImagePositionAlign(valueY, typeY, FULL_DIMENSION, DimensionUnit::PERCENT);
1168             break;
1169         case NUM_7:
1170             SetBackgroundImagePositionAlign(valueX, typeX, HALF_DIMENSION, DimensionUnit::PERCENT);
1171             SetBackgroundImagePositionAlign(valueY, typeY, FULL_DIMENSION, DimensionUnit::PERCENT);
1172             break;
1173         case NUM_8:
1174             SetBackgroundImagePositionAlign(valueX, typeX, FULL_DIMENSION, DimensionUnit::PERCENT);
1175             SetBackgroundImagePositionAlign(valueY, typeY, FULL_DIMENSION, DimensionUnit::PERCENT);
1176             break;
1177         default:
1178             break;
1179     }
1180 }
1181 
ParseAxisDimensionVp(const EcmaVM * vm,const Local<JSValueRef> & jsValue,CalcDimension & result,bool checkIllegal=false)1182 bool ParseAxisDimensionVp(const EcmaVM *vm, const Local<JSValueRef> &jsValue, CalcDimension &result,
1183     bool checkIllegal = false)
1184 {
1185     if (jsValue->IsNumber()) {
1186         result = Dimension(jsValue->ToNumber(vm)->Value(), DimensionUnit::VP);
1187         return true;
1188     }
1189     if (jsValue->IsString(vm)) {
1190         if (checkIllegal) {
1191             return StringUtils::StringToDimensionWithUnitNG(jsValue->ToString(vm)->ToString(vm), result,
1192                 DimensionUnit::VP);
1193         }
1194         result = StringUtils::StringToCalcDimension(jsValue->ToString(vm)->ToString(vm), false, DimensionUnit::VP);
1195         return true;
1196     }
1197     return false;
1198 }
1199 
ParseDirection(EcmaVM * vm,const Local<JSValueRef> & directionArg,float & value)1200 void ParseDirection(EcmaVM *vm, const Local<JSValueRef> &directionArg, float &value)
1201 {
1202     if (directionArg->IsNumber()) {
1203         value = directionArg->ToNumber(vm)->Value();
1204     }
1205 }
1206 
GetJsAngle(const EcmaVM * vm,const Local<JSValueRef> & angleArg,std::optional<float> & angle)1207 void GetJsAngle(const EcmaVM* vm, const Local<JSValueRef>& angleArg, std::optional<float>& angle)
1208 {
1209     if (angleArg->IsString(vm)) {
1210         angle = static_cast<float>(StringUtils::StringToDegree(angleArg->ToString(vm)->ToString(vm)));
1211     } else if (angleArg->IsNumber()) {
1212         angle = static_cast<float>(angleArg->ToNumber(vm)->Value());
1213     } else {
1214         LOGE("Invalid value type");
1215     }
1216 }
1217 
ParseCenterDimension(const EcmaVM * vm,const Local<JSValueRef> & centerArg,CalcDimension & centerDimension)1218 void ParseCenterDimension(const EcmaVM* vm, const Local<JSValueRef>& centerArg, CalcDimension& centerDimension)
1219 {
1220     if (!ArkTSUtils::ParseJsDimensionVp(vm, centerArg, centerDimension, false)) {
1221         centerDimension = Dimension(0.5f, DimensionUnit::PERCENT);
1222     }
1223 }
1224 
ParseRotate(ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUI_Float32 values[],int units[],int valuesLength,int unitsLength)1225 bool ParseRotate(ArkUIRuntimeCallInfo *runtimeCallInfo, ArkUI_Float32 values[], int units[],
1226     int valuesLength, int unitsLength)
1227 {
1228     if (valuesLength != SIZE_OF_EIGHT || unitsLength != SIZE_OF_THREE) {
1229         return false;
1230     }
1231     EcmaVM *vm = runtimeCallInfo->GetVM();
1232     Local<JSValueRef> xDirectionArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1233     Local<JSValueRef> yDirectionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1234     Local<JSValueRef> zDirectionArg = runtimeCallInfo->GetCallArgRef(NUM_3);
1235     Local<JSValueRef> angleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
1236     Local<JSValueRef> centerXArg = runtimeCallInfo->GetCallArgRef(NUM_5);
1237     Local<JSValueRef> centerYArg = runtimeCallInfo->GetCallArgRef(NUM_6);
1238     Local<JSValueRef> centerZArg = runtimeCallInfo->GetCallArgRef(NUM_7);
1239     Local<JSValueRef> perspectiveArg = runtimeCallInfo->GetCallArgRef(NUM_8);
1240     float xDirection = 0.0f;
1241     float yDirection = 0.0f;
1242     float zDirection = 0.0f;
1243     float angle = 0.0f;
1244     std::optional<float> angleOptional;
1245     CalcDimension centerX = 0.5_pct;
1246     CalcDimension centerY = 0.5_pct;
1247     CalcDimension centerZ = CalcDimension(0.0f, DimensionUnit::VP);
1248     GetJsAngle(vm, angleArg, angleOptional);
1249     if (!angleOptional) {
1250         return false;
1251     }
1252     angle = angleOptional.value();
1253     double perspective = 0.0;
1254     if (!xDirectionArg->IsNumber() && !yDirectionArg->IsNumber() && !zDirectionArg->IsNumber()) {
1255         zDirection = 1.0f;
1256     }
1257     ParseDirection(vm, xDirectionArg, xDirection);
1258     ParseDirection(vm, yDirectionArg, yDirection);
1259     ParseDirection(vm, zDirectionArg, zDirection);
1260     ParseCenterDimension(vm, centerXArg, centerX);
1261     ParseCenterDimension(vm, centerYArg, centerY);
1262     ParseCenterDimension(vm, centerZArg, centerZ);
1263     ArkTSUtils::ParseJsDouble(vm, perspectiveArg, perspective);
1264     values[NUM_0] = static_cast<ArkUI_Float32>(centerX.Value());
1265     units[NUM_0] = static_cast<int>(centerX.Unit());
1266     values[NUM_1] = static_cast<ArkUI_Float32>(centerY.Value());
1267     units[NUM_1] = static_cast<int>(centerY.Unit());
1268     values[NUM_2] = static_cast<ArkUI_Float32>(centerZ.Value());
1269     units[NUM_2] = static_cast<int>(centerZ.Unit());
1270     values[NUM_3] = static_cast<ArkUI_Float32>(xDirection);
1271     values[NUM_4] = static_cast<ArkUI_Float32>(yDirection);
1272     values[NUM_5] = static_cast<ArkUI_Float32>(zDirection);
1273     values[NUM_6] = static_cast<ArkUI_Float32>(angle);
1274     values[NUM_7] = static_cast<ArkUI_Float32>(perspective);
1275     return true;
1276 }
1277 
ParseBlurOption(const EcmaVM * vm,const Local<JSValueRef> blurOptionsArg,BlurOption & blurOption)1278 void ParseBlurOption(const EcmaVM* vm, const Local<JSValueRef> blurOptionsArg, BlurOption& blurOption)
1279 {
1280     if (blurOptionsArg->IsArray(vm)) {
1281         Local<panda::ArrayRef> params = static_cast<Local<panda::ArrayRef>>(blurOptionsArg);
1282         auto grey1 = params->GetValueAt(vm, blurOptionsArg, 0)->Uint32Value(vm);
1283         auto grey2 = params->GetValueAt(vm, blurOptionsArg, 1)->Uint32Value(vm);
1284         std::vector<float> greyVec(2);
1285         greyVec[0] = grey1;
1286         greyVec[1] = grey2;
1287         blurOption.grayscale = greyVec;
1288     }
1289 }
1290 
ParseDynamicBrightnessOption(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,ArkUI_Float32 & rate,ArkUI_Float32 & lightUpDegree,ArkUI_Float32 & cubicCoeff,ArkUI_Float32 & quadCoeff,ArkUI_Float32 & saturation,std::vector<float> & posRGB,std::vector<float> & negRGB,ArkUI_Float32 & fraction)1291 void ParseDynamicBrightnessOption(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm,
1292     ArkUI_Float32& rate, ArkUI_Float32& lightUpDegree, ArkUI_Float32& cubicCoeff, ArkUI_Float32& quadCoeff,
1293     ArkUI_Float32& saturation, std::vector<float>& posRGB, std::vector<float>& negRGB, ArkUI_Float32& fraction)
1294 {
1295     Local<JSValueRef> rateArg = runtimeCallInfo->GetCallArgRef(1);
1296     Local<JSValueRef> lightUpDegreeArg = runtimeCallInfo->GetCallArgRef(2);
1297     Local<JSValueRef> cubicCoeffArg = runtimeCallInfo->GetCallArgRef(3);
1298     Local<JSValueRef> quadCoeffArg = runtimeCallInfo->GetCallArgRef(4);
1299     Local<JSValueRef> saturationArg = runtimeCallInfo->GetCallArgRef(5);
1300     Local<JSValueRef> posRGBArg = runtimeCallInfo->GetCallArgRef(6);
1301     Local<JSValueRef> negRGBArg = runtimeCallInfo->GetCallArgRef(7);
1302     Local<JSValueRef> fractionArg = runtimeCallInfo->GetCallArgRef(8);
1303     if (rateArg->IsNumber()) {
1304         rate = rateArg->ToNumber(vm)->Value();
1305     }
1306     if (lightUpDegreeArg->IsNumber()) {
1307         lightUpDegree = lightUpDegreeArg->ToNumber(vm)->Value();
1308     }
1309     if (cubicCoeffArg->IsNumber()) {
1310         cubicCoeff = cubicCoeffArg->ToNumber(vm)->Value();
1311     }
1312     if (quadCoeffArg->IsNumber()) {
1313         quadCoeff = quadCoeffArg->ToNumber(vm)->Value();
1314     }
1315     if (saturationArg->IsNumber()) {
1316         saturation = saturationArg->ToNumber(vm)->Value();
1317     }
1318     if (posRGBArg->IsArray(vm)) {
1319         Local<panda::ArrayRef> params = static_cast<Local<panda::ArrayRef>>(posRGBArg);
1320         auto r = params->GetValueAt(vm, posRGBArg, 0)->Uint32Value(vm);
1321         auto g = params->GetValueAt(vm, posRGBArg, 1)->Uint32Value(vm);
1322         auto b = params->GetValueAt(vm, posRGBArg, 2)->Uint32Value(vm);
1323         posRGB[0] = r;
1324         posRGB[1] = g;
1325         posRGB[2] = b;
1326     }
1327     if (negRGBArg->IsArray(vm)) {
1328         Local<panda::ArrayRef> params = static_cast<Local<panda::ArrayRef>>(negRGBArg);
1329         auto r = params->GetValueAt(vm, negRGBArg, 0)->Uint32Value(vm);
1330         auto g = params->GetValueAt(vm, negRGBArg, 1)->Uint32Value(vm);
1331         auto b = params->GetValueAt(vm, negRGBArg, 2)->Uint32Value(vm);
1332         negRGB[0] = r;
1333         negRGB[1] = g;
1334         negRGB[2] = b;
1335     }
1336     if (fractionArg->IsNumber()) {
1337         fraction = fractionArg->ToNumber(vm)->Value();
1338     }
1339 }
1340 
ParseCalcDimension(const EcmaVM * vm,ArkUINodeHandle node,const Local<JSValueRef> & value,CalcDimension & result,bool isWidth)1341 bool ParseCalcDimension(const EcmaVM* vm,
1342     ArkUINodeHandle node, const Local<JSValueRef>& value, CalcDimension& result, bool isWidth)
1343 {
1344     CHECK_NULL_RETURN(vm, false);
1345     bool undefined = value->IsUndefined();
1346     if (undefined) {
1347         GetArkUINodeModifiers()->getCommonModifier()->clearWidthOrHeight(node, isWidth);
1348         return true;
1349     }
1350     if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
1351         if (!ArkTSUtils::ParseJsDimensionVpNG(vm, value, result)) {
1352             GetArkUINodeModifiers()->getCommonModifier()->clearWidthOrHeight(node, isWidth);
1353             return false;
1354         }
1355     } else if (!ArkTSUtils::ParseJsDimensionVp(vm, value, result)) {
1356         return false;
1357     }
1358 
1359     if (LessNotEqual(result.Value(), 0.0)) {
1360         result.SetValue(0.0);
1361     }
1362     std::string calc = result.CalcValue();
1363     if (isWidth) {
1364         GetArkUINodeModifiers()->getCommonModifier()->setWidth(
1365             node, result.Value(), static_cast<int32_t>(result.Unit()), calc.c_str());
1366     } else {
1367         GetArkUINodeModifiers()->getCommonModifier()->setHeight(
1368             node, result.Value(), static_cast<int32_t>(result.Unit()), calc.c_str());
1369     }
1370     return true;
1371 }
1372 
ParseResizableCalcDimensions(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count,std::vector<std::optional<CalcDimension>> & results,const CalcDimension & defValue)1373 void ParseResizableCalcDimensions(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count,
1374     std::vector<std::optional<CalcDimension>>& results, const CalcDimension& defValue)
1375 {
1376     auto end = offset + count;
1377     auto argsNumber = runtimeCallInfo->GetArgsNumber();
1378     if (end > argsNumber) {
1379         return;
1380     }
1381     CalcDimension defaultDimension(defValue);
1382     EcmaVM* vm = runtimeCallInfo->GetVM();
1383     for (uint32_t index = offset; index < end; index++) {
1384         auto arg = runtimeCallInfo->GetCallArgRef(index);
1385         std::optional<CalcDimension> optCalcDimension;
1386         CalcDimension dimension(defValue);
1387         if (ArkTSUtils::ParseJsDimensionVp(vm, arg, dimension, false)) {
1388             optCalcDimension = dimension;
1389         } else {
1390             optCalcDimension = defaultDimension;
1391         }
1392         results.push_back(optCalcDimension);
1393     }
1394 }
1395 
ParseJsAlignRule(const EcmaVM * vm,const Local<JSValueRef> & arg,std::string & anchor,ArkUI_Int32 & direction)1396 bool ParseJsAlignRule(const EcmaVM* vm, const Local<JSValueRef> &arg, std::string& anchor, ArkUI_Int32 &direction)
1397 {
1398     if (arg->IsString(vm)) {
1399         std::string directionString = arg->ToString(vm)->ToString(vm);
1400         if (directionString.empty()) {
1401             return false;
1402         }
1403         size_t pos = directionString.find('|');
1404         if (pos == std::string::npos) {
1405             return false;
1406         }
1407         char* endPtr = nullptr;
1408         long alignValue = std::strtol(directionString.substr(0, pos).c_str(), &endPtr, 10);
1409         direction = static_cast<int8_t>(alignValue);
1410         anchor = directionString.substr(pos + 1);
1411         return true;
1412     }
1413     return false;
1414 }
1415 
ParseResponseRegion(const EcmaVM * vm,const Local<JSValueRef> & jsValue,ArkUI_Float32 regionValues[],int32_t regionUnits[],int32_t length)1416 bool ParseResponseRegion(const EcmaVM* vm, const Local<JSValueRef>& jsValue, ArkUI_Float32 regionValues[],
1417     int32_t regionUnits[], int32_t length)
1418 {
1419     if (jsValue->IsUndefined() || !jsValue->IsArray(vm)) {
1420         return false;
1421     }
1422 
1423     Local<panda::ArrayRef> transArray = static_cast<Local<panda::ArrayRef>>(jsValue);
1424     for (int32_t i = 0; i < length; i = i + NUM_4) {
1425         Local<JSValueRef> x = transArray->GetValueAt(vm, jsValue, i + NUM_0);
1426         Local<JSValueRef> y = transArray->GetValueAt(vm, jsValue, i + NUM_1);
1427         Local<JSValueRef> width = transArray->GetValueAt(vm, jsValue, i + NUM_2);
1428         Local<JSValueRef> height = transArray->GetValueAt(vm, jsValue, i + NUM_3);
1429         CalcDimension xDimen = CalcDimension(0.0, DimensionUnit::VP);
1430         CalcDimension yDimen = CalcDimension(0.0, DimensionUnit::VP);
1431         CalcDimension widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
1432         CalcDimension heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
1433         auto s1 = width->ToString(vm)->ToString(vm);
1434         auto s2 = height->ToString(vm)->ToString(vm);
1435         if (s1.find('-') != std::string::npos) {
1436             width = ToJSValue("100%");
1437         }
1438         if (s2.find('-') != std::string::npos) {
1439             height = ToJSValue("100%");
1440         }
1441         if (!ArkTSUtils::ParseJsDimensionNG(vm, x, xDimen, DimensionUnit::VP)) {
1442             xDimen = CalcDimension(0.0, DimensionUnit::VP);
1443         }
1444         if (!ArkTSUtils::ParseJsDimensionNG(vm, y, yDimen, DimensionUnit::VP)) {
1445             yDimen = CalcDimension(0.0, DimensionUnit::VP);
1446         }
1447         if (!ArkTSUtils::ParseJsDimensionNG(vm, width, widthDimen, DimensionUnit::VP)) {
1448             widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
1449         }
1450         if (!ArkTSUtils::ParseJsDimensionNG(vm, height, heightDimen, DimensionUnit::VP)) {
1451             heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
1452         }
1453         regionValues[i + NUM_0] = static_cast<ArkUI_Float32>(xDimen.Value());
1454         regionUnits[i + NUM_0] = static_cast<int32_t>(xDimen.Unit());
1455         regionValues[i + NUM_1] = static_cast<ArkUI_Float32>(yDimen.Value());
1456         regionUnits[i + NUM_1] = static_cast<int32_t>(yDimen.Unit());
1457         regionValues[i + NUM_2] = static_cast<ArkUI_Float32>(widthDimen.Value());
1458         regionUnits[i + NUM_2] = static_cast<int32_t>(widthDimen.Unit());
1459         regionValues[i + NUM_3] = static_cast<ArkUI_Float32>(heightDimen.Value());
1460         regionUnits[i + NUM_3] = static_cast<int32_t>(heightDimen.Unit());
1461     }
1462     return true;
1463 }
1464 
ParseTransitionCallback(const JSRef<JSFunc> & jsFunc,const JSExecutionContext & context,FrameNode * node)1465 std::function<void(bool)> ParseTransitionCallback(
1466     const JSRef<JSFunc>& jsFunc, const JSExecutionContext& context, FrameNode* node)
1467 {
1468     auto jsFuncFinish = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(jsFunc));
1469     auto targetNode = AceType::WeakClaim(node);
1470     auto finishCallback = [execCtx = context, jsFuncFinish, targetNode](bool isTransitionIn) {
1471         JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
1472         NG::PipelineContext::SetCallBackNode(targetNode);
1473         JSRef<JSVal> newJSVal = JSRef<JSVal>::Make(ToJSValue(isTransitionIn));
1474         jsFuncFinish->ExecuteJS(1, &newJSVal);
1475     };
1476     return finishCallback;
1477 }
1478 
ParseColorMetricsToColor(const EcmaVM * vm,const Local<JSValueRef> & jsValue,Color & result)1479 bool ParseColorMetricsToColor(const EcmaVM *vm, const Local<JSValueRef> &jsValue, Color& result)
1480 {
1481     if (!jsValue->IsObject(vm)) {
1482         return false;
1483     }
1484     auto obj = jsValue->ToObject(vm);
1485     auto toNumericProp = obj->Get(vm, "toNumeric");
1486     if (toNumericProp->IsFunction(vm)) {
1487         panda::Local<panda::FunctionRef> func = toNumericProp;
1488             auto colorVal = func->Call(vm, obj, nullptr, 0);
1489         result.SetValue(colorVal->Uint32Value(vm));
1490         return true;
1491     }
1492     return false;
1493 }
1494 } // namespace
1495 
SetBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1496 ArkUINativeModuleValue CommonBridge::SetBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1497 {
1498     EcmaVM *vm = runtimeCallInfo->GetVM();
1499     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1500     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1501     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
1502     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1503     Color color;
1504     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
1505         GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundColor(nativeNode);
1506     } else {
1507         GetArkUINodeModifiers()->getCommonModifier()->setBackgroundColor(nativeNode, color.GetValue());
1508     }
1509     return panda::JSValueRef::Undefined(vm);
1510 }
1511 
ResetBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1512 ArkUINativeModuleValue CommonBridge::ResetBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1513 {
1514     EcmaVM *vm = runtimeCallInfo->GetVM();
1515     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1516     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1517     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1518     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundColor(nativeNode);
1519     return panda::JSValueRef::Undefined(vm);
1520 }
1521 
SetBorderWidthArray(const EcmaVM * vm,const Local<JSValueRef> & args,ArkUI_Float32 values[],int units[],int index)1522 void SetBorderWidthArray(const EcmaVM* vm, const Local<JSValueRef>& args, ArkUI_Float32 values[],
1523     int units[], int index)
1524 {
1525     CalcDimension borderDimension;
1526     if (!args->IsUndefined()) {
1527         if (ArkTSUtils::ParseAllBorder(vm, args, borderDimension)) {
1528             values[index] = borderDimension.Value();
1529             units[index] = static_cast<int>(borderDimension.Unit());
1530         } else {
1531             values[index] = 0;
1532             units[index] = static_cast<int>(DimensionUnit::VP);
1533         }
1534     } else {
1535         values[index] = -1;
1536         units[index] = static_cast<int>(DimensionUnit::INVALID);
1537     }
1538 }
1539 
ParseLocalizedBorderWidth(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen)1540 bool ParseLocalizedBorderWidth(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen)
1541 {
1542     if (ArkTSUtils::ParseJsLengthMetrics(vm, value, dimen)) {
1543         if (LessOrEqual(dimen.Value(), 0.0)) {
1544             dimen.SetValue(0.0);
1545             dimen.SetUnit(DimensionUnit::VP);
1546         }
1547         return true;
1548     }
1549     return false;
1550 }
1551 
SetBorderWidthArrayByDimen(CalcDimension & borderDimension,ArkUI_Float32 values[],int units[],int index)1552 void SetBorderWidthArrayByDimen(CalcDimension& borderDimension, ArkUI_Float32 values[], int units[], int index)
1553 {
1554     values[index] = borderDimension.Value();
1555     units[index] = static_cast<int>(borderDimension.Unit());
1556 }
1557 
SetBorderWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1558 ArkUINativeModuleValue CommonBridge::SetBorderWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1559 {
1560     EcmaVM* vm = runtimeCallInfo->GetVM();
1561     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1562     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1563     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1564     Local<JSValueRef> topArgs = runtimeCallInfo->GetCallArgRef(NUM_1);
1565     Local<JSValueRef> rightArgs = runtimeCallInfo->GetCallArgRef(NUM_2);
1566     Local<JSValueRef> bottomArgs = runtimeCallInfo->GetCallArgRef(NUM_3);
1567     Local<JSValueRef> leftArgs = runtimeCallInfo->GetCallArgRef(NUM_4);
1568     if (leftArgs->IsUndefined() && rightArgs->IsUndefined() && topArgs->IsUndefined() && bottomArgs->IsUndefined()) {
1569         GetArkUINodeModifiers()->getCommonModifier()->resetBorderWidth(nativeNode);
1570         return panda::JSValueRef::Undefined(vm);
1571     }
1572 
1573     CalcDimension top;
1574     CalcDimension right;
1575     CalcDimension bottom;
1576     CalcDimension left;
1577     bool isLengthMetrics = false;
1578 
1579     if (topArgs->IsObject(vm)) {
1580         isLengthMetrics |= ParseLocalizedBorderWidth(vm, topArgs, top);
1581     }
1582     if (rightArgs->IsObject(vm)) {
1583         isLengthMetrics |= ParseLocalizedBorderWidth(vm, rightArgs, right);
1584     }
1585     if (bottomArgs->IsObject(vm)) {
1586         isLengthMetrics |= ParseLocalizedBorderWidth(vm, bottomArgs, bottom);
1587     }
1588     if (leftArgs->IsObject(vm)) {
1589         isLengthMetrics |= ParseLocalizedBorderWidth(vm, leftArgs, left);
1590     }
1591 
1592     uint32_t size = SIZE_OF_FOUR;
1593     ArkUI_Float32 values[size];
1594     int units[size];
1595 
1596     if (isLengthMetrics) {
1597         auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
1598         SetBorderWidthArrayByDimen(top, values, units, NUM_0);
1599         SetBorderWidthArrayByDimen(isRightToLeft ? left : right, values, units, NUM_1);
1600         SetBorderWidthArrayByDimen(bottom, values, units, NUM_2);
1601         SetBorderWidthArrayByDimen(isRightToLeft ? right : left, values, units, NUM_3);
1602     } else {
1603         SetBorderWidthArray(vm, topArgs, values, units, NUM_0);
1604         SetBorderWidthArray(vm, rightArgs, values, units, NUM_1);
1605         SetBorderWidthArray(vm, bottomArgs, values, units, NUM_2);
1606         SetBorderWidthArray(vm, leftArgs, values, units, NUM_3);
1607     }
1608 
1609     GetArkUINodeModifiers()->getCommonModifier()->setBorderWidth(nativeNode, values, units, size);
1610     return panda::JSValueRef::Undefined(vm);
1611 }
1612 
ResetBorderWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1613 ArkUINativeModuleValue CommonBridge::ResetBorderWidth(ArkUIRuntimeCallInfo *runtimeCallInfo)
1614 {
1615     EcmaVM *vm = runtimeCallInfo->GetVM();
1616     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1617     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1618     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1619     GetArkUINodeModifiers()->getCommonModifier()->resetBorderWidth(nativeNode);
1620     return panda::JSValueRef::Undefined(vm);
1621 }
1622 
ParseMirrorDimen(ArkUI_Float32 values[],int units[],int idx,CalcDimension & calcDimen)1623 void ParseMirrorDimen(ArkUI_Float32 values[], int units[], int idx, CalcDimension& calcDimen)
1624 {
1625     values[idx] = calcDimen.Value();
1626     units[idx] = static_cast<int>(calcDimen.Unit());
1627 }
1628 
SetBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1629 ArkUINativeModuleValue CommonBridge::SetBorderRadius(ArkUIRuntimeCallInfo *runtimeCallInfo)
1630 {
1631     EcmaVM *vm = runtimeCallInfo->GetVM();
1632     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1633     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1634     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1635     Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(NUM_1);
1636     Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(NUM_2);
1637     Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(NUM_3);
1638     Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(NUM_4);
1639     if (topLeftArgs->IsUndefined() && topRightArgs->IsUndefined() && bottomLeftArgs->IsUndefined() &&
1640         bottomRightArgs->IsUndefined()) {
1641         GetArkUINodeModifiers()->getCommonModifier()->resetBorderRadius(nativeNode);
1642         return panda::JSValueRef::Undefined(vm);
1643     }
1644     CalcDimension topLeft;
1645     CalcDimension topRight;
1646     CalcDimension bottomLeft;
1647     CalcDimension bottomRight;
1648     bool isLengthMetrics = false;
1649     if (topLeftArgs->IsObject(vm)) {
1650         isLengthMetrics |= ParseLocalizedBorderRadius(vm, topLeftArgs, topLeft);
1651     }
1652     if (topRightArgs->IsObject(vm)) {
1653         isLengthMetrics |= ParseLocalizedBorderRadius(vm, topRightArgs, topRight);
1654     }
1655     if (bottomLeftArgs->IsObject(vm)) {
1656         isLengthMetrics |= ParseLocalizedBorderRadius(vm, bottomLeftArgs, bottomLeft);
1657     }
1658     if (bottomRightArgs->IsObject(vm)) {
1659         isLengthMetrics |= ParseLocalizedBorderRadius(vm, bottomRightArgs, bottomRight);
1660     }
1661     if (!isLengthMetrics) {
1662         ArkTSUtils::ParseAllBorder(vm, topLeftArgs, topLeft);
1663         ArkTSUtils::ParseAllBorder(vm, topRightArgs, topRight);
1664         ArkTSUtils::ParseAllBorder(vm, bottomLeftArgs, bottomLeft);
1665         ArkTSUtils::ParseAllBorder(vm, bottomRightArgs, bottomRight);
1666     }
1667     ArkUI_Float32 values[SIZE_OF_FOUR];
1668     int units[SIZE_OF_FOUR];
1669     bool isMirror = isLengthMetrics && AceApplicationInfo::GetInstance().IsRightToLeft();
1670     ParseMirrorDimen(values, units, NUM_0, isMirror ? topRight : topLeft);
1671     ParseMirrorDimen(values, units, NUM_1, isMirror ? topLeft : topRight);
1672     ParseMirrorDimen(values, units, NUM_2, isMirror ? bottomRight : bottomLeft);
1673     ParseMirrorDimen(values, units, NUM_3, isMirror ? bottomLeft : bottomRight);
1674     GetArkUINodeModifiers()->getCommonModifier()->setBorderRadius(nativeNode, values, units, SIZE_OF_FOUR);
1675     return panda::JSValueRef::Undefined(vm);
1676 }
1677 
ResetBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1678 ArkUINativeModuleValue CommonBridge::ResetBorderRadius(ArkUIRuntimeCallInfo *runtimeCallInfo)
1679 {
1680     EcmaVM *vm = runtimeCallInfo->GetVM();
1681     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1682     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1683     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1684     GetArkUINodeModifiers()->getCommonModifier()->resetBorderRadius(nativeNode);
1685     return panda::JSValueRef::Undefined(vm);
1686 }
1687 
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1688 ArkUINativeModuleValue CommonBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1689 {
1690     EcmaVM* vm = runtimeCallInfo->GetVM();
1691     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1692     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1693     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1694     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
1695 
1696     CalcDimension width;
1697     std::string calcStr;
1698     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, width)) {
1699         GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
1700     } else {
1701         if (LessNotEqual(width.Value(), 0.0)) {
1702             if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
1703                 GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
1704                 return panda::JSValueRef::Undefined(vm);
1705             }
1706             width.SetValue(0.0);
1707         }
1708 
1709         if (width.Unit() == DimensionUnit::CALC) {
1710             GetArkUINodeModifiers()->getCommonModifier()->setWidth(
1711                 nativeNode, 0, static_cast<int32_t>(width.Unit()), width.CalcValue().c_str());
1712         } else {
1713             GetArkUINodeModifiers()->getCommonModifier()->setWidth(
1714                 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()), calcStr.c_str());
1715         }
1716     }
1717     return panda::JSValueRef::Undefined(vm);
1718 }
1719 
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1720 ArkUINativeModuleValue CommonBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1721 {
1722     EcmaVM* vm = runtimeCallInfo->GetVM();
1723     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1724     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1725     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1726     GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
1727     return panda::JSValueRef::Undefined(vm);
1728 }
1729 
SetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)1730 ArkUINativeModuleValue CommonBridge::SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
1731 {
1732     EcmaVM* vm = runtimeCallInfo->GetVM();
1733     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1734     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1735     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1736     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
1737     CalcDimension height;
1738     std::string calcStr;
1739     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height)) {
1740         GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
1741     } else {
1742         if (LessNotEqual(height.Value(), 0.0)) {
1743             if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
1744                 GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
1745                 return panda::JSValueRef::Undefined(vm);
1746             }
1747             height.SetValue(0.0);
1748         }
1749         if (height.Unit() == DimensionUnit::CALC) {
1750             GetArkUINodeModifiers()->getCommonModifier()->setHeight(
1751                 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), height.CalcValue().c_str());
1752         } else {
1753             GetArkUINodeModifiers()->getCommonModifier()->setHeight(
1754                 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), calcStr.c_str());
1755         }
1756     }
1757     return panda::JSValueRef::Undefined(vm);
1758 }
1759 
ResetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)1760 ArkUINativeModuleValue CommonBridge::ResetHeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
1761 {
1762     EcmaVM *vm = runtimeCallInfo->GetVM();
1763     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1764     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1765     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1766     GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
1767     return panda::JSValueRef::Undefined(vm);
1768 }
1769 
SetPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)1770 ArkUINativeModuleValue CommonBridge::SetPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
1771 {
1772     EcmaVM* vm = runtimeCallInfo->GetVM();
1773     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1774     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1775     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1776     bool useEdges = runtimeCallInfo->GetCallArgRef(NUM_1)->ToBoolean(vm)->Value();
1777     std::vector<ArkUIStringAndFloat> options;
1778     std::vector<std::optional<CalcDimension>> edges;
1779 
1780     if (useEdges) {
1781         ParseResult res = ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_4, edges, CalcDimension(0.0));
1782         if (res == ParseResult::LENGTHMETRICS_SUCCESS && AceApplicationInfo::GetInstance().IsRightToLeft()) {
1783             // Swap left and right
1784             std::swap(edges[NUM_1], edges[NUM_3]);
1785         }
1786         PushDimensionsToVector(options, edges);
1787         GetArkUINodeModifiers()->getCommonModifier()->setPositionEdges(nativeNode, useEdges, options.data());
1788     } else {
1789         ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_2, edges, CalcDimension(0.0));
1790         PushDimensionsToVector(options, edges);
1791         GetArkUINodeModifiers()->getCommonModifier()->setPositionEdges(nativeNode, useEdges, options.data());
1792     }
1793     return panda::JSValueRef::Undefined(vm);
1794 }
1795 
ResetPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)1796 ArkUINativeModuleValue CommonBridge::ResetPosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
1797 {
1798     EcmaVM *vm = runtimeCallInfo->GetVM();
1799     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1800     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1801     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1802     GetArkUINodeModifiers()->getCommonModifier()->resetPositionEdges(nativeNode);
1803     return panda::JSValueRef::Undefined(vm);
1804 }
1805 
SetTransform(ArkUIRuntimeCallInfo * runtimeCallInfo)1806 ArkUINativeModuleValue CommonBridge::SetTransform(ArkUIRuntimeCallInfo *runtimeCallInfo)
1807 {
1808     EcmaVM *vm = runtimeCallInfo->GetVM();
1809     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1810     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1811     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1812     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
1813 
1814     if (!jsValue->IsArray(vm)) {
1815         GetArkUINodeModifiers()->getCommonModifier()->resetTransform(nativeNode);
1816         return panda::JSValueRef::Undefined(vm);
1817     }
1818 
1819     const auto matrix4Len = Matrix4::DIMENSION * Matrix4::DIMENSION;
1820     float matrix[matrix4Len];
1821     Local<panda::ArrayRef> transArray = static_cast<Local<panda::ArrayRef>>(jsValue);
1822     for (size_t i = 0; i < transArray->Length(vm); i++) {
1823         Local<JSValueRef> value = transArray->GetValueAt(vm, jsValue, i);
1824         matrix[i] = value->ToNumber(vm)->Value();
1825     }
1826     GetArkUINodeModifiers()->getCommonModifier()->setTransform(nativeNode, matrix, matrix4Len);
1827     return panda::JSValueRef::Undefined(vm);
1828 }
1829 
ResetTransform(ArkUIRuntimeCallInfo * runtimeCallInfo)1830 ArkUINativeModuleValue CommonBridge::ResetTransform(ArkUIRuntimeCallInfo *runtimeCallInfo)
1831 {
1832     EcmaVM *vm = runtimeCallInfo->GetVM();
1833     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1834     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1835     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1836 
1837     GetArkUINodeModifiers()->getCommonModifier()->resetTransform(nativeNode);
1838     return panda::JSValueRef::Undefined(vm);
1839 }
1840 
SetBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1841 ArkUINativeModuleValue CommonBridge::SetBorderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1842 {
1843     EcmaVM *vm = runtimeCallInfo->GetVM();
1844     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1845     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1846     Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1847     Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1848     Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(NUM_3);
1849     Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(NUM_4);
1850     Local<JSValueRef> isLocalizedArg = runtimeCallInfo->GetCallArgRef(NUM_5);
1851     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1852     auto isLocalized = (isLocalizedArg->IsBoolean()) ? isLocalizedArg->ToBoolean(vm)->Value() : false;
1853 
1854     Color topColor;
1855     Color rightColor;
1856     Color bottomColor;
1857     Color leftColor;
1858 
1859     if (!ArkTSUtils::ParseJsColorAlpha(vm, topArg, topColor)) {
1860         topColor.SetValue(COLOR_ALPHA_VALUE);
1861     }
1862     if (!ArkTSUtils::ParseJsColorAlpha(vm, rightArg, rightColor)) {
1863         rightColor.SetValue(COLOR_ALPHA_VALUE);
1864     }
1865     if (!ArkTSUtils::ParseJsColorAlpha(vm, bottomArg, bottomColor)) {
1866         bottomColor.SetValue(COLOR_ALPHA_VALUE);
1867     }
1868     if (!ArkTSUtils::ParseJsColorAlpha(vm, leftArg, leftColor)) {
1869         leftColor.SetValue(COLOR_ALPHA_VALUE);
1870     }
1871     auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
1872     GetArkUINodeModifiers()->getCommonModifier()->setBorderColor(nativeNode,
1873         topColor.GetValue(),
1874         (isRightToLeft && isLocalized) ? leftColor.GetValue() : rightColor.GetValue(),
1875         bottomColor.GetValue(),
1876         (isRightToLeft && isLocalized) ? rightColor.GetValue() : leftColor.GetValue());
1877     return panda::JSValueRef::Undefined(vm);
1878 }
1879 
ResetBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1880 ArkUINativeModuleValue CommonBridge::ResetBorderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1881 {
1882     EcmaVM *vm = runtimeCallInfo->GetVM();
1883     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1884     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1885     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1886     GetArkUINodeModifiers()->getCommonModifier()->resetBorderColor(nativeNode);
1887     return panda::JSValueRef::Undefined(vm);
1888 }
1889 
SetOutlineColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1890 ArkUINativeModuleValue CommonBridge::SetOutlineColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
1891 {
1892     EcmaVM* vm = runtimeCallInfo->GetVM();
1893     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1894     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1895     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1896     std::vector<uint32_t> colorOptions;
1897     ParseOuterBorderColor(runtimeCallInfo, vm, colorOptions, NUM_1);
1898     GetArkUINodeModifiers()->getCommonModifier()->setOutlineColor(
1899         nativeNode, colorOptions.data(), colorOptions.size());
1900     return panda::JSValueRef::Undefined(vm);
1901 }
1902 
ResetOutlineColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1903 ArkUINativeModuleValue CommonBridge::ResetOutlineColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
1904 {
1905     EcmaVM* vm = runtimeCallInfo->GetVM();
1906     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1907     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1908     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1909     GetArkUINodeModifiers()->getCommonModifier()->resetOutlineColor(nativeNode);
1910     return panda::JSValueRef::Undefined(vm);
1911 }
1912 
SetOutlineRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1913 ArkUINativeModuleValue CommonBridge::SetOutlineRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
1914 {
1915     EcmaVM* vm = runtimeCallInfo->GetVM();
1916     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1917     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1918     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1919     std::vector<ArkUI_Float32> radiusOptions;
1920     ParseOuterBorderRadius(runtimeCallInfo, vm, radiusOptions, NUM_1);
1921     GetArkUINodeModifiers()->getCommonModifier()->setOutlineRadius(
1922         nativeNode, radiusOptions.data(), radiusOptions.size());
1923     return panda::JSValueRef::Undefined(vm);
1924 }
1925 
ResetOutlineRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1926 ArkUINativeModuleValue CommonBridge::ResetOutlineRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
1927 {
1928     EcmaVM* vm = runtimeCallInfo->GetVM();
1929     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1930     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1931     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1932     GetArkUINodeModifiers()->getCommonModifier()->resetOutlineRadius(nativeNode);
1933     return panda::JSValueRef::Undefined(vm);
1934 }
1935 
SetOutlineWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1936 ArkUINativeModuleValue CommonBridge::SetOutlineWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1937 {
1938     EcmaVM* vm = runtimeCallInfo->GetVM();
1939     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1940     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1941     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1942     std::vector<ArkUI_Float32> widthOptions;
1943     ParseOuterBorderWidth(runtimeCallInfo, vm, widthOptions);
1944     GetArkUINodeModifiers()->getCommonModifier()->setOutlineWidth(
1945         nativeNode, widthOptions.data(), widthOptions.size());
1946     return panda::JSValueRef::Undefined(vm);
1947 }
1948 
ResetOutlineWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1949 ArkUINativeModuleValue CommonBridge::ResetOutlineWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1950 {
1951     EcmaVM* vm = runtimeCallInfo->GetVM();
1952     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1953     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1954     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1955     GetArkUINodeModifiers()->getCommonModifier()->resetOutlineWidth(nativeNode);
1956     return panda::JSValueRef::Undefined(vm);
1957 }
1958 
SetOutlineStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)1959 ArkUINativeModuleValue CommonBridge::SetOutlineStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
1960 {
1961     EcmaVM* vm = runtimeCallInfo->GetVM();
1962     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1963     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1964     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1965     std::vector<uint32_t> styleOptions;
1966     ParseOuterBorderStyle(runtimeCallInfo, vm, styleOptions, NUM_1);
1967     GetArkUINodeModifiers()->getCommonModifier()->setOutlineStyle(
1968         nativeNode, styleOptions.data(), styleOptions.size());
1969     return panda::JSValueRef::Undefined(vm);
1970 }
1971 
ResetOutlineStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)1972 ArkUINativeModuleValue CommonBridge::ResetOutlineStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
1973 {
1974     EcmaVM* vm = runtimeCallInfo->GetVM();
1975     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1976     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1977     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1978     GetArkUINodeModifiers()->getCommonModifier()->resetOutlineStyle(nativeNode);
1979     return panda::JSValueRef::Undefined(vm);
1980 }
1981 
SetOutline(ArkUIRuntimeCallInfo * runtimeCallInfo)1982 ArkUINativeModuleValue CommonBridge::SetOutline(ArkUIRuntimeCallInfo* runtimeCallInfo)
1983 {
1984     EcmaVM* vm = runtimeCallInfo->GetVM();
1985     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1986     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1987     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1988     std::vector<ArkUI_Float32> options;
1989     ParseOuterBorderWidth(runtimeCallInfo, vm, options);         // Outline Width args start index from 1
1990     ParseOuterBorderRadius(runtimeCallInfo, vm, options, NUM_9); // Outline Radius args start index
1991 
1992     std::vector<uint32_t> colorAndStyleOptions;
1993     ParseOuterBorderColor(runtimeCallInfo, vm, colorAndStyleOptions, NUM_5);  // Outline Color args start index
1994     ParseOuterBorderStyle(runtimeCallInfo, vm, colorAndStyleOptions, NUM_13); // Outline Style args start index
1995 
1996     GetArkUINodeModifiers()->getCommonModifier()->setOutline(
1997         nativeNode, options.data(), options.size(), colorAndStyleOptions.data(), colorAndStyleOptions.size());
1998     return panda::JSValueRef::Undefined(vm);
1999 }
2000 
ResetOutline(ArkUIRuntimeCallInfo * runtimeCallInfo)2001 ArkUINativeModuleValue CommonBridge::ResetOutline(ArkUIRuntimeCallInfo* runtimeCallInfo)
2002 {
2003     EcmaVM* vm = runtimeCallInfo->GetVM();
2004     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2005     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2006     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2007     GetArkUINodeModifiers()->getCommonModifier()->resetOutline(nativeNode);
2008     return panda::JSValueRef::Undefined(vm);
2009 }
2010 
SetBorderStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2011 ArkUINativeModuleValue CommonBridge::SetBorderStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2012 {
2013     EcmaVM *vm = runtimeCallInfo->GetVM();
2014     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2015     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2016     auto typeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2017     auto styleArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2018     auto topArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2019     auto rightArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2020     auto bottomArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2021     auto leftArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2022     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2023     if ((!typeArg->IsBoolean()) || (!typeArg->BooleaValue(vm))) {
2024         int32_t styles[] = { static_cast<int32_t>(BorderStyle::SOLID) };
2025         GetArkUINodeModifiers()->getCommonModifier()->setBorderStyle(nativeNode, styles,
2026             (sizeof(styles) / sizeof(styles[NUM_0])));
2027         return panda::JSValueRef::Undefined(vm);
2028     }
2029     if (styleArg->IsInt()) {
2030         int32_t styles[] = { styleArg->Int32Value(vm) };
2031         GetArkUINodeModifiers()->getCommonModifier()->setBorderStyle(nativeNode, styles,
2032             (sizeof(styles) / sizeof(styles[NUM_0])));
2033         return panda::JSValueRef::Undefined(vm);
2034     }
2035     int32_t styles[] = { -1, -1, -1, -1 };
2036     if (topArg->IsInt()) {
2037         styles[NUM_0] = topArg->Int32Value(vm);
2038     }
2039     if (rightArg->IsInt()) {
2040         styles[NUM_1] = rightArg->Int32Value(vm);
2041     }
2042     if (bottomArg->IsInt()) {
2043         styles[NUM_2] = bottomArg->Int32Value(vm);
2044     }
2045     if (leftArg->IsInt()) {
2046         styles[NUM_3] = leftArg->Int32Value(vm);
2047     }
2048     GetArkUINodeModifiers()->getCommonModifier()->setBorderStyle(nativeNode, styles,
2049         (sizeof(styles) / sizeof(styles[NUM_0])));
2050     return panda::JSValueRef::Undefined(vm);
2051 }
2052 
ResetBorderStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2053 ArkUINativeModuleValue CommonBridge::ResetBorderStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2054 {
2055     EcmaVM *vm = runtimeCallInfo->GetVM();
2056     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2057     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2058     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2059     GetArkUINodeModifiers()->getCommonModifier()->resetBorderStyle(nativeNode);
2060     return panda::JSValueRef::Undefined(vm);
2061 }
2062 
SetShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)2063 ArkUINativeModuleValue CommonBridge::SetShadow(ArkUIRuntimeCallInfo *runtimeCallInfo)
2064 {
2065     EcmaVM *vm = runtimeCallInfo->GetVM();
2066     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2067     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2068     auto styleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2069     auto radiusArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2070     auto typeArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2071     auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2072     auto offsetXArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2073     auto offsetYArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2074     auto fillArg = runtimeCallInfo->GetCallArgRef(NUM_7);
2075     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2076     int32_t shadowStyle = 0;
2077     if (ArkTSUtils::ParseJsInteger(vm, styleArg, shadowStyle)) {
2078         ArkUIInt32orFloat32 shadows[] = { {.i32 = shadowStyle} };
2079         GetArkUINodeModifiers()->getCommonModifier()->setBackShadow(nativeNode, shadows,
2080             (sizeof(shadows) / sizeof(shadows[NUM_0])));
2081         return panda::JSValueRef::Undefined(vm);
2082     }
2083     ArkUIInt32orFloat32 shadows[] = { { 0.0 }, { .i32 = 0  }, { 0.0 }, { 0.0 },
2084         { .i32 = static_cast<ArkUI_Int32>(ShadowType::COLOR) }, { .u32 = 0 }, { .i32 = 0 } };
2085     double radius;
2086     ArkTSUtils::ParseJsDouble(vm, radiusArg, radius);
2087     shadows[NUM_0].f32 = radius;
2088 
2089     shadows[NUM_0].f32 = (LessNotEqual(shadows[NUM_0].f32, 0.0)) ? 0.0 : shadows[NUM_0].f32;
2090     CalcDimension offsetX;
2091     if (ParseJsShadowDimension(vm, offsetXArg, offsetX)) {
2092         shadows[NUM_2].f32 = offsetX.Value();
2093     }
2094     CalcDimension offsetY;
2095     if (ParseJsShadowDimension(vm, offsetYArg, offsetY)) {
2096         shadows[NUM_3].f32 = offsetY.Value();
2097     }
2098     if (typeArg->IsInt()) {
2099         uint32_t shadowType = typeArg->Uint32Value(vm);
2100         shadows[NUM_4].i32 =
2101             std::clamp(shadowType, static_cast<uint32_t>(ShadowType::COLOR), static_cast<uint32_t>(ShadowType::BLUR));
2102     }
2103     int32_t type = 0;
2104     uint32_t color = 0;
2105     if (ParseJsShadowColor(vm, colorArg, type, color)) {
2106         shadows[NUM_1].i32 = type;
2107         shadows[NUM_5].u32 = color;
2108     }
2109     shadows[NUM_6].i32 = fillArg->IsBoolean() ? fillArg->BooleaValue(vm) : false;
2110     GetArkUINodeModifiers()->getCommonModifier()->setBackShadow(nativeNode, shadows,
2111         (sizeof(shadows) / sizeof(shadows[NUM_0])));
2112     return panda::JSValueRef::Undefined(vm);
2113 }
2114 
ResetShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)2115 ArkUINativeModuleValue CommonBridge::ResetShadow(ArkUIRuntimeCallInfo *runtimeCallInfo)
2116 {
2117     EcmaVM *vm = runtimeCallInfo->GetVM();
2118     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2119     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2120     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2121     GetArkUINodeModifiers()->getCommonModifier()->resetBackShadow(nativeNode);
2122     return panda::JSValueRef::Undefined(vm);
2123 }
2124 
SetHitTestBehavior(ArkUIRuntimeCallInfo * runtimeCallInfo)2125 ArkUINativeModuleValue CommonBridge::SetHitTestBehavior(ArkUIRuntimeCallInfo *runtimeCallInfo)
2126 {
2127     EcmaVM *vm = runtimeCallInfo->GetVM();
2128     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2129     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2130     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
2131     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2132     if (secondArg->IsNumber()) {
2133         uint32_t hitTestModeNG = secondArg->Uint32Value(vm);
2134         GetArkUINodeModifiers()->getCommonModifier()->setHitTestBehavior(nativeNode, hitTestModeNG);
2135     } else {
2136         GetArkUINodeModifiers()->getCommonModifier()->resetHitTestBehavior(nativeNode);
2137     }
2138     return panda::JSValueRef::Undefined(vm);
2139 }
2140 
ResetHitTestBehavior(ArkUIRuntimeCallInfo * runtimeCallInfo)2141 ArkUINativeModuleValue CommonBridge::ResetHitTestBehavior(ArkUIRuntimeCallInfo *runtimeCallInfo)
2142 {
2143     EcmaVM *vm = runtimeCallInfo->GetVM();
2144     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2145     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2146     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2147     GetArkUINodeModifiers()->getCommonModifier()->resetHitTestBehavior(nativeNode);
2148     return panda::JSValueRef::Undefined(vm);
2149 }
2150 
SetZIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)2151 ArkUINativeModuleValue CommonBridge::SetZIndex(ArkUIRuntimeCallInfo *runtimeCallInfo)
2152 {
2153     EcmaVM *vm = runtimeCallInfo->GetVM();
2154     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2155     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2156     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
2157     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2158     if (secondArg->IsNumber()) {
2159         int32_t value = secondArg->Int32Value(vm);
2160         GetArkUINodeModifiers()->getCommonModifier()->setZIndex(nativeNode, value);
2161     } else {
2162         GetArkUINodeModifiers()->getCommonModifier()->resetZIndex(nativeNode);
2163     }
2164     return panda::JSValueRef::Undefined(vm);
2165 }
2166 
ResetZIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)2167 ArkUINativeModuleValue CommonBridge::ResetZIndex(ArkUIRuntimeCallInfo *runtimeCallInfo)
2168 {
2169     EcmaVM *vm = runtimeCallInfo->GetVM();
2170     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2171     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2172     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2173     GetArkUINodeModifiers()->getCommonModifier()->resetZIndex(nativeNode);
2174     return panda::JSValueRef::Undefined(vm);
2175 }
2176 
SetOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)2177 ArkUINativeModuleValue CommonBridge::SetOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
2178 {
2179     EcmaVM *vm = runtimeCallInfo->GetVM();
2180     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2181     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2182     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
2183     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2184     double opacity;
2185     if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity)) {
2186         GetArkUINodeModifiers()->getCommonModifier()->resetOpacity(nativeNode);
2187     } else {
2188         GetArkUINodeModifiers()->getCommonModifier()->setOpacity(nativeNode, opacity);
2189     }
2190     return panda::JSValueRef::Undefined(vm);
2191 }
2192 
ResetOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)2193 ArkUINativeModuleValue CommonBridge::ResetOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
2194 {
2195     EcmaVM *vm = runtimeCallInfo->GetVM();
2196     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2197     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2198     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2199     GetArkUINodeModifiers()->getCommonModifier()->resetOpacity(nativeNode);
2200     return panda::JSValueRef::Undefined(vm);
2201 }
2202 
SetAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)2203 ArkUINativeModuleValue CommonBridge::SetAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
2204 {
2205     EcmaVM *vm = runtimeCallInfo->GetVM();
2206     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2207     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2208     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2209     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2210     if (secondArg->IsNumber()) {
2211         GetArkUINodeModifiers()->getCommonModifier()->setAlign(nativeNode, secondArg->ToNumber(vm)->Value());
2212     } else {
2213         GetArkUINodeModifiers()->getCommonModifier()->resetAlign(nativeNode);
2214     }
2215     return panda::JSValueRef::Undefined(vm);
2216 }
2217 
ResetAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)2218 ArkUINativeModuleValue CommonBridge::ResetAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
2219 {
2220     EcmaVM *vm = runtimeCallInfo->GetVM();
2221     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2222     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2223     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2224     GetArkUINodeModifiers()->getCommonModifier()->resetAlign(nativeNode);
2225     return panda::JSValueRef::Undefined(vm);
2226 }
2227 
SetBackdropBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2228 ArkUINativeModuleValue CommonBridge::SetBackdropBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2229 {
2230     EcmaVM *vm = runtimeCallInfo->GetVM();
2231     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2232     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2233     Local<JSValueRef> blurArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2234     Local<JSValueRef> blurOptionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2235     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2236 
2237     double blur = 0.0;
2238     if (!ArkTSUtils::ParseJsDouble(vm, blurArg, blur)) {
2239         GetArkUINodeModifiers()->getCommonModifier()->resetBackdropBlur(nativeNode);
2240         return panda::JSValueRef::Undefined(vm);
2241     }
2242     BlurOption blurOption;
2243     if (blurOptionArg->IsArray(vm)) {
2244         ParseBlurOption(vm, blurOptionArg, blurOption);
2245     }
2246     GetArkUINodeModifiers()->getCommonModifier()->setBackdropBlur(
2247         nativeNode, blur, blurOption.grayscale.data(), blurOption.grayscale.size());
2248     return panda::JSValueRef::Undefined(vm);
2249 }
2250 
ResetBackdropBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2251 ArkUINativeModuleValue CommonBridge::ResetBackdropBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2252 {
2253     EcmaVM *vm = runtimeCallInfo->GetVM();
2254     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2255     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2256     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2257     GetArkUINodeModifiers()->getCommonModifier()->resetBackdropBlur(nativeNode);
2258     return panda::JSValueRef::Undefined(vm);
2259 }
2260 
SetHueRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)2261 ArkUINativeModuleValue CommonBridge::SetHueRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2262 {
2263     EcmaVM *vm = runtimeCallInfo->GetVM();
2264     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2265     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2266     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2267     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2268     std::optional<float> degree;
2269     if (secondArg->IsString(vm)) {
2270         degree = static_cast<float>(StringUtils::StringToDegree(secondArg->ToString(vm)->ToString(vm)));
2271     } else if (secondArg->IsNumber()) {
2272         degree = static_cast<float>(secondArg->ToNumber(vm)->Value());
2273     } else {
2274         GetArkUINodeModifiers()->getCommonModifier()->resetHueRotate(nativeNode);
2275         return panda::JSValueRef::Undefined(vm);
2276     }
2277 
2278     float deg = 0.0f;
2279     if (degree) {
2280         deg = degree.value();
2281         degree.reset();
2282     }
2283     GetArkUINodeModifiers()->getCommonModifier()->setHueRotate(nativeNode, deg);
2284     return panda::JSValueRef::Undefined(vm);
2285 }
2286 
ResetHueRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)2287 ArkUINativeModuleValue CommonBridge::ResetHueRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2288 {
2289     EcmaVM *vm = runtimeCallInfo->GetVM();
2290     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2291     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2292     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2293     GetArkUINodeModifiers()->getCommonModifier()->resetHueRotate(nativeNode);
2294     return panda::JSValueRef::Undefined(vm);
2295 }
2296 
SetInvert(ArkUIRuntimeCallInfo * runtimeCallInfo)2297 ArkUINativeModuleValue CommonBridge::SetInvert(ArkUIRuntimeCallInfo *runtimeCallInfo)
2298 {
2299     EcmaVM* vm = runtimeCallInfo->GetVM();
2300     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2301     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2302     Local<JSValueRef> invertValueArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2303     Local<JSValueRef> optionLowArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2304     Local<JSValueRef> optionHighArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2305     Local<JSValueRef> optionThresholdArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2306     Local<JSValueRef> optionThresholdRangeArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2307     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2308 
2309     if (!invertValueArg->IsUndefined()) {
2310         double invertValue = 0.0;
2311         if (ArkTSUtils::ParseJsDouble(vm, invertValueArg, invertValue)) {
2312             ArkUI_Float32 invert[] = { invertValue };
2313             GetArkUINodeModifiers()->getCommonModifier()->setInvert(nativeNode, invert, NUM_1);
2314         } else {
2315             GetArkUINodeModifiers()->getCommonModifier()->resetInvert(nativeNode);
2316         }
2317     } else {
2318         ArkUI_Float32 invert[] = { 0.0, 0.0, 0.0, 0.0 };
2319         double low = 0.0;
2320         double high = 0.0;
2321         double threshold = 0.0;
2322         double thresholdRange = 0.0;
2323         if (ArkTSUtils::ParseJsDouble(vm, optionLowArg, low)) {
2324             invert[NUM_0] = std::clamp(low, 0.0, 1.0);
2325         }
2326         if (ArkTSUtils::ParseJsDouble(vm, optionHighArg, high)) {
2327             invert[NUM_1] = std::clamp(high, 0.0, 1.0);
2328         }
2329         if (ArkTSUtils::ParseJsDouble(vm, optionThresholdArg, threshold)) {
2330             invert[NUM_2] = std::clamp(threshold, 0.0, 1.0);
2331         }
2332         if (ArkTSUtils::ParseJsDouble(vm, optionThresholdRangeArg, thresholdRange)) {
2333             invert[NUM_3] = std::clamp(thresholdRange, 0.0, 1.0);
2334         }
2335         GetArkUINodeModifiers()->getCommonModifier()->setInvert(nativeNode, invert, NUM_4);
2336     }
2337 
2338     return panda::JSValueRef::Undefined(vm);
2339 }
2340 
ResetInvert(ArkUIRuntimeCallInfo * runtimeCallInfo)2341 ArkUINativeModuleValue CommonBridge::ResetInvert(ArkUIRuntimeCallInfo *runtimeCallInfo)
2342 {
2343     EcmaVM *vm = runtimeCallInfo->GetVM();
2344     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2345     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2346     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2347     GetArkUINodeModifiers()->getCommonModifier()->resetInvert(nativeNode);
2348     return panda::JSValueRef::Undefined(vm);
2349 }
2350 
SetSepia(ArkUIRuntimeCallInfo * runtimeCallInfo)2351 ArkUINativeModuleValue CommonBridge::SetSepia(ArkUIRuntimeCallInfo *runtimeCallInfo)
2352 {
2353     EcmaVM *vm = runtimeCallInfo->GetVM();
2354     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2355     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2356     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2357     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2358     if (secondArg->IsNumber()) {
2359         GetArkUINodeModifiers()->getCommonModifier()->setSepia(nativeNode, secondArg->ToNumber(vm)->Value());
2360     } else {
2361         GetArkUINodeModifiers()->getCommonModifier()->resetSepia(nativeNode);
2362     }
2363     return panda::JSValueRef::Undefined(vm);
2364 }
2365 
ResetSepia(ArkUIRuntimeCallInfo * runtimeCallInfo)2366 ArkUINativeModuleValue CommonBridge::ResetSepia(ArkUIRuntimeCallInfo *runtimeCallInfo)
2367 {
2368     EcmaVM *vm = runtimeCallInfo->GetVM();
2369     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2370     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2371     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2372     GetArkUINodeModifiers()->getCommonModifier()->resetSepia(nativeNode);
2373     return panda::JSValueRef::Undefined(vm);
2374 }
2375 
SetSaturate(ArkUIRuntimeCallInfo * runtimeCallInfo)2376 ArkUINativeModuleValue CommonBridge::SetSaturate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2377 {
2378     EcmaVM *vm = runtimeCallInfo->GetVM();
2379     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2380     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2381     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2382     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2383     if (secondArg->IsNumber()) {
2384         GetArkUINodeModifiers()->getCommonModifier()->setSaturate(nativeNode, secondArg->ToNumber(vm)->Value());
2385     } else {
2386         GetArkUINodeModifiers()->getCommonModifier()->resetSaturate(nativeNode);
2387     }
2388     return panda::JSValueRef::Undefined(vm);
2389 }
2390 
ResetSaturate(ArkUIRuntimeCallInfo * runtimeCallInfo)2391 ArkUINativeModuleValue CommonBridge::ResetSaturate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2392 {
2393     EcmaVM *vm = runtimeCallInfo->GetVM();
2394     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2395     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2396     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2397     GetArkUINodeModifiers()->getCommonModifier()->resetSaturate(nativeNode);
2398     return panda::JSValueRef::Undefined(vm);
2399 }
2400 
SetColorBlend(ArkUIRuntimeCallInfo * runtimeCallInfo)2401 ArkUINativeModuleValue CommonBridge::SetColorBlend(ArkUIRuntimeCallInfo *runtimeCallInfo)
2402 {
2403     EcmaVM *vm = runtimeCallInfo->GetVM();
2404     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2405     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2406     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2407     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2408     Color color;
2409     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
2410         GetArkUINodeModifiers()->getCommonModifier()->resetColorBlend(nativeNode);
2411         } else {
2412             GetArkUINodeModifiers()->getCommonModifier()->setColorBlend(nativeNode, color.GetValue());
2413         }
2414     return panda::JSValueRef::Undefined(vm);
2415 }
2416 
ResetColorBlend(ArkUIRuntimeCallInfo * runtimeCallInfo)2417 ArkUINativeModuleValue CommonBridge::ResetColorBlend(ArkUIRuntimeCallInfo *runtimeCallInfo)
2418 {
2419     EcmaVM *vm = runtimeCallInfo->GetVM();
2420     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2421     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2422     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2423     GetArkUINodeModifiers()->getCommonModifier()->resetColorBlend(nativeNode);
2424     return panda::JSValueRef::Undefined(vm);
2425 }
2426 
SetGrayscale(ArkUIRuntimeCallInfo * runtimeCallInfo)2427 ArkUINativeModuleValue CommonBridge::SetGrayscale(ArkUIRuntimeCallInfo *runtimeCallInfo)
2428 {
2429     EcmaVM *vm = runtimeCallInfo->GetVM();
2430     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2431     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2432     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2433     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2434     if (secondArg->IsNumber()) {
2435         GetArkUINodeModifiers()->getCommonModifier()->setGrayscale(nativeNode, secondArg->ToNumber(vm)->Value());
2436     } else {
2437         GetArkUINodeModifiers()->getCommonModifier()->resetGrayscale(nativeNode);
2438     }
2439     return panda::JSValueRef::Undefined(vm);
2440 }
2441 
ResetGrayscale(ArkUIRuntimeCallInfo * runtimeCallInfo)2442 ArkUINativeModuleValue CommonBridge::ResetGrayscale(ArkUIRuntimeCallInfo *runtimeCallInfo)
2443 {
2444     EcmaVM *vm = runtimeCallInfo->GetVM();
2445     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2446     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2447     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2448     GetArkUINodeModifiers()->getCommonModifier()->resetGrayscale(nativeNode);
2449     return panda::JSValueRef::Undefined(vm);
2450 }
2451 
SetContrast(ArkUIRuntimeCallInfo * runtimeCallInfo)2452 ArkUINativeModuleValue CommonBridge::SetContrast(ArkUIRuntimeCallInfo *runtimeCallInfo)
2453 {
2454     EcmaVM *vm = runtimeCallInfo->GetVM();
2455     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2456     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2457     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2458     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2459     if (secondArg->IsNumber()) {
2460         GetArkUINodeModifiers()->getCommonModifier()->setContrast(nativeNode, secondArg->ToNumber(vm)->Value());
2461     } else {
2462         GetArkUINodeModifiers()->getCommonModifier()->resetContrast(nativeNode);
2463     }
2464     return panda::JSValueRef::Undefined(vm);
2465 }
2466 
ResetContrast(ArkUIRuntimeCallInfo * runtimeCallInfo)2467 ArkUINativeModuleValue CommonBridge::ResetContrast(ArkUIRuntimeCallInfo *runtimeCallInfo)
2468 {
2469     EcmaVM *vm = runtimeCallInfo->GetVM();
2470     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2471     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2472     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2473     GetArkUINodeModifiers()->getCommonModifier()->resetContrast(nativeNode);
2474     return panda::JSValueRef::Undefined(vm);
2475 }
2476 
SetBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)2477 ArkUINativeModuleValue CommonBridge::SetBrightness(ArkUIRuntimeCallInfo *runtimeCallInfo)
2478 {
2479     EcmaVM *vm = runtimeCallInfo->GetVM();
2480     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2481     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2482     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2483     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2484     if (secondArg->IsNumber()) {
2485         GetArkUINodeModifiers()->getCommonModifier()->setBrightness(nativeNode, secondArg->ToNumber(vm)->Value());
2486     } else {
2487         GetArkUINodeModifiers()->getCommonModifier()->resetBrightness(nativeNode);
2488     }
2489     return panda::JSValueRef::Undefined(vm);
2490 }
2491 
ResetBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)2492 ArkUINativeModuleValue CommonBridge::ResetBrightness(ArkUIRuntimeCallInfo *runtimeCallInfo)
2493 {
2494     EcmaVM *vm = runtimeCallInfo->GetVM();
2495     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2496     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2497     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2498     GetArkUINodeModifiers()->getCommonModifier()->resetBrightness(nativeNode);
2499     return panda::JSValueRef::Undefined(vm);
2500 }
2501 
SetBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2502 ArkUINativeModuleValue CommonBridge::SetBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2503 {
2504     EcmaVM *vm = runtimeCallInfo->GetVM();
2505     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2506     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2507     Local<JSValueRef> blurArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2508     Local<JSValueRef> blurOptionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2509     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2510     double blur = 0.0;
2511     if (!ArkTSUtils::ParseJsDouble(vm, blurArg, blur)) {
2512         GetArkUINodeModifiers()->getCommonModifier()->resetBlur(nativeNode);
2513         return panda::JSValueRef::Undefined(vm);
2514     }
2515     BlurOption blurOption;
2516     if (blurOptionArg->IsArray(vm)) {
2517         ParseBlurOption(vm, blurOptionArg, blurOption);
2518     }
2519     GetArkUINodeModifiers()->getCommonModifier()->setBlur(
2520         nativeNode, blur, blurOption.grayscale.data(), blurOption.grayscale.size());
2521 
2522     return panda::JSValueRef::Undefined(vm);
2523 }
2524 
ResetBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2525 ArkUINativeModuleValue CommonBridge::ResetBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2526 {
2527     EcmaVM *vm = runtimeCallInfo->GetVM();
2528     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2529     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2530     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2531     GetArkUINodeModifiers()->getCommonModifier()->resetBlur(nativeNode);
2532     return panda::JSValueRef::Undefined(vm);
2533 }
2534 
SetLinearGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2535 ArkUINativeModuleValue CommonBridge::SetLinearGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2536 {
2537     EcmaVM *vm = runtimeCallInfo->GetVM();
2538     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2539     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2540     auto angleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2541     auto directionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2542     auto colorsArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2543     auto repeatingArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2544     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2545 
2546     std::vector<ArkUIInt32orFloat32> values;
2547     ParseGradientAngle(vm, angleArg, values);
2548     int32_t direction = static_cast<int32_t>(GradientDirection::NONE);
2549     ParseJsInt32(vm, directionArg, direction);
2550     values.push_back({.i32 = static_cast<ArkUI_Float32>(direction)});
2551 
2552     std::vector<ArkUIInt32orFloat32> colors;
2553     ParseGradientColorStops(vm, colorsArg, colors);
2554     auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(vm) : false;
2555     values.push_back({.i32 = static_cast<ArkUI_Float32>(repeating)});
2556     GetArkUINodeModifiers()->getCommonModifier()->setLinearGradient(nativeNode, values.data(), values.size(),
2557         colors.data(), colors.size());
2558     return panda::JSValueRef::Undefined(vm);
2559 }
2560 
ResetLinearGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2561 ArkUINativeModuleValue CommonBridge::ResetLinearGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2562 {
2563     EcmaVM *vm = runtimeCallInfo->GetVM();
2564     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2565     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2566     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2567     GetArkUINodeModifiers()->getCommonModifier()->resetLinearGradient(nativeNode);
2568     return panda::JSValueRef::Undefined(vm);
2569 }
2570 
SetSweepGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2571 ArkUINativeModuleValue CommonBridge::SetSweepGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2572 {
2573     EcmaVM *vm = runtimeCallInfo->GetVM();
2574     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2575     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2576     auto centerArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2577     auto startArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2578     auto endArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2579     auto rotationArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2580     auto colorsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2581     auto repeatingArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2582     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2583     std::vector<ArkUIInt32orFloat32> values;
2584     ParseGradientCenter(vm, centerArg, values);
2585     ParseGradientAngle(vm, startArg, values);
2586     ParseGradientAngle(vm, endArg, values);
2587     ParseGradientAngle(vm, rotationArg, values);
2588     std::vector<ArkUIInt32orFloat32> colors;
2589     ParseGradientColorStops(vm, colorsArg, colors);
2590     auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(vm) : false;
2591     values.push_back({.i32 = static_cast<ArkUI_Int32>(repeating)});
2592     GetArkUINodeModifiers()->getCommonModifier()->setSweepGradient(nativeNode, values.data(), values.size(),
2593         colors.data(), colors.size());
2594     return panda::JSValueRef::Undefined(vm);
2595 }
2596 
ResetSweepGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2597 ArkUINativeModuleValue CommonBridge::ResetSweepGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2598 {
2599     EcmaVM *vm = runtimeCallInfo->GetVM();
2600     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2601     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2602     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2603     GetArkUINodeModifiers()->getCommonModifier()->resetSweepGradient(nativeNode);
2604     return panda::JSValueRef::Undefined(vm);
2605 }
2606 
SetRadialGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2607 ArkUINativeModuleValue CommonBridge::SetRadialGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2608 {
2609     EcmaVM *vm = runtimeCallInfo->GetVM();
2610     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2611     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2612     auto centerArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2613     auto radiusArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2614     auto colorsArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2615     auto repeatingArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2616     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2617     std::vector<ArkUIInt32orFloat32> values;
2618     ParseGradientCenter(vm, centerArg, values);
2619     CalcDimension radius;
2620     auto hasRadius = ArkTSUtils::ParseJsDimensionVp(vm, radiusArg, radius, false);
2621     values.push_back({.i32 = static_cast<ArkUI_Int32>(hasRadius)});
2622     values.push_back({.f32 = static_cast<ArkUI_Float32>(radius.Value())});
2623     values.push_back({.i32 = static_cast<ArkUI_Int32>(radius.Unit())});
2624     std::vector<ArkUIInt32orFloat32> colors;
2625     ParseGradientColorStops(vm, colorsArg, colors);
2626     auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(vm) : false;
2627     values.push_back({.i32 = static_cast<ArkUI_Int32>(repeating)});
2628     GetArkUINodeModifiers()->getCommonModifier()->setRadialGradient(nativeNode, values.data(), values.size(),
2629         colors.data(), colors.size());
2630     return panda::JSValueRef::Undefined(vm);
2631 }
2632 
ResetRadialGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2633 ArkUINativeModuleValue CommonBridge::ResetRadialGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2634 {
2635     EcmaVM *vm = runtimeCallInfo->GetVM();
2636     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2637     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2638     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2639     GetArkUINodeModifiers()->getCommonModifier()->resetRadialGradient(nativeNode);
2640     return panda::JSValueRef::Undefined(vm);
2641 }
2642 
SetOverlay(ArkUIRuntimeCallInfo * runtimeCallInfo)2643 ArkUINativeModuleValue CommonBridge::SetOverlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
2644 {
2645     EcmaVM* vm = runtimeCallInfo->GetVM();
2646     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2647     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2648     auto valueArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2649     auto alignArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2650     auto offsetXArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2651     auto offsetYArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2652     auto hasOptionsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2653     auto hasOffsetArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2654     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2655 
2656     std::optional<std::string> text;
2657     if (valueArg->IsString(vm)) {
2658         text = valueArg->ToString(vm)->ToString(vm);
2659     }
2660     int32_t align = ALIGNMENT_TOP_LEFT;
2661     auto hasAlign = ArkTSUtils::ParseJsInteger(vm, alignArg, align);
2662     std::optional<CalcDimension> offsetX = CalcDimension(0);
2663     std::optional<CalcDimension> offsetY = CalcDimension(0);
2664     CalcDimension dimensionX;
2665     if (ArkTSUtils::ParseJsDimensionVp(vm, offsetXArg, dimensionX, false)) {
2666         offsetX = dimensionX;
2667     }
2668     CalcDimension dimensionY;
2669     if (ArkTSUtils::ParseJsDimensionVp(vm, offsetYArg, dimensionY, false)) {
2670         offsetY = dimensionY;
2671     }
2672     auto hasOptions = (hasOptionsArg->IsBoolean()) ? hasOptionsArg->ToBoolean(vm)->Value(): false;
2673     auto hasOffset = (hasOffsetArg->IsBoolean()) ? hasOffsetArg->ToBoolean(vm)->Value(): false;
2674     std::vector<ArkUI_Float32> options;
2675     options.push_back(static_cast<ArkUI_Float32>(hasAlign));
2676     options.push_back(static_cast<ArkUI_Float32>(align));
2677     options.push_back(static_cast<ArkUI_Float32>(offsetX.has_value()));
2678     options.push_back(static_cast<ArkUI_Float32>(offsetX.value().Value()));
2679     options.push_back(static_cast<ArkUI_Float32>(offsetX.value().Unit()));
2680     options.push_back(static_cast<ArkUI_Float32>(offsetY.has_value()));
2681     options.push_back(static_cast<ArkUI_Float32>(offsetY.value().Value()));
2682     options.push_back(static_cast<ArkUI_Float32>(offsetY.value().Unit()));
2683     options.push_back(static_cast<ArkUI_Float32>(hasOptions));
2684     options.push_back(static_cast<ArkUI_Float32>(hasOffset));
2685     auto textPtr = (text.has_value()) ? text.value().c_str() : nullptr;
2686     GetArkUINodeModifiers()->getCommonModifier()->setOverlay(nativeNode, textPtr, options.data(), options.size());
2687     return panda::JSValueRef::Undefined(vm);
2688 }
2689 
ResetOverlay(ArkUIRuntimeCallInfo * runtimeCallInfo)2690 ArkUINativeModuleValue CommonBridge::ResetOverlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
2691 {
2692     EcmaVM* vm = runtimeCallInfo->GetVM();
2693     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2694     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2695     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2696     GetArkUINodeModifiers()->getCommonModifier()->resetOverlay(nativeNode);
2697     return panda::JSValueRef::Undefined(vm);
2698 }
2699 
SetBorderImage(ArkUIRuntimeCallInfo * runtimeCallInfo)2700 ArkUINativeModuleValue CommonBridge::SetBorderImage(ArkUIRuntimeCallInfo* runtimeCallInfo)
2701 {
2702     EcmaVM* vm = runtimeCallInfo->GetVM();
2703     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2704     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2705     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2706     auto argsNumber = runtimeCallInfo->GetArgsNumber();
2707     if (IsArgsUndefined(runtimeCallInfo, NUM_1, argsNumber - NUM_1)) {
2708         return panda::JSValueRef::Undefined(vm);
2709     }
2710     std::string src;
2711     std::vector<ArkUIStringAndFloat> options;
2712     uint8_t bitsets = 0;
2713     uint32_t offset = NUM_1;
2714     std::vector<std::optional<CalcDimension>> sliceDimensions;
2715     ParseBorderImageSlice(runtimeCallInfo, offset, sliceDimensions, bitsets); // use 4 args
2716     PushDimensionsToVector(options, sliceDimensions);
2717     ParseBorderImageRepeat(runtimeCallInfo, offset, options, bitsets); // use 1 args
2718     if (!ParseBorderImageSource(runtimeCallInfo, offset, nativeNode, src, bitsets)) { // use 5 args
2719         return panda::JSValueRef::Undefined(vm);
2720     }
2721     std::vector<std::optional<CalcDimension>> widthDimensions;
2722     ParseBorderImageWidth(runtimeCallInfo, offset, widthDimensions, bitsets); // use 4 args
2723     PushDimensionsToVector(options, widthDimensions);
2724     std::vector<std::optional<CalcDimension>> outsetDimensions;
2725     ParseBorderImageOutset(runtimeCallInfo, offset, outsetDimensions, bitsets); // use 4 args
2726     PushDimensionsToVector(options, outsetDimensions);
2727     ParseBorderImageFill(runtimeCallInfo, offset, options); // use 1 args
2728     options.push_back(ArkUIStringAndFloat { static_cast<double>(bitsets), nullptr });
2729     GetArkUINodeModifiers()->getCommonModifier()->setBorderImage(nativeNode,
2730         src.c_str(), options.data(), options.size());
2731     ResetCalcDimensions(sliceDimensions);
2732     ResetCalcDimensions(widthDimensions);
2733     ResetCalcDimensions(outsetDimensions);
2734     return panda::JSValueRef::Undefined(vm);
2735 }
2736 
ResetBorderImage(ArkUIRuntimeCallInfo * runtimeCallInfo)2737 ArkUINativeModuleValue CommonBridge::ResetBorderImage(ArkUIRuntimeCallInfo* runtimeCallInfo)
2738 {
2739     EcmaVM* vm = runtimeCallInfo->GetVM();
2740     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2741     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2742     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2743     GetArkUINodeModifiers()->getCommonModifier()->resetBorderImage(nativeNode);
2744     return panda::JSValueRef::Undefined(vm);
2745 }
2746 
SetForegroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2747 ArkUINativeModuleValue CommonBridge::SetForegroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2748 {
2749     EcmaVM *vm = runtimeCallInfo->GetVM();
2750     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2751     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2752     auto blurStyleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2753     auto colorModeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2754     auto adaptiveColorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2755     auto scaleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2756     auto blurOptionsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2757     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2758     int32_t blurStyle = -1;
2759     if (blurStyleArg->IsNumber()) {
2760         blurStyle = blurStyleArg->Int32Value(vm);
2761     }
2762     bool isHasOptions = !(colorModeArg->IsUndefined() && adaptiveColorArg->IsUndefined() && scaleArg->IsUndefined() &&
2763                           blurOptionsArg->IsUndefined());
2764     int32_t colorMode = static_cast<int32_t>(ThemeColorMode::SYSTEM);
2765     int32_t adaptiveColor = static_cast<int32_t>(AdaptiveColor::DEFAULT);
2766     double scale = 1.0;
2767     BlurOption blurOption;
2768     if (isHasOptions) {
2769         ParseJsInt32(vm, colorModeArg, colorMode);
2770         ParseJsInt32(vm, adaptiveColorArg, adaptiveColor);
2771         if (scaleArg->IsNumber()) {
2772             scale = scaleArg->ToNumber(vm)->Value();
2773         }
2774         if (blurOptionsArg->IsArray(vm)) {
2775             ParseBlurOption(vm, blurOptionsArg, blurOption);
2776         }
2777     }
2778     int32_t intArray[NUM_3];
2779     intArray[NUM_0] = blurStyle;
2780     intArray[NUM_1] = colorMode;
2781     intArray[NUM_2] = adaptiveColor;
2782     GetArkUINodeModifiers()->getCommonModifier()->setForegroundBlurStyle(
2783         nativeNode, &intArray, scale, blurOption.grayscale.data(), blurOption.grayscale.size());
2784     return panda::JSValueRef::Undefined(vm);
2785 }
2786 
ResetForegroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2787 ArkUINativeModuleValue CommonBridge::ResetForegroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2788 {
2789     EcmaVM *vm = runtimeCallInfo->GetVM();
2790     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2791     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2792     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2793     GetArkUINodeModifiers()->getCommonModifier()->resetForegroundBlurStyle(nativeNode);
2794     return panda::JSValueRef::Undefined(vm);
2795 }
2796 
SetLinearGradientBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2797 ArkUINativeModuleValue CommonBridge::SetLinearGradientBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2798 {
2799     EcmaVM *vm = runtimeCallInfo->GetVM();
2800     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2801     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2802     auto blurRadiusArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2803     auto fractionStopsArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2804     auto directionArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2805     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2806     double blurRadius = 0.0;
2807     ParseJsDouble(vm, blurRadiusArg, blurRadius);
2808     auto direction = static_cast<int32_t>(GradientDirection::BOTTOM);
2809     if (directionArg->IsInt()) {
2810         direction = directionArg->Int32Value(vm);
2811     }
2812     std::vector<ArkUI_Float32> fractionStops;
2813     if (fractionStopsArg->IsArray(vm)) {
2814         auto array = panda::Local<panda::ArrayRef>(fractionStopsArg);
2815         auto length = array->Length(vm);
2816         for (uint32_t index = 0; index < length; index++) {
2817             auto fractionStop = panda::ArrayRef::GetValueAt(vm, array, index);
2818             ArkUI_Float32 first = 0.0;
2819             ArkUI_Float32 second = 0.0;
2820             if (!ParseJsDoublePair(vm, fractionStop, first, second)) {
2821                 continue;
2822             }
2823             fractionStops.push_back(first);
2824             fractionStops.push_back(second);
2825         }
2826     }
2827     GetArkUINodeModifiers()->getCommonModifier()->setLinearGradientBlur(nativeNode, blurRadius, fractionStops.data(),
2828         fractionStops.size(), direction);
2829     return panda::JSValueRef::Undefined(vm);
2830 }
2831 
ResetLinearGradientBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2832 ArkUINativeModuleValue CommonBridge::ResetLinearGradientBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2833 {
2834     EcmaVM *vm = runtimeCallInfo->GetVM();
2835     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2836     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2837     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2838     GetArkUINodeModifiers()->getCommonModifier()->resetLinearGradientBlur(nativeNode);
2839     return panda::JSValueRef::Undefined(vm);
2840 }
2841 
SetBackgroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2842 ArkUINativeModuleValue CommonBridge::SetBackgroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2843 {
2844     EcmaVM *vm = runtimeCallInfo->GetVM();
2845     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2846     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2847     auto blurStyleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2848     auto colorModeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2849     auto adaptiveColorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2850     auto scaleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2851     auto blurOptionsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2852     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2853     int32_t blurStyle = -1;
2854     if (blurStyleArg->IsNumber()) {
2855         blurStyle = blurStyleArg->Int32Value(vm);
2856     }
2857     bool isHasOptions = !(colorModeArg->IsUndefined() && adaptiveColorArg->IsUndefined() && scaleArg->IsUndefined() &&
2858                           blurOptionsArg->IsUndefined());
2859     int32_t colorMode = -1;
2860     int32_t adaptiveColor = -1;
2861     double scale = -1.0;
2862     BlurOption blurOption;
2863     if (isHasOptions) {
2864         colorMode = static_cast<int32_t>(ThemeColorMode::SYSTEM);
2865         ParseJsInt32(vm, colorModeArg, colorMode);
2866         adaptiveColor = static_cast<int32_t>(AdaptiveColor::DEFAULT);
2867         ParseJsInt32(vm, adaptiveColorArg, adaptiveColor);
2868         scale = 1.0;
2869         if (scaleArg->IsNumber()) {
2870             scale = scaleArg->ToNumber(vm)->Value();
2871         }
2872         if (blurOptionsArg->IsArray(vm)) {
2873             ParseBlurOption(vm, blurOptionsArg, blurOption);
2874         }
2875     }
2876     int32_t intArray[NUM_3];
2877     intArray[NUM_0] = blurStyle;
2878     intArray[NUM_1] = colorMode;
2879     intArray[NUM_2] = adaptiveColor;
2880     GetArkUINodeModifiers()->getCommonModifier()->setBackgroundBlurStyle(
2881         nativeNode, &intArray, scale, blurOption.grayscale.data(), blurOption.grayscale.size());
2882     return panda::JSValueRef::Undefined(vm);
2883 }
2884 
ResetBackgroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2885 ArkUINativeModuleValue CommonBridge::ResetBackgroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2886 {
2887     EcmaVM *vm = runtimeCallInfo->GetVM();
2888     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2889     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2890     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2891     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundBlurStyle(nativeNode);
2892     return panda::JSValueRef::Undefined(vm);
2893 }
2894 
SetBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)2895 ArkUINativeModuleValue CommonBridge::SetBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
2896 {
2897     EcmaVM *vm = runtimeCallInfo->GetVM();
2898     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2899     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2900     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2901 
2902     std::vector<ArkUI_Float32> options;
2903     ParseOuterBorderWidth(runtimeCallInfo, vm, options);         // Border Width args start index from 1
2904     ParseOuterBorderRadius(runtimeCallInfo, vm, options, NUM_9); // Border Radius args start index
2905 
2906     std::vector<uint32_t> colorAndStyleOptions;
2907     ParseOuterBorderColor(runtimeCallInfo, vm, colorAndStyleOptions, NUM_5);  // Border Color args start index
2908     ParseOuterBorderStyle(runtimeCallInfo, vm, colorAndStyleOptions, NUM_13); // Border Style args start index
2909 
2910     GetArkUINodeModifiers()->getCommonModifier()->setBorder(nativeNode, options.data(), options.size(),
2911         colorAndStyleOptions.data(), colorAndStyleOptions.size(), false, false, false);
2912     return panda::JSValueRef::Undefined(vm);
2913 }
2914 
SetLocalizedBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)2915 ArkUINativeModuleValue CommonBridge::SetLocalizedBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
2916 {
2917     EcmaVM *vm = runtimeCallInfo->GetVM();
2918     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2919     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2920     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::NativePointerRef::New(vm, nullptr));
2921     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2922 
2923     std::vector<ArkUI_Float32> options;
2924     ParseOuterBorderWidth(runtimeCallInfo, vm, options, true);         // Border Width args start index from 1
2925     ParseOuterBorderRadius(runtimeCallInfo, vm, options, NUM_9, true); // Border Radius args start index
2926 
2927     std::vector<uint32_t> colorAndStyleOptions;
2928     ParseOuterBorderColor(runtimeCallInfo, vm, colorAndStyleOptions, NUM_5, true);  // Border Color args start index
2929     ParseOuterBorderStyle(runtimeCallInfo, vm, colorAndStyleOptions, NUM_13); // Border Style args start index
2930 
2931     int32_t isLocalizedBorderWidth = 0;
2932     int32_t isLocalizedBorderColor = 0;
2933     int32_t isLocalizedBorderRadius = 0;
2934     ParseLocalizedBorder(runtimeCallInfo, isLocalizedBorderWidth, isLocalizedBorderColor, isLocalizedBorderRadius);
2935 
2936     GetArkUINodeModifiers()->getCommonModifier()->setBorder(nativeNode, options.data(), options.size(),
2937         colorAndStyleOptions.data(), colorAndStyleOptions.size(), isLocalizedBorderWidth, isLocalizedBorderColor,
2938         isLocalizedBorderRadius);
2939     return panda::JSValueRef::Undefined(vm);
2940 }
2941 
ParseLocalizedBorder(ArkUIRuntimeCallInfo * runtimeCallInfo,int & isLocalizedBorderWidth,int & isLocalizedBorderColor,int & isLocalizedBorderRadius)2942 void CommonBridge::ParseLocalizedBorder(ArkUIRuntimeCallInfo* runtimeCallInfo, int& isLocalizedBorderWidth,
2943     int& isLocalizedBorderColor, int& isLocalizedBorderRadius)
2944 {
2945     EcmaVM* vm = runtimeCallInfo->GetVM();
2946     CHECK_NULL_VOID(vm);
2947     Local<JSValueRef> isLocalizedBorderWidthArg =
2948         runtimeCallInfo->GetCallArgRef(33); // 33: index of is LocalizedBorderWidth or not
2949     Local<JSValueRef> isLocalizedBorderColorArg =
2950         runtimeCallInfo->GetCallArgRef(34); // 34: index of is LocalizedBorderColor or not
2951     Local<JSValueRef> isLocalizedBorderRadiusArg =
2952         runtimeCallInfo->GetCallArgRef(35); // 35: index of is LocalizedBorderRadius or not
2953     isLocalizedBorderWidth =
2954         (isLocalizedBorderWidthArg->IsBoolean()) ? isLocalizedBorderWidthArg->ToBoolean(vm)->Value() : false;
2955     isLocalizedBorderColor =
2956         (isLocalizedBorderColorArg->IsBoolean()) ? isLocalizedBorderColorArg->ToBoolean(vm)->Value() : false;
2957     isLocalizedBorderRadius =
2958         (isLocalizedBorderRadiusArg->IsBoolean()) ? isLocalizedBorderRadiusArg->ToBoolean(vm)->Value() : false;
2959 }
2960 
SetBorderWithDashParams(ArkUIRuntimeCallInfo * runtimeCallInfo)2961 ArkUINativeModuleValue CommonBridge::SetBorderWithDashParams(ArkUIRuntimeCallInfo* runtimeCallInfo)
2962 {
2963     int32_t isLocalizedBorderWidth = 0;
2964     int32_t isLocalizedBorderColor = 0;
2965     int32_t isLocalizedBorderRadius = 0;
2966     ParseLocalizedBorder(runtimeCallInfo, isLocalizedBorderWidth, isLocalizedBorderColor, isLocalizedBorderRadius);
2967     if (isLocalizedBorderWidth || isLocalizedBorderColor || isLocalizedBorderRadius) {
2968         CommonBridge::SetLocalizedBorder(runtimeCallInfo);
2969     } else {
2970         CommonBridge::SetBorder(runtimeCallInfo);
2971     }
2972 
2973     EcmaVM *vm = runtimeCallInfo->GetVM();
2974     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2975     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2976     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2977 
2978     std::vector<ArkUI_Float32> dashOptions;
2979     ParseOuterBorderDashParam(runtimeCallInfo, vm, dashOptions, 17); // Border DashGap args start index from 17
2980     ParseOuterBorderDashParam(runtimeCallInfo, vm, dashOptions, 21); // Border DashWidth args start index from 21
2981 
2982     GetArkUINodeModifiers()->getCommonModifier()->setBorderDashParams(nativeNode, dashOptions.data(),
2983         dashOptions.size());
2984     return panda::JSValueRef::Undefined(vm);
2985 }
2986 
ResetBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)2987 ArkUINativeModuleValue CommonBridge::ResetBorder(ArkUIRuntimeCallInfo *runtimeCallInfo)
2988 {
2989     EcmaVM *vm = runtimeCallInfo->GetVM();
2990     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2991     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2992     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2993     GetArkUINodeModifiers()->getCommonModifier()->resetBorder(nativeNode);
2994     return panda::JSValueRef::Undefined(vm);
2995 }
2996 
SetBackgroundImagePosition(ArkUIRuntimeCallInfo * runtimeCallInfo)2997 ArkUINativeModuleValue CommonBridge::SetBackgroundImagePosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
2998 {
2999     EcmaVM *vm = runtimeCallInfo->GetVM();
3000     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3001     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3002     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3003     Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3004     Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3005     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3006     double valueX = 0.0;
3007     double valueY = 0.0;
3008     DimensionUnit typeX = DimensionUnit::PX;
3009     DimensionUnit typeY = DimensionUnit::PX;
3010     bool isAlign = false;
3011 
3012     if (secondArg->IsNumber()) {
3013         int32_t align = secondArg->ToNumber(vm)->Value();
3014         ParseBackgroundImagePositionAlign(align, valueX, valueY, typeX, typeY);
3015         isAlign = true;
3016     } else {
3017         CalcDimension x(0, DimensionUnit::VP);
3018         CalcDimension y(0, DimensionUnit::VP);
3019         ArkTSUtils::ParseJsDimensionVp(vm, xArg, x);
3020         ArkTSUtils::ParseJsDimensionVp(vm, yArg, y);
3021         valueX = x.ConvertToPx();
3022         valueY = y.ConvertToPx();
3023         if (x.Unit() == DimensionUnit::PERCENT) {
3024             valueX = x.Value();
3025             typeX = DimensionUnit::PERCENT;
3026         }
3027         if (y.Unit() == DimensionUnit::PERCENT) {
3028             valueY = y.Value();
3029             typeY = DimensionUnit::PERCENT;
3030         }
3031     }
3032 
3033     ArkUI_Float32 values[SIZE_OF_TWO];
3034     int32_t types[SIZE_OF_TWO];
3035     values[NUM_0] = static_cast<ArkUI_Float32>(valueX);
3036     types[NUM_0] = static_cast<int32_t>(typeX);
3037     values[NUM_1] = static_cast<ArkUI_Float32>(valueY);
3038     types[NUM_1] = static_cast<int32_t>(typeY);
3039 
3040     GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImagePosition(nativeNode, values, types, isAlign,
3041         SIZE_OF_TWO);
3042     return panda::JSValueRef::Undefined(vm);
3043 }
3044 
ResetBackgroundImagePosition(ArkUIRuntimeCallInfo * runtimeCallInfo)3045 ArkUINativeModuleValue CommonBridge::ResetBackgroundImagePosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
3046 {
3047     EcmaVM *vm = runtimeCallInfo->GetVM();
3048     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3049     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3050     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3051     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImagePosition(nativeNode);
3052     return panda::JSValueRef::Undefined(vm);
3053 }
3054 
SetBackgroundImageResizable(ArkUIRuntimeCallInfo * runtimeCallInfo)3055 ArkUINativeModuleValue CommonBridge::SetBackgroundImageResizable(ArkUIRuntimeCallInfo *runtimeCallInfo)
3056 {
3057     EcmaVM* vm = runtimeCallInfo->GetVM();
3058     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3059     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3060 
3061     std::vector<ArkUIStringAndFloat> options;
3062     std::vector<std::optional<CalcDimension>> sliceDimensions;
3063     ParseResizableCalcDimensions(runtimeCallInfo, NUM_1, NUM_4, sliceDimensions, CalcDimension(0.0));
3064     PushDimensionsToVector(options, sliceDimensions);
3065 
3066     GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImageResizable(nativeNode, options.data());
3067     return panda::JSValueRef::Undefined(vm);
3068 }
3069 
ResetBackgroundImageResizable(ArkUIRuntimeCallInfo * runtimeCallInfo)3070 ArkUINativeModuleValue CommonBridge::ResetBackgroundImageResizable(ArkUIRuntimeCallInfo *runtimeCallInfo)
3071 {
3072     EcmaVM* vm = runtimeCallInfo->GetVM();
3073     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3074     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3075     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImageResizable(nativeNode);
3076     return panda::JSValueRef::Undefined(vm);
3077 }
3078 
SetBackgroundImageSize(ArkUIRuntimeCallInfo * runtimeCallInfo)3079 ArkUINativeModuleValue CommonBridge::SetBackgroundImageSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
3080 {
3081     EcmaVM *vm = runtimeCallInfo->GetVM();
3082     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3083     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3084     Local<JSValueRef> imageSizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3085     Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3086     Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3087     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3088 
3089     OHOS::Ace::BackgroundImageSizeType typeWidth = OHOS::Ace::BackgroundImageSizeType::AUTO;
3090     double valueWidth = 0.0;
3091     OHOS::Ace::BackgroundImageSizeType typeHeight = OHOS::Ace::BackgroundImageSizeType::AUTO;
3092     double valueHeight = 0.0;
3093 
3094     if (imageSizeArg->IsNumber()) {
3095         auto sizeType = imageSizeArg->ToNumber(vm)->Value();
3096         if (sizeType < static_cast<uint32_t>(BackgroundImageSizeType::CONTAIN) ||
3097             sizeType > static_cast<uint32_t>(BackgroundImageSizeType::FILL)) {
3098             sizeType = static_cast<uint32_t>(BackgroundImageSizeType::AUTO);
3099         }
3100         typeWidth = static_cast<OHOS::Ace::BackgroundImageSizeType>(sizeType);
3101         typeHeight = static_cast<OHOS::Ace::BackgroundImageSizeType>(sizeType);
3102     } else {
3103         CalcDimension width;
3104         CalcDimension height;
3105         ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width);
3106         ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height);
3107 
3108         valueWidth = width.ConvertToPx();
3109         valueHeight = height.ConvertToPx();
3110         typeWidth = BackgroundImageSizeType::LENGTH;
3111         typeHeight = BackgroundImageSizeType::LENGTH;
3112         if (width.Unit() == DimensionUnit::PERCENT) {
3113             typeWidth = BackgroundImageSizeType::PERCENT;
3114             valueWidth = width.Value() * FULL_DIMENSION;
3115         }
3116         if (height.Unit() == DimensionUnit::PERCENT) {
3117             typeHeight = BackgroundImageSizeType::PERCENT;
3118             valueHeight = height.Value() * FULL_DIMENSION;
3119         }
3120     }
3121     GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImageSize(
3122         nativeNode, valueWidth, valueHeight, static_cast<int32_t>(typeWidth), static_cast<int32_t>(typeHeight));
3123     return panda::JSValueRef::Undefined(vm);
3124 }
3125 
ResetBackgroundImageSize(ArkUIRuntimeCallInfo * runtimeCallInfo)3126 ArkUINativeModuleValue CommonBridge::ResetBackgroundImageSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
3127 {
3128     EcmaVM *vm = runtimeCallInfo->GetVM();
3129     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3130     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3131     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3132     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImageSize(nativeNode);
3133     return panda::JSValueRef::Undefined(vm);
3134 }
3135 
SetBackgroundImage(ArkUIRuntimeCallInfo * runtimeCallInfo)3136 ArkUINativeModuleValue CommonBridge::SetBackgroundImage(ArkUIRuntimeCallInfo *runtimeCallInfo)
3137 {
3138     EcmaVM *vm = runtimeCallInfo->GetVM();
3139     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3140     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3141     Local<JSValueRef> srcArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3142     Local<JSValueRef> repeatArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3143     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3144     std::string src;
3145     std::string bundle;
3146     std::string module;
3147     int32_t repeatIndex = 0;
3148     RefPtr<PixelMap> pixmap = nullptr;
3149     if (repeatArg->IsNumber()) {
3150         repeatIndex = repeatArg->ToNumber(vm)->Value();
3151     }
3152     if (srcArg->IsString(vm)) {
3153         src = srcArg->ToString(vm)->ToString(vm);
3154         GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImage(
3155             nativeNode, src.c_str(), bundle.c_str(), module.c_str(), repeatIndex);
3156     } else if (ArkTSUtils::ParseJsMedia(vm, srcArg, src)) {
3157         ArkTSUtils::GetJsMediaBundleInfo(vm, srcArg, bundle, module);
3158         GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImage(
3159             nativeNode, src.c_str(), bundle.c_str(), module.c_str(), repeatIndex);
3160     } else {
3161 #if defined(PIXEL_MAP_SUPPORTED)
3162         if (ArkTSUtils::IsDrawable(vm, srcArg)) {
3163             pixmap = ArkTSUtils::GetDrawablePixmap(vm, srcArg);
3164         } else {
3165             pixmap = ArkTSUtils::CreatePixelMapFromNapiValue(vm, srcArg);
3166         }
3167 #endif
3168         if (pixmap) {
3169             auto pixelMapSharedPtr = pixmap->GetPixelMapSharedPtr();
3170             GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImagePixelMapByPixelMapPtr(
3171                 nativeNode, &pixelMapSharedPtr, repeatIndex);
3172         } else {
3173             GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImage(nativeNode);
3174         }
3175     }
3176     return panda::JSValueRef::Undefined(vm);
3177 }
3178 
ResetBackgroundImage(ArkUIRuntimeCallInfo * runtimeCallInfo)3179 ArkUINativeModuleValue CommonBridge::ResetBackgroundImage(ArkUIRuntimeCallInfo *runtimeCallInfo)
3180 {
3181     EcmaVM *vm = runtimeCallInfo->GetVM();
3182     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3183     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3184     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3185     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImage(nativeNode);
3186     return panda::JSValueRef::Undefined(vm);
3187 }
3188 
SetTranslate(ArkUIRuntimeCallInfo * runtimeCallInfo)3189 ArkUINativeModuleValue CommonBridge::SetTranslate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3190 {
3191     EcmaVM *vm = runtimeCallInfo->GetVM();
3192     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3193     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3194     Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3195     Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3196     Local<JSValueRef> zArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3197     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3198     if (!xArg->IsNumber() && !xArg->IsString(vm) && !yArg->IsNumber() && !yArg->IsString(vm) && !zArg->IsNumber() &&
3199         !zArg->IsString(vm)) {
3200         GetArkUINodeModifiers()->getCommonModifier()->resetTranslate(nativeNode);
3201     } else {
3202         auto translateX = CalcDimension(0.0);
3203         auto translateY = CalcDimension(0.0);
3204         auto translateZ = CalcDimension(0.0);
3205         bool hasX = ParseAxisDimensionVp(vm, xArg, translateX, true);
3206         bool hasY = ParseAxisDimensionVp(vm, yArg, translateY, true);
3207         bool hasZ = ParseAxisDimensionVp(vm, zArg, translateZ, true);
3208         if (hasX || hasY || hasZ) {
3209             uint32_t size = SIZE_OF_THREE;
3210             ArkUI_Float32 values[size];
3211             int units[size];
3212 
3213             values[NUM_0] = static_cast<ArkUI_Float32>(translateX.Value());
3214             units[NUM_0] = static_cast<int>(translateX.Unit());
3215             values[NUM_1] = static_cast<ArkUI_Float32>(translateY.Value());
3216             units[NUM_1] = static_cast<int>(translateY.Unit());
3217             values[NUM_2] = static_cast<ArkUI_Float32>(translateZ.Value());
3218             units[NUM_2] = static_cast<int>(translateZ.Unit());
3219             GetArkUINodeModifiers()->getCommonModifier()->setTranslate(nativeNode, values, units, size);
3220         } else {
3221             GetArkUINodeModifiers()->getCommonModifier()->resetTranslate(nativeNode);
3222         }
3223     }
3224     return panda::JSValueRef::Undefined(vm);
3225 }
3226 
ResetTranslate(ArkUIRuntimeCallInfo * runtimeCallInfo)3227 ArkUINativeModuleValue CommonBridge::ResetTranslate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3228 {
3229     EcmaVM *vm = runtimeCallInfo->GetVM();
3230     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3231     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3232     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3233     GetArkUINodeModifiers()->getCommonModifier()->resetTranslate(nativeNode);
3234     return panda::JSValueRef::Undefined(vm);
3235 }
3236 
SetScale(ArkUIRuntimeCallInfo * runtimeCallInfo)3237 ArkUINativeModuleValue CommonBridge::SetScale(ArkUIRuntimeCallInfo *runtimeCallInfo)
3238 {
3239     EcmaVM *vm = runtimeCallInfo->GetVM();
3240     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3241     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3242     Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3243     Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3244     Local<JSValueRef> zArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3245     Local<JSValueRef> centerXArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3246     Local<JSValueRef> centerYArg = runtimeCallInfo->GetCallArgRef(NUM_5);
3247     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3248     if (xArg->IsNumber() || yArg->IsNumber() || zArg->IsNumber()) {
3249         auto scaleX = 1.0f;
3250         auto scaleY = 1.0f;
3251         auto scaleZ = 1.0f;
3252 
3253         CalcDimension centerX = 0.5_pct;
3254         CalcDimension centerY = 0.5_pct;
3255 
3256         if (xArg->IsNumber()) {
3257             scaleX = xArg->ToNumber(vm)->Value();
3258         }
3259         if (yArg->IsNumber()) {
3260             scaleY = yArg->ToNumber(vm)->Value();
3261         }
3262         if (zArg->IsNumber()) {
3263             scaleZ = zArg->ToNumber(vm)->Value();
3264         }
3265         if (centerXArg->IsNumber() || centerXArg->IsString(vm)) {
3266             ParseAxisDimensionVp(vm, centerXArg, centerX, true);
3267         }
3268         if (centerYArg->IsNumber() || centerYArg->IsString(vm)) {
3269             ParseAxisDimensionVp(vm, centerYArg, centerY, true);
3270         }
3271 
3272         ArkUI_Float32 values[SIZE_OF_FIVE];
3273         int units[SIZE_OF_TWO];
3274 
3275         values[NUM_0] = static_cast<ArkUI_Float32>(scaleX);
3276         values[NUM_1] = static_cast<ArkUI_Float32>(scaleY);
3277         values[NUM_2] = static_cast<ArkUI_Float32>(scaleZ);
3278         values[NUM_3] = static_cast<ArkUI_Float32>(centerX.Value());
3279         values[NUM_4] = static_cast<ArkUI_Float32>(centerY.Value());
3280         units[NUM_0] = static_cast<int>(centerX.Unit());
3281         units[NUM_1] = static_cast<int>(centerY.Unit());
3282         GetArkUINodeModifiers()->getCommonModifier()->setScale(nativeNode, values, SIZE_OF_FIVE, units, SIZE_OF_TWO);
3283     } else {
3284         GetArkUINodeModifiers()->getCommonModifier()->resetScale(nativeNode);
3285     }
3286 
3287     return panda::JSValueRef::Undefined(vm);
3288 }
3289 
ResetScale(ArkUIRuntimeCallInfo * runtimeCallInfo)3290 ArkUINativeModuleValue CommonBridge::ResetScale(ArkUIRuntimeCallInfo *runtimeCallInfo)
3291 {
3292     EcmaVM *vm = runtimeCallInfo->GetVM();
3293     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3294     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3295     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3296     GetArkUINodeModifiers()->getCommonModifier()->resetScale(nativeNode);
3297     return panda::JSValueRef::Undefined(vm);
3298 }
3299 
SetRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)3300 ArkUINativeModuleValue CommonBridge::SetRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3301 {
3302     EcmaVM *vm = runtimeCallInfo->GetVM();
3303     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3304     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3305     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3306 
3307     ArkUI_Float32 values[SIZE_OF_EIGHT];
3308     int units[SIZE_OF_THREE];
3309 
3310     if (ParseRotate(runtimeCallInfo, values, units, SIZE_OF_EIGHT, SIZE_OF_THREE)) {
3311         GetArkUINodeModifiers()->getCommonModifier()->setRotate(
3312             nativeNode, values, SIZE_OF_EIGHT, units, SIZE_OF_THREE);
3313     } else {
3314         GetArkUINodeModifiers()->getCommonModifier()->resetRotate(nativeNode);
3315     }
3316     return panda::JSValueRef::Undefined(vm);
3317 }
3318 
ResetRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)3319 ArkUINativeModuleValue CommonBridge::ResetRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3320 {
3321     EcmaVM *vm = runtimeCallInfo->GetVM();
3322     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3323     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3324     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3325     GetArkUINodeModifiers()->getCommonModifier()->resetRotate(nativeNode);
3326     return panda::JSValueRef::Undefined(vm);
3327 }
3328 
SetGeometryTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)3329 ArkUINativeModuleValue CommonBridge::SetGeometryTransition(ArkUIRuntimeCallInfo *runtimeCallInfo)
3330 {
3331     EcmaVM *vm = runtimeCallInfo->GetVM();
3332     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3333     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3334     Local<JSValueRef> idArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3335     Local<JSValueRef> followArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3336     Local<JSValueRef> hierarchyStrategyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3337     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3338     if (idArg->IsUndefined() || idArg->IsNull() || !idArg->IsString(vm)) {
3339         GetArkUINodeModifiers()->getCommonModifier()->resetGeometryTransition(nativeNode);
3340         return panda::JSValueRef::Undefined(vm);
3341     }
3342     std::string id = idArg->ToString(vm)->ToString(vm);
3343     ArkUIGeometryTransitionOptions options = {false, static_cast<int32_t>(TransitionHierarchyStrategy::ADAPTIVE)};
3344     if (followArg->IsBoolean()) {
3345         options.follow = followArg->ToBoolean(vm)->Value();
3346     }
3347     if (hierarchyStrategyArg->IsInt()) {
3348         options.hierarchyStrategy = hierarchyStrategyArg->Int32Value(vm);
3349         if (options.hierarchyStrategy < static_cast<int32_t>(TransitionHierarchyStrategy::NONE) ||
3350             options.hierarchyStrategy > static_cast<int32_t>(TransitionHierarchyStrategy::ADAPTIVE)) {
3351             options.hierarchyStrategy = static_cast<int32_t>(TransitionHierarchyStrategy::ADAPTIVE);
3352         }
3353     }
3354     GetArkUINodeModifiers()->getCommonModifier()->setGeometryTransition(nativeNode, id.c_str(), &options);
3355     return panda::JSValueRef::Undefined(vm);
3356 }
3357 
ResetGeometryTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)3358 ArkUINativeModuleValue CommonBridge::ResetGeometryTransition(ArkUIRuntimeCallInfo *runtimeCallInfo)
3359 {
3360     EcmaVM *vm = runtimeCallInfo->GetVM();
3361     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3362     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3363     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3364     GetArkUINodeModifiers()->getCommonModifier()->resetGeometryTransition(nativeNode);
3365     return panda::JSValueRef::Undefined(vm);
3366 }
3367 
ResetClip(ArkUIRuntimeCallInfo * runtimeCallInfo)3368 ArkUINativeModuleValue CommonBridge::ResetClip(ArkUIRuntimeCallInfo *runtimeCallInfo)
3369 {
3370     EcmaVM *vm = runtimeCallInfo->GetVM();
3371     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3372     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3373     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3374     auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3375     ViewAbstract::SetClipEdge(frameNode, false);
3376     return panda::JSValueRef::Undefined(vm);
3377 }
3378 
SetClip(ArkUIRuntimeCallInfo * runtimeCallInfo)3379 ArkUINativeModuleValue CommonBridge::SetClip(ArkUIRuntimeCallInfo *runtimeCallInfo)
3380 {
3381     EcmaVM *vm = runtimeCallInfo->GetVM();
3382     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3383     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3384     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3385     auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3386 
3387     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
3388     if (info[NUM_1]->IsUndefined()) {
3389         ViewAbstract::SetClipEdge(frameNode, false);
3390         return panda::JSValueRef::Undefined(vm);
3391     }
3392     if (info[NUM_1]->IsObject()) {
3393         Framework::JSShapeAbstract *clipShape =
3394             Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
3395         if (clipShape == nullptr) {
3396             return panda::JSValueRef::Undefined(vm);
3397         }
3398         ViewAbstract::SetClipShape(frameNode, clipShape->GetBasicShape());
3399     } else if (info[NUM_1]->IsBoolean()) {
3400         ViewAbstract::SetClipEdge(frameNode, info[NUM_1]->ToBoolean());
3401     }
3402     return panda::JSValueRef::Undefined(vm);
3403 }
3404 
SetClipShape(ArkUIRuntimeCallInfo * runtimeCallInfo)3405 ArkUINativeModuleValue CommonBridge::SetClipShape(ArkUIRuntimeCallInfo *runtimeCallInfo)
3406 {
3407     EcmaVM *vm = runtimeCallInfo->GetVM();
3408     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3409     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3410     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3411     auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3412 
3413     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
3414     if (info[NUM_1]->IsObject()) {
3415         Framework::JSShapeAbstract *clipShape =
3416             Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
3417         if (clipShape == nullptr) {
3418             return panda::JSValueRef::Undefined(vm);
3419         }
3420         ViewAbstract::SetClipShape(frameNode, clipShape->GetBasicShape());
3421     }
3422     return panda::JSValueRef::Undefined(vm);
3423 }
3424 
ResetClipShape(ArkUIRuntimeCallInfo * runtimeCallInfo)3425 ArkUINativeModuleValue CommonBridge::ResetClipShape(ArkUIRuntimeCallInfo *runtimeCallInfo)
3426 {
3427     EcmaVM *vm = runtimeCallInfo->GetVM();
3428     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3429     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3430     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3431     auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3432     ViewAbstract::SetClipEdge(frameNode, false);
3433     return panda::JSValueRef::Undefined(vm);
3434 }
3435 
SetPixelStretchEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3436 ArkUINativeModuleValue CommonBridge::SetPixelStretchEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3437 {
3438     EcmaVM *vm = runtimeCallInfo->GetVM();
3439     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3440     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3441     auto topArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3442     auto rightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3443     auto bottomArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3444     auto leftArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3445     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3446     CalcDimension left;
3447     ArkTSUtils::ParseJsDimensionVp(vm, leftArg, left);
3448     CalcDimension right;
3449     ArkTSUtils::ParseJsDimensionVp(vm, rightArg, right);
3450     CalcDimension top;
3451     ArkTSUtils::ParseJsDimensionVp(vm, topArg, top);
3452     CalcDimension bottom;
3453     ArkTSUtils::ParseJsDimensionVp(vm, bottomArg, bottom);
3454     ArkUI_Float32 values[] = { left.Value(), top.Value(), right.Value(), bottom.Value() };
3455     int units[] = { static_cast<int>(left.Unit()), static_cast<int>(top.Unit()), static_cast<int>(right.Unit()),
3456                     static_cast<int>(bottom.Unit()) };
3457     GetArkUINodeModifiers()->getCommonModifier()->setPixelStretchEffect(nativeNode, values, units,
3458         (sizeof(values) / sizeof(values[NUM_0])));
3459     return panda::JSValueRef::Undefined(vm);
3460 }
3461 
ResetPixelStretchEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3462 ArkUINativeModuleValue CommonBridge::ResetPixelStretchEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3463 {
3464     EcmaVM *vm = runtimeCallInfo->GetVM();
3465     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3466     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3467     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3468     GetArkUINodeModifiers()->getCommonModifier()->resetPixelStretchEffect(nativeNode);
3469     return panda::JSValueRef::Undefined(vm);
3470 }
3471 
SetLightUpEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3472 ArkUINativeModuleValue CommonBridge::SetLightUpEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3473 {
3474     EcmaVM *vm = runtimeCallInfo->GetVM();
3475     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3476     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3477     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3478     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3479     auto radio = 1.0;
3480     if (secondArg->IsNumber()) {
3481         radio = secondArg->ToNumber(vm)->Value();
3482     }
3483     GetArkUINodeModifiers()->getCommonModifier()->setLightUpEffect(nativeNode, radio);
3484     return panda::JSValueRef::Undefined(vm);
3485 }
3486 
ResetLightUpEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3487 ArkUINativeModuleValue CommonBridge::ResetLightUpEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3488 {
3489     EcmaVM *vm = runtimeCallInfo->GetVM();
3490     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3491     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3492     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3493     GetArkUINodeModifiers()->getCommonModifier()->resetLightUpEffect(nativeNode);
3494     return panda::JSValueRef::Undefined(vm);
3495 }
3496 
SetSphericalEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3497 ArkUINativeModuleValue CommonBridge::SetSphericalEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3498 {
3499     EcmaVM *vm = runtimeCallInfo->GetVM();
3500     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3501     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3502     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3503     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3504     auto radio = 0.0;
3505     if (secondArg->IsNumber()) {
3506         radio = secondArg->ToNumber(vm)->Value();
3507     }
3508     GetArkUINodeModifiers()->getCommonModifier()->setSphericalEffect(nativeNode, radio);
3509     return panda::JSValueRef::Undefined(vm);
3510 }
3511 
ResetSphericalEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3512 ArkUINativeModuleValue CommonBridge::ResetSphericalEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3513 {
3514     EcmaVM *vm = runtimeCallInfo->GetVM();
3515     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3516     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3517     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3518     GetArkUINodeModifiers()->getCommonModifier()->resetSphericalEffect(nativeNode);
3519     return panda::JSValueRef::Undefined(vm);
3520 }
3521 
SetRenderGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)3522 ArkUINativeModuleValue CommonBridge::SetRenderGroup(ArkUIRuntimeCallInfo *runtimeCallInfo)
3523 {
3524     EcmaVM *vm = runtimeCallInfo->GetVM();
3525     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3526     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3527     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3528     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3529     auto isRenderGroup = false;
3530     if (secondArg->IsBoolean()) {
3531         isRenderGroup = secondArg->ToBoolean(vm)->Value();
3532     }
3533     GetArkUINodeModifiers()->getCommonModifier()->setRenderGroup(nativeNode, isRenderGroup);
3534     return panda::JSValueRef::Undefined(vm);
3535 }
3536 
ResetRenderGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)3537 ArkUINativeModuleValue CommonBridge::ResetRenderGroup(ArkUIRuntimeCallInfo *runtimeCallInfo)
3538 {
3539     EcmaVM *vm = runtimeCallInfo->GetVM();
3540     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3541     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3542     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3543     GetArkUINodeModifiers()->getCommonModifier()->resetRenderGroup(nativeNode);
3544     return panda::JSValueRef::Undefined(vm);
3545 }
3546 
SetRenderFit(ArkUIRuntimeCallInfo * runtimeCallInfo)3547 ArkUINativeModuleValue CommonBridge::SetRenderFit(ArkUIRuntimeCallInfo *runtimeCallInfo)
3548 {
3549     EcmaVM *vm = runtimeCallInfo->GetVM();
3550     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3551     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3552     auto fitModeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3553     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3554     auto renderFit = static_cast<int32_t>(RenderFit::TOP_LEFT);
3555     if (fitModeArg->IsNumber()) {
3556         renderFit = fitModeArg->Int32Value(vm);
3557     }
3558     GetArkUINodeModifiers()->getCommonModifier()->setRenderFit(nativeNode, renderFit);
3559     return panda::JSValueRef::Undefined(vm);
3560 }
3561 
ResetRenderFit(ArkUIRuntimeCallInfo * runtimeCallInfo)3562 ArkUINativeModuleValue CommonBridge::ResetRenderFit(ArkUIRuntimeCallInfo *runtimeCallInfo)
3563 {
3564     EcmaVM *vm = runtimeCallInfo->GetVM();
3565     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3566     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3567     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3568     GetArkUINodeModifiers()->getCommonModifier()->resetRenderFit(nativeNode);
3569     return panda::JSValueRef::Undefined(vm);
3570 }
3571 
SetUseEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3572 ArkUINativeModuleValue CommonBridge::SetUseEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3573 {
3574     EcmaVM *vm = runtimeCallInfo->GetVM();
3575     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3576     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3577     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3578     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3579     auto useEffect = false;
3580     if (secondArg->IsBoolean()) {
3581         useEffect = secondArg->ToBoolean(vm)->Value();
3582     }
3583     GetArkUINodeModifiers()->getCommonModifier()->setUseEffect(nativeNode, useEffect);
3584     return panda::JSValueRef::Undefined(vm);
3585 }
3586 
ResetUseEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3587 ArkUINativeModuleValue CommonBridge::ResetUseEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3588 {
3589     EcmaVM *vm = runtimeCallInfo->GetVM();
3590     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3591     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3592     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3593     GetArkUINodeModifiers()->getCommonModifier()->resetUseEffect(nativeNode);
3594     return panda::JSValueRef::Undefined(vm);
3595 }
3596 
SetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)3597 ArkUINativeModuleValue CommonBridge::SetForegroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
3598 {
3599     EcmaVM *vm = runtimeCallInfo->GetVM();
3600     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3601     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3602     auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3603     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3604     if (colorArg->IsString(vm)) {
3605         std::string colorStr = colorArg->ToString(vm)->ToString(vm);
3606         colorStr.erase(std::remove(colorStr.begin(), colorStr.end(), ' '), colorStr.end());
3607         std::transform(colorStr.begin(), colorStr.end(), colorStr.begin(), ::tolower);
3608         if (colorStr.compare("invert") == 0) {
3609             auto strategy = static_cast<uint32_t>(ForegroundColorStrategy::INVERT);
3610             GetArkUINodeModifiers()->getCommonModifier()->setForegroundColor(nativeNode, false, strategy);
3611             return panda::JSValueRef::Undefined(vm);
3612         }
3613     }
3614     Color foregroundColor;
3615     if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, foregroundColor)) {
3616         return panda::JSValueRef::Undefined(vm);
3617     }
3618     GetArkUINodeModifiers()->getCommonModifier()->setForegroundColor(nativeNode, true, foregroundColor.GetValue());
3619     return panda::JSValueRef::Undefined(vm);
3620 }
3621 
ResetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)3622 ArkUINativeModuleValue CommonBridge::ResetForegroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
3623 {
3624     EcmaVM *vm = runtimeCallInfo->GetVM();
3625     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3626     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3627     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3628     GetArkUINodeModifiers()->getCommonModifier()->resetForegroundColor(nativeNode);
3629     return panda::JSValueRef::Undefined(vm);
3630 }
3631 
SetMotionPath(ArkUIRuntimeCallInfo * runtimeCallInfo)3632 ArkUINativeModuleValue CommonBridge::SetMotionPath(ArkUIRuntimeCallInfo *runtimeCallInfo)
3633 {
3634     EcmaVM *vm = runtimeCallInfo->GetVM();
3635     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3636     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3637     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3638     auto pathArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3639     auto fromArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3640     auto toArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3641     auto rotatableArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3642     std::string pathStringValue;
3643     if (pathArg->IsString(vm)) {
3644         pathStringValue = pathArg->ToString(vm)->ToString(vm);
3645     }
3646     float fromValue = (fromArg->IsNumber()) ? fromArg->ToNumber(vm)->Value() : 0.0f;
3647     float toValue = (toArg->IsNumber()) ? toArg->ToNumber(vm)->Value() : 1.0f;
3648     if (fromValue > 1.0f || fromValue < 0.0f) {
3649         fromValue = 0.0f;
3650     }
3651     if (toValue > 1.0f || toValue < 0.0f) {
3652         toValue = 1.0f;
3653     } else if (toValue < fromValue) {
3654         toValue = fromValue;
3655     }
3656     bool rotatableValue = (rotatableArg->IsBoolean()) ? rotatableArg->ToBoolean(vm)->Value() : false;
3657     GetArkUINodeModifiers()->getCommonModifier()->setMotionPath(nativeNode, pathStringValue.c_str(), fromValue,
3658         toValue, rotatableValue);
3659     return panda::JSValueRef::Undefined(vm);
3660 }
3661 
ResetMotionPath(ArkUIRuntimeCallInfo * runtimeCallInfo)3662 ArkUINativeModuleValue CommonBridge::ResetMotionPath(ArkUIRuntimeCallInfo *runtimeCallInfo)
3663 {
3664     EcmaVM *vm = runtimeCallInfo->GetVM();
3665     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3666     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3667     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3668     GetArkUINodeModifiers()->getCommonModifier()->resetMotionPath(nativeNode);
3669     return panda::JSValueRef::Undefined(vm);
3670 }
3671 
3672 
SetMotionBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)3673 ArkUINativeModuleValue CommonBridge::SetMotionBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
3674 {
3675     EcmaVM *vm = runtimeCallInfo->GetVM();
3676     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3677     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3678     Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3679     Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3680     Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3681     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3682     double radius = 0.0;
3683     if (!ArkTSUtils::ParseJsDouble(vm, radiusArg, radius) || LessNotEqual(radius, 0.0)) {
3684         radius = 0.0;
3685     }
3686     double x = 0.0;
3687     double y = 0.0;
3688     if (!ArkTSUtils::ParseJsDouble(vm, xArg, x) || LessNotEqual(x, 0.0)) {
3689         x = 0.0;
3690     }
3691     if (!ArkTSUtils::ParseJsDouble(vm, yArg, y) || LessNotEqual(y, 0.0)) {
3692         y = 0.0;
3693     }
3694     x = std::clamp(x, 0.0, 1.0);
3695     y = std::clamp(y, 0.0, 1.0);
3696     GetArkUINodeModifiers()->getCommonModifier()->setMotionBlur(nativeNode, radius, x, y);
3697     return panda::JSValueRef::Undefined(vm);
3698 }
3699 
ResetMotionBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)3700 ArkUINativeModuleValue CommonBridge::ResetMotionBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
3701 {
3702     EcmaVM *vm = runtimeCallInfo->GetVM();
3703     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3704     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3705     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3706     GetArkUINodeModifiers()->getCommonModifier()->resetMotionBlur(nativeNode);
3707     return panda::JSValueRef::Undefined(vm);
3708 }
3709 
SetGroupDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)3710 ArkUINativeModuleValue CommonBridge::SetGroupDefaultFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
3711 {
3712     EcmaVM *vm = runtimeCallInfo->GetVM();
3713     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3714     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3715     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3716     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3717     if (secondArg->IsBoolean()) {
3718         bool groupDefaultFocus = secondArg->ToBoolean(vm)->Value();
3719         GetArkUINodeModifiers()->getCommonModifier()->setGroupDefaultFocus(nativeNode, groupDefaultFocus);
3720     } else {
3721         GetArkUINodeModifiers()->getCommonModifier()->resetGroupDefaultFocus(nativeNode);
3722     }
3723     return panda::JSValueRef::Undefined(vm);
3724 }
3725 
ResetGroupDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)3726 ArkUINativeModuleValue CommonBridge::ResetGroupDefaultFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
3727 {
3728     EcmaVM *vm = runtimeCallInfo->GetVM();
3729     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3730     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3731     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3732     GetArkUINodeModifiers()->getCommonModifier()->resetGroupDefaultFocus(nativeNode);
3733     return panda::JSValueRef::Undefined(vm);
3734 }
3735 
SetFocusOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)3736 ArkUINativeModuleValue CommonBridge::SetFocusOnTouch(ArkUIRuntimeCallInfo *runtimeCallInfo)
3737 {
3738     EcmaVM *vm = runtimeCallInfo->GetVM();
3739     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3740     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3741     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3742     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3743     if (secondArg->IsBoolean()) {
3744         bool focusOnTouch = secondArg->ToBoolean(vm)->Value();
3745         GetArkUINodeModifiers()->getCommonModifier()->setFocusOnTouch(nativeNode, focusOnTouch);
3746     } else {
3747         GetArkUINodeModifiers()->getCommonModifier()->resetFocusOnTouch(nativeNode);
3748     }
3749     return panda::JSValueRef::Undefined(vm);
3750 }
3751 
ResetFocusOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)3752 ArkUINativeModuleValue CommonBridge::ResetFocusOnTouch(ArkUIRuntimeCallInfo *runtimeCallInfo)
3753 {
3754     EcmaVM *vm = runtimeCallInfo->GetVM();
3755     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3756     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3757     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3758     GetArkUINodeModifiers()->getCommonModifier()->resetFocusOnTouch(nativeNode);
3759     return panda::JSValueRef::Undefined(vm);
3760 }
3761 
SetFocusable(ArkUIRuntimeCallInfo * runtimeCallInfo)3762 ArkUINativeModuleValue CommonBridge::SetFocusable(ArkUIRuntimeCallInfo* runtimeCallInfo)
3763 {
3764     EcmaVM* vm = runtimeCallInfo->GetVM();
3765     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3766     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3767     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3768     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3769     if (secondArg->IsBoolean()) {
3770         bool focusable = secondArg->ToBoolean(vm)->Value();
3771         GetArkUINodeModifiers()->getCommonModifier()->setFocusable(nativeNode, focusable);
3772     }
3773     return panda::JSValueRef::Undefined(vm);
3774 }
3775 
ResetFocusable(ArkUIRuntimeCallInfo * runtimeCallInfo)3776 ArkUINativeModuleValue CommonBridge::ResetFocusable(ArkUIRuntimeCallInfo* runtimeCallInfo)
3777 {
3778     EcmaVM* vm = runtimeCallInfo->GetVM();
3779     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3780     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3781     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3782     GetArkUINodeModifiers()->getCommonModifier()->resetFocusable(nativeNode);
3783     return panda::JSValueRef::Undefined(vm);
3784 }
3785 
SetTouchable(ArkUIRuntimeCallInfo * runtimeCallInfo)3786 ArkUINativeModuleValue CommonBridge::SetTouchable(ArkUIRuntimeCallInfo* runtimeCallInfo)
3787 {
3788     EcmaVM* vm = runtimeCallInfo->GetVM();
3789     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3790     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3791     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3792     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3793     if (secondArg->IsBoolean()) {
3794         bool touchable = secondArg->ToBoolean(vm)->Value();
3795         GetArkUINodeModifiers()->getCommonModifier()->setTouchable(nativeNode, touchable);
3796     } else {
3797         GetArkUINodeModifiers()->getCommonModifier()->resetTouchable(nativeNode);
3798     }
3799     return panda::JSValueRef::Undefined(vm);
3800 }
3801 
ResetTouchable(ArkUIRuntimeCallInfo * runtimeCallInfo)3802 ArkUINativeModuleValue CommonBridge::ResetTouchable(ArkUIRuntimeCallInfo* runtimeCallInfo)
3803 {
3804     EcmaVM* vm = runtimeCallInfo->GetVM();
3805     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3806     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3807     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3808     GetArkUINodeModifiers()->getCommonModifier()->resetTouchable(nativeNode);
3809     return panda::JSValueRef::Undefined(vm);
3810 }
3811 
SetDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)3812 ArkUINativeModuleValue CommonBridge::SetDefaultFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
3813 {
3814     EcmaVM* vm = runtimeCallInfo->GetVM();
3815     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3816     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3817     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3818     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3819     if (secondArg->IsBoolean()) {
3820         bool defaultFocus = secondArg->ToBoolean(vm)->Value();
3821         GetArkUINodeModifiers()->getCommonModifier()->setDefaultFocus(nativeNode, defaultFocus);
3822     } else {
3823         GetArkUINodeModifiers()->getCommonModifier()->resetDefaultFocus(nativeNode);
3824     }
3825     return panda::JSValueRef::Undefined(vm);
3826 }
3827 
ResetDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)3828 ArkUINativeModuleValue CommonBridge::ResetDefaultFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
3829 {
3830     EcmaVM* vm = runtimeCallInfo->GetVM();
3831     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3832     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3833     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3834     GetArkUINodeModifiers()->getCommonModifier()->resetDefaultFocus(nativeNode);
3835     return panda::JSValueRef::Undefined(vm);
3836 }
3837 
SetDisplayPriority(ArkUIRuntimeCallInfo * runtimeCallInfo)3838 ArkUINativeModuleValue CommonBridge::SetDisplayPriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
3839 {
3840     EcmaVM* vm = runtimeCallInfo->GetVM();
3841     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3842     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3843     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3844     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3845     if (secondArg->IsNumber()) {
3846         double value = secondArg->ToNumber(vm)->Value();
3847         GetArkUINodeModifiers()->getCommonModifier()->setDisplayPriority(nativeNode, value);
3848     } else {
3849         GetArkUINodeModifiers()->getCommonModifier()->resetDisplayPriority(nativeNode);
3850     }
3851     return panda::JSValueRef::Undefined(vm);
3852 }
3853 
ResetDisplayPriority(ArkUIRuntimeCallInfo * runtimeCallInfo)3854 ArkUINativeModuleValue CommonBridge::ResetDisplayPriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
3855 {
3856     EcmaVM* vm = runtimeCallInfo->GetVM();
3857     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3858     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3859     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3860     GetArkUINodeModifiers()->getCommonModifier()->resetDisplayPriority(nativeNode);
3861     return panda::JSValueRef::Undefined(vm);
3862 }
3863 
SetAccessibilityLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)3864 ArkUINativeModuleValue CommonBridge::SetAccessibilityLevel(ArkUIRuntimeCallInfo* runtimeCallInfo)
3865 {
3866     EcmaVM* vm = runtimeCallInfo->GetVM();
3867     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3868     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3869     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3870     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3871     if (secondArg->IsString(vm)) {
3872         std::string stringValue = secondArg->ToString(vm)->ToString(vm);
3873         GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityLevel(nativeNode, stringValue.c_str());
3874     } else {
3875         GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityLevel(nativeNode);
3876     }
3877     return panda::JSValueRef::Undefined(vm);
3878 }
3879 
ResetAccessibilityLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)3880 ArkUINativeModuleValue CommonBridge::ResetAccessibilityLevel(ArkUIRuntimeCallInfo* runtimeCallInfo)
3881 {
3882     EcmaVM* vm = runtimeCallInfo->GetVM();
3883     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3884     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3885     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3886     GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityLevel(nativeNode);
3887     return panda::JSValueRef::Undefined(vm);
3888 }
3889 
SetAccessibilityDescription(ArkUIRuntimeCallInfo * runtimeCallInfo)3890 ArkUINativeModuleValue CommonBridge::SetAccessibilityDescription(ArkUIRuntimeCallInfo* runtimeCallInfo)
3891 {
3892     EcmaVM* vm = runtimeCallInfo->GetVM();
3893     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3894     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3895     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3896     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3897     if (secondArg->IsString(vm)) {
3898         std::string stringValue = secondArg->ToString(vm)->ToString(vm);
3899         GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityDescription(nativeNode, stringValue.c_str());
3900     } else {
3901         GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityDescription(nativeNode);
3902     }
3903     return panda::JSValueRef::Undefined(vm);
3904 }
3905 
ResetAccessibilityDescription(ArkUIRuntimeCallInfo * runtimeCallInfo)3906 ArkUINativeModuleValue CommonBridge::ResetAccessibilityDescription(ArkUIRuntimeCallInfo* runtimeCallInfo)
3907 {
3908     EcmaVM* vm = runtimeCallInfo->GetVM();
3909     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3910     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3911     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3912     GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityDescription(nativeNode);
3913     return panda::JSValueRef::Undefined(vm);
3914 }
3915 
SetOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)3916 ArkUINativeModuleValue CommonBridge::SetOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
3917 {
3918     EcmaVM* vm = runtimeCallInfo->GetVM();
3919     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3920     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3921     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3922     bool useEdges = runtimeCallInfo->GetCallArgRef(NUM_1)->ToBoolean(vm)->Value();
3923     std::vector<ArkUIStringAndFloat> options;
3924     std::vector<std::optional<CalcDimension>> edges;
3925 
3926     if (useEdges) {
3927         ParseResult res = ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_4, edges, CalcDimension(0.0));
3928         if (res == ParseResult::LENGTHMETRICS_SUCCESS && AceApplicationInfo::GetInstance().IsRightToLeft()) {
3929             // Swap left and right
3930             std::swap(edges[NUM_1], edges[NUM_3]);
3931         }
3932         PushDimensionsToVector(options, edges);
3933         GetArkUINodeModifiers()->getCommonModifier()->setOffsetEdges(nativeNode, useEdges, options.data());
3934     } else {
3935         ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_2, edges, CalcDimension(0.0));
3936         PushDimensionsToVector(options, edges);
3937         GetArkUINodeModifiers()->getCommonModifier()->setOffsetEdges(nativeNode, useEdges, options.data());
3938     }
3939     return panda::JSValueRef::Undefined(vm);
3940 }
3941 
ResetOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)3942 ArkUINativeModuleValue CommonBridge::ResetOffset(ArkUIRuntimeCallInfo *runtimeCallInfo)
3943 {
3944     EcmaVM *vm = runtimeCallInfo->GetVM();
3945     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3946     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3947     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3948 
3949     GetArkUINodeModifiers()->getCommonModifier()->resetOffset(nativeNode);
3950     return panda::JSValueRef::Undefined(vm);
3951 }
3952 
ParsePadding(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)3953 void ParsePadding(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen, ArkUISizeType& result)
3954 {
3955     if (ArkTSUtils::ParseJsDimensionVp(vm, value, dimen)) {
3956         if (LessOrEqual(dimen.Value(), 0.0)) {
3957             dimen.SetValue(0.0);
3958             dimen.SetUnit(DimensionUnit::VP);
3959         }
3960         result.unit = static_cast<int8_t>(dimen.Unit());
3961         if (dimen.CalcValue() != "") {
3962             result.string = dimen.CalcValue().c_str();
3963         } else {
3964             result.value = dimen.Value();
3965         }
3966     }
3967 }
3968 
ParseLocalizedPadding(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)3969 bool ParseLocalizedPadding(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen,
3970     ArkUISizeType& result)
3971 {
3972     if (ArkTSUtils::ParseJsLengthMetrics(vm, value, dimen)) {
3973         if (LessOrEqual(dimen.Value(), 0.0)) {
3974             dimen.SetValue(0.0);
3975             dimen.SetUnit(DimensionUnit::VP);
3976         }
3977         result.unit = static_cast<int8_t>(dimen.Unit());
3978         if (dimen.CalcValue() != "") {
3979             result.string = dimen.CalcValue().c_str();
3980         } else {
3981             result.value = dimen.Value();
3982         }
3983         return true;
3984     }
3985     return false;
3986 }
3987 
SetPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)3988 ArkUINativeModuleValue CommonBridge::SetPadding(ArkUIRuntimeCallInfo *runtimeCallInfo)
3989 {
3990     EcmaVM *vm = runtimeCallInfo->GetVM();
3991     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3992     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3993     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3994     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3995     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3996     Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3997     Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3998 
3999     struct ArkUISizeType top = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4000     struct ArkUISizeType right = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4001     struct ArkUISizeType bottom = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4002     struct ArkUISizeType left = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4003 
4004     CalcDimension topDimen(0, DimensionUnit::VP);
4005     CalcDimension rightDimen(0, DimensionUnit::VP);
4006     CalcDimension bottomDimen(0, DimensionUnit::VP);
4007     CalcDimension leftDimen(0, DimensionUnit::VP);
4008 
4009     bool isLengthMetrics = false;
4010     if (secondArg->IsObject(vm)) {
4011         isLengthMetrics |= ParseLocalizedPadding(vm, secondArg, topDimen, top);
4012     }
4013     if (thirdArg->IsObject(vm)) {
4014         isLengthMetrics |= ParseLocalizedPadding(vm, thirdArg, rightDimen, right);
4015     }
4016     if (forthArg->IsObject(vm)) {
4017         isLengthMetrics |= ParseLocalizedPadding(vm, forthArg, bottomDimen, bottom);
4018     }
4019     if (fifthArg->IsObject(vm)) {
4020         isLengthMetrics |= ParseLocalizedPadding(vm, fifthArg, leftDimen, left);
4021     }
4022 
4023     if (isLengthMetrics) {
4024         auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
4025         GetArkUINodeModifiers()->getCommonModifier()->setPadding(nativeNode,
4026             &top,
4027             isRightToLeft ? &left : &right,
4028             &bottom,
4029             isRightToLeft ? &right : &left);
4030         return panda::JSValueRef::Undefined(vm);
4031     }
4032 
4033     ParsePadding(vm, secondArg, topDimen, top);
4034     ParsePadding(vm, thirdArg, rightDimen, right);
4035     ParsePadding(vm, forthArg, bottomDimen, bottom);
4036     ParsePadding(vm, fifthArg, leftDimen, left);
4037     GetArkUINodeModifiers()->getCommonModifier()->setPadding(nativeNode, &top, &right, &bottom, &left);
4038 
4039     return panda::JSValueRef::Undefined(vm);
4040 }
4041 
ResetPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)4042 ArkUINativeModuleValue CommonBridge::ResetPadding(ArkUIRuntimeCallInfo *runtimeCallInfo)
4043 {
4044     EcmaVM *vm = runtimeCallInfo->GetVM();
4045     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4046     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4047     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4048     GetArkUINodeModifiers()->getCommonModifier()->resetPadding(nativeNode);
4049     return panda::JSValueRef::Undefined(vm);
4050 }
4051 
ParseLocalizedMargin(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)4052 bool ParseLocalizedMargin(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen, ArkUISizeType& result)
4053 {
4054     if (ArkTSUtils::ParseJsLengthMetrics(vm, value, dimen)) {
4055         result.unit = static_cast<int8_t>(dimen.Unit());
4056         if (dimen.CalcValue() != "") {
4057             result.string = dimen.CalcValue().c_str();
4058         } else {
4059             result.value = dimen.Value();
4060         }
4061         return true;
4062     }
4063     return false;
4064 }
4065 
ParseMargin(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)4066 void ParseMargin(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen, ArkUISizeType& result)
4067 {
4068     if (ArkTSUtils::ParseJsDimensionVp(vm, value, dimen)) {
4069         result.unit = static_cast<int8_t>(dimen.Unit());
4070         if (dimen.CalcValue() != "") {
4071             result.string = dimen.CalcValue().c_str();
4072         } else {
4073             result.value = dimen.Value();
4074         }
4075     }
4076 }
4077 
SetMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)4078 ArkUINativeModuleValue CommonBridge::SetMargin(ArkUIRuntimeCallInfo *runtimeCallInfo)
4079 {
4080     EcmaVM *vm = runtimeCallInfo->GetVM();
4081     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4082     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4083     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4084     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4085     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4086     Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
4087     Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
4088     ArkUISizeType top = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4089     ArkUISizeType right = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4090     ArkUISizeType bottom = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4091     ArkUISizeType left = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4092     CalcDimension topDimen(0, DimensionUnit::VP);
4093     CalcDimension rightDimen(0, DimensionUnit::VP);
4094     CalcDimension bottomDimen(0, DimensionUnit::VP);
4095     CalcDimension leftDimen(0, DimensionUnit::VP);
4096 
4097     bool isLengthMetrics = false;
4098     if (secondArg->IsObject(vm)) {
4099         isLengthMetrics |= ParseLocalizedMargin(vm, secondArg, topDimen, top);
4100     }
4101     if (thirdArg->IsObject(vm)) {
4102         isLengthMetrics |= ParseLocalizedMargin(vm, thirdArg, rightDimen, right);
4103     }
4104     if (forthArg->IsObject(vm)) {
4105         isLengthMetrics |= ParseLocalizedMargin(vm, forthArg, bottomDimen, bottom);
4106     }
4107     if (fifthArg->IsObject(vm)) {
4108         isLengthMetrics |= ParseLocalizedMargin(vm, fifthArg, leftDimen, left);
4109     }
4110     if (isLengthMetrics) {
4111         auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
4112         GetArkUINodeModifiers()->getCommonModifier()->setMargin(nativeNode,
4113             &top,
4114             isRightToLeft ? &left : &right,
4115             &bottom,
4116             isRightToLeft ? &right : &left);
4117         return panda::JSValueRef::Undefined(vm);
4118     }
4119     ParseMargin(vm, secondArg, topDimen, top);
4120     ParseMargin(vm, thirdArg, rightDimen, right);
4121     ParseMargin(vm, forthArg, bottomDimen, bottom);
4122     ParseMargin(vm, fifthArg, leftDimen, left);
4123     GetArkUINodeModifiers()->getCommonModifier()->setMargin(nativeNode, &top, &right, &bottom, &left);
4124     return panda::JSValueRef::Undefined(vm);
4125 }
4126 
ResetMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)4127 ArkUINativeModuleValue CommonBridge::ResetMargin(ArkUIRuntimeCallInfo *runtimeCallInfo)
4128 {
4129     EcmaVM *vm = runtimeCallInfo->GetVM();
4130     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4131     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4132     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4133     GetArkUINodeModifiers()->getCommonModifier()->resetMargin(nativeNode);
4134     return panda::JSValueRef::Undefined(vm);
4135 }
4136 
SetMarkAnchor(ArkUIRuntimeCallInfo * runtimeCallInfo)4137 ArkUINativeModuleValue CommonBridge::SetMarkAnchor(ArkUIRuntimeCallInfo* runtimeCallInfo)
4138 {
4139     EcmaVM* vm = runtimeCallInfo->GetVM();
4140     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4141     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4142     Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4143     Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4144     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4145     CalcDimension x(0.0, DimensionUnit::VP);
4146     CalcDimension y(0.0, DimensionUnit::VP);
4147     bool useLengthMetrics = ArkTSUtils::ParseJsLengthMetrics(vm, xArg, x);
4148     useLengthMetrics = ArkTSUtils::ParseJsLengthMetrics(vm, yArg, y) || useLengthMetrics;
4149     if (useLengthMetrics && AceApplicationInfo::GetInstance().IsRightToLeft()) {
4150         x.SetValue(-x.Value());
4151     }
4152     bool hasX = useLengthMetrics || ArkTSUtils::ParseJsDimensionNG(vm, xArg, x, DimensionUnit::VP);
4153     bool hasY = useLengthMetrics || ArkTSUtils::ParseJsDimensionNG(vm, yArg, y, DimensionUnit::VP);
4154     if (useLengthMetrics || hasX || hasY) {
4155         GetArkUINodeModifiers()->getCommonModifier()->setMarkAnchor(
4156             nativeNode, x.Value(), static_cast<int32_t>(x.Unit()), y.Value(), static_cast<int32_t>(y.Unit()));
4157     } else {
4158         GetArkUINodeModifiers()->getCommonModifier()->resetMarkAnchor(nativeNode);
4159     }
4160     return panda::JSValueRef::Undefined(vm);
4161 }
4162 
ResetMarkAnchor(ArkUIRuntimeCallInfo * runtimeCallInfo)4163 ArkUINativeModuleValue CommonBridge::ResetMarkAnchor(ArkUIRuntimeCallInfo *runtimeCallInfo)
4164 {
4165     EcmaVM *vm = runtimeCallInfo->GetVM();
4166     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4167     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
4168     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4169     GetArkUINodeModifiers()->getCommonModifier()->resetMarkAnchor(nativeNode);
4170     return panda::JSValueRef::Undefined(vm);
4171 }
4172 
SetVisibility(ArkUIRuntimeCallInfo * runtimeCallInfo)4173 ArkUINativeModuleValue CommonBridge::SetVisibility(ArkUIRuntimeCallInfo *runtimeCallInfo)
4174 {
4175     EcmaVM *vm = runtimeCallInfo->GetVM();
4176     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4177     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4178     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4179     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4180     int32_t value = 0;
4181     if (secondArg->IsNumber()) {
4182         value = secondArg->Int32Value(vm);
4183         if (value<NUM_0 || value>NUM_2) {
4184             value = 0;
4185         }
4186     }
4187     GetArkUINodeModifiers()->getCommonModifier()->setVisibility(nativeNode, value);
4188     return panda::JSValueRef::Undefined(vm);
4189 }
4190 
ResetVisibility(ArkUIRuntimeCallInfo * runtimeCallInfo)4191 ArkUINativeModuleValue CommonBridge::ResetVisibility(ArkUIRuntimeCallInfo *runtimeCallInfo)
4192 {
4193     EcmaVM *vm = runtimeCallInfo->GetVM();
4194     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4195     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4196     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4197     GetArkUINodeModifiers()->getCommonModifier()->resetVisibility(nativeNode);
4198     return panda::JSValueRef::Undefined(vm);
4199 }
4200 
SetAccessibilityText(ArkUIRuntimeCallInfo * runtimeCallInfo)4201 ArkUINativeModuleValue CommonBridge::SetAccessibilityText(ArkUIRuntimeCallInfo* runtimeCallInfo)
4202 {
4203     EcmaVM* vm = runtimeCallInfo->GetVM();
4204     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4205     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4206     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4207     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4208     if (secondArg->IsString(vm)) {
4209         std::string stringValue = secondArg->ToString(vm)->ToString(vm);
4210         GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityText(nativeNode, stringValue.c_str());
4211     } else {
4212         GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityText(nativeNode);
4213     }
4214     return panda::JSValueRef::Undefined(vm);
4215 }
4216 
ResetAccessibilityText(ArkUIRuntimeCallInfo * runtimeCallInfo)4217 ArkUINativeModuleValue CommonBridge::ResetAccessibilityText(ArkUIRuntimeCallInfo* runtimeCallInfo)
4218 {
4219     EcmaVM* vm = runtimeCallInfo->GetVM();
4220     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4221     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4222     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4223     GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityText(nativeNode);
4224     return panda::JSValueRef::Undefined(vm);
4225 }
4226 
SetConstraintSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4227 ArkUINativeModuleValue CommonBridge::SetConstraintSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4228 {
4229     EcmaVM* vm = runtimeCallInfo->GetVM();
4230     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4231     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4232     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4233     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4234     Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
4235     Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
4236     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4237     CalcDimension minWidth;
4238     CalcDimension maxWidth;
4239     CalcDimension minHeight;
4240     CalcDimension maxHeight;
4241     struct ArkUISizeType minWidthValue = {0.0, 0};
4242     struct ArkUISizeType maxWidthValue = {0.0, 0};
4243     struct ArkUISizeType minHeightValue = {0.0, 0};
4244     struct ArkUISizeType maxHeightValue = {0.0, 0};
4245 
4246     bool version10OrLarger = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN);
4247     if (ArkTSUtils::ParseJsDimensionVp(vm, secondArg, minWidth, false)) {
4248         if (minWidth.CalcValue() != "") {
4249             minWidthValue.string = minWidth.CalcValue().c_str();
4250         } else {
4251             minWidthValue.value = minWidth.Value();
4252             minWidthValue.unit = static_cast<int8_t>(minWidth.Unit());
4253         }
4254         GetArkUINodeModifiers()->getCommonModifier()->setMinWidth(nativeNode, &minWidthValue);
4255     } else if (version10OrLarger) {
4256         GetArkUINodeModifiers()->getCommonModifier()->resetMinWidth(nativeNode);
4257     }
4258 
4259     if (ArkTSUtils::ParseJsDimensionVp(vm, thirdArg, maxWidth, false)) {
4260         if (maxWidth.CalcValue() != "") {
4261             maxWidthValue.string = maxWidth.CalcValue().c_str();
4262         } else {
4263             maxWidthValue.value = maxWidth.Value();
4264             maxWidthValue.unit = static_cast<int8_t>(maxWidth.Unit());
4265         }
4266         GetArkUINodeModifiers()->getCommonModifier()->setMaxWidth(nativeNode, &maxWidthValue);
4267     } else if (version10OrLarger) {
4268         GetArkUINodeModifiers()->getCommonModifier()->resetMaxWidth(nativeNode);
4269     }
4270 
4271     if (ArkTSUtils::ParseJsDimensionVp(vm, forthArg, minHeight, false)) {
4272         if (minHeight.CalcValue() != "") {
4273             minHeightValue.string = minHeight.CalcValue().c_str();
4274         } else {
4275             minHeightValue.value = minHeight.Value();
4276             minHeightValue.unit = static_cast<int8_t>(minHeight.Unit());
4277         }
4278         GetArkUINodeModifiers()->getCommonModifier()->setMinHeight(nativeNode, &minHeightValue);
4279     } else if (version10OrLarger) {
4280         GetArkUINodeModifiers()->getCommonModifier()->resetMinHeight(nativeNode);
4281     }
4282 
4283     if (ArkTSUtils::ParseJsDimensionVp(vm, fifthArg, maxHeight, false)) {
4284         if (maxHeight.CalcValue() != "") {
4285             maxHeightValue.string = maxHeight.CalcValue().c_str();
4286         } else {
4287             maxHeightValue.value = maxHeight.Value();
4288             maxHeightValue.unit = static_cast<int8_t>(maxHeight.Unit());
4289         }
4290         GetArkUINodeModifiers()->getCommonModifier()->setMaxHeight(nativeNode, &maxHeightValue);
4291     } else if (version10OrLarger) {
4292         GetArkUINodeModifiers()->getCommonModifier()->resetMaxHeight(nativeNode);
4293     }
4294     return panda::JSValueRef::Undefined(vm);
4295 }
4296 
ResetConstraintSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4297 ArkUINativeModuleValue CommonBridge::ResetConstraintSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4298 {
4299     EcmaVM* vm = runtimeCallInfo->GetVM();
4300     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4301     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4302     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4303     GetArkUINodeModifiers()->getCommonModifier()->resetMaxHeight(nativeNode);
4304     GetArkUINodeModifiers()->getCommonModifier()->resetMaxWidth(nativeNode);
4305     GetArkUINodeModifiers()->getCommonModifier()->resetMinHeight(nativeNode);
4306     GetArkUINodeModifiers()->getCommonModifier()->resetMinWidth(nativeNode);
4307     return panda::JSValueRef::Undefined(vm);
4308 }
4309 
SetDirection(ArkUIRuntimeCallInfo * runtimeCallInfo)4310 ArkUINativeModuleValue CommonBridge::SetDirection(ArkUIRuntimeCallInfo* runtimeCallInfo)
4311 {
4312     EcmaVM* vm = runtimeCallInfo->GetVM();
4313     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4314     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4315     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4316     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4317     std::string dir;
4318     int32_t direction = NUM_3;
4319     if (secondArg->IsString(vm)) {
4320         dir = secondArg->ToString(vm)->ToString(vm);
4321         if (dir == "Ltr") {
4322             direction = NUM_0;
4323         } else if (dir == "Rtl") {
4324             direction = NUM_1;
4325         } else if (dir == "Auto") {
4326             direction = NUM_3;
4327         } else if (dir == "undefined" && Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
4328             direction = NUM_3;
4329         }
4330     }
4331     GetArkUINodeModifiers()->getCommonModifier()->setDirection(nativeNode, direction);
4332     return panda::JSValueRef::Undefined(vm);
4333 }
4334 
ResetDirection(ArkUIRuntimeCallInfo * runtimeCallInfo)4335 ArkUINativeModuleValue CommonBridge::ResetDirection(ArkUIRuntimeCallInfo* runtimeCallInfo)
4336 {
4337     EcmaVM* vm = runtimeCallInfo->GetVM();
4338     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4339     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4340     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4341     GetArkUINodeModifiers()->getCommonModifier()->resetDirection(nativeNode);
4342     return panda::JSValueRef::Undefined(vm);
4343 }
4344 
SetLayoutWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)4345 ArkUINativeModuleValue CommonBridge::SetLayoutWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
4346 {
4347     EcmaVM* vm = runtimeCallInfo->GetVM();
4348     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4349     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4350     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4351     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4352     float layoutWeight = 0.0f;
4353     if (secondArg->IsNumber()) {
4354         if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE)) {
4355             layoutWeight = secondArg->ToNumber(vm)->Value();
4356         } else {
4357             layoutWeight = secondArg->Int32Value(vm);
4358         }
4359     } else if (secondArg->IsString(vm)) {
4360         if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE)) {
4361             layoutWeight = StringUtils::StringToFloat(secondArg->ToString(vm)->ToString(vm));
4362         } else {
4363             layoutWeight = StringUtils::StringToInt(secondArg->ToString(vm)->ToString(vm));
4364         }
4365     }
4366     GetArkUINodeModifiers()->getCommonModifier()->setLayoutWeight(nativeNode, layoutWeight);
4367     return panda::JSValueRef::Undefined(vm);
4368 }
4369 
ResetLayoutWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)4370 ArkUINativeModuleValue CommonBridge::ResetLayoutWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
4371 {
4372     EcmaVM* vm = runtimeCallInfo->GetVM();
4373     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4374     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4375     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4376     GetArkUINodeModifiers()->getCommonModifier()->resetLayoutWeight(nativeNode);
4377     return panda::JSValueRef::Undefined(vm);
4378 }
4379 
SetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4380 ArkUINativeModuleValue CommonBridge::SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4381 {
4382     EcmaVM* vm = runtimeCallInfo->GetVM();
4383     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4384     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4385     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4386     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4387     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4388     CalcDimension wVal(0.0, DimensionUnit::VP);
4389     CalcDimension hVal(0.0, DimensionUnit::VP);
4390     ParseCalcDimension(vm, nativeNode, secondArg, wVal, true);
4391     ParseCalcDimension(vm, nativeNode, thirdArg, hVal, false);
4392     return panda::JSValueRef::Undefined(vm);
4393 }
4394 
ResetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4395 ArkUINativeModuleValue CommonBridge::ResetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4396 {
4397     EcmaVM* vm = runtimeCallInfo->GetVM();
4398     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4399     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4400     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4401     GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
4402     GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
4403     return panda::JSValueRef::Undefined(vm);
4404 }
4405 
SetAlignSelf(ArkUIRuntimeCallInfo * runtimeCallInfo)4406 ArkUINativeModuleValue CommonBridge::SetAlignSelf(ArkUIRuntimeCallInfo* runtimeCallInfo)
4407 {
4408     EcmaVM* vm = runtimeCallInfo->GetVM();
4409     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4410     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4411     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4412     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4413 
4414     if (secondArg->IsNumber() && secondArg->ToNumber(vm)->Value() >= 0 &&
4415         secondArg->ToNumber(vm)->Value() <= MAX_ALIGN_VALUE) {
4416         GetArkUINodeModifiers()->getCommonModifier()->setAlignSelf(nativeNode, secondArg->Int32Value(vm));
4417     } else {
4418         GetArkUINodeModifiers()->getCommonModifier()->resetAlignSelf(nativeNode);
4419     }
4420     return panda::JSValueRef::Undefined(vm);
4421 }
4422 
ResetAlignSelf(ArkUIRuntimeCallInfo * runtimeCallInfo)4423 ArkUINativeModuleValue CommonBridge::ResetAlignSelf(ArkUIRuntimeCallInfo* runtimeCallInfo)
4424 {
4425     EcmaVM* vm = runtimeCallInfo->GetVM();
4426     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4427     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4428     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4429     GetArkUINodeModifiers()->getCommonModifier()->resetAlignSelf(nativeNode);
4430     return panda::JSValueRef::Undefined(vm);
4431 }
4432 
SetAspectRatio(ArkUIRuntimeCallInfo * runtimeCallInfo)4433 ArkUINativeModuleValue CommonBridge::SetAspectRatio(ArkUIRuntimeCallInfo* runtimeCallInfo)
4434 {
4435     EcmaVM* vm = runtimeCallInfo->GetVM();
4436     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4437     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4438     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4439     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4440 
4441     if (secondArg->IsNumber()) {
4442         double value = secondArg->ToNumber(vm)->Value();
4443         GetArkUINodeModifiers()->getCommonModifier()->setAspectRatio(nativeNode, value);
4444     } else {
4445         GetArkUINodeModifiers()->getCommonModifier()->resetAspectRatio(nativeNode);
4446     }
4447     return panda::JSValueRef::Undefined(vm);
4448 }
4449 
ResetAspectRatio(ArkUIRuntimeCallInfo * runtimeCallInfo)4450 ArkUINativeModuleValue CommonBridge::ResetAspectRatio(ArkUIRuntimeCallInfo* runtimeCallInfo)
4451 {
4452     EcmaVM* vm = runtimeCallInfo->GetVM();
4453     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4454     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4455     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4456     GetArkUINodeModifiers()->getCommonModifier()->resetAspectRatio(nativeNode);
4457     return panda::JSValueRef::Undefined(vm);
4458 }
4459 
SetFlexGrow(ArkUIRuntimeCallInfo * runtimeCallInfo)4460 ArkUINativeModuleValue CommonBridge::SetFlexGrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
4461 {
4462     EcmaVM* vm = runtimeCallInfo->GetVM();
4463     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4464     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4465     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4466     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4467 
4468     if (secondArg->IsNumber()) {
4469         double value = secondArg->ToNumber(vm)->Value();
4470         GetArkUINodeModifiers()->getCommonModifier()->setFlexGrow(nativeNode, value);
4471     } else {
4472         GetArkUINodeModifiers()->getCommonModifier()->resetFlexGrow(nativeNode);
4473     }
4474     return panda::JSValueRef::Undefined(vm);
4475 }
4476 
ResetFlexGrow(ArkUIRuntimeCallInfo * runtimeCallInfo)4477 ArkUINativeModuleValue CommonBridge::ResetFlexGrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
4478 {
4479     EcmaVM* vm = runtimeCallInfo->GetVM();
4480     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4481     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4482     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4483     GetArkUINodeModifiers()->getCommonModifier()->resetFlexGrow(nativeNode);
4484     return panda::JSValueRef::Undefined(vm);
4485 }
4486 
SetFlexShrink(ArkUIRuntimeCallInfo * runtimeCallInfo)4487 ArkUINativeModuleValue CommonBridge::SetFlexShrink(ArkUIRuntimeCallInfo* runtimeCallInfo)
4488 {
4489     EcmaVM* vm = runtimeCallInfo->GetVM();
4490     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4491     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4492     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4493     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4494 
4495     if (secondArg->IsNumber()) {
4496         double value = secondArg->ToNumber(vm)->Value();
4497         GetArkUINodeModifiers()->getCommonModifier()->setFlexShrink(nativeNode, value);
4498     } else {
4499         GetArkUINodeModifiers()->getCommonModifier()->resetFlexShrink(nativeNode);
4500     }
4501     return panda::JSValueRef::Undefined(vm);
4502 }
4503 
ResetFlexShrink(ArkUIRuntimeCallInfo * runtimeCallInfo)4504 ArkUINativeModuleValue CommonBridge::ResetFlexShrink(ArkUIRuntimeCallInfo* runtimeCallInfo)
4505 {
4506     EcmaVM* vm = runtimeCallInfo->GetVM();
4507     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4508     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4509     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4510     GetArkUINodeModifiers()->getCommonModifier()->resetFlexShrink(nativeNode);
4511     return panda::JSValueRef::Undefined(vm);
4512 }
4513 
SetGridOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)4514 ArkUINativeModuleValue CommonBridge::SetGridOffset(ArkUIRuntimeCallInfo *runtimeCallInfo)
4515 {
4516     EcmaVM* vm = runtimeCallInfo->GetVM();
4517     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4518     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4519     Local<JSValueRef> offsetArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4520     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4521     int32_t offset = 0;
4522     if (offsetArg->IsNumber()) {
4523         offset = offsetArg->Int32Value(vm);
4524         GetArkUINodeModifiers()->getCommonModifier()->setGridOffset(nativeNode, offset);
4525     } else {
4526         GetArkUINodeModifiers()->getCommonModifier()->resetGridOffset(nativeNode);
4527     }
4528     return panda::JSValueRef::Undefined(vm);
4529 }
4530 
ResetGridOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)4531 ArkUINativeModuleValue CommonBridge::ResetGridOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
4532 {
4533     EcmaVM* vm = runtimeCallInfo->GetVM();
4534     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4535     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4536     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4537     GetArkUINodeModifiers()->getCommonModifier()->resetGridOffset(nativeNode);
4538     return panda::JSValueRef::Undefined(vm);
4539 }
4540 
SetGridSpan(ArkUIRuntimeCallInfo * runtimeCallInfo)4541 ArkUINativeModuleValue CommonBridge::SetGridSpan(ArkUIRuntimeCallInfo *runtimeCallInfo)
4542 {
4543     EcmaVM* vm = runtimeCallInfo->GetVM();
4544     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4545     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4546     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4547     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4548     int32_t value = 0;
4549     if (secondArg->IsNumber()) {
4550         value = secondArg->Int32Value(vm);
4551         GetArkUINodeModifiers()->getCommonModifier()->setGridSpan(nativeNode, value);
4552     } else {
4553         GetArkUINodeModifiers()->getCommonModifier()->resetGridSpan(nativeNode);
4554     }
4555     return panda::JSValueRef::Undefined(vm);
4556 }
4557 
ResetGridSpan(ArkUIRuntimeCallInfo * runtimeCallInfo)4558 ArkUINativeModuleValue CommonBridge::ResetGridSpan(ArkUIRuntimeCallInfo *runtimeCallInfo)
4559 {
4560     EcmaVM* vm = runtimeCallInfo->GetVM();
4561     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4562     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4563     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4564     GetArkUINodeModifiers()->getCommonModifier()->resetGridSpan(nativeNode);
4565     return panda::JSValueRef::Undefined(vm);
4566 }
4567 
SetExpandSafeArea(ArkUIRuntimeCallInfo * runtimeCallInfo)4568 ArkUINativeModuleValue CommonBridge::SetExpandSafeArea(ArkUIRuntimeCallInfo *runtimeCallInfo)
4569 {
4570     EcmaVM* vm = runtimeCallInfo->GetVM();
4571     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4572     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4573     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4574     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4575     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4576     std::string typeCppStr = "";
4577     std::string edgesCppStr = "";
4578     uint32_t safeAreaType = NG::SAFE_AREA_TYPE_NONE;
4579     uint32_t safeAreaEdge = NG::SAFE_AREA_EDGE_NONE;
4580     if (secondArg->IsString(vm)) {
4581         typeCppStr = secondArg->ToString(vm)->ToString(vm);
4582         safeAreaType = ParseStrToUint(typeCppStr);
4583     } else {
4584         safeAreaType = NG::SAFE_AREA_TYPE_ALL;
4585     }
4586 
4587     if (thirdArg->IsString(vm)) {
4588         edgesCppStr = thirdArg->ToString(vm)->ToString(vm);
4589         safeAreaEdge = ParseStrToUint(edgesCppStr);
4590     } else {
4591         safeAreaEdge = NG::SAFE_AREA_EDGE_ALL;
4592     }
4593     GetArkUINodeModifiers()->getCommonModifier()->setExpandSafeArea(nativeNode, safeAreaType, safeAreaEdge);
4594     return panda::JSValueRef::Undefined(vm);
4595 }
4596 
ResetExpandSafeArea(ArkUIRuntimeCallInfo * runtimeCallInfo)4597 ArkUINativeModuleValue CommonBridge::ResetExpandSafeArea(ArkUIRuntimeCallInfo* runtimeCallInfo)
4598 {
4599     EcmaVM* vm = runtimeCallInfo->GetVM();
4600     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4601     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4602     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4603     GetArkUINodeModifiers()->getCommonModifier()->resetExpandSafeArea(nativeNode);
4604     return panda::JSValueRef::Undefined(vm);
4605 }
4606 
SetAlignRules(ArkUIRuntimeCallInfo * runtimeCallInfo)4607 ArkUINativeModuleValue CommonBridge::SetAlignRules(ArkUIRuntimeCallInfo* runtimeCallInfo)
4608 {
4609     EcmaVM* vm = runtimeCallInfo->GetVM();
4610     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4611     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4612     Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4613     Local<JSValueRef> middleArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4614     Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(NUM_3);
4615     Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(NUM_4);
4616     Local<JSValueRef> centerArg = runtimeCallInfo->GetCallArgRef(NUM_5);
4617     Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(NUM_6);
4618     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4619 
4620     auto anchors = std::make_unique<std::string []>(ALIGN_RULES_NUM);
4621     auto direction = std::make_unique<ArkUI_Int32 []>(ALIGN_RULES_NUM);
4622     for (int32_t i = 0; i < ALIGN_RULES_NUM; i++) {
4623         anchors[i] = "";
4624         direction[i] = ALIGN_DIRECTION_DEFAULT;
4625     }
4626     bool leftParseResult = ParseJsAlignRule(vm, leftArg, anchors[0], direction[0]);
4627     bool middleParseResult = ParseJsAlignRule(vm, middleArg, anchors[1], direction[1]);
4628     bool rightParseResult = ParseJsAlignRule(vm, rightArg, anchors[2], direction[2]);
4629     bool topParseResult = ParseJsAlignRule(vm, topArg, anchors[3], direction[3]);
4630     bool centerParseResult = ParseJsAlignRule(vm, centerArg, anchors[4], direction[4]);
4631     bool bottomParseResult = ParseJsAlignRule(vm, bottomArg, anchors[5], direction[5]);
4632     if (!leftParseResult && !middleParseResult && !rightParseResult && !topParseResult && !centerParseResult &&
4633         !bottomParseResult) {
4634         GetArkUINodeModifiers()->getCommonModifier()->resetAlignRules(nativeNode);
4635         return panda::JSValueRef::Undefined(vm);
4636     }
4637     auto realAnchors = std::make_unique<char* []>(ALIGN_RULES_NUM);
4638     for (int32_t i = 0; i < ALIGN_RULES_NUM; i++) {
4639         realAnchors[i] = const_cast<char*>(anchors[i].c_str());
4640     }
4641     GetArkUINodeModifiers()->getCommonModifier()->setAlignRules(nativeNode, realAnchors.get(), direction.get(),
4642         ALIGN_RULES_NUM);
4643     return panda::JSValueRef::Undefined(vm);
4644 }
4645 
ResetAlignRules(ArkUIRuntimeCallInfo * runtimeCallInfo)4646 ArkUINativeModuleValue CommonBridge::ResetAlignRules(ArkUIRuntimeCallInfo* runtimeCallInfo)
4647 {
4648     EcmaVM* vm = runtimeCallInfo->GetVM();
4649     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4650     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4651     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4652     GetArkUINodeModifiers()->getCommonModifier()->resetAlignRules(nativeNode);
4653     return panda::JSValueRef::Undefined(vm);
4654 }
4655 
SetFlexBasis(ArkUIRuntimeCallInfo * runtimeCallInfo)4656 ArkUINativeModuleValue CommonBridge::SetFlexBasis(ArkUIRuntimeCallInfo* runtimeCallInfo)
4657 {
4658     EcmaVM* vm = runtimeCallInfo->GetVM();
4659     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4660     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4661     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4662     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4663     struct ArkUIStringAndFloat flexBasis { 0.0, nullptr};
4664     std::string tempValueStr = "";
4665     if (secondArg->IsNumber()) {
4666         flexBasis.value = secondArg->ToNumber(vm)->Value();
4667         GetArkUINodeModifiers()->getCommonModifier()->setFlexBasis(nativeNode, &flexBasis);
4668     } else if (secondArg->IsString(vm)) {
4669         tempValueStr = secondArg->ToString(vm)->ToString(vm);
4670         flexBasis.valueStr = tempValueStr.c_str();
4671         GetArkUINodeModifiers()->getCommonModifier()->setFlexBasis(nativeNode, &flexBasis);
4672     } else {
4673         GetArkUINodeModifiers()->getCommonModifier()->resetFlexBasis(nativeNode);
4674     }
4675     return panda::JSValueRef::Undefined(vm);
4676 }
4677 
ResetFlexBasis(ArkUIRuntimeCallInfo * runtimeCallInfo)4678 ArkUINativeModuleValue CommonBridge::ResetFlexBasis(ArkUIRuntimeCallInfo* runtimeCallInfo)
4679 {
4680     EcmaVM* vm = runtimeCallInfo->GetVM();
4681     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4682     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4683     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4684     GetArkUINodeModifiers()->getCommonModifier()->resetFlexBasis(nativeNode);
4685     return panda::JSValueRef::Undefined(vm);
4686 }
4687 
SetAllowDrop(ArkUIRuntimeCallInfo * runtimeCallInfo)4688 ArkUINativeModuleValue CommonBridge::SetAllowDrop(ArkUIRuntimeCallInfo* runtimeCallInfo)
4689 {
4690     EcmaVM* vm = runtimeCallInfo->GetVM();
4691     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4692     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4693     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4694     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4695     if (secondArg->IsUndefined()) {
4696         GetArkUINodeModifiers()->getCommonModifier()->resetAllowDrop(nativeNode);
4697         return panda::JSValueRef::Undefined(vm);
4698     }
4699     Local<panda::ArrayRef> allowDropArray = static_cast<Local<panda::ArrayRef>>(secondArg);
4700     auto length = allowDropArray->Length(vm);
4701     if (length <= 0) {
4702         GetArkUINodeModifiers()->getCommonModifier()->resetAllowDrop(nativeNode);
4703         return panda::JSValueRef::Undefined(vm);
4704     }
4705     std::vector<std::string> keepStr(length);
4706     std::vector<const char*> strList;
4707     for (size_t i = 0; i < length; i++) {
4708         Local<JSValueRef> objValue = allowDropArray->GetValueAt(vm, secondArg, i);
4709         keepStr[i] = objValue->ToString(vm)->ToString(vm);
4710         strList.push_back(keepStr[i].c_str());
4711     }
4712     GetArkUINodeModifiers()->getCommonModifier()->setAllowDrop(nativeNode, strList.data(), strList.size());
4713     return panda::JSValueRef::Undefined(vm);
4714 }
4715 
ResetAllowDrop(ArkUIRuntimeCallInfo * runtimeCallInfo)4716 ArkUINativeModuleValue CommonBridge::ResetAllowDrop(ArkUIRuntimeCallInfo* runtimeCallInfo)
4717 {
4718     EcmaVM* vm = runtimeCallInfo->GetVM();
4719     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4720     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4721     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4722     GetArkUINodeModifiers()->getCommonModifier()->resetAllowDrop(nativeNode);
4723     return panda::JSValueRef::Undefined(vm);
4724 }
4725 
SetId(ArkUIRuntimeCallInfo * runtimeCallInfo)4726 ArkUINativeModuleValue CommonBridge::SetId(ArkUIRuntimeCallInfo* runtimeCallInfo)
4727 {
4728     EcmaVM* vm = runtimeCallInfo->GetVM();
4729     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4730     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4731     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4732     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4733     if (secondArg->IsString(vm)) {
4734         std::string stringValue = secondArg->ToString(vm)->ToString(vm);
4735         GetArkUINodeModifiers()->getCommonModifier()->setId(nativeNode, stringValue.c_str());
4736     } else {
4737         GetArkUINodeModifiers()->getCommonModifier()->resetId(nativeNode);
4738     }
4739     return panda::JSValueRef::Undefined(vm);
4740 }
4741 
ResetId(ArkUIRuntimeCallInfo * runtimeCallInfo)4742 ArkUINativeModuleValue CommonBridge::ResetId(ArkUIRuntimeCallInfo* runtimeCallInfo)
4743 {
4744     EcmaVM* vm = runtimeCallInfo->GetVM();
4745     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4746     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4747     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4748     GetArkUINodeModifiers()->getCommonModifier()->resetId(nativeNode);
4749     return panda::JSValueRef::Undefined(vm);
4750 }
4751 
SetKey(ArkUIRuntimeCallInfo * runtimeCallInfo)4752 ArkUINativeModuleValue CommonBridge::SetKey(ArkUIRuntimeCallInfo* runtimeCallInfo)
4753 {
4754     EcmaVM* vm = runtimeCallInfo->GetVM();
4755     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4756     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4757     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4758     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4759     if (secondArg->IsString(vm)) {
4760         std::string stringValue = secondArg->ToString(vm)->ToString(vm);
4761         GetArkUINodeModifiers()->getCommonModifier()->setKey(nativeNode, stringValue.c_str());
4762     } else {
4763         GetArkUINodeModifiers()->getCommonModifier()->resetKey(nativeNode);
4764     }
4765     return panda::JSValueRef::Undefined(vm);
4766 }
4767 
ResetKey(ArkUIRuntimeCallInfo * runtimeCallInfo)4768 ArkUINativeModuleValue CommonBridge::ResetKey(ArkUIRuntimeCallInfo* runtimeCallInfo)
4769 {
4770     EcmaVM* vm = runtimeCallInfo->GetVM();
4771     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4772     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4773     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4774     GetArkUINodeModifiers()->getCommonModifier()->resetKey(nativeNode);
4775     return panda::JSValueRef::Undefined(vm);
4776 }
4777 
SetRestoreId(ArkUIRuntimeCallInfo * runtimeCallInfo)4778 ArkUINativeModuleValue CommonBridge::SetRestoreId(ArkUIRuntimeCallInfo* runtimeCallInfo)
4779 {
4780     EcmaVM* vm = runtimeCallInfo->GetVM();
4781     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4782     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4783     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4784     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4785     if (secondArg->IsNumber()) {
4786         uint32_t value = secondArg->Uint32Value(vm);
4787         GetArkUINodeModifiers()->getCommonModifier()->setRestoreId(nativeNode, value);
4788     } else {
4789         GetArkUINodeModifiers()->getCommonModifier()->resetRestoreId(nativeNode);
4790     }
4791     return panda::JSValueRef::Undefined(vm);
4792 }
4793 
ResetRestoreId(ArkUIRuntimeCallInfo * runtimeCallInfo)4794 ArkUINativeModuleValue CommonBridge::ResetRestoreId(ArkUIRuntimeCallInfo* runtimeCallInfo)
4795 {
4796     EcmaVM* vm = runtimeCallInfo->GetVM();
4797     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4798     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4799     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4800     GetArkUINodeModifiers()->getCommonModifier()->resetRestoreId(nativeNode);
4801     return panda::JSValueRef::Undefined(vm);
4802 }
4803 
SetTabIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)4804 ArkUINativeModuleValue CommonBridge::SetTabIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
4805 {
4806     EcmaVM* vm = runtimeCallInfo->GetVM();
4807     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4808     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4809     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4810     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4811     if (secondArg->IsNumber()) {
4812         int32_t index = secondArg->Int32Value(vm);
4813         GetArkUINodeModifiers()->getCommonModifier()->setTabIndex(nativeNode, index);
4814     } else {
4815         GetArkUINodeModifiers()->getCommonModifier()->resetTabIndex(nativeNode);
4816     }
4817     return panda::JSValueRef::Undefined(vm);
4818 }
4819 
ResetTabIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)4820 ArkUINativeModuleValue CommonBridge::ResetTabIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
4821 {
4822     EcmaVM* vm = runtimeCallInfo->GetVM();
4823     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4824     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4825     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4826     GetArkUINodeModifiers()->getCommonModifier()->resetTabIndex(nativeNode);
4827     return panda::JSValueRef::Undefined(vm);
4828 }
4829 
SetObscured(ArkUIRuntimeCallInfo * runtimeCallInfo)4830 ArkUINativeModuleValue CommonBridge::SetObscured(ArkUIRuntimeCallInfo* runtimeCallInfo)
4831 {
4832     EcmaVM* vm = runtimeCallInfo->GetVM();
4833     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4834     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4835     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4836     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4837 
4838     if (secondArg->IsUndefined() || !secondArg->IsArray(vm)) {
4839         GetArkUINodeModifiers()->getCommonModifier()->resetObscured(nativeNode);
4840         return panda::JSValueRef::Undefined(vm);
4841     }
4842     Local<panda::ArrayRef> transArray = static_cast<Local<panda::ArrayRef>>(secondArg);
4843     auto length = transArray->Length(vm);
4844     int32_t reasonArray[length];
4845 
4846     for (size_t i = 0; i < length; i++) {
4847         Local<JSValueRef> value = transArray->GetValueAt(vm, secondArg, i);
4848         reasonArray[i] = value->Int32Value(vm);
4849     }
4850     GetArkUINodeModifiers()->getCommonModifier()->setObscured(nativeNode, reasonArray, length);
4851     return panda::JSValueRef::Undefined(vm);
4852 }
4853 
ResetObscured(ArkUIRuntimeCallInfo * runtimeCallInfo)4854 ArkUINativeModuleValue CommonBridge::ResetObscured(ArkUIRuntimeCallInfo* runtimeCallInfo)
4855 {
4856     EcmaVM* vm = runtimeCallInfo->GetVM();
4857     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4858     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4859     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4860     GetArkUINodeModifiers()->getCommonModifier()->resetObscured(nativeNode);
4861     return panda::JSValueRef::Undefined(vm);
4862 }
4863 
SetForegroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)4864 ArkUINativeModuleValue CommonBridge::SetForegroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
4865 {
4866     EcmaVM* vm = runtimeCallInfo->GetVM();
4867     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
4868     Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(1);
4869     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
4870     CalcDimension radius;
4871     if (!ArkTSUtils::ParseJsDimensionVp(vm, radiusArg, radius) || LessNotEqual(radius.Value(), 0.0f)) {
4872         radius.SetValue(0.0f);
4873     }
4874     ArkUI_Float32 radiusArk = static_cast<ArkUI_Int32>(radius.Value());
4875     GetArkUINodeModifiers()->getCommonModifier()->setForegroundEffect(nativeNode, radiusArk);
4876     return panda::JSValueRef::Undefined(vm);
4877 }
4878 
ResetForegroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)4879 ArkUINativeModuleValue CommonBridge::ResetForegroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
4880 {
4881     EcmaVM* vm = runtimeCallInfo->GetVM();
4882     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4883     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4884     GetArkUINodeModifiers()->getCommonModifier()->resetForegroundEffect(nativeNode);
4885     return panda::JSValueRef::Undefined(vm);
4886 }
4887 
SetBackgroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)4888 ArkUINativeModuleValue CommonBridge::SetBackgroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
4889 {
4890     EcmaVM* vm = runtimeCallInfo->GetVM();
4891     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4892     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);     // 0:index of parameter frameNode
4893     Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(1);        // 1:index of parameter radius
4894     Local<JSValueRef> saturationArg = runtimeCallInfo->GetCallArgRef(2);    // 2:index of parameter saturation
4895     Local<JSValueRef> brightnessArg = runtimeCallInfo->GetCallArgRef(3);    // 3:index of parameter brightness
4896     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(4);         // 4:index of parameter color
4897     Local<JSValueRef> adaptiveColorArg = runtimeCallInfo->GetCallArgRef(5); // 5:index of parameter adaptiveColor
4898     Local<JSValueRef> blurOptionsArg = runtimeCallInfo->GetCallArgRef(6);   // 6:index of parameter blurOptions
4899     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
4900     CalcDimension radius;
4901     if (!ArkTSUtils::ParseJsDimensionVp(vm, radiusArg, radius) || LessNotEqual(radius.Value(), 0.0f)) {
4902         radius.SetValue(0.0f);
4903     }
4904     ArkUI_Float32 saturation = 1.0f;
4905     if (saturationArg->IsNumber()) {
4906         saturation = saturationArg->ToNumber(vm)->Value();
4907         saturation = (saturation > 0.0f || NearZero(saturation)) ? saturation : 1.0f;
4908     }
4909     ArkUI_Float32 brightness = 1.0f;
4910     if (brightnessArg->IsNumber()) {
4911         brightness = brightnessArg->ToNumber(vm)->Value();
4912         brightness = (brightness > 0.0f || NearZero(brightness)) ? brightness : 1.0f;
4913     }
4914     Color color = Color::TRANSPARENT;
4915     if (!ArkTSUtils::ParseJsColor(vm, colorArg, color)) {
4916         color.SetValue(Color::TRANSPARENT.GetValue());
4917     }
4918     auto adaptiveColorValue = static_cast<int32_t>(AdaptiveColor::DEFAULT);
4919     auto adaptiveColor = AdaptiveColor::DEFAULT;
4920     if (adaptiveColorArg->IsNumber()) {
4921         adaptiveColorValue = adaptiveColorArg->Int32Value(vm);
4922         if (adaptiveColorValue >= static_cast<int32_t>(AdaptiveColor::DEFAULT) &&
4923             adaptiveColorValue <= static_cast<int32_t>(AdaptiveColor::AVERAGE)) {
4924             adaptiveColor = static_cast<AdaptiveColor>(adaptiveColorValue);
4925         }
4926     }
4927     BlurOption blurOption;
4928     if (blurOptionsArg->IsArray(vm)) {
4929         ParseBlurOption(vm, blurOptionsArg, blurOption);
4930     }
4931 
4932     GetArkUINodeModifiers()->getCommonModifier()->setBackgroundEffect(
4933         nativeNode, static_cast<ArkUI_Float32>(radius.Value()),
4934         saturation, brightness, color.GetValue(), static_cast<ArkUI_Int32>(adaptiveColor),
4935         blurOption.grayscale.data(), blurOption.grayscale.size());
4936 
4937     return panda::JSValueRef::Undefined(vm);
4938 }
4939 
ResetBackgroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)4940 ArkUINativeModuleValue CommonBridge::ResetBackgroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
4941 {
4942     EcmaVM* vm = runtimeCallInfo->GetVM();
4943     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4944     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4945     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4946     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundEffect(nativeNode);
4947     return panda::JSValueRef::Undefined(vm);
4948 }
4949 
SetBackgroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)4950 ArkUINativeModuleValue CommonBridge::SetBackgroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
4951 {
4952     EcmaVM* vm = runtimeCallInfo->GetVM();
4953     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4954     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);     // 0:index of parameter frameNode
4955     Local<JSValueRef> ratedArg = runtimeCallInfo->GetCallArgRef(1);         // 1:index of parameter ratedArg
4956     Local<JSValueRef> lightUpDegreeArg = runtimeCallInfo->GetCallArgRef(2); // 2:index of parameter lightUpDegreeArg
4957     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
4958     double rate = 0.0;
4959     double lightUpDegree = 0.0;
4960     if (!ArkTSUtils::ParseJsDouble(vm, ratedArg, rate)) {
4961         return panda::JSValueRef::Undefined(vm);
4962     }
4963     if (!ArkTSUtils::ParseJsDouble(vm, lightUpDegreeArg, lightUpDegree)) {
4964         return panda::JSValueRef::Undefined(vm);
4965     }
4966     GetArkUINodeModifiers()->getCommonModifier()->setBackgroundBrightness(nativeNode, rate, lightUpDegree);
4967     return panda::JSValueRef::Undefined(vm);
4968 }
4969 
ResetBackgroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)4970 ArkUINativeModuleValue CommonBridge::ResetBackgroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
4971 {
4972     EcmaVM* vm = runtimeCallInfo->GetVM();
4973     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4974     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4975     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4976     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundBrightness(nativeNode);
4977     return panda::JSValueRef::Undefined(vm);
4978 }
4979 
SetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo * runtimeCallInfo)4980 ArkUINativeModuleValue CommonBridge::SetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo* runtimeCallInfo)
4981 {
4982     EcmaVM* vm = runtimeCallInfo->GetVM();
4983     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4984     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
4985     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
4986     ArkUI_Float32 rate = 1.0f;
4987     ArkUI_Float32 lightUpDegree = 0.0f;
4988     ArkUI_Float32 cubicCoeff = 0.0f;
4989     ArkUI_Float32 quadCoeff = 0.0f;
4990     ArkUI_Float32 saturation = 1.0f;
4991     std::vector<float> posRGB(3, 0.0);
4992     std::vector<float> negRGB(3, 0.0);
4993     ArkUI_Float32 fraction = 1.0f;
4994     ParseDynamicBrightnessOption(runtimeCallInfo, vm, rate, lightUpDegree,
4995         cubicCoeff, quadCoeff, saturation, posRGB, negRGB, fraction);
4996     GetArkUINodeModifiers()->getCommonModifier()->setBackgroundBrightnessInternal(
4997         nativeNode, rate, lightUpDegree, cubicCoeff, quadCoeff, saturation,
4998         posRGB.data(), posRGB.size(), negRGB.data(), negRGB.size(), fraction);
4999     return panda::JSValueRef::Undefined(vm);
5000 }
5001 
ResetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo * runtimeCallInfo)5002 ArkUINativeModuleValue CommonBridge::ResetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo* runtimeCallInfo)
5003 {
5004     EcmaVM* vm = runtimeCallInfo->GetVM();
5005     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5006     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5007     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5008     GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundBrightnessInternal(nativeNode);
5009     return panda::JSValueRef::Undefined(vm);
5010 }
5011 
SetForegroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)5012 ArkUINativeModuleValue CommonBridge::SetForegroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
5013 {
5014     EcmaVM* vm = runtimeCallInfo->GetVM();
5015     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5016     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5017     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5018     ArkUI_Float32 rate = 1.0f;
5019     ArkUI_Float32 lightUpDegree = 0.0f;
5020     ArkUI_Float32 cubicCoeff = 0.0f;
5021     ArkUI_Float32 quadCoeff = 0.0f;
5022     ArkUI_Float32 saturation = 1.0f;
5023     std::vector<float> posRGB(3, 0.0);
5024     std::vector<float> negRGB(3, 0.0);
5025     ArkUI_Float32 fraction = 1.0f;
5026     ParseDynamicBrightnessOption(runtimeCallInfo, vm, rate, lightUpDegree,
5027         cubicCoeff, quadCoeff, saturation, posRGB, negRGB, fraction);
5028     GetArkUINodeModifiers()->getCommonModifier()->setForegroundBrightness(
5029         nativeNode, rate, lightUpDegree, cubicCoeff, quadCoeff, saturation,
5030         posRGB.data(), posRGB.size(), negRGB.data(), negRGB.size(), fraction);
5031     return panda::JSValueRef::Undefined(vm);
5032 }
5033 
ResetForegroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)5034 ArkUINativeModuleValue CommonBridge::ResetForegroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
5035 {
5036     EcmaVM* vm = runtimeCallInfo->GetVM();
5037     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5038     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5039     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5040     GetArkUINodeModifiers()->getCommonModifier()->resetForegroundBrightness(nativeNode);
5041     return panda::JSValueRef::Undefined(vm);
5042 }
5043 
SetDragPreviewOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)5044 ArkUINativeModuleValue CommonBridge::SetDragPreviewOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
5045 {
5046     EcmaVM* vm = runtimeCallInfo->GetVM();
5047     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5048     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5049     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5050     Local<JSValueRef> mode = runtimeCallInfo->GetCallArgRef(NUM_1);
5051     Local<JSValueRef> numberBadge = runtimeCallInfo->GetCallArgRef(NUM_2);
5052     Local<JSValueRef> isMultiSelectionEnabled = runtimeCallInfo->GetCallArgRef(NUM_3);
5053     Local<JSValueRef> defaultAnimationBeforeLifting = runtimeCallInfo->GetCallArgRef(NUM_4);
5054 
5055     struct ArkUIDragPreViewOptions preViewOptions = { 1, 0, 0, nullptr, false, true, false};
5056     int32_t* modeIntArray = nullptr;
5057     if (mode->IsNumber()) {
5058         preViewOptions.isModeArray = false;
5059         preViewOptions.mode = mode->Int32Value(vm);
5060     } else if (mode->IsArray(vm)) {
5061         Local<panda::ArrayRef> modeArray = static_cast<Local<panda::ArrayRef>>(mode);
5062         int32_t arrLength = static_cast<int32_t>(modeArray->Length(vm));
5063         if (arrLength > NUM_4) {
5064             arrLength = NUM_4;
5065         }
5066         modeIntArray = new int32_t[arrLength];
5067         for (int32_t i = 0; i < arrLength; i++) {
5068             Local<JSValueRef> objValue = modeArray->GetValueAt(vm, modeArray, i);
5069             modeIntArray[i] = objValue->Int32Value(vm);
5070         }
5071         preViewOptions.isModeArray = true;
5072         preViewOptions.modeArray = modeIntArray;
5073         preViewOptions.modeArrayLength = static_cast<ArkUI_Int32>(arrLength);
5074     }
5075 
5076     if (numberBadge->IsBoolean()) {
5077         preViewOptions.isBadgeNumber = false;
5078         preViewOptions.isShowBadge = numberBadge->ToBoolean(vm)->Value();
5079     } else if (numberBadge->IsNumber()) {
5080         preViewOptions.isBadgeNumber = true;
5081         preViewOptions.badgeNumber = numberBadge->Int32Value(vm);
5082     }
5083 
5084     struct ArkUIDragInteractionOptions interactionOptions = { false, false };
5085     if (isMultiSelectionEnabled->IsBoolean()) {
5086         interactionOptions.isMultiSelectionEnabled = isMultiSelectionEnabled->ToBoolean(vm)->Value();
5087     }
5088     if (defaultAnimationBeforeLifting->IsBoolean()) {
5089         interactionOptions.defaultAnimationBeforeLifting = defaultAnimationBeforeLifting->ToBoolean(vm)->Value();
5090     }
5091     GetArkUINodeModifiers()->getCommonModifier()->setDragPreviewOptions(
5092         nativeNode, preViewOptions, interactionOptions);
5093     delete[] modeIntArray;
5094     return panda::JSValueRef::Undefined(vm);
5095 }
5096 
ResetDragPreviewOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)5097 ArkUINativeModuleValue CommonBridge::ResetDragPreviewOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
5098 {
5099     EcmaVM* vm = runtimeCallInfo->GetVM();
5100     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5101     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5102     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5103     GetArkUINodeModifiers()->getCommonModifier()->resetDragPreviewOptions(nativeNode);
5104     return panda::JSValueRef::Undefined(vm);
5105 }
5106 
SetDragPreview(ArkUIRuntimeCallInfo * runtimeCallInfo)5107 ArkUINativeModuleValue CommonBridge::SetDragPreview(ArkUIRuntimeCallInfo* runtimeCallInfo)
5108 {
5109     EcmaVM* vm = runtimeCallInfo->GetVM();
5110     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5111     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5112     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5113     Local<JSValueRef> inspectorId = runtimeCallInfo->GetCallArgRef(NUM_1);
5114 
5115     struct ArkUIDragPreview dragPreview = { "" };
5116     std::string stringValue;
5117     if (inspectorId->IsString(vm)) {
5118         stringValue = inspectorId->ToString(vm)->ToString(vm);
5119         dragPreview.inspectorId = stringValue.c_str();
5120     }
5121 
5122     GetArkUINodeModifiers()->getCommonModifier()->setDragPreview(
5123         nativeNode, dragPreview);
5124     return panda::JSValueRef::Undefined(vm);
5125 }
5126 
ResetDragPreview(ArkUIRuntimeCallInfo * runtimeCallInfo)5127 ArkUINativeModuleValue CommonBridge::ResetDragPreview(ArkUIRuntimeCallInfo* runtimeCallInfo)
5128 {
5129     EcmaVM* vm = runtimeCallInfo->GetVM();
5130     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5131     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5132     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5133     GetArkUINodeModifiers()->getCommonModifier()->resetDragPreview(nativeNode);
5134     return panda::JSValueRef::Undefined(vm);
5135 }
5136 
SetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5137 ArkUINativeModuleValue CommonBridge::SetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5138 {
5139     EcmaVM* vm = runtimeCallInfo->GetVM();
5140     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5141     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5142     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5143     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5144     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5145     int32_t length = thirdArg->Int32Value(vm);
5146     ArkUI_Float32 regionArray[length];
5147     int32_t regionUnits[length];
5148     if (!ParseResponseRegion(vm, secondArg, regionArray, regionUnits, length)) {
5149         GetArkUINodeModifiers()->getCommonModifier()->resetResponseRegion(nativeNode);
5150         return panda::JSValueRef::Undefined(vm);
5151     }
5152     GetArkUINodeModifiers()->getCommonModifier()->setResponseRegion(nativeNode, regionArray, regionUnits, length);
5153     return panda::JSValueRef::Undefined(vm);
5154 }
5155 
ResetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5156 ArkUINativeModuleValue CommonBridge::ResetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5157 {
5158     EcmaVM* vm = runtimeCallInfo->GetVM();
5159     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5160     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5161     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5162     GetArkUINodeModifiers()->getCommonModifier()->resetResponseRegion(nativeNode);
5163     return panda::JSValueRef::Undefined(vm);
5164 }
5165 
ResetTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5166 ArkUINativeModuleValue CommonBridge::ResetTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5167 {
5168     EcmaVM* vm = runtimeCallInfo->GetVM();
5169     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5170     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5171     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5172     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5173     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5174     ViewAbstract::CleanTransition(frameNode);
5175     ViewAbstract::SetChainedTransition(frameNode, nullptr, nullptr);
5176     return panda::JSValueRef::Undefined(vm);
5177 }
5178 
SetTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5179 ArkUINativeModuleValue CommonBridge::SetTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5180 {
5181     EcmaVM* vm = runtimeCallInfo->GetVM();
5182     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5183     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5184     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5185     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5186     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5187     if (!info[1]->IsObject()) {
5188         ViewAbstract::CleanTransition(frameNode);
5189         ViewAbstract::SetChainedTransition(frameNode, nullptr, nullptr);
5190         return panda::JSValueRef::Undefined(vm);
5191     }
5192     auto obj = Framework::JSRef<Framework::JSObject>::Cast(info[1]);
5193     if (!obj->GetProperty("successor_")->IsUndefined()) {
5194         auto chainedEffect = ParseChainedTransition(obj, info.GetExecutionContext());
5195         std::function<void(bool)> finishCallback;
5196         if (info.Length() > 2 && info[2]->IsFunction()) {
5197             finishCallback =
5198                 ParseTransitionCallback(JSRef<JSFunc>::Cast(info[2]), info.GetExecutionContext(), frameNode);
5199         }
5200         ViewAbstract::SetChainedTransition(frameNode, chainedEffect, std::move(finishCallback));
5201         return panda::JSValueRef::Undefined(vm);
5202     }
5203     auto options = ParseJsTransition(info[1]);
5204     ViewAbstract::SetTransition(frameNode, options);
5205     return panda::JSValueRef::Undefined(vm);
5206 }
5207 
ResetTransitionPassThrough(ArkUIRuntimeCallInfo * runtimeCallInfo)5208 ArkUINativeModuleValue CommonBridge::ResetTransitionPassThrough(ArkUIRuntimeCallInfo* runtimeCallInfo)
5209 {
5210     return CommonBridge::ResetTransition(runtimeCallInfo);
5211 }
5212 
SetTransitionPassThrough(ArkUIRuntimeCallInfo * runtimeCallInfo)5213 ArkUINativeModuleValue CommonBridge::SetTransitionPassThrough(ArkUIRuntimeCallInfo* runtimeCallInfo)
5214 {
5215     return CommonBridge::SetTransition(runtimeCallInfo);
5216 }
5217 
ResetSharedTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5218 ArkUINativeModuleValue CommonBridge::ResetSharedTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5219 {
5220     EcmaVM* vm = runtimeCallInfo->GetVM();
5221     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5222     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5223     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5224     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5225     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5226     if (!info[1]->IsString() || info[1]->ToString().empty()) {
5227         return panda::JSValueRef::Undefined(vm);
5228     }
5229     auto id = info[1]->ToString();
5230     std::shared_ptr<SharedTransitionOption> sharedOption;
5231     sharedOption = std::make_shared<SharedTransitionOption>();
5232     sharedOption->duration = DEFAULT_DURATION;
5233     sharedOption->delay = NUM_0;
5234     sharedOption->curve = Curves::LINEAR;
5235     sharedOption->zIndex = NUM_0;
5236     sharedOption->type = DEFAULT_SHARED_EFFECT;
5237 
5238     ViewAbstract::SetSharedTransition(frameNode, id, sharedOption);
5239     return panda::JSValueRef::Undefined(vm);
5240 }
5241 
SetSharedTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5242 ArkUINativeModuleValue CommonBridge::SetSharedTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5243 {
5244     EcmaVM* vm = runtimeCallInfo->GetVM();
5245     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5246     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5247     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5248     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5249     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5250     if (!info[NUM_1]->IsString() || info[NUM_1]->ToString().empty()) {
5251         return panda::JSValueRef::Undefined(vm);
5252     }
5253     auto id = info[NUM_1]->ToString();
5254     std::shared_ptr<SharedTransitionOption> sharedOption;
5255     if (info[NUM_2]->IsObject()) {
5256         Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(info[NUM_2]);
5257         sharedOption = std::make_shared<SharedTransitionOption>();
5258         sharedOption->duration = jsObj->GetPropertyValue<int32_t>("duration", DEFAULT_DURATION);
5259         if (sharedOption->duration < 0) {
5260             sharedOption->duration = DEFAULT_DURATION;
5261         }
5262         sharedOption->delay = jsObj->GetPropertyValue<int32_t>("delay", 0);
5263         if (sharedOption->delay < 0) {
5264             sharedOption->delay = 0;
5265         }
5266         RefPtr<Curve> curve;
5267         Framework::JSRef<Framework::JSVal> curveArgs = jsObj->GetProperty("curve");
5268         if (curveArgs->IsString()) {
5269             curve = Framework::CreateCurve(jsObj->GetPropertyValue<std::string>("curve", "linear"), false);
5270         } else if (curveArgs->IsObject()) {
5271             Framework::JSRef<Framework::JSVal> curveString =
5272                 Framework::JSRef<Framework::JSObject>::Cast(curveArgs)->GetProperty("__curveString");
5273             if (!curveString->IsString()) {
5274                 return panda::JSValueRef::Undefined(vm);
5275             }
5276             curve = Framework::CreateCurve(curveString->ToString(), false);
5277         }
5278         if (!curve) {
5279             curve = Curves::LINEAR;
5280         }
5281         sharedOption->curve = curve;
5282         if (jsObj->HasProperty("motionPath")) {
5283             MotionPathOption motionPathOption;
5284             if (ParseMotionPath(jsObj->GetProperty("motionPath"), motionPathOption)) {
5285                 sharedOption->motionPathOption = motionPathOption;
5286             }
5287         }
5288         sharedOption->zIndex = jsObj->GetPropertyValue<int32_t>("zIndex", 0);
5289         int32_t type = jsObj->GetPropertyValue<int32_t>("type", static_cast<int32_t>(DEFAULT_SHARED_EFFECT));
5290         sharedOption->type = static_cast<SharedTransitionEffectType>(type);
5291     }
5292     ViewAbstract::SetSharedTransition(frameNode, id, sharedOption);
5293     return panda::JSValueRef::Undefined(vm);
5294 }
SetMask(ArkUIRuntimeCallInfo * runtimeCallInfo)5295 ArkUINativeModuleValue CommonBridge::SetMask(ArkUIRuntimeCallInfo* runtimeCallInfo)
5296 {
5297     EcmaVM* vm = runtimeCallInfo->GetVM();
5298     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5299     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5300     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5301     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5302 
5303     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5304     if (!info[NUM_1]->IsObject()) {
5305         ViewAbstract::SetProgressMask(frameNode, nullptr);
5306         return panda::JSValueRef::Undefined(vm);
5307     }
5308     auto paramObject = Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1]);
5309     Framework::JSRef<Framework::JSVal> typeParam = paramObject->GetProperty("type");
5310     if (!typeParam->IsNull() && !typeParam->IsUndefined() && typeParam->IsString() &&
5311         typeParam->ToString() == "ProgressMask") {
5312         auto progressMask = AceType::MakeRefPtr<NG::ProgressMaskProperty>();
5313         Framework::JSRef<Framework::JSVal> jValue = paramObject->GetProperty("value");
5314         auto value = jValue->IsNumber() ? jValue->ToNumber<float>() : 0.0f;
5315         if (value < 0.0f) {
5316             value = 0.0f;
5317         }
5318         progressMask->SetValue(value);
5319         Framework::JSRef<Framework::JSVal> jTotal = paramObject->GetProperty("total");
5320         auto total = jTotal->IsNumber() ? jTotal->ToNumber<float>() : DEFAULT_PROGRESS_TOTAL;
5321         if (total < 0.0f) {
5322             total = DEFAULT_PROGRESS_TOTAL;
5323         }
5324         progressMask->SetMaxValue(total);
5325         Framework::JSRef<Framework::JSVal> jColor = paramObject->GetProperty("color");
5326         Color colorVal;
5327         if (Framework::JSViewAbstract::ParseJsColor(jColor, colorVal)) {
5328             progressMask->SetColor(colorVal);
5329         } else {
5330             auto theme = Framework::JSShapeAbstract::GetTheme<ProgressTheme>();
5331             progressMask->SetColor(theme->GetMaskColor());
5332         }
5333         ViewAbstract::SetProgressMask(frameNode, progressMask);
5334     } else {
5335         Framework::JSShapeAbstract* maskShape =
5336             Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
5337         if (maskShape == nullptr) {
5338             return panda::JSValueRef::Undefined(vm);
5339         };
5340         ViewAbstract::SetMask(frameNode, maskShape->GetBasicShape());
5341     }
5342     return panda::JSValueRef::Undefined(vm);
5343 }
5344 
ResetMask(ArkUIRuntimeCallInfo * runtimeCallInfo)5345 ArkUINativeModuleValue CommonBridge::ResetMask(ArkUIRuntimeCallInfo* runtimeCallInfo)
5346 {
5347     EcmaVM* vm = runtimeCallInfo->GetVM();
5348     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5349     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5350     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5351     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5352     ViewAbstract::SetProgressMask(frameNode, nullptr);
5353     return panda::JSValueRef::Undefined(vm);
5354 }
5355 
SetMaskShape(ArkUIRuntimeCallInfo * runtimeCallInfo)5356 ArkUINativeModuleValue CommonBridge::SetMaskShape(ArkUIRuntimeCallInfo* runtimeCallInfo)
5357 {
5358     EcmaVM* vm = runtimeCallInfo->GetVM();
5359     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5360     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5361     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5362     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5363 
5364     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5365     if (!info[NUM_1]->IsObject()) {
5366         return panda::JSValueRef::Undefined(vm);
5367     }
5368 
5369     Framework::JSShapeAbstract* maskShape =
5370         Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
5371     if (maskShape == nullptr) {
5372         return panda::JSValueRef::Undefined(vm);
5373     };
5374     ViewAbstract::SetMask(frameNode, maskShape->GetBasicShape());
5375 
5376     return panda::JSValueRef::Undefined(vm);
5377 }
5378 
ResetMaskShape(ArkUIRuntimeCallInfo * runtimeCallInfo)5379 ArkUINativeModuleValue CommonBridge::ResetMaskShape(ArkUIRuntimeCallInfo* runtimeCallInfo)
5380 {
5381     EcmaVM* vm = runtimeCallInfo->GetVM();
5382     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5383     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5384     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5385     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5386     ViewAbstract::SetProgressMask(frameNode, nullptr);
5387     return panda::JSValueRef::Undefined(vm);
5388 }
5389 
SetMouseResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5390 ArkUINativeModuleValue CommonBridge::SetMouseResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5391 {
5392     EcmaVM* vm = runtimeCallInfo->GetVM();
5393     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5394     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5395     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5396     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5397     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5398     int32_t length = thirdArg->Int32Value(vm);
5399     ArkUI_Float32 regionArray[length];
5400     int32_t regionUnits[length];
5401     if (!ParseResponseRegion(vm, secondArg, regionArray, regionUnits, length)) {
5402         GetArkUINodeModifiers()->getCommonModifier()->resetMouseResponseRegion(nativeNode);
5403         return panda::JSValueRef::Undefined(vm);
5404     }
5405     GetArkUINodeModifiers()->getCommonModifier()->setMouseResponseRegion(nativeNode, regionArray, regionUnits, length);
5406     return panda::JSValueRef::Undefined(vm);
5407 }
5408 
ResetMouseResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5409 ArkUINativeModuleValue CommonBridge::ResetMouseResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5410 {
5411     EcmaVM* vm = runtimeCallInfo->GetVM();
5412     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5413     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5414     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5415     GetArkUINodeModifiers()->getCommonModifier()->resetMouseResponseRegion(nativeNode);
5416     return panda::JSValueRef::Undefined(vm);
5417 }
5418 
SetEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)5419 ArkUINativeModuleValue CommonBridge::SetEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
5420 {
5421     EcmaVM* vm = runtimeCallInfo->GetVM();
5422     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5423     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5424     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5425     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5426     if (secondArg->IsBoolean()) {
5427         bool boolValue = secondArg->ToBoolean(vm)->Value();
5428         GetArkUINodeModifiers()->getCommonModifier()->setEnabled(nativeNode, boolValue);
5429     } else {
5430         GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
5431     }
5432     return panda::JSValueRef::Undefined(vm);
5433 }
5434 
ResetEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)5435 ArkUINativeModuleValue CommonBridge::ResetEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
5436 {
5437     EcmaVM* vm = runtimeCallInfo->GetVM();
5438     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5439     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5440     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5441     GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
5442     return panda::JSValueRef::Undefined(vm);
5443 }
5444 
SetUseShadowBatching(ArkUIRuntimeCallInfo * runtimeCallInfo)5445 ArkUINativeModuleValue CommonBridge::SetUseShadowBatching(ArkUIRuntimeCallInfo* runtimeCallInfo)
5446 {
5447     EcmaVM* vm = runtimeCallInfo->GetVM();
5448     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5449     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5450     Local<JSValueRef> booleanArg = runtimeCallInfo->GetCallArgRef(1);
5451     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5452     if (booleanArg->IsBoolean()) {
5453         bool boolValue = booleanArg->ToBoolean(vm)->Value();
5454         GetArkUINodeModifiers()->getCommonModifier()->setUseShadowBatching(nativeNode, boolValue);
5455     } else {
5456         GetArkUINodeModifiers()->getCommonModifier()->resetUseShadowBatching(nativeNode);
5457     }
5458     return panda::JSValueRef::Undefined(vm);
5459 }
5460 
ResetUseShadowBatching(ArkUIRuntimeCallInfo * runtimeCallInfo)5461 ArkUINativeModuleValue CommonBridge::ResetUseShadowBatching(ArkUIRuntimeCallInfo* runtimeCallInfo)
5462 {
5463     EcmaVM* vm = runtimeCallInfo->GetVM();
5464     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5465     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5466     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5467     GetArkUINodeModifiers()->getCommonModifier()->resetUseShadowBatching(nativeNode);
5468     return panda::JSValueRef::Undefined(vm);
5469 }
5470 
SetBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)5471 ArkUINativeModuleValue CommonBridge::SetBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
5472 {
5473     EcmaVM* vm = runtimeCallInfo->GetVM();
5474     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5475     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);      // 0: index of parameter frameNode
5476     Local<JSValueRef> blendModeArg = runtimeCallInfo->GetCallArgRef(1);      // 1: index of parameter blendMode
5477     Local<JSValueRef> blendApplyTypeArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of parameter blendApplyType
5478     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5479     int32_t blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::NONE);
5480     int32_t blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::FAST);
5481     if (blendModeArg->IsNumber()) {
5482         int32_t blendModeNum = blendModeArg->Int32Value(vm);
5483         if (blendModeNum >= static_cast<int32_t>(OHOS::Ace::BlendMode::NONE) &&
5484             blendModeNum <= static_cast<int32_t>(OHOS::Ace::BlendMode::LUMINOSITY)) {
5485             blendModeValue = blendModeNum;
5486         } else if (blendModeNum == BACKWARD_COMPAT_MAGIC_NUMBER_OFFSCREEN) {
5487             blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::SRC_OVER);
5488             blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::OFFSCREEN);
5489         }
5490         if (blendApplyTypeArg->IsNumber()) {
5491             int32_t blendApplyTypeNum = blendApplyTypeArg->Int32Value(vm);
5492             if (blendApplyTypeNum >= static_cast<int>(OHOS::Ace::BlendApplyType::FAST) &&
5493                 blendApplyTypeNum <= static_cast<int>(OHOS::Ace::BlendApplyType::OFFSCREEN)) {
5494                 blendApplyTypeValue = blendApplyTypeNum;
5495             }
5496         }
5497         GetArkUINodeModifiers()->getCommonModifier()->setBlendMode(nativeNode, blendModeValue, blendApplyTypeValue);
5498     } else {
5499         GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
5500     }
5501     return panda::JSValueRef::Undefined(vm);
5502 }
5503 
ResetBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)5504 ArkUINativeModuleValue CommonBridge::ResetBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
5505 {
5506     EcmaVM *vm = runtimeCallInfo->GetVM();
5507     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5508     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5509     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5510     GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
5511     return panda::JSValueRef::Undefined(vm);
5512 }
5513 
SetAdvancedBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)5514 ArkUINativeModuleValue CommonBridge::SetAdvancedBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
5515 {
5516     EcmaVM* vm = runtimeCallInfo->GetVM();
5517     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
5518     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);      // 0: index of parameter frameNode
5519     Local<JSValueRef> blendModeArg = runtimeCallInfo->GetCallArgRef(1);      // 1: index of parameter blendMode
5520     Local<JSValueRef> blendApplyTypeArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of parameter blendApplyType
5521     CHECK_NULL_RETURN(frameNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
5522     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5523     int32_t blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::NONE);
5524     int32_t blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::FAST);
5525     if (blendApplyTypeArg->IsNumber()) {
5526         int32_t blendApplyTypeNum = blendApplyTypeArg->Int32Value(vm);
5527         if (blendApplyTypeNum >= static_cast<int>(OHOS::Ace::BlendApplyType::FAST) &&
5528             blendApplyTypeNum <= static_cast<int>(OHOS::Ace::BlendApplyType::OFFSCREEN)) {
5529             blendApplyTypeValue = blendApplyTypeNum;
5530         }
5531     }
5532     if (blendModeArg->IsNumber()) {
5533         int32_t blendModeNum = blendModeArg->Int32Value(vm);
5534         if (blendModeNum >= static_cast<int32_t>(OHOS::Ace::BlendMode::NONE) &&
5535             blendModeNum <= static_cast<int32_t>(OHOS::Ace::BlendMode::LUMINOSITY)) {
5536             blendModeValue = blendModeNum;
5537         } else if (blendModeNum == BACKWARD_COMPAT_MAGIC_NUMBER_OFFSCREEN) {
5538             blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::SRC_OVER);
5539             blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::OFFSCREEN);
5540         }
5541         GetArkUINodeModifiers()->getCommonModifier()->setBlendMode(nativeNode, blendModeValue, blendApplyTypeValue);
5542     } else if (blendModeArg->IsObject(vm)) {
5543         auto arkBlender = ArkTSUtils::CreateRSBrightnessBlenderFromNapiValue(vm, blendModeArg);
5544         auto blender = reinterpret_cast<ArkUINodeHandle>(arkBlender);
5545         GetArkUINodeModifiers()->getCommonModifier()->setBlendModeByBlender(nativeNode, blender, blendApplyTypeValue);
5546     } else {
5547         GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
5548     }
5549     return panda::JSValueRef::Undefined(vm);
5550 }
5551 
ResetAdvancedBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)5552 ArkUINativeModuleValue CommonBridge::ResetAdvancedBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
5553 {
5554     EcmaVM *vm = runtimeCallInfo->GetVM();
5555     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
5556     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5557     CHECK_NULL_RETURN(frameNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
5558     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5559     GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
5560     return panda::JSValueRef::Undefined(vm);
5561 }
5562 
SetMonopolizeEvents(ArkUIRuntimeCallInfo * runtimeCallInfo)5563 ArkUINativeModuleValue CommonBridge::SetMonopolizeEvents(ArkUIRuntimeCallInfo* runtimeCallInfo)
5564 {
5565     EcmaVM* vm = runtimeCallInfo->GetVM();
5566     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5567     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5568     Local<JSValueRef> booleanArg = runtimeCallInfo->GetCallArgRef(1);
5569     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5570     if (booleanArg->IsBoolean()) {
5571         bool boolValue = booleanArg->ToBoolean(vm)->Value();
5572         GetArkUINodeModifiers()->getCommonModifier()->setMonopolizeEvents(nativeNode, boolValue);
5573     } else {
5574         GetArkUINodeModifiers()->getCommonModifier()->resetMonopolizeEvents(nativeNode);
5575     }
5576     return panda::JSValueRef::Undefined(vm);
5577 }
5578 
ResetMonopolizeEvents(ArkUIRuntimeCallInfo * runtimeCallInfo)5579 ArkUINativeModuleValue CommonBridge::ResetMonopolizeEvents(ArkUIRuntimeCallInfo* runtimeCallInfo)
5580 {
5581     EcmaVM* vm = runtimeCallInfo->GetVM();
5582     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5583     Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5584     auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5585     GetArkUINodeModifiers()->getCommonModifier()->resetMonopolizeEvents(nativeNode);
5586     return panda::JSValueRef::Undefined(vm);
5587 }
5588 
SetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)5589 ArkUINativeModuleValue CommonBridge::SetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
5590 {
5591     EcmaVM* vm = runtimeCallInfo->GetVM();
5592     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5593     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5594     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5595     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5596     if (secondArg->IsBoolean()) {
5597         bool boolValue = secondArg->ToBoolean(vm)->Value();
5598         GetArkUINodeModifiers()->getCommonModifier()->setDraggable(nativeNode, boolValue);
5599     } else {
5600         GetArkUINodeModifiers()->getCommonModifier()->resetDraggable(nativeNode);
5601     }
5602     return panda::JSValueRef::Undefined(vm);
5603 }
5604 
ResetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)5605 ArkUINativeModuleValue CommonBridge::ResetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
5606 {
5607     EcmaVM* vm = runtimeCallInfo->GetVM();
5608     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5609     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5610     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5611     GetArkUINodeModifiers()->getCommonModifier()->resetDraggable(nativeNode);
5612     return panda::JSValueRef::Undefined(vm);
5613 }
5614 
SetAccessibilityGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)5615 ArkUINativeModuleValue CommonBridge::SetAccessibilityGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
5616 {
5617     EcmaVM* vm = runtimeCallInfo->GetVM();
5618     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5619     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5620     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5621     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5622     if (secondArg->IsBoolean()) {
5623         bool boolValue = secondArg->ToBoolean(vm)->Value();
5624         GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityGroup(nativeNode, boolValue);
5625     } else {
5626         GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityGroup(nativeNode);
5627     }
5628     return panda::JSValueRef::Undefined(vm);
5629 }
5630 
ResetAccessibilityGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)5631 ArkUINativeModuleValue CommonBridge::ResetAccessibilityGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
5632 {
5633     EcmaVM* vm = runtimeCallInfo->GetVM();
5634     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5635     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5636     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5637     GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityGroup(nativeNode);
5638     return panda::JSValueRef::Undefined(vm);
5639 }
5640 
SetHoverEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5641 ArkUINativeModuleValue CommonBridge::SetHoverEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5642 {
5643     EcmaVM* vm = runtimeCallInfo->GetVM();
5644     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5645     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5646     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5647     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5648 
5649     if (secondArg->IsUndefined() || !secondArg->IsNumber()) {
5650         GetArkUINodeModifiers()->getCommonModifier()->resetHoverEffect(nativeNode);
5651         return panda::JSValueRef::Undefined(vm);
5652     }
5653     int32_t intValue = secondArg->Int32Value(vm);
5654     GetArkUINodeModifiers()->getCommonModifier()->setHoverEffect(nativeNode, intValue);
5655     return panda::JSValueRef::Undefined(vm);
5656 }
5657 
ResetHoverEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5658 ArkUINativeModuleValue CommonBridge::ResetHoverEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5659 {
5660     EcmaVM* vm = runtimeCallInfo->GetVM();
5661     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5662     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5663     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5664     GetArkUINodeModifiers()->getCommonModifier()->resetHoverEffect(nativeNode);
5665     return panda::JSValueRef::Undefined(vm);
5666 }
5667 
SetClickEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5668 ArkUINativeModuleValue CommonBridge::SetClickEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5669 {
5670     EcmaVM* vm = runtimeCallInfo->GetVM();
5671     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5672     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5673     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5674     Local<JSValueRef> levelArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5675     Local<JSValueRef> scaleArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5676 
5677     int32_t clickEffectLevelValue = 0;
5678     if (levelArg->IsNumber()) {
5679         clickEffectLevelValue = levelArg->Int32Value(vm);
5680         if (clickEffectLevelValue < static_cast<int32_t>(OHOS::Ace::ClickEffectLevel::LIGHT) ||
5681             clickEffectLevelValue > static_cast<int32_t>(OHOS::Ace::ClickEffectLevel::HEAVY)) {
5682             clickEffectLevelValue = 0;
5683         }
5684     }
5685     float scaleNumberValue = 0.9f;
5686     if (!scaleArg->IsNumber()) {
5687         if ((OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::MIDDLE ||
5688             (OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::HEAVY) {
5689             scaleNumberValue = 0.95f;
5690         }
5691     } else {
5692         scaleNumberValue = scaleArg->ToNumber(vm)->Value();
5693         if (LessNotEqual(scaleNumberValue, 0.0) || GreatNotEqual(scaleNumberValue, 1.0)) {
5694             if ((OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::MIDDLE ||
5695                 (OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::HEAVY) {
5696                 scaleNumberValue = 0.95f;
5697             } else {
5698                 scaleNumberValue = 0.9f;
5699             }
5700         }
5701     }
5702     GetArkUINodeModifiers()->getCommonModifier()->setClickEffect(nativeNode, clickEffectLevelValue,
5703         scaleNumberValue);
5704     return panda::JSValueRef::Undefined(vm);
5705 }
5706 
ResetClickEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5707 ArkUINativeModuleValue CommonBridge::ResetClickEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5708 {
5709     EcmaVM* vm = runtimeCallInfo->GetVM();
5710     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5711     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5712     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5713     GetArkUINodeModifiers()->getCommonModifier()->resetClickEffect(nativeNode);
5714     return panda::JSValueRef::Undefined(vm);
5715 }
5716 
SetKeyBoardShortCut(ArkUIRuntimeCallInfo * runtimeCallInfo)5717 ArkUINativeModuleValue CommonBridge::SetKeyBoardShortCut(ArkUIRuntimeCallInfo* runtimeCallInfo)
5718 {
5719     EcmaVM* vm = runtimeCallInfo->GetVM();
5720     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5721     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5722     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5723     Local<JSValueRef> keysArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5724     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5725     if ((!valueArg->IsString(vm) && !valueArg->IsNumber()) || !keysArg->IsArray(vm)) {
5726         GetArkUINodeModifiers()->getCommonModifier()->resetKeyBoardShortCut(nativeNode);
5727         return panda::JSValueRef::Undefined(vm);
5728     }
5729     std::string stringValue;
5730     if (valueArg->IsNumber()) {
5731         OHOS::Ace::FunctionKey functionkey = static_cast<OHOS::Ace::FunctionKey>(valueArg->Int32Value(vm));
5732         stringValue = JSViewAbstract::GetFunctionKeyName(functionkey);
5733     } else {
5734         stringValue = valueArg->ToString(vm)->ToString(vm);
5735     }
5736     Local<panda::ArrayRef> keysArray = static_cast<Local<panda::ArrayRef>>(keysArg);
5737     auto arrLength = keysArray->Length(vm);
5738     if (arrLength > NUM_10) {
5739         arrLength = NUM_10;
5740     }
5741     int32_t* keysIntArray = new int32_t[arrLength];
5742     for (size_t i = 0; i < arrLength; i++) {
5743         Local<JSValueRef> objValue = keysArray->GetValueAt(vm, keysArg, i);
5744         keysIntArray[i] = objValue->Int32Value(vm);
5745     }
5746     GetArkUINodeModifiers()->getCommonModifier()->setKeyBoardShortCut(
5747         nativeNode, stringValue.c_str(), keysIntArray, arrLength);
5748     delete[] keysIntArray;
5749     return panda::JSValueRef::Undefined(vm);
5750 }
5751 
ResetKeyBoardShortCut(ArkUIRuntimeCallInfo * runtimeCallInfo)5752 ArkUINativeModuleValue CommonBridge::ResetKeyBoardShortCut(ArkUIRuntimeCallInfo* runtimeCallInfo)
5753 {
5754     EcmaVM* vm = runtimeCallInfo->GetVM();
5755     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5756     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5757     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5758     GetArkUINodeModifiers()->getCommonModifier()->resetKeyBoardShortCut(nativeNode);
5759     return panda::JSValueRef::Undefined(vm);
5760 }
5761 
CreateResourceWrapper()5762 RefPtr<ResourceWrapper> CreateResourceWrapper()
5763 {
5764     RefPtr<ResourceAdapter> resourceAdapter = nullptr;
5765     RefPtr<ThemeConstants> themeConstants = nullptr;
5766     if (SystemProperties::GetResourceDecoupling()) {
5767         resourceAdapter = ResourceManager::GetInstance().GetResourceAdapter();
5768         if (!resourceAdapter) {
5769             return nullptr;
5770         }
5771     } else {
5772         themeConstants = JSViewAbstract::GetThemeConstants();
5773         if (!themeConstants) {
5774             return nullptr;
5775         }
5776     }
5777     auto resourceWrapper = AceType::MakeRefPtr<ResourceWrapper>(themeConstants, resourceAdapter);
5778     return resourceWrapper;
5779 }
5780 
ParseLightPosition(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,ArkUISizeType & dimPosX,ArkUISizeType & dimPosY,ArkUISizeType & dimPosZ)5781 bool ParseLightPosition(ArkUIRuntimeCallInfo *runtimeCallInfo, EcmaVM* vm, ArkUISizeType& dimPosX,
5782     ArkUISizeType& dimPosY, ArkUISizeType& dimPosZ)
5783 {
5784     Local<JSValueRef> positionXArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5785     Local<JSValueRef> positionYArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5786     Local<JSValueRef> positionZArg = runtimeCallInfo->GetCallArgRef(NUM_3);
5787     CalcDimension dimPositionX;
5788     CalcDimension dimPositionY;
5789     CalcDimension dimPositionZ;
5790     bool xSuccess = ArkTSUtils::ParseJsDimensionVp(vm, positionXArg, dimPositionX, false);
5791     bool ySuccess = ArkTSUtils::ParseJsDimensionVp(vm, positionYArg, dimPositionY, false);
5792     bool zSuccess = ArkTSUtils::ParseJsDimensionVp(vm, positionZArg, dimPositionZ, false);
5793     if (!(xSuccess && ySuccess && zSuccess)) {
5794         return false;
5795     }
5796     dimPosX.value = dimPositionX.Value();
5797     dimPosX.unit = static_cast<int8_t>(dimPositionX.Unit());
5798     dimPosY.value = dimPositionY.Value();
5799     dimPosY.unit = static_cast<int8_t>(dimPositionY.Unit());
5800     dimPosZ.value = dimPositionZ.Value();
5801     dimPosZ.unit = static_cast<int8_t>(dimPositionZ.Unit());
5802     return true;
5803 }
5804 
ParseLightSource(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,ArkUINodeHandle & nativeNode)5805 void ParseLightSource(ArkUIRuntimeCallInfo *runtimeCallInfo, EcmaVM* vm, ArkUINodeHandle& nativeNode)
5806 {
5807     struct ArkUISizeType dimPosX = { 0.0, 0 };
5808     struct ArkUISizeType dimPosY = { 0.0, 0 };
5809     struct ArkUISizeType dimPosZ = { 0.0, 0 };
5810     bool success = ParseLightPosition(runtimeCallInfo, vm, dimPosX, dimPosY, dimPosZ);
5811     if (success) {
5812         GetArkUINodeModifiers()->getCommonModifier()->setPointLightPosition(nativeNode, &dimPosX, &dimPosY, &dimPosZ);
5813     } else {
5814         GetArkUINodeModifiers()->getCommonModifier()->resetPointLightPosition(nativeNode);
5815     }
5816 
5817     Local<JSValueRef> intensityArg = runtimeCallInfo->GetCallArgRef(NUM_4);
5818     if (intensityArg->IsNumber()) {
5819         auto intensityValue = static_cast<ArkUI_Float32>((intensityArg->ToNumber(vm)->Value()));
5820         GetArkUINodeModifiers()->getCommonModifier()->setPointLightIntensity(nativeNode, intensityValue);
5821     } else {
5822         GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIntensity(nativeNode);
5823     }
5824 
5825     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_5);
5826     Color colorValue;
5827     if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, colorValue)) {
5828         GetArkUINodeModifiers()->getCommonModifier()->setPointLightColor(nativeNode, colorValue.GetValue());
5829     } else {
5830         GetArkUINodeModifiers()->getCommonModifier()->resetPointLightColor(nativeNode);
5831     }
5832 }
5833 
SetPointLightStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)5834 ArkUINativeModuleValue CommonBridge::SetPointLightStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
5835 {
5836     EcmaVM* vm = runtimeCallInfo->GetVM();
5837 #ifdef POINT_LIGHT_ENABLE
5838     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5839     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5840     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5841 
5842     ParseLightSource(runtimeCallInfo, vm, nativeNode);
5843 
5844     auto resourceWrapper = CreateResourceWrapper();
5845     Local<JSValueRef> illuminatedArg = runtimeCallInfo->GetCallArgRef(NUM_6);
5846     if (illuminatedArg->IsNumber() || !resourceWrapper) {
5847         auto illuminatedValue = static_cast<ArkUI_Uint32>(illuminatedArg->ToNumber(vm)->Value());
5848         Dimension illuminatedBorderWidth = resourceWrapper->GetDimensionByName(ILLUMINATED_BORDER_WIDTH_SYS_RES_NAME);
5849         struct ArkUISizeType illuminatedBorderWidthValue = { 0.0, 0 };
5850         illuminatedBorderWidthValue.value = illuminatedBorderWidth.Value();
5851         illuminatedBorderWidthValue.unit = static_cast<int8_t>(illuminatedBorderWidth.Unit());
5852         GetArkUINodeModifiers()->getCommonModifier()->setPointLightIlluminated(
5853             nativeNode, illuminatedValue, &illuminatedBorderWidthValue);
5854     } else {
5855         GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIlluminated(nativeNode);
5856     }
5857 
5858     Local<JSValueRef> bloomArg = runtimeCallInfo->GetCallArgRef(NUM_7);
5859     if (bloomArg->IsNumber() || !resourceWrapper) {
5860         auto bloomValue = static_cast<ArkUI_Float32>(bloomArg->ToNumber(vm)->Value());
5861         double bloomRadius = resourceWrapper->GetDoubleByName(BLOOM_RADIUS_SYS_RES_NAME);
5862         Color bloomColor = resourceWrapper->GetColorByName(BLOOM_COLOR_SYS_RES_NAME);
5863         GetArkUINodeModifiers()->getCommonModifier()->setPointLightBloom(nativeNode, bloomValue,
5864             static_cast<ArkUI_Float32>(bloomRadius), static_cast<ArkUI_Uint32>(bloomColor.GetValue()));
5865     } else {
5866         GetArkUINodeModifiers()->getCommonModifier()->resetPointLightBloom(nativeNode);
5867     }
5868 #endif
5869     return panda::JSValueRef::Undefined(vm);
5870 }
5871 
ResetPointLightStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)5872 ArkUINativeModuleValue CommonBridge::ResetPointLightStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
5873 {
5874     EcmaVM *vm = runtimeCallInfo->GetVM();
5875 #ifdef POINT_LIGHT_ENABLE
5876     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5877     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5878     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5879     GetArkUINodeModifiers()->getCommonModifier()->resetPointLightPosition(nativeNode);
5880     GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIntensity(nativeNode);
5881     GetArkUINodeModifiers()->getCommonModifier()->resetPointLightColor(nativeNode);
5882     GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIlluminated(nativeNode);
5883     GetArkUINodeModifiers()->getCommonModifier()->resetPointLightBloom(nativeNode);
5884 #endif
5885     return panda::JSValueRef::Undefined(vm);
5886 }
5887 
SetClipWithEdge(ArkUIRuntimeCallInfo * runtimeCallInfo)5888 ArkUINativeModuleValue CommonBridge::SetClipWithEdge(ArkUIRuntimeCallInfo *runtimeCallInfo)
5889 {
5890     EcmaVM *vm = runtimeCallInfo->GetVM();
5891     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5892     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5893     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5894     auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
5895 
5896     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5897     if (info[NUM_1]->IsUndefined()) {
5898         ViewAbstract::SetClipEdge(frameNode, true);
5899         return panda::JSValueRef::Undefined(vm);
5900     }
5901     if (info[NUM_1]->IsObject()) {
5902         Framework::JSShapeAbstract *clipShape =
5903             Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
5904         if (clipShape == nullptr) {
5905             return panda::JSValueRef::Undefined(vm);
5906         }
5907         ViewAbstract::SetClipShape(frameNode, clipShape->GetBasicShape());
5908     } else if (info[NUM_1]->IsBoolean()) {
5909         ViewAbstract::SetClipEdge(frameNode, info[NUM_1]->ToBoolean());
5910     }
5911     return panda::JSValueRef::Undefined(vm);
5912 }
5913 
ResetClipWithEdge(ArkUIRuntimeCallInfo * runtimeCallInfo)5914 ArkUINativeModuleValue CommonBridge::ResetClipWithEdge(ArkUIRuntimeCallInfo *runtimeCallInfo)
5915 {
5916     EcmaVM *vm = runtimeCallInfo->GetVM();
5917     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5918     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5919     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5920     auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
5921     ViewAbstract::SetClipEdge(frameNode, true);
5922     return panda::JSValueRef::Undefined(vm);
5923 }
5924 
GetFrameNode(ArkUIRuntimeCallInfo * runtimeCallInfo)5925 FrameNode* CommonBridge::GetFrameNode(ArkUIRuntimeCallInfo* runtimeCallInfo)
5926 {
5927     EcmaVM* vm = runtimeCallInfo->GetVM();
5928     CHECK_NULL_RETURN(vm, nullptr);
5929     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5930     CHECK_NULL_RETURN(!firstArg.IsNull(), nullptr);
5931     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5932     CHECK_NULL_RETURN(nativeNode, nullptr);
5933     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5934     return frameNode;
5935 }
5936 
CreateGestureInfo(EcmaVM * vm,const RefPtr<NG::GestureInfo> & gestureInfo)5937 Local<panda::ObjectRef> CommonBridge::CreateGestureInfo(EcmaVM* vm, const RefPtr<NG::GestureInfo>& gestureInfo)
5938 {
5939     if (gestureInfo->GetTag().has_value()) {
5940         const char* keys[] = { "tag", "type", "isSystemGesture" };
5941         Local<JSValueRef> values[] = { panda::StringRef::NewFromUtf8(vm, gestureInfo->GetTag().value().c_str()),
5942             panda::NumberRef::New(vm, static_cast<int32_t>(gestureInfo->GetType())),
5943             panda::BooleanRef::New(vm, gestureInfo->IsSystemGesture()) };
5944         return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
5945     }
5946     const char* keys[] = { "type", "isSystemGesture" };
5947     Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(gestureInfo->GetType())),
5948         panda::BooleanRef::New(vm, gestureInfo->IsSystemGesture()) };
5949     return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
5950 }
5951 
CreateGestureEventInfo(EcmaVM * vm,GestureTypeName typeName,const std::shared_ptr<BaseGestureEvent> & info)5952 Local<panda::ObjectRef> CommonBridge::CreateGestureEventInfo(
5953     EcmaVM* vm, GestureTypeName typeName, const std::shared_ptr<BaseGestureEvent>& info)
5954 {
5955     auto obj = SetUniqueAttributes(vm, typeName, info);
5956     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "timestamp"),
5957         panda::NumberRef::New(vm, static_cast<double>(info->GetTimeStamp().time_since_epoch().count())));
5958     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "source"),
5959         panda::NumberRef::New(vm, static_cast<int32_t>(info->GetSourceDevice())));
5960     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "pressure"), panda::NumberRef::New(vm, info->GetForce()));
5961     if (info->GetTiltX().has_value()) {
5962         obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltX"), panda::NumberRef::New(vm, info->GetTiltX().value()));
5963     }
5964     if (info->GetTiltY().has_value()) {
5965         obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltY"), panda::NumberRef::New(vm, info->GetTiltY().value()));
5966     }
5967     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sourceTool"),
5968         panda::NumberRef::New(vm, static_cast<int32_t>(info->GetSourceTool())));
5969     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "deviceId"),
5970         panda::NumberRef::New(vm, static_cast<int32_t>(info->GetDeviceId())));
5971 
5972     auto fingerArr = panda::ArrayRef::New(vm);
5973     const std::list<FingerInfo>& fingerList = info->GetFingerList();
5974     std::list<FingerInfo> notTouchFingerList;
5975     int32_t maxFingerId = -1;
5976     for (const FingerInfo& fingerInfo : fingerList) {
5977         auto element = CreateFingerInfo(vm, fingerInfo);
5978         if (fingerInfo.sourceType_ == SourceType::TOUCH && fingerInfo.sourceTool_ == SourceTool::FINGER) {
5979             fingerArr->SetValueAt(vm, fingerArr, fingerInfo.fingerId_, element);
5980             if (fingerInfo.fingerId_ > maxFingerId) {
5981                 maxFingerId = fingerInfo.fingerId_;
5982             }
5983         } else {
5984             notTouchFingerList.emplace_back(fingerInfo);
5985         }
5986     }
5987     auto idx = maxFingerId + 1;
5988     for (const FingerInfo& fingerInfo : notTouchFingerList) {
5989         auto element = CreateFingerInfo(vm, fingerInfo);
5990         fingerArr->SetValueAt(vm, fingerArr, idx++, element);
5991     }
5992     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "fingerList"), fingerArr);
5993     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "target"), CreateEventTargetObject(vm, info));
5994     return obj;
5995 }
5996 
SetUniqueAttributes(EcmaVM * vm,GestureTypeName typeName,const std::shared_ptr<BaseGestureEvent> & info)5997 Local<panda::ObjectRef> CommonBridge::SetUniqueAttributes(
5998     EcmaVM* vm, GestureTypeName typeName, const std::shared_ptr<BaseGestureEvent>& info)
5999 {
6000     double density = PipelineBase::GetCurrentDensity();
6001     switch (typeName) {
6002         case OHOS::Ace::GestureTypeName::LONG_PRESS_GESTURE: {
6003             auto* longPressGestureEvent = TypeInfoHelper::DynamicCast<LongPressGestureEvent>(info.get());
6004             if (longPressGestureEvent) {
6005                 const char* keys[] = { "repeat" };
6006                 Local<JSValueRef> values[] = { panda::BooleanRef::New(vm, longPressGestureEvent->GetRepeat()) };
6007                 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6008             }
6009             return panda::ObjectRef::New(vm);
6010         }
6011         case OHOS::Ace::GestureTypeName::PAN_GESTURE: {
6012             auto* panGestureEvent = TypeInfoHelper::DynamicCast<PanGestureEvent>(info.get());
6013             if (panGestureEvent) {
6014                 const char* keys[] = { "offsetX", "offsetY", "velocityX", "velocityY", "velocity" };
6015                 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, panGestureEvent->GetOffsetX() / density),
6016                     panda::NumberRef::New(vm, panGestureEvent->GetOffsetY() / density),
6017                     panda::NumberRef::New(vm, panGestureEvent->GetVelocity().GetVelocityX() / density),
6018                     panda::NumberRef::New(vm, panGestureEvent->GetVelocity().GetVelocityY() / density),
6019                     panda::NumberRef::New(vm, panGestureEvent->GetVelocity().GetVelocityValue() / density) };
6020                 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6021             }
6022             return panda::ObjectRef::New(vm);
6023         }
6024         case OHOS::Ace::GestureTypeName::PINCH_GESTURE: {
6025             auto* pinchGestureEvent = TypeInfoHelper::DynamicCast<PinchGestureEvent>(info.get());
6026             if (pinchGestureEvent) {
6027                 const char* keys[] = { "scale", "pinchCenterX", "pinchCenterY" };
6028                 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, pinchGestureEvent->GetScale()),
6029                     panda::NumberRef::New(vm, pinchGestureEvent->GetPinchCenter().GetX() / density),
6030                     panda::NumberRef::New(vm, pinchGestureEvent->GetPinchCenter().GetY() / density) };
6031                 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6032             }
6033             return panda::ObjectRef::New(vm);
6034         }
6035         case OHOS::Ace::GestureTypeName::ROTATION_GESTURE: {
6036             auto* rotationGestureEvent = TypeInfoHelper::DynamicCast<RotationGestureEvent>(info.get());
6037             if (rotationGestureEvent) {
6038                 const char* keys[] = { "angle" };
6039                 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, rotationGestureEvent->GetAngle()) };
6040                 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6041             }
6042             return panda::ObjectRef::New(vm);
6043         }
6044         case OHOS::Ace::GestureTypeName::SWIPE_GESTURE: {
6045             auto* swipeGestureEvent = TypeInfoHelper::DynamicCast<SwipeGestureEvent>(info.get());
6046             if (swipeGestureEvent) {
6047                 const char* keys[] = { "angle", "speed" };
6048                 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, swipeGestureEvent->GetAngle()),
6049                     panda::NumberRef::New(vm, swipeGestureEvent->GetSpeed()) };
6050                 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6051             }
6052             return panda::ObjectRef::New(vm);
6053         }
6054         default:
6055             return panda::ObjectRef::New(vm);
6056     }
6057 }
6058 
CreateRecognizerObject(EcmaVM * vm,const RefPtr<NG::NGGestureRecognizer> & target)6059 Local<panda::ObjectRef> CommonBridge::CreateRecognizerObject(EcmaVM* vm, const RefPtr<NG::NGGestureRecognizer>& target)
6060 {
6061     auto panRecognizer = AceType::DynamicCast<NG::PanRecognizer>(target);
6062     if (panRecognizer) {
6063         JSRef<JSObject> recognizerObj = JSClass<JSPanRecognizer>::NewInstance();
6064         auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSPanRecognizer>());
6065         currentRecognizer->SetRecognizer(panRecognizer);
6066         currentRecognizer->SetPanGestureOptions(
6067             panRecognizer->GetFingers(), panRecognizer->GetDistance(), panRecognizer->GetDirection());
6068         return recognizerObj->GetLocalHandle();
6069     }
6070     JSRef<JSObject> recognizerObj = JSClass<JSGestureRecognizer>::NewInstance();
6071     auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSGestureRecognizer>());
6072     currentRecognizer->SetRecognizer(target);
6073     return recognizerObj->GetLocalHandle();
6074 }
6075 
CreateFingerInfo(EcmaVM * vm,const FingerInfo & fingerInfo)6076 Local<panda::ObjectRef> CommonBridge::CreateFingerInfo(EcmaVM* vm, const FingerInfo& fingerInfo)
6077 {
6078     const OHOS::Ace::Offset& globalLocation = fingerInfo.globalLocation_;
6079     const OHOS::Ace::Offset& localLocation = fingerInfo.localLocation_;
6080     const OHOS::Ace::Offset& screenLocation = fingerInfo.screenLocation_;
6081     double density = PipelineBase::GetCurrentDensity();
6082     const char* keys[] = { "id", "globalX", "globalY", "localX", "localY", "displayX", "displayY" };
6083     Local<JSValueRef> values[] = { panda::NumberRef::New(vm, fingerInfo.fingerId_),
6084         panda::NumberRef::New(vm, globalLocation.GetX() / density),
6085         panda::NumberRef::New(vm, globalLocation.GetY() / density),
6086         panda::NumberRef::New(vm, localLocation.GetX() / density),
6087         panda::NumberRef::New(vm, localLocation.GetY() / density),
6088         panda::NumberRef::New(vm, screenLocation.GetX() / density),
6089         panda::NumberRef::New(vm, screenLocation.GetY() / density) };
6090         return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6091 }
6092 
CreateEventTargetObject(EcmaVM * vm,const std::shared_ptr<BaseGestureEvent> & info)6093 Local<panda::ObjectRef> CommonBridge::CreateEventTargetObject(EcmaVM* vm, const std::shared_ptr<BaseGestureEvent>& info)
6094 {
6095     const auto& localOffset = info->GetTarget().area.GetOffset();
6096     const auto& origin = info->GetTarget().origin;
6097     const char* keysOfOffset[] = { "x", "y" };
6098     Local<JSValueRef> valuesOfOffset[] = { panda::NumberRef::New(vm, localOffset.GetX().ConvertToVp()),
6099         panda::NumberRef::New(vm, localOffset.GetY().ConvertToVp()) };
6100     auto offset = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfOffset), keysOfOffset, valuesOfOffset);
6101 
6102     const char* keysOfGlobalOffset[] = { "x", "y" };
6103     Local<JSValueRef> valuesOfGlobalOffset[] = { panda::NumberRef::New(
6104         vm, (origin.GetX() + localOffset.GetX()).ConvertToVp()),
6105         panda::NumberRef::New(vm, (origin.GetY() + localOffset.GetY()).ConvertToVp()) };
6106     auto globalOffset = panda::ObjectRef::NewWithNamedProperties(
6107         vm, ArraySize(keysOfGlobalOffset), keysOfGlobalOffset, valuesOfGlobalOffset);
6108     const char* keysOfArea[] = { "position", "globalPosition", "width", "height" };
6109     Local<JSValueRef> valuesOfArea[] = { offset, globalOffset,
6110         panda::NumberRef::New(vm, info->GetTarget().area.GetWidth().ConvertToVp()),
6111         panda::NumberRef::New(vm, info->GetTarget().area.GetHeight().ConvertToVp()) };
6112     auto area = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfArea), keysOfArea, valuesOfArea);
6113     auto target = panda::ObjectRef::New(vm);
6114     target->Set(vm, panda::StringRef::NewFromUtf8(vm, "area"), area);
6115     return target;
6116 }
6117 
CreateAreaObject(EcmaVM * vm,const RectF & rect,const OffsetF & origin)6118 Local<panda::ObjectRef> CommonBridge::CreateAreaObject(EcmaVM* vm, const RectF& rect, const OffsetF& origin)
6119 {
6120     double density = PipelineBase::GetCurrentDensity();
6121     auto localOffset = rect.GetOffset();
6122     const char* keysOfOffset[] = { "x", "y" };
6123     Local<JSValueRef> valuesOfOffset[] = { panda::NumberRef::New(vm, localOffset.GetX() / density),
6124         panda::NumberRef::New(vm, localOffset.GetY() / density) };
6125     auto offset = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfOffset), keysOfOffset, valuesOfOffset);
6126     const char* keysOfGlobalOffset[] = { "x", "y" };
6127     Local<JSValueRef> valuesOfGlobalOffset[] = { panda::NumberRef::New(
6128         vm, (localOffset.GetX() + origin.GetX()) / density),
6129         panda::NumberRef::New(vm, (localOffset.GetY() + origin.GetY()) / density) };
6130     auto globalOffset = panda::ObjectRef::NewWithNamedProperties(
6131         vm, ArraySize(keysOfGlobalOffset), keysOfGlobalOffset, valuesOfGlobalOffset);
6132 
6133     const char* keysOfArea[] = { "pos", "position", "globalPos", "globalPosition", "width", "height" };
6134     Local<JSValueRef> valuesOfArea[] = { offset, offset, globalOffset, globalOffset,
6135         panda::NumberRef::New(vm, rect.Width() / density), panda::NumberRef::New(vm, rect.Height() / density) };
6136     return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfArea), keysOfArea, valuesOfArea);
6137 }
6138 
GetGestureCommonValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & priority,int32_t & mask)6139 void CommonBridge::GetGestureCommonValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& priority, int32_t& mask)
6140 {
6141     EcmaVM* vm = runtimeCallInfo->GetVM();
6142     CHECK_NULL_VOID(vm);
6143     Local<JSValueRef> priorityArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6144     if (!priorityArg.IsNull() && !priorityArg->IsUndefined()) {
6145         priority = static_cast<int32_t>(priorityArg->ToNumber(vm)->Value());
6146     }
6147     Local<JSValueRef> maskArg = runtimeCallInfo->GetCallArgRef(NUM_2);
6148     if (!maskArg.IsNull() && !maskArg->IsUndefined()) {
6149         mask = static_cast<int32_t>(maskArg->ToNumber(vm)->Value());
6150     }
6151 }
6152 
SetGestureTag(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t argNumber,ArkUIGesture * gesture)6153 void CommonBridge::SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture)
6154 {
6155     EcmaVM* vm = runtimeCallInfo->GetVM();
6156     CHECK_NULL_VOID(vm);
6157     Local<JSValueRef> gestureTagArg = runtimeCallInfo->GetCallArgRef(argNumber);
6158     if (!gestureTagArg.IsNull() && !gestureTagArg->IsUndefined()) {
6159         auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
6160         gesturePtr->SetTag(gestureTagArg->ToString(vm)->ToString(vm));
6161     }
6162 }
6163 
GetTapGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,int32_t & count,double & distanceThreshold,uint32_t argNumber)6164 void CommonBridge::GetTapGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers,
6165     int32_t& count, double& distanceThreshold, uint32_t argNumber)
6166 {
6167     EcmaVM* vm = runtimeCallInfo->GetVM();
6168     CHECK_NULL_VOID(vm);
6169     Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6170     if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6171         auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6172         fingers = (fingersValue < DEFAULT_TAP_FINGER || fingersValue > DEFAULT_MAX_FINGERS) ? DEFAULT_TAP_FINGER
6173                                                                                             : fingersValue;
6174     }
6175     Local<JSValueRef> countArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6176     if (!countArg.IsNull() && !countArg->IsUndefined()) {
6177         auto countValue = static_cast<int32_t>(countArg->ToNumber(vm)->Value());
6178         count = countValue < DEFAULT_TAP_COUNT ? DEFAULT_TAP_COUNT : countValue;
6179     }
6180     Local<JSValueRef> distanceArg = runtimeCallInfo->GetCallArgRef(argNumber + 2); // 2: get the third arg
6181     if (!distanceArg.IsNull() && !distanceArg->IsUndefined()) {
6182         auto distanceValue = static_cast<int32_t>(distanceArg->ToNumber(vm)->Value());
6183         distanceThreshold = distanceValue < 0 ? DEFAULT_TAP_DISTANCE : distanceValue;
6184     }
6185 }
6186 
GetLongPressGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,bool & repeat,int32_t & duration,uint32_t argNumber)6187 void CommonBridge::GetLongPressGestureValue(
6188     ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, bool& repeat, int32_t& duration, uint32_t argNumber)
6189 {
6190     EcmaVM* vm = runtimeCallInfo->GetVM();
6191     CHECK_NULL_VOID(vm);
6192     Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6193     if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6194         auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6195         fingers = (fingersValue < DEFAULT_LONG_PRESS_FINGER || fingersValue > DEFAULT_MAX_FINGERS)
6196                       ? DEFAULT_LONG_PRESS_FINGER
6197                       : fingersValue;
6198     }
6199     Local<JSValueRef> repeatArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6200     if (!repeatArg.IsNull() && !repeatArg->IsUndefined()) {
6201         repeat = repeatArg->ToBoolean(vm)->Value();
6202     }
6203     Local<JSValueRef> durationArg = runtimeCallInfo->GetCallArgRef(argNumber + NUM_2);
6204     if (!durationArg.IsNull() && !durationArg->IsUndefined()) {
6205         auto durationValue = static_cast<int32_t>(durationArg->ToNumber(vm)->Value());
6206         duration = durationValue <= 0 ? DEFAULT_LONG_PRESS_DURATION : durationValue;
6207     }
6208 }
6209 
GetPanGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,int32_t & direction,double & distance,uint32_t argNumber)6210 void CommonBridge::GetPanGestureValue(
6211     ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, int32_t& direction, double& distance, uint32_t argNumber)
6212 {
6213     EcmaVM* vm = runtimeCallInfo->GetVM();
6214     CHECK_NULL_VOID(vm);
6215     Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6216     if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6217         auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6218         fingers = (fingersValue < DEFAULT_PAN_FINGER || fingersValue > DEFAULT_MAX_FINGERS) ? DEFAULT_PAN_FINGER
6219                                                                                             : fingersValue;
6220     }
6221     Local<JSValueRef> directionArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6222     if (!directionArg.IsNull() && !directionArg->IsUndefined()) {
6223         direction = static_cast<int32_t>(directionArg->ToNumber(vm)->Value());
6224     }
6225     Local<JSValueRef> distanceArg = runtimeCallInfo->GetCallArgRef(argNumber + 2);
6226     if (!distanceArg.IsNull() && !distanceArg->IsUndefined()) {
6227         auto distanceValue = static_cast<double>(distanceArg->ToNumber(vm)->Value());
6228         distance = distanceValue < 0.0f ? DEFAULT_PAN_DISTANCE.ConvertToPx() : distanceValue;
6229     }
6230 }
6231 
GetSwipeGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,int32_t & direction,double & speed,uint32_t argNumber)6232 void CommonBridge::GetSwipeGestureValue(
6233     ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, int32_t& direction, double& speed, uint32_t argNumber)
6234 {
6235     EcmaVM* vm = runtimeCallInfo->GetVM();
6236     CHECK_NULL_VOID(vm);
6237     Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6238     if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6239         auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6240         fingers = (fingersValue < DEFAULT_SLIDE_FINGER || fingersValue > DEFAULT_MAX_FINGERS) ? DEFAULT_SLIDE_FINGER
6241                                                                                               : fingersValue;
6242     }
6243     Local<JSValueRef> directionArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6244     if (!directionArg.IsNull() && !directionArg->IsUndefined()) {
6245         direction = static_cast<int32_t>(directionArg->ToNumber(vm)->Value());
6246     }
6247     Local<JSValueRef> speedArg = runtimeCallInfo->GetCallArgRef(argNumber + 2);
6248     if (!speedArg.IsNull() && !speedArg->IsUndefined()) {
6249         auto speedValue = static_cast<double>(speedArg->ToNumber(vm)->Value());
6250         speed = LessOrEqual(speedValue, 0.0) ? DEFAULT_SLIDE_SPEED : speedValue;
6251     }
6252 }
6253 
GetPinchGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,double & distance,uint32_t argNumber)6254 void CommonBridge::GetPinchGestureValue(
6255     ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, double& distance, uint32_t argNumber)
6256 {
6257     EcmaVM* vm = runtimeCallInfo->GetVM();
6258     CHECK_NULL_VOID(vm);
6259     Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6260     if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6261         auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6262         fingers = (fingersValue < DEFAULT_PINCH_FINGER || fingersValue > DEFAULT_MAX_PINCH_FINGER)
6263                       ? DEFAULT_PINCH_FINGER
6264                       : fingersValue;
6265     }
6266     Local<JSValueRef> distanceArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6267     if (!distanceArg.IsNull() && !distanceArg->IsUndefined()) {
6268         auto distanceValue = static_cast<double>(distanceArg->ToNumber(vm)->Value());
6269         distance = distanceValue <= 0.0 ? DEFAULT_PINCH_DISTANCE : distanceValue;
6270     }
6271 }
6272 
GetRotationGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,double & angle,uint32_t argNumber)6273 void CommonBridge::GetRotationGestureValue(
6274     ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, double& angle, uint32_t argNumber)
6275 {
6276     EcmaVM* vm = runtimeCallInfo->GetVM();
6277     CHECK_NULL_VOID(vm);
6278     Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6279     if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6280         auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6281         fingers = (fingersValue < DEFAULT_ROTATION_FINGER || fingersValue > DEFAULT_MAX_ROTATION_FINGER)
6282                       ? DEFAULT_ROTATION_FINGER
6283                       : fingersValue;
6284     }
6285     Local<JSValueRef> angleArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6286     if (!angleArg.IsNull() && !angleArg->IsUndefined()) {
6287         auto angleValue = static_cast<double>(angleArg->ToNumber(vm)->Value());
6288         angle = (angleValue <= 0 || angleValue > DEFAULT_MAX_ROTATION_ANGLE) ? DEFAULT_ROTATION_ANGLE : angleValue;
6289     }
6290 }
6291 
GetGestureModeValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & mode,uint32_t argNumber)6292 void CommonBridge::GetGestureModeValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& mode, uint32_t argNumber)
6293 {
6294     EcmaVM* vm = runtimeCallInfo->GetVM();
6295     CHECK_NULL_VOID(vm);
6296     Local<JSValueRef> modeArg = runtimeCallInfo->GetCallArgRef(argNumber);
6297     if (!modeArg.IsNull() && !modeArg->IsUndefined()) {
6298         mode = static_cast<int32_t>(modeArg->ToNumber(vm)->Value());
6299     }
6300 }
6301 
SetOnGestureEvent(ArkUIRuntimeCallInfo * runtimeCallInfo,const GestureEventAction & action,uint32_t argNumber,ArkUIGesture * gesture)6302 void CommonBridge::SetOnGestureEvent(
6303     ArkUIRuntimeCallInfo* runtimeCallInfo, const GestureEventAction& action, uint32_t argNumber, ArkUIGesture* gesture)
6304 {
6305     EcmaVM* vm = runtimeCallInfo->GetVM();
6306     CHECK_NULL_VOID(vm);
6307     Local<JSValueRef> eventArg = runtimeCallInfo->GetCallArgRef(argNumber);
6308     if (eventArg.IsNull() || eventArg->IsUndefined() || !eventArg->IsFunction(vm)) {
6309         return;
6310     }
6311     auto obj = eventArg->ToObject(vm);
6312     auto containerId = Container::CurrentId();
6313     panda::Local<panda::FunctionRef> func = obj;
6314 
6315     if (action == Ace::GestureEventAction::CANCEL) {
6316         auto onActionCancelFunc = [vm, func = panda::CopyableGlobal(vm, func), containerId]() {
6317             panda::LocalScope pandaScope(vm);
6318             panda::TryCatch trycatch(vm);
6319             ContainerScope scope(containerId);
6320             func->Call(vm, func.ToLocal(), nullptr, 0);
6321         };
6322         auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
6323         gesturePtr->SetOnActionCancelId(onActionCancelFunc);
6324         return;
6325     }
6326     auto event = [vm, func = panda::CopyableGlobal(vm, func), containerId](GestureEvent& info) {
6327         panda::LocalScope pandaScope(vm);
6328         panda::TryCatch trycatch(vm);
6329         ContainerScope scope(containerId);
6330         auto obj = CreateCommonGestureEventInfo(vm, info);
6331         panda::Local<panda::JSValueRef> params[1] = { obj };
6332         func->Call(vm, func.ToLocal(), params, 1);
6333     };
6334     auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
6335     switch (action) {
6336         case Ace::GestureEventAction::ACTION:
6337             gesturePtr->SetOnActionId(event);
6338             break;
6339         case Ace::GestureEventAction::START:
6340             gesturePtr->SetOnActionStartId(event);
6341             break;
6342         case Ace::GestureEventAction::UPDATE:
6343             gesturePtr->SetOnActionUpdateId(event);
6344             break;
6345         case Ace::GestureEventAction::END:
6346             gesturePtr->SetOnActionEndId(event);
6347             break;
6348         default:
6349             break;
6350     }
6351 }
6352 
CreateCommonGestureEventInfo(EcmaVM * vm,GestureEvent & info)6353 Local<panda::ObjectRef> CommonBridge::CreateCommonGestureEventInfo(EcmaVM* vm, GestureEvent& info)
6354 {
6355     double density = PipelineBase::GetCurrentDensity();
6356     const char* keys[] = { "repeat", "offsetX", "offsetY", "scale", "angle", "speed", "timestamp", "pinchCenterX",
6357         "pinchCenterY", "source", "pressure", "sourceTool", "velocityX", "velocityY", "velocity",
6358         "getModifierKeyState", "deviceId" };
6359     Local<JSValueRef> values[] = { panda::BooleanRef::New(vm, info.GetRepeat()),
6360         panda::NumberRef::New(vm, info.GetOffsetX() / density), panda::NumberRef::New(vm, info.GetOffsetY() / density),
6361         panda::NumberRef::New(vm, info.GetScale()), panda::NumberRef::New(vm, info.GetAngle()),
6362         panda::NumberRef::New(vm, info.GetSpeed()),
6363         panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
6364         panda::NumberRef::New(vm, info.GetPinchCenter().GetX() / density),
6365         panda::NumberRef::New(vm, info.GetPinchCenter().GetY() / density),
6366         panda::NumberRef::New(vm, static_cast<int32_t>(info.GetSourceDevice())),
6367         panda::NumberRef::New(vm, info.GetForce()),
6368         panda::NumberRef::New(vm, static_cast<int32_t>(static_cast<int32_t>(info.GetSourceTool()))),
6369         panda::NumberRef::New(vm, info.GetVelocity().GetVelocityX() / density),
6370         panda::NumberRef::New(vm, info.GetVelocity().GetVelocityY() / density),
6371         panda::NumberRef::New(vm, info.GetVelocity().GetVelocityValue() / density),
6372         panda::NumberRef::New(vm, info.GetDeviceId()),
6373         panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState) };
6374     auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6375     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltX"),
6376         panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltX().value_or(0.0f))));
6377     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltY"),
6378         panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltY().value_or(0.0f))));
6379     auto fingerArr = CreateFingerListArray(vm, info);
6380     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "fingerList"), fingerArr);
6381     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "target"), FrameNodeBridge::CreateEventTargetObject(vm, info));
6382     obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "axisVertical"), panda::NumberRef::New(vm, info.GetVerticalAxis()));
6383     obj->Set(
6384         vm, panda::StringRef::NewFromUtf8(vm, "axisHorizontal"), panda::NumberRef::New(vm, info.GetHorizontalAxis()));
6385     obj->SetNativePointerFieldCount(vm, 1);
6386     obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
6387     return obj;
6388 }
6389 
CreateFingerListArray(EcmaVM * vm,GestureEvent & info)6390 Local<panda::ArrayRef> CommonBridge::CreateFingerListArray(EcmaVM* vm, GestureEvent& info)
6391 {
6392     auto fingerArr = panda::ArrayRef::New(vm);
6393     const std::list<FingerInfo>& fingerList = info.GetFingerList();
6394     std::list<FingerInfo> notTouchFingerList;
6395     int32_t maxFingerId = -1;
6396     for (const FingerInfo& fingerInfo : fingerList) {
6397         auto element = CreateFingerInfo(vm, fingerInfo);
6398         if (fingerInfo.sourceType_ == SourceType::TOUCH && fingerInfo.sourceTool_ == SourceTool::FINGER) {
6399             fingerArr->SetValueAt(vm, fingerArr, fingerInfo.fingerId_, element);
6400             if (fingerInfo.fingerId_ > maxFingerId) {
6401                 maxFingerId = fingerInfo.fingerId_;
6402             }
6403         } else {
6404             notTouchFingerList.emplace_back(fingerInfo);
6405         }
6406     }
6407     auto idx = maxFingerId + 1;
6408     for (const FingerInfo& fingerInfo : notTouchFingerList) {
6409         auto element = CreateFingerInfo(vm, fingerInfo);
6410         fingerArr->SetValueAt(vm, fingerArr, idx++, element);
6411     }
6412     return fingerArr;
6413 }
6414 
GetGestureGroup(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t argNumber)6415 ArkUIGesture* CommonBridge::GetGestureGroup(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber)
6416 {
6417     EcmaVM* vm = runtimeCallInfo->GetVM();
6418     CHECK_NULL_RETURN(vm, nullptr);
6419     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(argNumber);
6420     CHECK_NULL_RETURN(!firstArg.IsNull(), nullptr);
6421     auto* group = reinterpret_cast<ArkUIGesture*>(firstArg->ToNativePointer(vm)->Value());
6422     return group;
6423 }
6424 
SetOnClick(ArkUIRuntimeCallInfo * runtimeCallInfo)6425 ArkUINativeModuleValue CommonBridge::SetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo)
6426 {
6427     EcmaVM* vm = runtimeCallInfo->GetVM();
6428     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6429     auto* frameNode = GetFrameNode(runtimeCallInfo);
6430     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6431     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6432     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6433     auto obj = secondeArg->ToObject(vm);
6434     auto containerId = Container::CurrentId();
6435     panda::Local<panda::FunctionRef> func = obj;
6436     auto onClick = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
6437                        GestureEvent& info) {
6438         panda::LocalScope pandaScope(vm);
6439         panda::TryCatch trycatch(vm);
6440         ContainerScope scope(containerId);
6441         PipelineContext::SetCallBackNode(node);
6442         auto obj = FrameNodeBridge::CreateGestureEventInfo(vm, info);
6443         panda::Local<panda::JSValueRef> params[1] = { obj };
6444         func->Call(vm, func.ToLocal(), params, 1);
6445     };
6446     NG::ViewAbstract::SetOnClick(frameNode, std::move(onClick));
6447     return panda::JSValueRef::Undefined(vm);
6448 }
6449 
ResetOnClick(ArkUIRuntimeCallInfo * runtimeCallInfo)6450 ArkUINativeModuleValue CommonBridge::ResetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo)
6451 {
6452     EcmaVM* vm = runtimeCallInfo->GetVM();
6453     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6454     auto* frameNode = GetFrameNode(runtimeCallInfo);
6455     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6456     ViewAbstract::DisableOnClick(frameNode);
6457     return panda::JSValueRef::Undefined(vm);
6458 }
6459 
SetOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)6460 ArkUINativeModuleValue CommonBridge::SetOnTouch(ArkUIRuntimeCallInfo* runtimeCallInfo)
6461 {
6462     EcmaVM* vm = runtimeCallInfo->GetVM();
6463     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6464     auto* frameNode = GetFrameNode(runtimeCallInfo);
6465     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6466     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6467     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6468     auto obj = secondeArg->ToObject(vm);
6469     auto containerId = Container::CurrentId();
6470     panda::Local<panda::FunctionRef> func = obj;
6471     auto onTouch = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
6472                        TouchEventInfo& info) {
6473         panda::LocalScope pandaScope(vm);
6474         panda::TryCatch trycatch(vm);
6475         ContainerScope scope(containerId);
6476         PipelineContext::SetCallBackNode(node);
6477         auto eventObj = FrameNodeBridge::CreateTouchEventInfo(vm, info);
6478         panda::Local<panda::JSValueRef> params[1] = { eventObj };
6479         func->Call(vm, func.ToLocal(), params, 1);
6480     };
6481     NG::ViewAbstract::SetOnTouch(frameNode, std::move(onTouch));
6482     return panda::JSValueRef::Undefined(vm);
6483 }
6484 
ResetOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)6485 ArkUINativeModuleValue CommonBridge::ResetOnTouch(ArkUIRuntimeCallInfo* runtimeCallInfo)
6486 {
6487     EcmaVM* vm = runtimeCallInfo->GetVM();
6488     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6489     auto* frameNode = GetFrameNode(runtimeCallInfo);
6490     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6491     ViewAbstract::DisableOnTouch(frameNode);
6492     return panda::JSValueRef::Undefined(vm);
6493 }
6494 
SetChainMode(ArkUIRuntimeCallInfo * runtimeCallInfo)6495 ArkUINativeModuleValue CommonBridge::SetChainMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
6496 {
6497     EcmaVM* vm = runtimeCallInfo->GetVM();
6498     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6499     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6500     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6501     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
6502     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6503     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
6504     int32_t direction = 0;
6505     int32_t style = 0;
6506     if (!secondArg.IsNull() && !secondArg->IsUndefined()) {
6507         direction = static_cast<int32_t>(secondArg->ToNumber(vm)->Value());
6508     }
6509     if (!thirdArg.IsNull() && !thirdArg->IsUndefined()) {
6510         style = static_cast<int32_t>(thirdArg->ToNumber(vm)->Value());
6511     }
6512     GetArkUINodeModifiers()->getCommonModifier()->setChainStyle(nativeNode, direction, style);
6513     return panda::JSValueRef::Undefined(vm);
6514 }
6515 
ResetChainMode(ArkUIRuntimeCallInfo * runtimeCallInfo)6516 ArkUINativeModuleValue CommonBridge::ResetChainMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
6517 {
6518     EcmaVM* vm = runtimeCallInfo->GetVM();
6519     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6520     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6521     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6522     GetArkUINodeModifiers()->getCommonModifier()->resetChainStyle(nativeNode);
6523     return panda::JSValueRef::Undefined(vm);
6524 }
SetOnAppear(ArkUIRuntimeCallInfo * runtimeCallInfo)6525 ArkUINativeModuleValue CommonBridge::SetOnAppear(ArkUIRuntimeCallInfo* runtimeCallInfo)
6526 {
6527     EcmaVM* vm = runtimeCallInfo->GetVM();
6528     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6529     auto* frameNode = GetFrameNode(runtimeCallInfo);
6530     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6531     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6532     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6533     auto obj = secondeArg->ToObject(vm);
6534     auto containerId = Container::CurrentId();
6535     panda::Local<panda::FunctionRef> func = obj;
6536     auto onAppear = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
6537         panda::LocalScope pandaScope(vm);
6538         panda::TryCatch trycatch(vm);
6539         ContainerScope scope(containerId);
6540         PipelineContext::SetCallBackNode(node);
6541         func->Call(vm, func.ToLocal(), nullptr, 0);
6542     };
6543     NG::ViewAbstract::SetOnAppear(frameNode, std::move(onAppear));
6544     return panda::JSValueRef::Undefined(vm);
6545 }
6546 
ResetOnAppear(ArkUIRuntimeCallInfo * runtimeCallInfo)6547 ArkUINativeModuleValue CommonBridge::ResetOnAppear(ArkUIRuntimeCallInfo* runtimeCallInfo)
6548 {
6549     EcmaVM* vm = runtimeCallInfo->GetVM();
6550     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6551     auto* frameNode = GetFrameNode(runtimeCallInfo);
6552     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6553     ViewAbstract::DisableOnAppear(frameNode);
6554     return panda::JSValueRef::Undefined(vm);
6555 }
6556 
SetOnDisappear(ArkUIRuntimeCallInfo * runtimeCallInfo)6557 ArkUINativeModuleValue CommonBridge::SetOnDisappear(ArkUIRuntimeCallInfo* runtimeCallInfo)
6558 {
6559     EcmaVM* vm = runtimeCallInfo->GetVM();
6560     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6561     auto* frameNode = GetFrameNode(runtimeCallInfo);
6562     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6563     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6564     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6565     auto obj = secondeArg->ToObject(vm);
6566     auto containerId = Container::CurrentId();
6567     panda::Local<panda::FunctionRef> func = obj;
6568     auto onDisappear = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
6569                            containerId]() {
6570         panda::LocalScope pandaScope(vm);
6571         panda::TryCatch trycatch(vm);
6572         ContainerScope scope(containerId);
6573         PipelineContext::SetCallBackNode(node);
6574         func->Call(vm, func.ToLocal(), nullptr, 0);
6575     };
6576     NG::ViewAbstract::SetOnDisappear(frameNode, std::move(onDisappear));
6577     return panda::JSValueRef::Undefined(vm);
6578 }
6579 
ResetOnDisappear(ArkUIRuntimeCallInfo * runtimeCallInfo)6580 ArkUINativeModuleValue CommonBridge::ResetOnDisappear(ArkUIRuntimeCallInfo* runtimeCallInfo)
6581 {
6582     EcmaVM* vm = runtimeCallInfo->GetVM();
6583     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6584     auto* frameNode = GetFrameNode(runtimeCallInfo);
6585     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6586     ViewAbstract::DisableOnDisappear(frameNode);
6587     return panda::JSValueRef::Undefined(vm);
6588 }
6589 
SetOnAttach(ArkUIRuntimeCallInfo * runtimeCallInfo)6590 ArkUINativeModuleValue CommonBridge::SetOnAttach(ArkUIRuntimeCallInfo* runtimeCallInfo)
6591 {
6592     EcmaVM* vm = runtimeCallInfo->GetVM();
6593     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6594     auto* frameNode = GetFrameNode(runtimeCallInfo);
6595     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6596     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6597     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6598     auto obj = secondeArg->ToObject(vm);
6599     auto containerId = Container::CurrentId();
6600     panda::Local<panda::FunctionRef> func = obj;
6601     auto onAttach = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
6602         panda::LocalScope pandaScope(vm);
6603         panda::TryCatch trycatch(vm);
6604         ContainerScope scope(containerId);
6605         PipelineContext::SetCallBackNode(node);
6606         func->Call(vm, func.ToLocal(), nullptr, 0);
6607     };
6608     NG::ViewAbstract::SetOnAttach(frameNode, std::move(onAttach));
6609     return panda::JSValueRef::Undefined(vm);
6610 }
6611 
ResetOnAttach(ArkUIRuntimeCallInfo * runtimeCallInfo)6612 ArkUINativeModuleValue CommonBridge::ResetOnAttach(ArkUIRuntimeCallInfo* runtimeCallInfo)
6613 {
6614     EcmaVM* vm = runtimeCallInfo->GetVM();
6615     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6616     auto* frameNode = GetFrameNode(runtimeCallInfo);
6617     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6618     ViewAbstract::DisableOnAttach(frameNode);
6619     return panda::JSValueRef::Undefined(vm);
6620 }
6621 
SetOnDetach(ArkUIRuntimeCallInfo * runtimeCallInfo)6622 ArkUINativeModuleValue CommonBridge::SetOnDetach(ArkUIRuntimeCallInfo* runtimeCallInfo)
6623 {
6624     EcmaVM* vm = runtimeCallInfo->GetVM();
6625     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6626     auto* frameNode = GetFrameNode(runtimeCallInfo);
6627     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6628     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6629     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6630     auto obj = secondeArg->ToObject(vm);
6631     auto containerId = Container::CurrentId();
6632     panda::Local<panda::FunctionRef> func = obj;
6633     auto onDetach = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
6634                            containerId]() {
6635         panda::LocalScope pandaScope(vm);
6636         panda::TryCatch trycatch(vm);
6637         ContainerScope scope(containerId);
6638         PipelineContext::SetCallBackNode(node);
6639         func->Call(vm, func.ToLocal(), nullptr, 0);
6640     };
6641     NG::ViewAbstract::SetOnDetach(frameNode, std::move(onDetach));
6642     return panda::JSValueRef::Undefined(vm);
6643 }
6644 
ResetOnDetach(ArkUIRuntimeCallInfo * runtimeCallInfo)6645 ArkUINativeModuleValue CommonBridge::ResetOnDetach(ArkUIRuntimeCallInfo* runtimeCallInfo)
6646 {
6647     EcmaVM* vm = runtimeCallInfo->GetVM();
6648     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6649     auto* frameNode = GetFrameNode(runtimeCallInfo);
6650     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6651     ViewAbstract::DisableOnDetach(frameNode);
6652     return panda::JSValueRef::Undefined(vm);
6653 }
6654 
SetOnKeyEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)6655 ArkUINativeModuleValue CommonBridge::SetOnKeyEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
6656 {
6657     EcmaVM* vm = runtimeCallInfo->GetVM();
6658     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6659     auto* frameNode = GetFrameNode(runtimeCallInfo);
6660     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6661     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6662     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6663     auto obj = secondeArg->ToObject(vm);
6664     auto containerId = Container::CurrentId();
6665     panda::Local<panda::FunctionRef> func = obj;
6666     auto onKeyEvent = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
6667                           KeyEventInfo& info) {
6668         panda::LocalScope pandaScope(vm);
6669         panda::TryCatch trycatch(vm);
6670         ContainerScope scope(containerId);
6671         PipelineContext::SetCallBackNode(node);
6672         const char* keys[] = { "type", "keyCode", "keyText", "keySource", "deviceId", "metaKey", "timestamp",
6673             "stopPropagation", "getModifierKeyState", "intentionCode" };
6674         Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyType())),
6675             panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyCode())),
6676             panda::StringRef::NewFromUtf8(vm, info.GetKeyText()),
6677             panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeySource())),
6678             panda::NumberRef::New(vm, info.GetDeviceId()), panda::NumberRef::New(vm, info.GetMetaKey()),
6679             panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
6680             panda::FunctionRef::New(vm, Framework::JsStopPropagation),
6681             panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
6682             panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyIntention())) };
6683         auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6684         obj->SetNativePointerFieldCount(vm, 1);
6685         obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
6686         panda::Local<panda::JSValueRef> params[] = { obj };
6687         func->Call(vm, func.ToLocal(), params, 1);
6688     };
6689     NG::ViewAbstract::SetOnKeyEvent(frameNode, std::move(onKeyEvent));
6690     return panda::JSValueRef::Undefined(vm);
6691 }
6692 
ResetOnKeyEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)6693 ArkUINativeModuleValue CommonBridge::ResetOnKeyEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
6694 {
6695     EcmaVM* vm = runtimeCallInfo->GetVM();
6696     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6697     auto* frameNode = GetFrameNode(runtimeCallInfo);
6698     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6699     ViewAbstract::DisableOnKeyEvent(frameNode);
6700     return panda::JSValueRef::Undefined(vm);
6701 }
6702 
SetOnKeyPreIme(ArkUIRuntimeCallInfo * runtimeCallInfo)6703 ArkUINativeModuleValue CommonBridge::SetOnKeyPreIme(ArkUIRuntimeCallInfo* runtimeCallInfo)
6704 {
6705     EcmaVM* vm = runtimeCallInfo->GetVM();
6706     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6707     auto* frameNode = GetFrameNode(runtimeCallInfo);
6708     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6709     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6710     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6711     auto obj = secondeArg->ToObject(vm);
6712     auto containerId = Container::CurrentId();
6713     panda::Local<panda::FunctionRef> func = obj;
6714     auto onPreImeEvent = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
6715                              containerId](KeyEventInfo& info) -> bool {
6716         panda::LocalScope pandaScope(vm);
6717         panda::TryCatch trycatch(vm);
6718         ContainerScope scope(containerId);
6719         PipelineContext::SetCallBackNode(node);
6720         const char* keys[] = { "type", "keyCode", "keyText", "keySource", "deviceId", "metaKey", "timestamp",
6721             "stopPropagation", "intentionCode" };
6722         Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyType())),
6723             panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyCode())),
6724             panda::StringRef::NewFromUtf8(vm, info.GetKeyText()),
6725             panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeySource())),
6726             panda::NumberRef::New(vm, info.GetDeviceId()), panda::NumberRef::New(vm, info.GetMetaKey()),
6727             panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
6728             panda::FunctionRef::New(vm, Framework::JsStopPropagation),
6729             panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyIntention())) };
6730         auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6731         obj->SetNativePointerFieldCount(vm, 1);
6732         obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
6733         panda::Local<panda::JSValueRef> params[] = { obj };
6734         auto ret = func->Call(vm, func.ToLocal(), params, 1);
6735         if (ret->IsBoolean()) {
6736             return ret->ToBoolean(vm)->Value();
6737         }
6738         return false;
6739     };
6740     NG::ViewAbstractModelNG::SetOnKeyPreIme(frameNode, std::move(onPreImeEvent));
6741     return panda::JSValueRef::Undefined(vm);
6742 }
6743 
ResetOnKeyPreIme(ArkUIRuntimeCallInfo * runtimeCallInfo)6744 ArkUINativeModuleValue CommonBridge::ResetOnKeyPreIme(ArkUIRuntimeCallInfo* runtimeCallInfo)
6745 {
6746     EcmaVM* vm = runtimeCallInfo->GetVM();
6747     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6748     auto* frameNode = GetFrameNode(runtimeCallInfo);
6749     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6750     NG::ViewAbstractModelNG::DisableOnKeyPreIme(frameNode);
6751     return panda::JSValueRef::Undefined(vm);
6752 }
6753 
SetOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)6754 ArkUINativeModuleValue CommonBridge::SetOnFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
6755 {
6756     EcmaVM* vm = runtimeCallInfo->GetVM();
6757     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6758     auto* frameNode = GetFrameNode(runtimeCallInfo);
6759     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6760     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6761     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6762     auto obj = secondeArg->ToObject(vm);
6763     auto containerId = Container::CurrentId();
6764     panda::Local<panda::FunctionRef> func = obj;
6765     auto onFocus = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
6766         panda::LocalScope pandaScope(vm);
6767         panda::TryCatch trycatch(vm);
6768         ContainerScope scope(containerId);
6769         PipelineContext::SetCallBackNode(node);
6770         func->Call(vm, func.ToLocal(), nullptr, 0);
6771     };
6772     NG::ViewAbstract::SetOnFocus(frameNode, std::move(onFocus));
6773     return panda::JSValueRef::Undefined(vm);
6774 }
6775 
ResetOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)6776 ArkUINativeModuleValue CommonBridge::ResetOnFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
6777 {
6778     EcmaVM* vm = runtimeCallInfo->GetVM();
6779     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6780     auto* frameNode = GetFrameNode(runtimeCallInfo);
6781     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6782     ViewAbstract::DisableOnFocus(frameNode);
6783     return panda::JSValueRef::Undefined(vm);
6784 }
6785 
SetOnBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)6786 ArkUINativeModuleValue CommonBridge::SetOnBlur(ArkUIRuntimeCallInfo* runtimeCallInfo)
6787 {
6788     EcmaVM* vm = runtimeCallInfo->GetVM();
6789     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6790     auto* frameNode = GetFrameNode(runtimeCallInfo);
6791     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6792     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6793     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6794     auto obj = secondeArg->ToObject(vm);
6795     auto containerId = Container::CurrentId();
6796     panda::Local<panda::FunctionRef> func = obj;
6797     auto onBlur = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
6798         panda::LocalScope pandaScope(vm);
6799         panda::TryCatch trycatch(vm);
6800         ContainerScope scope(containerId);
6801         PipelineContext::SetCallBackNode(node);
6802         func->Call(vm, func.ToLocal(), nullptr, 0);
6803     };
6804     NG::ViewAbstract::SetOnBlur(frameNode, std::move(onBlur));
6805     return panda::JSValueRef::Undefined(vm);
6806 }
6807 
ResetOnBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)6808 ArkUINativeModuleValue CommonBridge::ResetOnBlur(ArkUIRuntimeCallInfo* runtimeCallInfo)
6809 {
6810     EcmaVM* vm = runtimeCallInfo->GetVM();
6811     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6812     auto* frameNode = GetFrameNode(runtimeCallInfo);
6813     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6814     ViewAbstract::DisableOnBlur(frameNode);
6815     return panda::JSValueRef::Undefined(vm);
6816 }
6817 
SetOnHover(ArkUIRuntimeCallInfo * runtimeCallInfo)6818 ArkUINativeModuleValue CommonBridge::SetOnHover(ArkUIRuntimeCallInfo* runtimeCallInfo)
6819 {
6820     EcmaVM* vm = runtimeCallInfo->GetVM();
6821     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6822     auto* frameNode = GetFrameNode(runtimeCallInfo);
6823     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6824     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6825     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6826     auto obj = secondeArg->ToObject(vm);
6827     auto containerId = Container::CurrentId();
6828     panda::Local<panda::FunctionRef> func = obj;
6829     auto onHover = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
6830                        bool isHover, HoverInfo& hoverInfo) {
6831         panda::LocalScope pandaScope(vm);
6832         panda::TryCatch trycatch(vm);
6833         ContainerScope scope(containerId);
6834         PipelineContext::SetCallBackNode(node);
6835         auto isHoverParam = panda::BooleanRef::New(vm, isHover);
6836         const char* keys[] = {
6837             "stopPropagation",
6838             "getModifierKeyState",
6839             "timestamp",
6840             "source",
6841             "target",
6842             "deviceId",
6843         };
6844         Local<JSValueRef> values[] = { panda::FunctionRef::New(vm, Framework::JsStopPropagation),
6845             panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
6846             panda::NumberRef::New(vm, static_cast<double>(hoverInfo.GetTimeStamp().time_since_epoch().count())),
6847             panda::NumberRef::New(vm, static_cast<int32_t>(hoverInfo.GetSourceDevice())),
6848             FrameNodeBridge::CreateEventTargetObject(vm, hoverInfo),
6849             panda::NumberRef::New(vm, hoverInfo.GetDeviceId()) };
6850         auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6851         obj->SetNativePointerFieldCount(vm, 1);
6852         obj->SetNativePointerField(vm, 0, static_cast<void*>(&hoverInfo));
6853         panda::Local<panda::JSValueRef> params[] = { isHoverParam, obj };
6854         func->Call(vm, func.ToLocal(), params, ArraySize(params));
6855     };
6856     NG::ViewAbstract::SetOnHover(frameNode, std::move(onHover));
6857     return panda::JSValueRef::Undefined(vm);
6858 }
6859 
ResetOnHover(ArkUIRuntimeCallInfo * runtimeCallInfo)6860 ArkUINativeModuleValue CommonBridge::ResetOnHover(ArkUIRuntimeCallInfo* runtimeCallInfo)
6861 {
6862     EcmaVM* vm = runtimeCallInfo->GetVM();
6863     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6864     auto* frameNode = GetFrameNode(runtimeCallInfo);
6865     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6866     ViewAbstract::DisableOnHover(frameNode);
6867     return panda::JSValueRef::Undefined(vm);
6868 }
6869 
SetOnMouse(ArkUIRuntimeCallInfo * runtimeCallInfo)6870 ArkUINativeModuleValue CommonBridge::SetOnMouse(ArkUIRuntimeCallInfo* runtimeCallInfo)
6871 {
6872     EcmaVM* vm = runtimeCallInfo->GetVM();
6873     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6874     auto* frameNode = GetFrameNode(runtimeCallInfo);
6875     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6876     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6877     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6878     auto obj = secondeArg->ToObject(vm);
6879     auto containerId = Container::CurrentId();
6880     panda::Local<panda::FunctionRef> func = obj;
6881     auto onMouse = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
6882                        MouseInfo& info) {
6883         panda::LocalScope pandaScope(vm);
6884         panda::TryCatch trycatch(vm);
6885         ContainerScope scope(containerId);
6886         PipelineContext::SetCallBackNode(node);
6887         auto obj = FrameNodeBridge::CreateMouseInfo(vm, info);
6888         panda::Local<panda::JSValueRef> params[1] = { obj };
6889         func->Call(vm, func.ToLocal(), params, 1);
6890     };
6891     NG::ViewAbstract::SetOnMouse(frameNode, std::move(onMouse));
6892     return panda::JSValueRef::Undefined(vm);
6893 }
6894 
ResetOnMouse(ArkUIRuntimeCallInfo * runtimeCallInfo)6895 ArkUINativeModuleValue CommonBridge::ResetOnMouse(ArkUIRuntimeCallInfo* runtimeCallInfo)
6896 {
6897     EcmaVM* vm = runtimeCallInfo->GetVM();
6898     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6899     auto* frameNode = GetFrameNode(runtimeCallInfo);
6900     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6901     ViewAbstract::DisableOnMouse(frameNode);
6902     return panda::JSValueRef::Undefined(vm);
6903 }
6904 
SetOnSizeChange(ArkUIRuntimeCallInfo * runtimeCallInfo)6905 ArkUINativeModuleValue CommonBridge::SetOnSizeChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
6906 {
6907     EcmaVM* vm = runtimeCallInfo->GetVM();
6908     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6909     auto* frameNode = GetFrameNode(runtimeCallInfo);
6910     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6911     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6912     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6913     auto obj = secondeArg->ToObject(vm);
6914     auto containerId = Container::CurrentId();
6915     panda::Local<panda::FunctionRef> func = obj;
6916     auto onSizeChange = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
6917                             const NG::RectF& oldRect, const NG::RectF& rect) {
6918         panda::LocalScope pandaScope(vm);
6919         panda::TryCatch trycatch(vm);
6920         ContainerScope scope(containerId);
6921         PipelineContext::SetCallBackNode(node);
6922         double density = PipelineBase::GetCurrentDensity();
6923         const char* keys[] = { "width", "height" };
6924         Local<JSValueRef> oldValues[] = { panda::NumberRef::New(vm, oldRect.Width() / density),
6925             panda::NumberRef::New(vm, oldRect.Height() / density) };
6926         auto oldSize = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, oldValues);
6927         Local<JSValueRef> newValues[] = { panda::NumberRef::New(vm, rect.Width() / density),
6928             panda::NumberRef::New(vm, rect.Height() / density) };
6929         auto newSize = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, newValues);
6930         panda::Local<panda::JSValueRef> params[2] = { oldSize, newSize };
6931         func->Call(vm, func.ToLocal(), params, 2);
6932     };
6933     NG::ViewAbstract::SetOnSizeChanged(frameNode, std::move(onSizeChange));
6934     return panda::JSValueRef::Undefined(vm);
6935 }
6936 
ResetOnSizeChange(ArkUIRuntimeCallInfo * runtimeCallInfo)6937 ArkUINativeModuleValue CommonBridge::ResetOnSizeChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
6938 {
6939     EcmaVM* vm = runtimeCallInfo->GetVM();
6940     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6941     auto* frameNode = GetFrameNode(runtimeCallInfo);
6942     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6943     ViewAbstract::SetOnSizeChanged(frameNode, nullptr);
6944     return panda::JSValueRef::Undefined(vm);
6945 }
6946 
SetOnAreaChange(ArkUIRuntimeCallInfo * runtimeCallInfo)6947 ArkUINativeModuleValue CommonBridge::SetOnAreaChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
6948 {
6949     EcmaVM* vm = runtimeCallInfo->GetVM();
6950     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6951     auto* frameNode = GetFrameNode(runtimeCallInfo);
6952     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6953     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6954     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6955     auto obj = secondeArg->ToObject(vm);
6956     auto containerId = Container::CurrentId();
6957     panda::Local<panda::FunctionRef> func = obj;
6958     auto onAreaChange = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
6959                             const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) {
6960         panda::LocalScope pandaScope(vm);
6961         panda::TryCatch trycatch(vm);
6962         ContainerScope scope(containerId);
6963         PipelineContext::SetCallBackNode(node);
6964         auto oldArea = CreateAreaObject(vm, oldRect, oldOrigin);
6965         auto area = CreateAreaObject(vm, rect, origin);
6966         panda::Local<panda::JSValueRef> params[2] = { oldArea, area };
6967         func->Call(vm, func.ToLocal(), params, 2);
6968     };
6969     NG::ViewAbstract::SetOnAreaChanged(frameNode, std::move(onAreaChange));
6970     return panda::JSValueRef::Undefined(vm);
6971 }
6972 
ResetOnAreaChange(ArkUIRuntimeCallInfo * runtimeCallInfo)6973 ArkUINativeModuleValue CommonBridge::ResetOnAreaChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
6974 {
6975     EcmaVM* vm = runtimeCallInfo->GetVM();
6976     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6977     auto* frameNode = GetFrameNode(runtimeCallInfo);
6978     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6979     ViewAbstract::DisableOnAreaChange(frameNode);
6980     return panda::JSValueRef::Undefined(vm);
6981 }
6982 
SetOnGestureJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)6983 ArkUINativeModuleValue CommonBridge::SetOnGestureJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
6984 {
6985     EcmaVM* vm = runtimeCallInfo->GetVM();
6986     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6987     auto* frameNode = GetFrameNode(runtimeCallInfo);
6988     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
6989     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
6990     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
6991     auto obj = secondeArg->ToObject(vm);
6992     auto containerId = Container::CurrentId();
6993     panda::Local<panda::FunctionRef> func = obj;
6994     auto onGestureJudgeBegin = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
6995                                    containerId](const RefPtr<GestureInfo>& gestureInfo,
6996                                    const std::shared_ptr<BaseGestureEvent>& info) -> GestureJudgeResult {
6997         panda::LocalScope pandaScope(vm);
6998         panda::TryCatch trycatch(vm);
6999         ContainerScope scope(containerId);
7000         PipelineContext::SetCallBackNode(node);
7001         auto gestureInfoObj = CreateGestureInfo(vm, gestureInfo);
7002         auto gestureEventObj = CreateGestureEventInfo(vm, gestureInfo->GetType(), info);
7003         panda::Local<panda::JSValueRef> params[2] = { gestureInfoObj, gestureEventObj };
7004         auto returnValue = GestureJudgeResult::CONTINUE;
7005         auto value = func->Call(vm, func.ToLocal(), params, 2);
7006         if (value->IsNumber()) {
7007             returnValue = static_cast<GestureJudgeResult>(value->ToNumber(vm)->Value());
7008         }
7009         return returnValue;
7010     };
7011     NG::ViewAbstract::SetOnGestureJudgeBegin(frameNode, std::move(onGestureJudgeBegin));
7012     return panda::JSValueRef::Undefined(vm);
7013 }
7014 
ResetOnGestureJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)7015 ArkUINativeModuleValue CommonBridge::ResetOnGestureJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
7016 {
7017     EcmaVM* vm = runtimeCallInfo->GetVM();
7018     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7019     auto* frameNode = GetFrameNode(runtimeCallInfo);
7020     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7021     ViewAbstract::SetOnGestureJudgeBegin(frameNode, nullptr);
7022     return panda::JSValueRef::Undefined(vm);
7023 }
7024 
SetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)7025 ArkUINativeModuleValue CommonBridge::SetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
7026 {
7027     EcmaVM* vm = runtimeCallInfo->GetVM();
7028     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7029     auto* frameNode = GetFrameNode(runtimeCallInfo);
7030     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7031     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7032     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7033     auto obj = secondeArg->ToObject(vm);
7034     auto containerId = Container::CurrentId();
7035     panda::Local<panda::FunctionRef> func = obj;
7036     auto onGestureRecognizerJudgeBegin =
7037         [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
7038             const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current,
7039             const std::list<RefPtr<NGGestureRecognizer>>& others) -> GestureJudgeResult {
7040         panda::LocalScope pandaScope(vm);
7041         panda::TryCatch trycatch(vm);
7042         ContainerScope scope(containerId);
7043         PipelineContext::SetCallBackNode(node);
7044         auto gestureInfo = current->GetGestureInfo();
7045         CHECK_NULL_RETURN(gestureInfo, GestureJudgeResult::CONTINUE);
7046         auto gestureEventObj = CreateGestureEventInfo(vm, gestureInfo->GetType(), info);
7047         auto currentObj = CreateRecognizerObject(vm, current);
7048         auto othersArr = panda::ArrayRef::New(vm);
7049         uint32_t othersIdx = 0;
7050         for (const auto& item : others) {
7051             auto othersObj = CreateRecognizerObject(vm, item);
7052             othersArr->SetValueAt(vm, othersArr, othersIdx++, othersObj);
7053         }
7054         panda::Local<panda::JSValueRef> params[3] = { gestureEventObj, currentObj, othersArr };
7055         auto returnValue = GestureJudgeResult::CONTINUE;
7056         auto value = func->Call(vm, func.ToLocal(), params, 3);
7057         if (value->IsNumber()) {
7058             returnValue = static_cast<GestureJudgeResult>(value->ToNumber(vm)->Value());
7059         }
7060         return returnValue;
7061     };
7062     NG::ViewAbstract::SetOnGestureRecognizerJudgeBegin(frameNode, std::move(onGestureRecognizerJudgeBegin));
7063     return panda::JSValueRef::Undefined(vm);
7064 }
7065 
ResetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)7066 ArkUINativeModuleValue CommonBridge::ResetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
7067 {
7068     EcmaVM* vm = runtimeCallInfo->GetVM();
7069     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7070     auto* frameNode = GetFrameNode(runtimeCallInfo);
7071     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7072     ViewAbstract::SetOnGestureRecognizerJudgeBegin(frameNode, nullptr);
7073     return panda::JSValueRef::Undefined(vm);
7074 }
7075 
SetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo * runtimeCallInfo)7076 ArkUINativeModuleValue CommonBridge::SetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo* runtimeCallInfo)
7077 {
7078     EcmaVM* vm = runtimeCallInfo->GetVM();
7079     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7080     auto* frameNode = GetFrameNode(runtimeCallInfo);
7081     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7082     Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7083     CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7084     auto obj = secondeArg->ToObject(vm);
7085     auto containerId = Container::CurrentId();
7086     panda::Local<panda::FunctionRef> func = obj;
7087     auto shouldBuiltInRecognizerParallelWithFunc =
7088         [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
7089             const RefPtr<NG::NGGestureRecognizer>& current,
7090             const std::vector<RefPtr<NG::NGGestureRecognizer>>& others) -> RefPtr<NG::NGGestureRecognizer> {
7091         panda::LocalScope pandaScope(vm);
7092         panda::TryCatch trycatch(vm);
7093         ContainerScope scope(containerId);
7094         PipelineContext::SetCallBackNode(node);
7095         auto currentObj = CreateRecognizerObject(vm, current);
7096         auto othersArr = panda::ArrayRef::New(vm);
7097         uint32_t othersIdx = 0;
7098         for (const auto& item : others) {
7099             auto othersObj = CreateRecognizerObject(vm, item);
7100             othersArr->SetValueAt(vm, othersArr, othersIdx++, othersObj);
7101         }
7102         panda::Local<panda::JSValueRef> params[2] = { currentObj, othersArr };
7103         auto value = func->Call(vm, func.ToLocal(), params, 2);
7104         if (!value->IsObject(vm)) {
7105             return nullptr;
7106         }
7107         RefPtr<NG::NGGestureRecognizer> returnValue = nullptr;
7108         auto valueObj = value->ToObject(vm);
7109         valueObj->Freeze(vm);
7110         auto jsObj = JSRef<JSObject>(JSObject(valueObj));
7111         returnValue = Referenced::Claim(jsObj->Unwrap<JSGestureRecognizer>())->GetRecognizer().Upgrade();
7112         return returnValue;
7113     };
7114     NG::ViewAbstract::SetShouldBuiltInRecognizerParallelWith(
7115         frameNode, std::move(shouldBuiltInRecognizerParallelWithFunc));
7116     return panda::JSValueRef::Undefined(vm);
7117 }
7118 
ResetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo * runtimeCallInfo)7119 ArkUINativeModuleValue CommonBridge::ResetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo* runtimeCallInfo)
7120 {
7121     EcmaVM* vm = runtimeCallInfo->GetVM();
7122     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7123     auto* frameNode = GetFrameNode(runtimeCallInfo);
7124     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7125     ViewAbstract::SetShouldBuiltInRecognizerParallelWith(frameNode, nullptr);
7126     return panda::JSValueRef::Undefined(vm);
7127 }
7128 
AddTapGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)7129 ArkUINativeModuleValue CommonBridge::AddTapGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
7130 {
7131     EcmaVM* vm = runtimeCallInfo->GetVM();
7132     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7133     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7134     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7135     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7136     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7137     int32_t priority = 0;
7138     int32_t mask = 0;
7139     GetGestureCommonValue(runtimeCallInfo, priority, mask);
7140     int32_t fingers = DEFAULT_TAP_FINGER;
7141     int32_t count = DEFAULT_TAP_COUNT;
7142     double distanceThreshold = DEFAULT_TAP_DISTANCE;
7143     GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_4);
7144     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
7145         createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, nullptr);
7146     SetGestureTag(runtimeCallInfo, NUM_3, gesture);
7147     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_6, gesture);
7148     GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
7149         nativeNode, gesture, priority, mask);
7150     return panda::JSValueRef::Undefined(vm);
7151 }
7152 
AddLongPressGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)7153 ArkUINativeModuleValue CommonBridge::AddLongPressGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
7154 {
7155     EcmaVM* vm = runtimeCallInfo->GetVM();
7156     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7157     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7158     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7159     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7160     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7161     int32_t priority = 0;
7162     int32_t mask = 0;
7163     GetGestureCommonValue(runtimeCallInfo, priority, mask);
7164     int32_t fingers = DEFAULT_LONG_PRESS_FINGER;
7165     bool repeat = false;
7166     int32_t duration = DEFAULT_LONG_PRESS_DURATION;
7167     GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_4);
7168     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(
7169         fingers, repeat, duration, nullptr);
7170     SetGestureTag(runtimeCallInfo, NUM_3, gesture);
7171     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture);
7172     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
7173     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
7174     GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
7175         nativeNode, gesture, priority, mask);
7176     return panda::JSValueRef::Undefined(vm);
7177 }
7178 
AddPanGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)7179 ArkUINativeModuleValue CommonBridge::AddPanGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
7180 {
7181     EcmaVM* vm = runtimeCallInfo->GetVM();
7182     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7183     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7184     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7185     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7186     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7187     int32_t priority = 0;
7188     int32_t mask = 0;
7189     GetGestureCommonValue(runtimeCallInfo, priority, mask);
7190     int32_t fingers = DEFAULT_PAN_FINGER;
7191     int32_t direction = PanDirection::ALL;
7192     double distance = DEFAULT_PAN_DISTANCE.ConvertToPx();
7193     GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_4);
7194     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(
7195         fingers, direction, distance, nullptr);
7196     SetGestureTag(runtimeCallInfo, NUM_3, gesture);
7197     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_7, gesture);
7198     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_8, gesture);
7199     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_9, gesture);
7200     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_10, gesture);
7201     GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
7202         nativeNode, gesture, priority, mask);
7203     return panda::JSValueRef::Undefined(vm);
7204 }
7205 
AddSwipeGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)7206 ArkUINativeModuleValue CommonBridge::AddSwipeGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
7207 {
7208     EcmaVM* vm = runtimeCallInfo->GetVM();
7209     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7210     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7211     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7212     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7213     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7214     int32_t priority = 0;
7215     int32_t mask = 0;
7216     GetGestureCommonValue(runtimeCallInfo, priority, mask);
7217     int32_t fingers = DEFAULT_SLIDE_FINGER;
7218     int32_t direction = SwipeDirection::ALL;
7219     double speed = DEFAULT_SLIDE_SPEED;
7220     GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, NUM_4);
7221     auto* gesture =
7222         GetArkUINodeModifiers()->getGestureModifier()->createSwipeGestureByModifier(fingers, direction, speed);
7223     SetGestureTag(runtimeCallInfo, NUM_3, gesture);
7224     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture);
7225     GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
7226         nativeNode, gesture, priority, mask);
7227     return panda::JSValueRef::Undefined(vm);
7228 }
7229 
AddPinchGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)7230 ArkUINativeModuleValue CommonBridge::AddPinchGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
7231 {
7232     EcmaVM* vm = runtimeCallInfo->GetVM();
7233     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7234     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7235     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7236     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7237     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7238     int32_t priority = 0;
7239     int32_t mask = 0;
7240     GetGestureCommonValue(runtimeCallInfo, priority, mask);
7241     int32_t fingers = DEFAULT_PINCH_FINGER;
7242     double distance = DEFAULT_PINCH_DISTANCE;
7243     GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_4);
7244     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance, nullptr);
7245     SetGestureTag(runtimeCallInfo, NUM_3, gesture);
7246     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture);
7247     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture);
7248     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
7249     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
7250     GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
7251         nativeNode, gesture, priority, mask);
7252     return panda::JSValueRef::Undefined(vm);
7253 }
7254 
AddRotationGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)7255 ArkUINativeModuleValue CommonBridge::AddRotationGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
7256 {
7257     EcmaVM* vm = runtimeCallInfo->GetVM();
7258     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7259     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7260     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7261     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7262     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7263     int32_t priority = 0;
7264     int32_t mask = 0;
7265     GetGestureCommonValue(runtimeCallInfo, priority, mask);
7266     int32_t fingers = DEFAULT_ROTATION_FINGER;
7267     double angle = DEFAULT_ROTATION_ANGLE;
7268     GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_4);
7269     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle, nullptr);
7270     SetGestureTag(runtimeCallInfo, NUM_3, gesture);
7271     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture);
7272     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture);
7273     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
7274     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
7275     GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
7276         nativeNode, gesture, priority, mask);
7277     return panda::JSValueRef::Undefined(vm);
7278 }
7279 
AddGestureGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7280 ArkUINativeModuleValue CommonBridge::AddGestureGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7281 {
7282     EcmaVM* vm = runtimeCallInfo->GetVM();
7283     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7284     int32_t mode = 2;
7285     GetGestureModeValue(runtimeCallInfo, mode, NUM_2);
7286     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createGestureGroup(mode);
7287     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7288     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_1, gesture);
7289     return panda::NativePointerRef::New(vm, gesture);
7290 }
7291 
AddTapGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7292 ArkUINativeModuleValue CommonBridge::AddTapGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7293 {
7294     EcmaVM* vm = runtimeCallInfo->GetVM();
7295     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7296     int32_t fingers = DEFAULT_TAP_FINGER;
7297     int32_t count = DEFAULT_TAP_COUNT;
7298     double distanceThreshold = DEFAULT_TAP_DISTANCE;
7299     GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_1);
7300     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
7301         createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, nullptr);
7302     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7303     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_3, gesture);
7304     auto* group = GetGestureGroup(runtimeCallInfo, NUM_4);
7305     GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
7306     return panda::JSValueRef::Undefined(vm);
7307 }
7308 
AddLongPressGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7309 ArkUINativeModuleValue CommonBridge::AddLongPressGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7310 {
7311     EcmaVM* vm = runtimeCallInfo->GetVM();
7312     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7313     int32_t fingers = DEFAULT_LONG_PRESS_FINGER;
7314     bool repeat = false;
7315     int32_t duration = DEFAULT_LONG_PRESS_DURATION;
7316     GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_1);
7317     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(
7318         fingers, repeat, duration, nullptr);
7319     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7320     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_4, gesture);
7321     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_5, gesture);
7322     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_6, gesture);
7323     auto* group = GetGestureGroup(runtimeCallInfo, NUM_7);
7324     GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
7325     return panda::JSValueRef::Undefined(vm);
7326 }
7327 
AddPanGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7328 ArkUINativeModuleValue CommonBridge::AddPanGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7329 {
7330     EcmaVM* vm = runtimeCallInfo->GetVM();
7331     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7332     int32_t fingers = DEFAULT_PAN_FINGER;
7333     int32_t direction = PanDirection::ALL;
7334     double distance = DEFAULT_PAN_DISTANCE.ConvertToPx();
7335     GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_1);
7336     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(
7337         fingers, direction, distance, nullptr);
7338     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7339     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_4, gesture);
7340     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_5, gesture);
7341     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_6, gesture);
7342     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_7, gesture);
7343     auto* group = GetGestureGroup(runtimeCallInfo, NUM_8);
7344     GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
7345     return panda::JSValueRef::Undefined(vm);
7346 }
7347 
AddSwipeGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7348 ArkUINativeModuleValue CommonBridge::AddSwipeGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7349 {
7350     EcmaVM* vm = runtimeCallInfo->GetVM();
7351     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7352     int32_t fingers = DEFAULT_SLIDE_FINGER;
7353     int32_t direction = SwipeDirection::ALL;
7354     double speed = DEFAULT_SLIDE_SPEED;
7355     GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, NUM_1);
7356     auto* gesture =
7357         GetArkUINodeModifiers()->getGestureModifier()->createSwipeGestureByModifier(fingers, direction, speed);
7358     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7359     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_4, gesture);
7360     auto* group = GetGestureGroup(runtimeCallInfo, NUM_5);
7361     GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
7362     return panda::JSValueRef::Undefined(vm);
7363 }
7364 
AddPinchGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7365 ArkUINativeModuleValue CommonBridge::AddPinchGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7366 {
7367     EcmaVM* vm = runtimeCallInfo->GetVM();
7368     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7369     int32_t fingers = DEFAULT_PINCH_FINGER;
7370     double distance = DEFAULT_PINCH_DISTANCE;
7371     GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_1);
7372     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance, nullptr);
7373     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7374     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_3, gesture);
7375     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_4, gesture);
7376     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_5, gesture);
7377     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_6, gesture);
7378     auto* group = GetGestureGroup(runtimeCallInfo, NUM_7);
7379     GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
7380     return panda::JSValueRef::Undefined(vm);
7381 }
7382 
AddRotationGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7383 ArkUINativeModuleValue CommonBridge::AddRotationGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7384 {
7385     EcmaVM* vm = runtimeCallInfo->GetVM();
7386     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7387     int32_t fingers = DEFAULT_ROTATION_FINGER;
7388     double angle = DEFAULT_ROTATION_ANGLE;
7389     GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_1);
7390     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle, nullptr);
7391     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7392     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_3, gesture);
7393     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_4, gesture);
7394     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_5, gesture);
7395     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_6, gesture);
7396     auto* group = GetGestureGroup(runtimeCallInfo, NUM_7);
7397     GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
7398     return panda::JSValueRef::Undefined(vm);
7399 }
7400 
AddGestureGroupToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7401 ArkUINativeModuleValue CommonBridge::AddGestureGroupToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7402 {
7403     EcmaVM* vm = runtimeCallInfo->GetVM();
7404     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7405     int32_t mode = 2;
7406     GetGestureModeValue(runtimeCallInfo, mode, NUM_2);
7407     auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createGestureGroup(mode);
7408     SetGestureTag(runtimeCallInfo, NUM_0, gesture);
7409     SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_1, gesture);
7410     auto* group = GetGestureGroup(runtimeCallInfo, NUM_3);
7411     GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
7412     return panda::NativePointerRef::New(vm, gesture);
7413 }
7414 
AttachGestureGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)7415 ArkUINativeModuleValue CommonBridge::AttachGestureGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
7416 {
7417     EcmaVM* vm = runtimeCallInfo->GetVM();
7418     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7419     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7420     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7421     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7422     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7423     int32_t priority = 0;
7424     int32_t mask = 0;
7425     GetGestureCommonValue(runtimeCallInfo, priority, mask);
7426     auto* group = GetGestureGroup(runtimeCallInfo, NUM_3);
7427     GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
7428         nativeNode, group, priority, mask);
7429     return panda::JSValueRef::Undefined(vm);
7430 }
7431 
RemoveGestureByTag(ArkUIRuntimeCallInfo * runtimeCallInfo)7432 ArkUINativeModuleValue CommonBridge::RemoveGestureByTag(ArkUIRuntimeCallInfo* runtimeCallInfo)
7433 {
7434     EcmaVM* vm = runtimeCallInfo->GetVM();
7435     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7436     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7437     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7438     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7439     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7440     Local<JSValueRef> gestureTagArg = runtimeCallInfo->GetCallArgRef(NUM_1);
7441     if (!gestureTagArg.IsNull() && !gestureTagArg->IsUndefined()) {
7442         auto tag = gestureTagArg->ToString(vm)->ToString(vm);
7443         GetArkUINodeModifiers()->getGestureModifier()->removeGestureFromNodeByTag(nativeNode, tag.c_str());
7444     }
7445     return panda::JSValueRef::Undefined(vm);
7446 }
7447 
ClearGestures(ArkUIRuntimeCallInfo * runtimeCallInfo)7448 ArkUINativeModuleValue CommonBridge::ClearGestures(ArkUIRuntimeCallInfo* runtimeCallInfo)
7449 {
7450     EcmaVM* vm = runtimeCallInfo->GetVM();
7451     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7452     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7453     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7454     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7455     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7456     GetArkUINodeModifiers()->getGestureModifier()->clearGestures(nativeNode);
7457     return panda::JSValueRef::Undefined(vm);
7458 }
7459 
GetWindowName(ArkUIRuntimeCallInfo * runtimeCallInfo)7460 ArkUINativeModuleValue CommonBridge::GetWindowName(ArkUIRuntimeCallInfo* runtimeCallInfo)
7461 {
7462     EcmaVM* vm = runtimeCallInfo->GetVM();
7463     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7464     auto context = PipelineBase::GetCurrentContext();
7465     CHECK_NULL_RETURN(context, panda::JSValueRef::Undefined(vm));
7466     std::string windowName = context->GetWindow()->GetWindowName();
7467     return panda::StringRef::NewFromUtf8(vm, windowName.c_str());
7468 }
7469 
GetWindowWidthBreakpoint(ArkUIRuntimeCallInfo * runtimeCallInfo)7470 ArkUINativeModuleValue CommonBridge::GetWindowWidthBreakpoint(ArkUIRuntimeCallInfo* runtimeCallInfo)
7471 {
7472     EcmaVM* vm = runtimeCallInfo->GetVM();
7473     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7474     auto container = Container::Current();
7475     CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
7476     auto window = container->GetWindow();
7477     CHECK_NULL_RETURN(window, panda::JSValueRef::Undefined(vm));
7478     double density = PipelineBase::GetCurrentDensity();
7479     double width;
7480     if (NearZero(density)) {
7481         width = window->GetCurrentWindowRect().Width();
7482     } else {
7483         width = window->GetCurrentWindowRect().Width() / density;
7484     }
7485 
7486     WidthBreakpoint breakpoint;
7487     if (width < WIDTH_BREAKPOINT_320VP) {
7488         breakpoint = WidthBreakpoint::WIDTH_XS;
7489     } else if (width < WIDTH_BREAKPOINT_600VP) {
7490         breakpoint = WidthBreakpoint::WIDTH_SM;
7491     } else if (width < WIDTH_BREAKPOINT_840VP) {
7492         breakpoint = WidthBreakpoint::WIDTH_MD;
7493     } else if (width < WIDTH_BREAKPOINT_1440VP) {
7494         breakpoint = WidthBreakpoint::WIDTH_LG;
7495     } else {
7496         breakpoint = WidthBreakpoint::WIDTH_XL;
7497     }
7498     return panda::IntegerRef::NewFromUnsigned(vm, static_cast<uint32_t>(breakpoint));
7499 }
7500 
GetWindowHeightBreakpoint(ArkUIRuntimeCallInfo * runtimeCallInfo)7501 ArkUINativeModuleValue CommonBridge::GetWindowHeightBreakpoint(ArkUIRuntimeCallInfo* runtimeCallInfo)
7502 {
7503     EcmaVM* vm = runtimeCallInfo->GetVM();
7504     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7505     auto container = Container::Current();
7506     CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
7507     auto window = container->GetWindow();
7508     CHECK_NULL_RETURN(window, panda::JSValueRef::Undefined(vm));
7509     auto width = window->GetCurrentWindowRect().Width();
7510     auto height = window->GetCurrentWindowRect().Height();
7511     auto aspectRatio = 0.0;
7512     if (NearZero(width)) {
7513         aspectRatio = 0.0;
7514     } else {
7515         aspectRatio = height / width;
7516     }
7517     HeightBreakpoint breakpoint;
7518     if (aspectRatio < HEIGHT_ASPECTRATIO_THRESHOLD1) {
7519         breakpoint = HeightBreakpoint::HEIGHT_SM;
7520     } else if (aspectRatio < HEIGHT_ASPECTRATIO_THRESHOLD2) {
7521         breakpoint = HeightBreakpoint::HEIGHT_MD;
7522     } else {
7523         breakpoint = HeightBreakpoint::HEIGHT_LG;
7524     }
7525     return panda::IntegerRef::NewFromUnsigned(vm, static_cast<uint32_t>(breakpoint));
7526 }
7527 
SetSystemBarEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)7528 ArkUINativeModuleValue CommonBridge::SetSystemBarEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
7529 {
7530     EcmaVM* vm = runtimeCallInfo->GetVM();
7531     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7532     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7533     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7534     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7535     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7536     Local<JSValueRef> enableArg = runtimeCallInfo->GetCallArgRef(NUM_1);
7537     if (enableArg->IsBoolean()) {
7538         auto enable = enableArg->ToBoolean(vm);
7539         GetArkUINodeModifiers()->getCommonModifier()->setSystemBarEffect(nativeNode, enable->Value());
7540     }
7541     return panda::JSValueRef::Undefined(vm);
7542 }
7543 
PostFrameCallback(ArkUIRuntimeCallInfo * runtimeCallInfo)7544 ArkUINativeModuleValue CommonBridge::PostFrameCallback(ArkUIRuntimeCallInfo* runtimeCallInfo)
7545 {
7546     EcmaVM* vm = runtimeCallInfo->GetVM();
7547     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7548 
7549     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0); // frameCallback
7550     if (firstArg->IsNull() || firstArg->IsUndefined() || !firstArg->IsObject(vm)) {
7551         return panda::JSValueRef::Undefined(vm);
7552     }
7553     auto frameCallback = firstArg->ToObject(vm);
7554 
7555     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
7556     int64_t delayMillis = 0;
7557     if (secondArg->IsNumber()) {
7558         delayMillis = secondArg->IntegerValue(vm);
7559     }
7560 
7561     if (frameCallback->IsNull() || frameCallback->IsUndefined() || !frameCallback->IsObject(vm)) {
7562         return panda::JSValueRef::Undefined(vm);
7563     }
7564 
7565     FrameCallbackFunc onFrameCallbackFunc = nullptr;
7566     FrameCallbackFunc onIdleCallbackFunc = nullptr;
7567 
7568     if (frameCallback->Get(vm, "onFrame")->IsFunction(vm)) {
7569         onFrameCallbackFunc = [vm, frameCallbackObj = panda::CopyableGlobal(vm, frameCallback),
7570                                   delayMillis](int64_t nanoTimestamp) -> void {
7571             Local<FunctionRef> onFrameFunc = frameCallbackObj->Get(vm, "onFrame");
7572 
7573             auto nanoTimestampRef = NumberRef::New(vm, nanoTimestamp);
7574             Local<JSValueRef> params[] = { nanoTimestampRef };
7575             onFrameFunc->Call(vm, frameCallbackObj.ToLocal(), params, 1);
7576         };
7577     }
7578 
7579     if (frameCallback->Get(vm, "onIdle")->IsFunction(vm)) {
7580         onIdleCallbackFunc = [vm, frameCallbackObj = panda::CopyableGlobal(vm, frameCallback),
7581                                  delayMillis](int64_t nanoTimestamp) -> void {
7582             Local<FunctionRef> onIdleFunc = frameCallbackObj->Get(vm, "onIdle");
7583 
7584             auto nanoTimestampRef = NumberRef::New(vm, nanoTimestamp);
7585             Local<JSValueRef> params[] = { nanoTimestampRef };
7586             onIdleFunc->Call(vm, frameCallbackObj.ToLocal(), params, 1);
7587         };
7588     }
7589 
7590     if (onFrameCallbackFunc == nullptr && onIdleCallbackFunc == nullptr) {
7591         return panda::JSValueRef::Undefined(vm);
7592     }
7593 
7594     auto context = PipelineContext::GetCurrentContext();
7595     CHECK_NULL_RETURN(context, panda::JSValueRef::Undefined(vm));
7596     context->AddFrameCallback(std::move(onFrameCallbackFunc), std::move(onIdleCallbackFunc), delayMillis);
7597     return panda::JSValueRef::Undefined(vm);
7598 }
7599 
ResetFocusScopeId(ArkUIRuntimeCallInfo * runtimeCallInfo)7600 ArkUINativeModuleValue CommonBridge::ResetFocusScopeId(ArkUIRuntimeCallInfo* runtimeCallInfo)
7601 {
7602     EcmaVM* vm = runtimeCallInfo->GetVM();
7603     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7604     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7605     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7606     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7607     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7608     GetArkUINodeModifiers()->getCommonModifier()->resetFocusScopeId(nativeNode);
7609     return panda::JSValueRef::Undefined(vm);
7610 }
7611 
SetFocusScopeId(ArkUIRuntimeCallInfo * runtimeCallInfo)7612 ArkUINativeModuleValue CommonBridge::SetFocusScopeId(ArkUIRuntimeCallInfo* runtimeCallInfo)
7613 {
7614     EcmaVM* vm = runtimeCallInfo->GetVM();
7615     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7616     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7617     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7618     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7619     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7620     Local<JSValueRef> idArg = runtimeCallInfo->GetCallArgRef(NUM_1);
7621     Local<JSValueRef> isGroupArg = runtimeCallInfo->GetCallArgRef(NUM_2);
7622     if (!idArg->IsString(vm)) {
7623         return panda::JSValueRef::Undefined(vm);
7624     }
7625     auto id = idArg->ToString(vm)->ToString(vm);
7626     bool isGroup = false;
7627     if (isGroupArg->IsBoolean()) {
7628         isGroup = isGroupArg->ToBoolean(vm)->Value();
7629     }
7630     GetArkUINodeModifiers()->getCommonModifier()->setFocusScopeId(nativeNode, id.c_str(), isGroup);
7631     return panda::JSValueRef::Undefined(vm);
7632 }
7633 
ResetFocusScopePriority(ArkUIRuntimeCallInfo * runtimeCallInfo)7634 ArkUINativeModuleValue CommonBridge::ResetFocusScopePriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
7635 {
7636     EcmaVM* vm = runtimeCallInfo->GetVM();
7637     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7638     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7639     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7640     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7641     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7642     GetArkUINodeModifiers()->getCommonModifier()->resetFocusScopePriority(nativeNode);
7643     return panda::JSValueRef::Undefined(vm);
7644 }
7645 
SetFocusScopePriority(ArkUIRuntimeCallInfo * runtimeCallInfo)7646 ArkUINativeModuleValue CommonBridge::SetFocusScopePriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
7647 {
7648     EcmaVM* vm = runtimeCallInfo->GetVM();
7649     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7650     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7651     CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
7652     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7653     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7654     Local<JSValueRef> scopeIdArg = runtimeCallInfo->GetCallArgRef(NUM_1);
7655     Local<JSValueRef> priorityArg = runtimeCallInfo->GetCallArgRef(NUM_2);
7656     if (!scopeIdArg->IsString(vm)) {
7657         return panda::JSValueRef::Undefined(vm);
7658     }
7659     auto scopeId = scopeIdArg->ToString(vm)->ToString(vm);
7660     int32_t priority = 0;
7661     if (priorityArg->IsNumber()) {
7662         priority = priorityArg->Int32Value(vm);
7663     }
7664     GetArkUINodeModifiers()->getCommonModifier()->setFocusScopePriority(nativeNode, scopeId.c_str(), priority);
7665     return panda::JSValueRef::Undefined(vm);
7666 }
7667 
SetPixelRound(ArkUIRuntimeCallInfo * runtimeCallInfo)7668 ArkUINativeModuleValue CommonBridge::SetPixelRound(ArkUIRuntimeCallInfo* runtimeCallInfo)
7669 {
7670     EcmaVM* vm = runtimeCallInfo->GetVM();
7671     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7672     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
7673     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7674     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7675     auto startArg = runtimeCallInfo->GetCallArgRef(NUM_1);
7676     auto topArg = runtimeCallInfo->GetCallArgRef(NUM_2);
7677     auto endArg = runtimeCallInfo->GetCallArgRef(NUM_3);
7678     auto bottomArg = runtimeCallInfo->GetCallArgRef(NUM_4);
7679     if (startArg->IsUndefined() && topArg->IsUndefined() && endArg->IsUndefined() && bottomArg->IsUndefined()) {
7680         GetArkUINodeModifiers()->getCommonModifier()->resetPixelRound(nativeNode);
7681         return panda::JSValueRef::Undefined(vm);
7682     }
7683     int32_t values[] = { -1, -1, -1, -1 };
7684     if (startArg->IsInt()) {
7685         values[NUM_0] = startArg->Int32Value(vm);
7686     }
7687     if (topArg->IsInt()) {
7688         values[NUM_1] = topArg->Int32Value(vm);
7689     }
7690     if (endArg->IsInt()) {
7691         values[NUM_2] = endArg->Int32Value(vm);
7692     }
7693     if (bottomArg->IsInt()) {
7694         values[NUM_3] = bottomArg->Int32Value(vm);
7695     }
7696     GetArkUINodeModifiers()->getCommonModifier()->setPixelRound(
7697         nativeNode, values, (sizeof(values) / sizeof(values[NUM_0])));
7698     return panda::JSValueRef::Undefined(vm);
7699 }
7700 
ResetPixelRound(ArkUIRuntimeCallInfo * runtimeCallInfo)7701 ArkUINativeModuleValue CommonBridge::ResetPixelRound(ArkUIRuntimeCallInfo* runtimeCallInfo)
7702 {
7703     EcmaVM* vm = runtimeCallInfo->GetVM();
7704     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7705     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7706     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7707     GetArkUINodeModifiers()->getCommonModifier()->resetPixelRound(nativeNode);
7708     return panda::JSValueRef::Undefined(vm);
7709 }
7710 
GreatOrEqualAPITargetVersion(ArkUIRuntimeCallInfo * runtimeCallInfo)7711 ArkUINativeModuleValue CommonBridge::GreatOrEqualAPITargetVersion(ArkUIRuntimeCallInfo* runtimeCallInfo)
7712 {
7713     EcmaVM* vm = runtimeCallInfo->GetVM();
7714     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7715 
7716     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7717     if (firstArg->IsNull() || firstArg->IsUndefined() || !firstArg->IsNumber()) {
7718         return panda::BooleanRef::New(vm, false);
7719     }
7720     int32_t apiTargetVersion = firstArg->Int32Value(vm);
7721     auto platformVersion = static_cast<PlatformVersion>(apiTargetVersion);
7722     return panda::BooleanRef::New(vm, Container::GreatOrEqualAPITargetVersion(platformVersion));
7723 }
7724 
LessThanAPITargetVersion(ArkUIRuntimeCallInfo * runtimeCallInfo)7725 ArkUINativeModuleValue CommonBridge::LessThanAPITargetVersion(ArkUIRuntimeCallInfo* runtimeCallInfo)
7726 {
7727     EcmaVM* vm = runtimeCallInfo->GetVM();
7728     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7729 
7730     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7731     if (firstArg->IsNull() || firstArg->IsUndefined() || !firstArg->IsNumber()) {
7732         return panda::BooleanRef::New(vm, false);
7733     }
7734     int32_t apiTargetVersion = firstArg->Int32Value(vm);
7735     auto platformVersion = static_cast<PlatformVersion>(apiTargetVersion);
7736     return panda::BooleanRef::New(vm, Container::LessThanAPITargetVersion(platformVersion));
7737 }
7738 
GetApiTargetVersion(ArkUIRuntimeCallInfo * runtimeCallInfo)7739 ArkUINativeModuleValue CommonBridge::GetApiTargetVersion(ArkUIRuntimeCallInfo* runtimeCallInfo)
7740 {
7741     EcmaVM* vm = runtimeCallInfo->GetVM();
7742     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7743 
7744     auto container = Container::CurrentSafely();
7745     CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
7746     int32_t apiTargetVersion = container->GetApiTargetVersion();
7747     return panda::NumberRef::New(vm, apiTargetVersion);
7748 }
7749 
SetFocusBox(ArkUIRuntimeCallInfo * runtimeCallInfo)7750 ArkUINativeModuleValue CommonBridge::SetFocusBox(ArkUIRuntimeCallInfo* runtimeCallInfo)
7751 {
7752     EcmaVM* vm = runtimeCallInfo->GetVM();
7753     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7754     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
7755     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7756     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7757     auto marginArg = runtimeCallInfo->GetCallArgRef(NUM_1);
7758     auto widthArg = runtimeCallInfo->GetCallArgRef(NUM_2);
7759     auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
7760     ArkUI_Uint32 hasValue = 0;
7761     CalcDimension margin;
7762     if (!marginArg->IsUndefined() && !marginArg->IsNull()) {
7763         if (ArkTSUtils::ParseJsDimensionFpNG(vm, marginArg, margin, false)) {
7764             hasValue = 1;
7765         } else if (ArkTSUtils::ParseJsLengthMetrics(vm, marginArg, margin)) {
7766             hasValue = 1;
7767         }
7768     }
7769     hasValue = hasValue << 1;
7770     CalcDimension width;
7771     if (!widthArg->IsUndefined() && !widthArg->IsNull()) {
7772         if (ArkTSUtils::ParseJsDimensionFpNG(vm, widthArg, width, false) && GreatOrEqual(width.Value(), 0.0f)) {
7773             hasValue += 1;
7774         } else if (ArkTSUtils::ParseJsLengthMetrics(vm, widthArg, width) && GreatOrEqual(width.Value(), 0.0f)) {
7775             hasValue += 1;
7776         }
7777     }
7778     hasValue = hasValue << 1;
7779     Color strokeColor;
7780     if (!colorArg->IsUndefined() && !colorArg->IsNull() && ParseColorMetricsToColor(vm, colorArg, strokeColor)) {
7781         hasValue += 1;
7782     }
7783     GetArkUINodeModifiers()->getCommonModifier()->setFocusBoxStyle(nativeNode, margin.Value(),
7784         static_cast<int>(margin.Unit()), width.Value(), static_cast<int>(width.Unit()), strokeColor.GetValue(),
7785         hasValue);
7786     return panda::JSValueRef::Undefined(vm);
7787 }
7788 
ResetFocusBox(ArkUIRuntimeCallInfo * runtimeCallInfo)7789 ArkUINativeModuleValue CommonBridge::ResetFocusBox(ArkUIRuntimeCallInfo* runtimeCallInfo)
7790 {
7791     EcmaVM* vm = runtimeCallInfo->GetVM();
7792     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7793     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
7794     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7795     GetArkUINodeModifiers()->getCommonModifier()->resetFocusBoxStyle(nativeNode);
7796     return panda::JSValueRef::Undefined(vm);
7797 }
7798 } // namespace OHOS::Ace::NG
7799