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