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 "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
34 #include "frameworks/bridge/declarative_frontend/jsview/js_shape_abstract.h"
35
36 #include "base/log/ace_scoring_log.h"
37 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
38 #include "bridge/declarative_frontend/jsview/js_utils.h"
39 #include "bridge/declarative_frontend/jsview/js_accessibility.h"
40 #include "bridge/declarative_frontend/jsview/js_popups.h"
41 using namespace OHOS::Ace::Framework;
42
43 namespace OHOS::Ace::NG {
44 namespace {
45 constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000;
46 constexpr uint32_t ALIGNMENT_TOP_LEFT = 0;
47 constexpr float DEFAULT_PROGRESS_TOTAL = 100.0f;
48 constexpr int NUM_0 = 0;
49 constexpr int NUM_1 = 1;
50 constexpr int NUM_2 = 2;
51 constexpr int NUM_3 = 3;
52 constexpr int NUM_4 = 4;
53 constexpr int NUM_5 = 5;
54 constexpr int NUM_6 = 6;
55 constexpr int NUM_7 = 7;
56 constexpr int NUM_8 = 8;
57 constexpr int NUM_9 = 9;
58 constexpr int NUM_10 = 10;
59 constexpr int NUM_11 = 11;
60 constexpr int NUM_12 = 12;
61 constexpr int NUM_13 = 13;
62 constexpr int SIZE_OF_TWO = 2;
63 constexpr int SIZE_OF_THREE = 3;
64 constexpr int SIZE_OF_FOUR = 4;
65 constexpr int SIZE_OF_FIVE = 5;
66 constexpr int SIZE_OF_EIGHT = 8;
67 constexpr int32_t ALIGN_RULES_NUM = 6;
68 constexpr int32_t ALIGN_DIRECTION_DEFAULT = 2;
69 constexpr double FULL_DIMENSION = 100.0;
70 constexpr double HALF_DIMENSION = 50.0;
71 constexpr uint32_t DEFAULT_DURATION = 1000;
72 constexpr int64_t MICROSEC_TO_MILLISEC = 1000;
73 constexpr int32_t MAX_ALIGN_VALUE = 8;
74 constexpr int32_t BACKWARD_COMPAT_MAGIC_NUMBER_OFFSCREEN = 1000;
75 constexpr SharedTransitionEffectType DEFAULT_SHARED_EFFECT = SharedTransitionEffectType::SHARED_EFFECT_EXCHANGE;
76 constexpr int32_t DEFAULT_TAP_FINGER = 1;
77 constexpr int32_t DEFAULT_TAP_COUNT = 1;
78 constexpr double DEFAULT_TAP_DISTANCE = std::numeric_limits<double>::infinity();
79 constexpr int32_t DEFAULT_LONG_PRESS_FINGER = 1;
80 constexpr int32_t DEFAULT_LONG_PRESS_DURATION = 500;
81 constexpr int32_t DEFAULT_PINCH_FINGER = 2;
82 constexpr int32_t DEFAULT_MAX_PINCH_FINGER = 5;
83 constexpr double DEFAULT_PINCH_DISTANCE = 5.0;
84 constexpr int32_t DEFAULT_PAN_FINGER = 1;
85 constexpr int32_t DEFAULT_MAX_FINGERS = 10;
86 constexpr OHOS::Ace::Dimension DEFAULT_PAN_DISTANCE = 5.0_vp;
87 constexpr int32_t DEFAULT_SLIDE_FINGER = DEFAULT_PAN_FINGER;
88 constexpr double DEFAULT_SLIDE_SPEED = 100.0;
89 constexpr int32_t DEFAULT_ROTATION_FINGER = 2;
90 constexpr int32_t DEFAULT_MAX_ROTATION_FINGER = 5;
91 constexpr double DEFAULT_ROTATION_ANGLE = 1.0;
92 constexpr double DEFAULT_MAX_ROTATION_ANGLE = 360.0;
93 const std::string BLOOM_RADIUS_SYS_RES_NAME = "sys.float.ohos_id_point_light_bloom_radius";
94 const std::string BLOOM_COLOR_SYS_RES_NAME = "sys.color.ohos_id_point_light_bloom_color";
95 const std::string ILLUMINATED_BORDER_WIDTH_SYS_RES_NAME = "sys.float.ohos_id_point_light_illuminated_border_width";
96 constexpr double WIDTH_BREAKPOINT_320VP = 320.0; // window width threshold
97 constexpr double WIDTH_BREAKPOINT_600VP = 600.0;
98 constexpr double WIDTH_BREAKPOINT_840VP = 840.0;
99 constexpr double WIDTH_BREAKPOINT_1440VP = 1440.0;
100 constexpr double HEIGHT_ASPECTRATIO_THRESHOLD1 = 0.8; // window height/width = 0.8
101 constexpr double HEIGHT_ASPECTRATIO_THRESHOLD2 = 1.2;
102
103 enum class WidthBreakpoint {WIDTH_XS, WIDTH_SM, WIDTH_MD, WIDTH_LG, WIDTH_XL};
104 enum class HeightBreakpoint {HEIGHT_SM, HEIGHT_MD, HEIGHT_LG};
105 enum ParseResult { LENGTHMETRICS_SUCCESS, DIMENSION_SUCCESS, FAIL };
106 constexpr int32_t PARAMETER_LENGTH_SECOND = 2;
107 constexpr int32_t PARAMETER_LENGTH_THIRD = 3;
108
ConvertBorderStyle(int32_t value)109 BorderStyle ConvertBorderStyle(int32_t value)
110 {
111 auto style = static_cast<BorderStyle>(value);
112 if (style < BorderStyle::SOLID || style > BorderStyle::NONE) {
113 style = BorderStyle::SOLID;
114 }
115 return style;
116 }
117
ParseJsDouble(const EcmaVM * vm,const Local<JSValueRef> & value,double & result)118 bool ParseJsDouble(const EcmaVM *vm, const Local<JSValueRef> &value, double &result)
119 {
120 if (value->IsNumber()) {
121 result = value->ToNumber(vm)->Value();
122 return true;
123 }
124 if (value->IsString(vm)) {
125 return StringUtils::StringToDouble(value->ToString(vm)->ToString(vm), result);
126 }
127
128 return false;
129 }
130
ParseJsInt32(const EcmaVM * vm,const Local<JSValueRef> & value,int32_t & result)131 bool ParseJsInt32(const EcmaVM *vm, const Local<JSValueRef> &value, int32_t &result)
132 {
133 if (value->IsNumber()) {
134 result = value->Int32Value(vm);
135 return true;
136 }
137 if (value->IsString(vm)) {
138 result = StringUtils::StringToInt(value->ToString(vm)->ToString(vm));
139 return true;
140 }
141
142 return false;
143 }
144
ParseJsAngle(const EcmaVM * vm,const Local<JSValueRef> & value,std::optional<float> & angle)145 void ParseJsAngle(const EcmaVM *vm, const Local<JSValueRef> &value, std::optional<float> &angle)
146 {
147 if (value->IsNumber()) {
148 angle = static_cast<float>(value->ToNumber(vm)->Value());
149 return;
150 }
151 if (value->IsString(vm)) {
152 angle = static_cast<float>(StringUtils::StringToDegree(value->ToString(vm)->ToString(vm)));
153 return;
154 }
155 return;
156 }
157
ParseGradientAngle(const EcmaVM * vm,const Local<JSValueRef> & value,std::vector<ArkUIInt32orFloat32> & values)158 void ParseGradientAngle(const EcmaVM *vm, const Local<JSValueRef> &value, std::vector<ArkUIInt32orFloat32> &values)
159 {
160 std::optional<float> degree;
161 ParseJsAngle(vm, value, degree);
162 auto angleHasValue = degree.has_value();
163 auto angleValue = angleHasValue ? degree.value() : 0.0f;
164 degree.reset();
165 values.push_back({.i32 = static_cast<ArkUI_Int32>(angleHasValue)});
166 values.push_back({.f32 = static_cast<ArkUI_Float32>(angleValue)});
167 }
168
ParseGradientColorStops(const EcmaVM * vm,const Local<JSValueRef> & value,std::vector<ArkUIInt32orFloat32> & colors)169 void ParseGradientColorStops(const EcmaVM *vm, const Local<JSValueRef> &value, std::vector<ArkUIInt32orFloat32> &colors)
170 {
171 if (!value->IsArray(vm)) {
172 return;
173 }
174 auto array = panda::Local<panda::ArrayRef>(value);
175 auto length = array->Length(vm);
176 for (uint32_t index = 0; index < length; index++) {
177 auto item = panda::ArrayRef::GetValueAt(vm, array, index);
178 if (!item->IsArray(vm)) {
179 continue;
180 }
181 auto itemArray = panda::Local<panda::ArrayRef>(item);
182 auto itemLength = itemArray->Length(vm);
183 if (itemLength < NUM_1) {
184 continue;
185 }
186 Color color;
187 auto colorParams = panda::ArrayRef::GetValueAt(vm, itemArray, NUM_0);
188 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorParams, color)) {
189 continue;
190 }
191 bool hasDimension = false;
192 double dimension = 0.0;
193 if (itemLength > NUM_1) {
194 auto stopDimension = panda::ArrayRef::GetValueAt(vm, itemArray, NUM_1);
195 if (ArkTSUtils::ParseJsDouble(vm, stopDimension, dimension)) {
196 hasDimension = true;
197 }
198 }
199 colors.push_back({.u32 = static_cast<ArkUI_Uint32>(color.GetValue())});
200 colors.push_back({.i32 = static_cast<ArkUI_Int32>(hasDimension)});
201 colors.push_back({.f32 = static_cast<ArkUI_Float32>(dimension)});
202 }
203 }
204
ParseJsShadowColorStrategy(const EcmaVM * vm,const Local<JSValueRef> & value,ShadowColorStrategy & strategy)205 bool ParseJsShadowColorStrategy(const EcmaVM *vm, const Local<JSValueRef> &value, ShadowColorStrategy& strategy)
206 {
207 if (value->IsString(vm)) {
208 std::string colorStr = value->ToString(vm)->ToString(vm);
209 if (colorStr.compare("average") == 0) {
210 strategy = ShadowColorStrategy::AVERAGE;
211 return true;
212 } else if (colorStr.compare("primary") == 0) {
213 strategy = ShadowColorStrategy::PRIMARY;
214 return true;
215 }
216 }
217 return false;
218 }
219
ParseJsShadowDimension(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimension)220 bool ParseJsShadowDimension(const EcmaVM *vm, const Local<JSValueRef> &value, CalcDimension& dimension)
221 {
222 if (ArkTSUtils::ParseJsResource(vm, value, dimension)) {
223 return true;
224 } else {
225 if (ArkTSUtils::ParseJsDimensionVp(vm, value, dimension)) {
226 return true;
227 }
228 }
229 return false;
230 }
231
ParseJsShadowColor(const EcmaVM * vm,const Local<JSValueRef> & colorArg,int32_t & type,uint32_t & colorValue)232 bool ParseJsShadowColor(const EcmaVM *vm, const Local<JSValueRef> &colorArg,
233 int32_t& type, uint32_t& colorValue)
234 {
235 Color color;
236 ShadowColorStrategy shadowColorStrategy;
237 if (ParseJsShadowColorStrategy(vm, colorArg, shadowColorStrategy)) {
238 type = 1; // 1: has shadowColorStrategy
239 colorValue = static_cast<uint32_t>(shadowColorStrategy);
240 return true;
241 } else if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
242 type = 2; // 2: has shadowColor
243 colorValue = color.GetValue();
244 return true;
245 }
246 return false;
247 }
248
ParseCalcDimensions(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count,std::vector<std::optional<CalcDimension>> & results,const CalcDimension & defValue)249 bool ParseCalcDimensions(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count,
250 std::vector<std::optional<CalcDimension>>& results, const CalcDimension& defValue)
251 {
252 auto end = offset + count;
253 auto argsNumber = runtimeCallInfo->GetArgsNumber();
254 if (end > argsNumber) {
255 return false;
256 }
257 bool hasValue = false;
258 EcmaVM* vm = runtimeCallInfo->GetVM();
259 for (uint32_t index = offset; index < end; index++) {
260 auto arg = runtimeCallInfo->GetCallArgRef(index);
261 std::optional<CalcDimension> optCalcDimension;
262 CalcDimension dimension(defValue);
263 if (ArkTSUtils::ParseJsDimensionVp(vm, arg, dimension, false)) {
264 optCalcDimension = dimension;
265 hasValue = true;
266 }
267 results.push_back(optCalcDimension);
268 }
269 return hasValue;
270 }
271
ParseCalcDimensionsNG(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count,std::vector<std::optional<CalcDimension>> & results,const CalcDimension & defValue)272 ParseResult ParseCalcDimensionsNG(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count,
273 std::vector<std::optional<CalcDimension>>& results, const CalcDimension& defValue)
274 {
275 auto end = offset + count;
276 auto argsNumber = runtimeCallInfo->GetArgsNumber();
277 if (end > argsNumber) {
278 return ParseResult::FAIL;
279 }
280 ParseResult res = ParseResult::FAIL;
281 EcmaVM* vm = runtimeCallInfo->GetVM();
282 for (uint32_t index = offset; index < end; index++) {
283 auto arg = runtimeCallInfo->GetCallArgRef(index);
284 std::optional<CalcDimension> optCalcDimension;
285 CalcDimension dimension(defValue);
286 // Parse string, '10abc' return false
287 if (ArkTSUtils::ParseJsDimensionVpNG(vm, arg, dimension, true)) {
288 optCalcDimension = dimension;
289 res = ParseResult::DIMENSION_SUCCESS;
290 } else if (ArkTSUtils::ParseJsLengthMetrics(vm, arg, dimension)) {
291 optCalcDimension = dimension;
292 res = ParseResult::LENGTHMETRICS_SUCCESS;
293 }
294 results.push_back(optCalcDimension);
295 }
296 return res;
297 }
298
ParseTipsOptionsTime(EcmaVM * vm,ArkUIBindTipsOptionsTime & options,Local<JSValueRef> arg,ArkUI_Float32 & targetField)299 void ParseTipsOptionsTime(
300 EcmaVM* vm, ArkUIBindTipsOptionsTime& options, Local<JSValueRef> arg, ArkUI_Float32& targetField)
301 {
302 if (!arg->IsUndefined() && !arg->IsNull() && arg->IsNumber()) {
303 ArkUI_Float32 value = arg->ToNumber(vm)->Value();
304 if (value >= 0) {
305 targetField = value;
306 }
307 }
308 }
309
ParseTipsOptionsArrowSize(EcmaVM * vm,Local<JSValueRef> arg,ArkUI_Float64 & targetValue,ArkUI_Int32 & targetUnit)310 void ParseTipsOptionsArrowSize(EcmaVM* vm, Local<JSValueRef> arg, ArkUI_Float64& targetValue, ArkUI_Int32& targetUnit)
311 {
312 CalcDimension dimension;
313 if (!arg->IsUndefined() && !arg->IsNull() && ArkTSUtils::ParseJsDimensionVp(vm, arg, dimension, true)) {
314 if (dimension.Value() > 0 && dimension.Unit() != DimensionUnit::PERCENT) {
315 targetValue = dimension.Value();
316 targetUnit = static_cast<ArkUI_Int32>(dimension.Unit());
317 }
318 }
319 }
320
ResetCalcDimensions(std::vector<std::optional<CalcDimension>> & optDimensions)321 void ResetCalcDimensions(std::vector<std::optional<CalcDimension>>& optDimensions)
322 {
323 for (uint32_t index = 0; index < optDimensions.size(); index++) {
324 auto optDimension = optDimensions[index];
325 optDimension.reset();
326 }
327 }
328
PushDimensionsToVector(std::vector<ArkUIStringAndFloat> & results,const std::vector<std::optional<CalcDimension>> & optDimensions)329 void PushDimensionsToVector(std::vector<ArkUIStringAndFloat>& results,
330 const std::vector<std::optional<CalcDimension>>& optDimensions)
331 {
332 for (uint32_t index = 0; index < optDimensions.size(); index++) {
333 auto optDimension = optDimensions[index];
334 auto hasValue = optDimension.has_value();
335 DimensionUnit unit = DimensionUnit::PX;
336 ArkUIStringAndFloat value = { 0.0, nullptr };
337 if (hasValue) {
338 unit = optDimension.value().Unit();
339 if (unit == DimensionUnit::CALC) {
340 value.valueStr = optDimension.value().CalcValue().c_str();
341 } else {
342 value.value = optDimension.value().Value();
343 }
344 }
345 results.push_back(ArkUIStringAndFloat { static_cast<double>(hasValue), nullptr });
346 results.push_back(value);
347 results.push_back(ArkUIStringAndFloat { static_cast<double>(unit), nullptr });
348 }
349 }
350
ParseBorderImageSlice(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<std::optional<CalcDimension>> & optDimensions,uint8_t & bitsets)351 void ParseBorderImageSlice(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::SLICE_BIT;
356 }
357 offset += NUM_4;
358 }
359
ParseBorderImageWidth(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<std::optional<CalcDimension>> & optDimensions,uint8_t & bitsets)360 void ParseBorderImageWidth(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
361 std::vector<std::optional<CalcDimension>>& optDimensions, uint8_t& bitsets)
362 {
363 if (ParseCalcDimensions(runtimeCallInfo, offset, NUM_4, optDimensions, CalcDimension(0.0))) {
364 bitsets |= BorderImage::WIDTH_BIT;
365 }
366 offset += NUM_4;
367 }
368
ParseBorderImageOutset(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<std::optional<CalcDimension>> & optDimensions,uint8_t & bitsets)369 void ParseBorderImageOutset(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
370 std::vector<std::optional<CalcDimension>>& optDimensions, uint8_t& bitsets)
371 {
372 if (ParseCalcDimensions(runtimeCallInfo, offset, NUM_4, optDimensions, CalcDimension(0.0))) {
373 bitsets |= BorderImage::OUTSET_BIT;
374 }
375 offset += NUM_4;
376 }
377
ParseBorderImageRepeat(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<ArkUIStringAndFloat> & options,uint8_t & bitsets)378 bool ParseBorderImageRepeat(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
379 std::vector<ArkUIStringAndFloat>& options, uint8_t& bitsets)
380 {
381 auto argsNumber = runtimeCallInfo->GetArgsNumber();
382 if ((offset + NUM_1) > argsNumber) {
383 return false;
384 }
385 auto vm = runtimeCallInfo->GetVM();
386 auto repeatArg = runtimeCallInfo->GetCallArgRef(offset);
387 auto repeatHasValue = repeatArg->IsString(vm);
388 auto repeatValue = BorderImageRepeat::STRETCH;
389 if (repeatHasValue) {
390 auto repeatStr = repeatArg->ToString(vm)->ToString(vm);
391 if (repeatStr == "Repeat") {
392 repeatValue = BorderImageRepeat::REPEAT;
393 } else if (repeatStr == "Round") {
394 repeatValue = BorderImageRepeat::ROUND;
395 } else if (repeatStr == "Space") {
396 repeatValue = BorderImageRepeat::SPACE;
397 } else {
398 repeatValue = BorderImageRepeat::STRETCH;
399 }
400 }
401 options.push_back(ArkUIStringAndFloat { static_cast<double>(repeatHasValue), nullptr });
402 options.push_back(ArkUIStringAndFloat { static_cast<double>(repeatValue), nullptr });
403 if (repeatHasValue) {
404 bitsets |= BorderImage::REPEAT_BIT;
405 }
406 offset += NUM_1;
407 return true;
408 }
409
ParseBorderImageFill(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,std::vector<ArkUIStringAndFloat> & options)410 bool ParseBorderImageFill(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
411 std::vector<ArkUIStringAndFloat>& options)
412 {
413 auto argsNumber = runtimeCallInfo->GetArgsNumber();
414 if ((offset + NUM_1) > argsNumber) {
415 return false;
416 }
417 auto fillArg = runtimeCallInfo->GetCallArgRef(offset);
418 auto hasValue = fillArg->IsBoolean();
419 auto fill = (hasValue) ? fillArg->BooleaValue(runtimeCallInfo->GetVM()) : false;
420 options.push_back(ArkUIStringAndFloat {static_cast<double>(hasValue), nullptr });
421 options.push_back(ArkUIStringAndFloat {static_cast<double>(fill), nullptr });
422 offset += NUM_1;
423 return true;
424 }
425
IsArgsUndefined(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count)426 bool IsArgsUndefined(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count)
427 {
428 auto argsNumber = runtimeCallInfo->GetArgsNumber();
429 auto end = offset + count;
430 end = (end > argsNumber) ? argsNumber : end;
431 for (uint32_t index = offset; index < end; index++) {
432 auto jsArg = runtimeCallInfo->GetCallArgRef(index);
433 if (jsArg->IsUndefined()) {
434 continue;
435 }
436 return false;
437 }
438 return true;
439 }
440
ParseBorderImageLinearGradient(ArkUINodeHandle node,ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint8_t & bitsets)441 void ParseBorderImageLinearGradient(ArkUINodeHandle node,
442 ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset,
443 uint8_t& bitsets)
444 {
445 auto argsNumber = runtimeCallInfo->GetArgsNumber();
446 if ((offset + NUM_4) > argsNumber) {
447 return;
448 }
449 auto angleArg = runtimeCallInfo->GetCallArgRef(offset);
450 auto directionArg = runtimeCallInfo->GetCallArgRef(offset + NUM_1);
451 auto colorsArg = runtimeCallInfo->GetCallArgRef(offset + NUM_2);
452 auto repeatingArg = runtimeCallInfo->GetCallArgRef(offset + NUM_3);
453 if (angleArg->IsUndefined() && directionArg->IsUndefined() &&
454 colorsArg->IsUndefined() && repeatingArg->IsUndefined()) {
455 return;
456 }
457 auto vm = runtimeCallInfo->GetVM();
458 std::vector<ArkUIInt32orFloat32> options;
459 ParseGradientAngle(vm, angleArg, options);
460 int32_t direction = static_cast<int32_t>(GradientDirection::NONE);
461 ParseJsInt32(vm, directionArg, direction);
462 options.push_back({.i32 = static_cast<ArkUI_Int32>(direction)});
463
464 std::vector<ArkUIInt32orFloat32> colors;
465 ParseGradientColorStops(vm, colorsArg, colors);
466 auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(runtimeCallInfo->GetVM()) : false;
467 options.push_back({.i32 = static_cast<ArkUI_Int32>(repeating)});
468 GetArkUINodeModifiers()->getCommonModifier()->setBorderImageGradient(node,
469 options.data(), options.size(), colors.data(), colors.size());
470 }
471
ParseBorderImageSource(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t & offset,ArkUINodeHandle node,std::string & src,uint8_t & bitsets)472 bool ParseBorderImageSource(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t& offset,
473 ArkUINodeHandle node, std::string& src, uint8_t& bitsets)
474 {
475 auto argsNumber = runtimeCallInfo->GetArgsNumber();
476 if ((offset + NUM_5) > argsNumber) {
477 return false;
478 }
479 if (IsArgsUndefined(runtimeCallInfo, offset, NUM_5)) {
480 return false;
481 }
482 auto sourceArg = runtimeCallInfo->GetCallArgRef(offset); // use 1 args
483 offset += NUM_1;
484 auto vm = runtimeCallInfo->GetVM();
485 if (sourceArg->IsString(vm)) {
486 src = sourceArg->ToString(vm)->ToString(vm);
487 bitsets |= BorderImage::SOURCE_BIT;
488 } else {
489 if (ArkTSUtils::ParseJsMedia(vm, sourceArg, src)) {
490 bitsets |= BorderImage::SOURCE_BIT;
491 } else {
492 ParseBorderImageLinearGradient(node, runtimeCallInfo, offset, bitsets);
493 }
494 }
495 offset += NUM_4; // skip 4 args
496 return true;
497 }
498
ParseChainedMoveTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)499 RefPtr<NG::ChainedTransitionEffect> ParseChainedMoveTransition(
500 const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
501 {
502 int32_t edge = 0;
503 if (JSViewAbstract::ParseJsInt32(effectOption, edge)) {
504 if (edge < static_cast<int32_t>(NG::TransitionEdge::TOP) ||
505 edge > static_cast<int32_t>(NG::TransitionEdge::END)) {
506 edge = static_cast<int32_t>(NG::TransitionEdge::START);
507 }
508 return AceType::MakeRefPtr<NG::ChainedMoveEffect>(static_cast<NG::TransitionEdge>(edge));
509 }
510 return nullptr;
511 }
512
ParseChainedOpacityTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)513 RefPtr<NG::ChainedTransitionEffect> ParseChainedOpacityTransition(
514 const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
515 {
516 double opacity = 1.0;
517 if (Framework::JSViewAbstract::ParseJsDouble(effectOption, opacity)) {
518 if ((LessNotEqual(opacity, 0.0)) || opacity > 1.0) {
519 opacity = 1.0;
520 }
521 return AceType::MakeRefPtr<NG::ChainedOpacityEffect>(opacity);
522 }
523 return nullptr;
524 }
525
ParseJsTranslate(const Framework::JSRef<Framework::JSVal> & jsValue,CalcDimension & translateX,CalcDimension & translateY,CalcDimension & translateZ)526 void ParseJsTranslate(const Framework::JSRef<Framework::JSVal>& jsValue, CalcDimension& translateX,
527 CalcDimension& translateY, CalcDimension& translateZ)
528 {
529 if (!jsValue->IsObject()) {
530 return;
531 }
532 Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
533 Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("x"), translateX);
534 Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("y"), translateY);
535 Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("z"), translateZ);
536 }
537
ParseStrToUint(std::string safeAreaTypeStr)538 uint32_t ParseStrToUint(std::string safeAreaTypeStr)
539 {
540 uint32_t uintType = NG::SAFE_AREA_TYPE_NONE;
541 std::string delimiter = "|";
542 std::string type;
543 size_t pos = 0;
544 while ((pos = safeAreaTypeStr.find(delimiter)) != std::string::npos) {
545 type = safeAreaTypeStr.substr(0, pos);
546 uintType |= (1 << StringUtils::StringToUint(type));
547 safeAreaTypeStr.erase(0, pos + delimiter.length());
548 }
549 uintType |= (1 << StringUtils::StringToUint(safeAreaTypeStr));
550 return uintType;
551 }
552
ParseChainedTranslateTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)553 RefPtr<NG::ChainedTransitionEffect> ParseChainedTranslateTransition(
554 const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
555 {
556 if (effectOption->IsObject()) {
557 // default: x, y, z (0.0, 0.0, 0.0)
558 NG::TranslateOptions translate;
559 ParseJsTranslate(effectOption, translate.x, translate.y, translate.z);
560 return AceType::MakeRefPtr<NG::ChainedTranslateEffect>(translate);
561 }
562 return nullptr;
563 }
564
GetDefaultRotateVector(double & dx,double & dy,double & dz)565 void GetDefaultRotateVector(double& dx, double& dy, double& dz)
566 {
567 dx = 0.0;
568 dy = 0.0;
569 dz = 0.0;
570 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_NINE)) {
571 dz = 1.0;
572 }
573 }
574
ParseJsRotate(const Framework::JSRef<Framework::JSVal> & jsValue,NG::RotateOptions & rotate,std::optional<float> & angle)575 void ParseJsRotate(
576 const Framework::JSRef<Framework::JSVal>& jsValue, NG::RotateOptions& rotate, std::optional<float>& angle)
577 {
578 if (!jsValue->IsObject()) {
579 return;
580 }
581 // default: dx, dy, dz (0.0, 0.0, 0.0)
582 double dxVal = 0.0;
583 double dyVal = 0.0;
584 double dzVal = 0.0;
585 Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
586 if (!jsObj->HasProperty("x") && !jsObj->HasProperty("y") && !jsObj->HasProperty("z")) {
587 GetDefaultRotateVector(dxVal, dyVal, dzVal);
588 } else {
589 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("x"), dxVal);
590 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("y"), dyVal);
591 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("z"), dzVal);
592 }
593 rotate.xDirection = static_cast<float>(dxVal);
594 rotate.yDirection = static_cast<float>(dyVal);
595 rotate.zDirection = static_cast<float>(dzVal);
596 // if specify centerX
597 if (!Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerX"), rotate.centerX)) {
598 rotate.centerX = Dimension(0.5f, DimensionUnit::PERCENT);
599 }
600 // if specify centerY
601 if (!Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerY"), rotate.centerY)) {
602 rotate.centerY = Dimension(0.5f, DimensionUnit::PERCENT);
603 }
604 // if specify centerZ
605 if (!Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerZ"), rotate.centerZ)) {
606 rotate.centerZ = Dimension(0.5f, DimensionUnit::PERCENT);
607 }
608 // if specify angle
609 Framework::JSViewAbstract::GetJsAngle(static_cast<int32_t>(ArkUIIndex::ANGLE), jsObj, angle);
610 rotate.perspective = 0.0f;
611 Framework::JSViewAbstract::GetJsPerspective(static_cast<int32_t>(ArkUIIndex::PERSPECTIVE), jsObj,
612 rotate.perspective);
613 }
614
ParseChainedRotateTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)615 RefPtr<NG::ChainedTransitionEffect> ParseChainedRotateTransition(
616 const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
617 {
618 RefPtr<NG::ChainedTransitionEffect> effect;
619 if (effectOption->IsObject()) {
620 NG::RotateOptions rotate(0.0f, 0.0f, 0.0f, 0.0f, 0.5_pct, 0.5_pct);
621 std::optional<float> angle;
622 ParseJsRotate(effectOption, rotate, angle);
623 if (angle.has_value()) {
624 rotate.angle = angle.value();
625 return AceType::MakeRefPtr<NG::ChainedRotateEffect>(rotate);
626 }
627 }
628 return nullptr;
629 }
630
ParseJsScale(const Framework::JSRef<Framework::JSVal> & jsValue,float & scaleX,float & scaleY,float & scaleZ,CalcDimension & centerX,CalcDimension & centerY)631 void ParseJsScale(const Framework::JSRef<Framework::JSVal>& jsValue, float& scaleX, float& scaleY, float& scaleZ,
632 CalcDimension& centerX, CalcDimension& centerY)
633 {
634 double xVal = 1.0;
635 double yVal = 1.0;
636 double zVal = 1.0;
637 if (!jsValue->IsObject()) {
638 scaleX = static_cast<float>(xVal);
639 scaleY = static_cast<float>(yVal);
640 scaleZ = static_cast<float>(zVal);
641 CalcDimension length;
642 centerX = length;
643 centerY = length;
644 return;
645 }
646 Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
647 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("x"), xVal);
648 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("y"), yVal);
649 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("z"), zVal);
650 scaleX = static_cast<float>(xVal);
651 scaleY = static_cast<float>(yVal);
652 scaleZ = static_cast<float>(zVal);
653 // if specify centerX
654 Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerX"), centerX);
655 // if specify centerY
656 Framework::JSViewAbstract::ParseJsDimensionVp(jsObj->GetProperty("centerY"), centerY);
657 }
658
ParseChainedScaleTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)659 RefPtr<NG::ChainedTransitionEffect> ParseChainedScaleTransition(
660 const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
661 {
662 if (effectOption->IsObject()) {
663 // default: x, y, z (1.0, 1.0, 1.0), centerX, centerY 50% 50%;
664 NG::ScaleOptions scale(1.0f, 1.0f, 1.0f, 0.5_pct, 0.5_pct);
665 ParseJsScale(effectOption, scale.xScale, scale.yScale, scale.zScale, scale.centerX, scale.centerY);
666 return AceType::MakeRefPtr<NG::ChainedScaleEffect>(scale);
667 }
668 return nullptr;
669 }
670
671 RefPtr<NG::ChainedTransitionEffect> ParseChainedTransition(
672 const JSRef<JSObject>& object, const JSExecutionContext& context);
673
ParseChainedAsymmetricTransition(const Framework::JSRef<Framework::JSVal> & effectOption,const JSExecutionContext & context)674 RefPtr<NG::ChainedTransitionEffect> ParseChainedAsymmetricTransition(
675 const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
676 {
677 if (effectOption->IsObject()) {
678 auto effectObj = Framework::JSRef<Framework::JSObject>::Cast(effectOption);
679 auto appearJsVal = effectObj->GetProperty("appear");
680 auto disappearJsVal = effectObj->GetProperty("disappear");
681 RefPtr<NG::ChainedTransitionEffect> appearEffect;
682 RefPtr<NG::ChainedTransitionEffect> disappearEffect;
683 if (appearJsVal->IsObject()) {
684 auto appearObj = Framework::JSRef<Framework::JSObject>::Cast(appearJsVal);
685 appearEffect = ParseChainedTransition(appearObj, context);
686 }
687 if (disappearJsVal->IsObject()) {
688 auto disappearObj = Framework::JSRef<Framework::JSObject>::Cast(disappearJsVal);
689 disappearEffect = ParseChainedTransition(disappearObj, context);
690 }
691 return AceType::MakeRefPtr<NG::ChainedAsymmetricEffect>(appearEffect, disappearEffect);
692 }
693 return nullptr;
694 }
695
GetFormAnimationTimeInterval(const RefPtr<PipelineBase> & pipelineContext)696 int64_t GetFormAnimationTimeInterval(const RefPtr<PipelineBase>& pipelineContext)
697 {
698 CHECK_NULL_RETURN(pipelineContext, 0);
699 return (GetMicroTickCount() - pipelineContext->GetFormAnimationStartTime()) / MICROSEC_TO_MILLISEC;
700 }
701
702 using ChainedTransitionEffectCreator = RefPtr<NG::ChainedTransitionEffect> (*)(
703 const Framework::JSRef<Framework::JSVal>&, const JSExecutionContext&);
704
GetAnimationOptionResult(shared_ptr<AnimationOption> & animationOptionResult,const JSRef<JSObject> & propAnimationOption,const RefPtr<PipelineBase> & pipelineContext,const JSExecutionContext & context)705 void GetAnimationOptionResult(shared_ptr<AnimationOption>& animationOptionResult,
706 const JSRef<JSObject>& propAnimationOption, const RefPtr<PipelineBase>& pipelineContext,
707 const JSExecutionContext& context)
708 {
709 // The maximum of the form-animation-playback duration value is 1000 ms.
710 if (pipelineContext->IsFormRenderExceptDynamicComponent() && pipelineContext->IsFormAnimation()) {
711 auto formAnimationTimeInterval = GetFormAnimationTimeInterval(pipelineContext);
712 // If the duration exceeds 1000ms, init it to 0 ms.
713 if (formAnimationTimeInterval > DEFAULT_DURATION) {
714 animationOptionResult->SetDuration(0);
715 } else if (animationOptionResult->GetDuration() > (DEFAULT_DURATION - formAnimationTimeInterval)) {
716 // If remaining time is less than 1000ms, check for update duration.
717 animationOptionResult->SetDuration(DEFAULT_DURATION - formAnimationTimeInterval);
718 TAG_LOGI(AceLogTag::ACE_FORM, "[Form animation] Form Transition SetDuration: %{public}lld ms",
719 static_cast<long long>(DEFAULT_DURATION - formAnimationTimeInterval));
720 }
721 }
722 auto animationOptionObj = Framework::JSRef<Framework::JSObject>::Cast(propAnimationOption);
723 Framework::JSRef<Framework::JSVal> onFinish = animationOptionObj->GetProperty("onFinish");
724 if (onFinish->IsFunction()) {
725 RefPtr<JsFunction> jsFunc =
726 AceType::MakeRefPtr<JsFunction>(Framework::JSRef<Framework::JSObject>(), JSRef<JSFunc>::Cast(onFinish));
727 std::function<void()> onFinishEvent = [execCtx = context, func = std::move(jsFunc),
728 id = Container::CurrentId()]() {
729 ContainerScope scope(id);
730 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
731 func->Execute();
732 };
733 animationOptionResult->SetOnFinishEvent(onFinishEvent);
734 }
735 }
736
ParseChainedTransition(const Framework::JSRef<Framework::JSObject> & object,const JSExecutionContext & context)737 RefPtr<NG::ChainedTransitionEffect> ParseChainedTransition(
738 const Framework::JSRef<Framework::JSObject>& object, const JSExecutionContext& context)
739 {
740 auto propType = object->GetProperty("type_");
741 if (!propType->IsString()) {
742 return nullptr;
743 }
744 std::string type = propType->ToString();
745 auto propEffectOption = object->GetProperty("effect_");
746 auto propAnimationOption = object->GetProperty("animation_");
747 auto propSuccessor = object->GetProperty("successor_");
748 static const LinearMapNode<ChainedTransitionEffectCreator> creatorMap[] = {
749 { "asymmetric", ParseChainedAsymmetricTransition },
750 { "identity",
751 [](const Framework::JSRef<Framework::JSVal>& effectOption, const JSExecutionContext& context)
752 -> RefPtr<NG::ChainedTransitionEffect> { return AceType::MakeRefPtr<NG::ChainedIdentityEffect>(); } },
753 { "move", ParseChainedMoveTransition },
754 { "opacity", ParseChainedOpacityTransition },
755 { "rotate", ParseChainedRotateTransition },
756 { "scale", ParseChainedScaleTransition },
757 { "slideSwitch",
758 [](const Framework::JSRef<Framework::JSVal>& effectOption,
759 const JSExecutionContext& context) -> RefPtr<NG::ChainedTransitionEffect> {
760 return AceType::MakeRefPtr<NG::ChainedSlideSwitchEffect>();
761 } },
762 { "translate", ParseChainedTranslateTransition },
763 };
764 int64_t index = BinarySearchFindIndex(creatorMap, ArraySize(creatorMap), type.c_str());
765 if (index < 0) {
766 return nullptr;
767 }
768 RefPtr<NG::ChainedTransitionEffect> result = creatorMap[index].value(propEffectOption, context);
769 if (!result) {
770 return nullptr;
771 }
772 if (propAnimationOption->IsObject()) {
773 auto container = Container::Current();
774 CHECK_NULL_RETURN(container, nullptr);
775 auto pipelineContext = container->GetPipelineContext();
776 CHECK_NULL_RETURN(pipelineContext, nullptr);
777 auto animationOptionResult = std::make_shared<AnimationOption>(
778 JSViewContext::CreateAnimation(propAnimationOption, pipelineContext->IsFormRenderExceptDynamicComponent()));
779 GetAnimationOptionResult(animationOptionResult, propAnimationOption, pipelineContext, context);
780 result->SetAnimationOption(animationOptionResult);
781 }
782 if (propSuccessor->IsObject()) {
783 result->SetNext(ParseChainedTransition(Framework::JSRef<Framework::JSObject>::Cast(propSuccessor), context));
784 }
785 return result;
786 }
787
ParseJsTransition(const Framework::JSRef<Framework::JSVal> & transitionArgs)788 NG::TransitionOptions ParseJsTransition(const Framework::JSRef<Framework::JSVal>& transitionArgs)
789 {
790 NG::TransitionOptions transitionOption;
791 if (!transitionArgs->IsObject()) {
792 return transitionOption;
793 }
794 Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(transitionArgs);
795 bool hasEffect = false;
796 transitionOption.Type = ParseTransitionType(jsObj->GetPropertyValue<std::string>("type", "All"));
797 if (jsObj->HasProperty("opacity")) {
798 double opacity = 1.0;
799 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("opacity"), opacity);
800 opacity = std::clamp(opacity, 0.0, 1.0);
801 transitionOption.UpdateOpacity(static_cast<float>(opacity));
802 hasEffect = true;
803 }
804 if (jsObj->HasProperty("translate")) {
805 // default: x, y, z (0.0, 0.0, 0.0)
806 NG::TranslateOptions translate;
807 ParseJsTranslate(jsObj->GetProperty("translate"), translate.x, translate.y, translate.z);
808 transitionOption.UpdateTranslate(translate);
809 hasEffect = true;
810 }
811 if (jsObj->HasProperty("scale")) {
812 // default: x, y, z (1.0, 1.0, 1.0), centerX, centerY 50% 50%;
813 NG::ScaleOptions scale(1.0f, 1.0f, 1.0f, 0.5_pct, 0.5_pct);
814 ParseJsScale(
815 jsObj->GetProperty("scale"), scale.xScale, scale.yScale, scale.zScale, scale.centerX, scale.centerY);
816 transitionOption.UpdateScale(scale);
817 hasEffect = true;
818 }
819 if (jsObj->HasProperty("rotate")) {
820 // default: dx, dy, dz (0.0, 0.0, 0.0), angle 0, centerX, centerY 50% 50%;
821 NG::RotateOptions rotate(0.0f, 0.0f, 0.0f, 0.0f, 0.5_pct, 0.5_pct);
822 std::optional<float> angle;
823 ParseJsRotate(jsObj->GetProperty("rotate"), rotate, angle);
824 if (angle.has_value()) {
825 rotate.angle = angle.value();
826 transitionOption.UpdateRotate(rotate);
827 hasEffect = true;
828 }
829 }
830 if (!hasEffect) {
831 // default transition
832 transitionOption = NG::TransitionOptions::GetDefaultTransition(transitionOption.Type);
833 }
834 return transitionOption;
835 }
836
ParseMotionPath(const Framework::JSRef<Framework::JSVal> & jsValue,MotionPathOption & option)837 bool ParseMotionPath(const Framework::JSRef<Framework::JSVal>& jsValue, MotionPathOption& option)
838 {
839 if (!jsValue->IsObject()) {
840 return false;
841 }
842
843 Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(jsValue);
844 auto path = jsObj->GetPropertyValue<std::string>("path", "");
845 if (path.empty()) {
846 return false;
847 }
848 option.SetPath(path);
849 double from = 0.0;
850 double to = 1.0;
851 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("from"), from);
852 Framework::JSViewAbstract::ParseJsDouble(jsObj->GetProperty("to"), to);
853 if (GreatNotEqual(from, 1.0) || LessNotEqual(from, 0.0)) {
854 from = 0.0;
855 }
856 if (GreatNotEqual(to, 1.0) || LessNotEqual(to, 0.0)) {
857 to = 1.0;
858 } else if (to < from) {
859 to = from;
860 }
861 option.SetBegin(static_cast<float>(from));
862 option.SetEnd(static_cast<float>(to));
863 option.SetRotate(jsObj->GetPropertyValue<bool>("rotatable", false));
864 return true;
865 }
866
ParseJsDoublePair(const EcmaVM * vm,const Local<JSValueRef> & value,ArkUI_Float32 & first,ArkUI_Float32 & second)867 bool ParseJsDoublePair(const EcmaVM *vm, const Local<JSValueRef> &value, ArkUI_Float32 &first, ArkUI_Float32 &second)
868 {
869 if (!value->IsArray(vm)) {
870 return false;
871 }
872 auto array = panda::Local<panda::ArrayRef>(value);
873 if (array->Length(vm) != NUM_2) {
874 return false;
875 }
876 auto firstArg = panda::ArrayRef::GetValueAt(vm, array, NUM_0);
877 if (!firstArg->IsNumber()) {
878 return false;
879 }
880 auto secondArg = panda::ArrayRef::GetValueAt(vm, array, NUM_1);
881 if (!secondArg->IsNumber()) {
882 return false;
883 }
884 first = static_cast<ArkUI_Float32>(firstArg->ToNumber(vm)->Value());
885 second = static_cast<ArkUI_Float32>(secondArg->ToNumber(vm)->Value());
886 return true;
887 }
888
ParseGradientCenter(const EcmaVM * vm,const Local<JSValueRef> & value,std::vector<ArkUIInt32orFloat32> & values)889 void ParseGradientCenter(const EcmaVM* vm, const Local<JSValueRef>& value, std::vector<ArkUIInt32orFloat32>& values)
890 {
891 bool hasValueX = false;
892 bool hasValueY = false;
893 CalcDimension valueX;
894 CalcDimension valueY;
895 if (value->IsArray(vm)) {
896 auto array = panda::Local<panda::ArrayRef>(value);
897 auto length = array->Length(vm);
898 if (length == NUM_2) {
899 hasValueX =
900 ArkTSUtils::ParseJsDimensionVp(vm, panda::ArrayRef::GetValueAt(vm, array, NUM_0), valueX, false);
901 hasValueY =
902 ArkTSUtils::ParseJsDimensionVp(vm, panda::ArrayRef::GetValueAt(vm, array, NUM_1), valueY, false);
903 }
904 }
905 values.push_back({.i32 = static_cast<ArkUI_Int32>(hasValueX)});
906 values.push_back({.f32 = static_cast<ArkUI_Float32>(valueX.Value())});
907 values.push_back({.i32 = static_cast<ArkUI_Int32>(valueX.Unit())});
908 values.push_back({.i32 = static_cast<ArkUI_Int32>(hasValueY)});
909 values.push_back({.f32 = static_cast<ArkUI_Float32>(valueY.Value())});
910 values.push_back({.i32 = static_cast<ArkUI_Int32>(valueY.Unit())});
911 }
912
PushOuterBorderDimensionVector(const std::optional<CalcDimension> & valueDim,std::vector<ArkUI_Float32> & options)913 void PushOuterBorderDimensionVector(const std::optional<CalcDimension>& valueDim, std::vector<ArkUI_Float32> &options)
914 {
915 options.push_back(static_cast<ArkUI_Float32>(valueDim.has_value()));
916 if (valueDim.has_value()) {
917 options.push_back(static_cast<ArkUI_Float32>(valueDim.value().Value()));
918 options.push_back(static_cast<ArkUI_Float32>(valueDim.value().Unit()));
919 } else {
920 options.push_back(0);
921 options.push_back(0);
922 }
923 }
924
ParseOuterBorderWidth(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values,bool needLocalized=false)925 void ParseOuterBorderWidth(
926 ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<ArkUI_Float32>& values, bool needLocalized = false)
927 {
928 Local<JSValueRef> leftArgs = runtimeCallInfo->GetCallArgRef(NUM_1);
929 Local<JSValueRef> rightArgs = runtimeCallInfo->GetCallArgRef(NUM_2);
930 Local<JSValueRef> topArgs = runtimeCallInfo->GetCallArgRef(NUM_3);
931 Local<JSValueRef> bottomArgs = runtimeCallInfo->GetCallArgRef(NUM_4);
932
933 std::optional<CalcDimension> leftDim;
934 std::optional<CalcDimension> rightDim;
935 std::optional<CalcDimension> topDim;
936 std::optional<CalcDimension> bottomDim;
937 std::optional<CalcDimension> startDim;
938 std::optional<CalcDimension> endDim;
939
940 ArkTSUtils::ParseOuterBorder(vm, leftArgs, leftDim);
941 ArkTSUtils::ParseOuterBorder(vm, rightArgs, rightDim);
942 if (needLocalized) {
943 Local<JSValueRef> startArgs = runtimeCallInfo->GetCallArgRef(25); // 25: index of BorderWidth.start
944 Local<JSValueRef> endArgs = runtimeCallInfo->GetCallArgRef(26); // 26: index of BorderWidth.end
945 ArkTSUtils::ParseOuterBorderForDashParams(vm, startArgs, startDim);
946 ArkTSUtils::ParseOuterBorderForDashParams(vm, endArgs, endDim);
947 ArkTSUtils::ParseOuterBorderForDashParams(vm, topArgs, topDim);
948 ArkTSUtils::ParseOuterBorderForDashParams(vm, bottomArgs, bottomDim);
949 } else {
950 ArkTSUtils::ParseOuterBorder(vm, topArgs, topDim);
951 ArkTSUtils::ParseOuterBorder(vm, bottomArgs, bottomDim);
952 }
953
954 if (startDim.has_value() || endDim.has_value()) {
955 PushOuterBorderDimensionVector(startDim, values);
956 PushOuterBorderDimensionVector(endDim, values);
957 } else {
958 PushOuterBorderDimensionVector(leftDim, values);
959 PushOuterBorderDimensionVector(rightDim, values);
960 }
961 PushOuterBorderDimensionVector(topDim, values);
962 PushOuterBorderDimensionVector(bottomDim, values);
963 }
964
PushOuterBorderColorVector(const std::optional<Color> & valueColor,std::vector<uint32_t> & options)965 void PushOuterBorderColorVector(const std::optional<Color>& valueColor, std::vector<uint32_t> &options)
966 {
967 options.push_back(static_cast<uint32_t>(valueColor.has_value()));
968 if (valueColor.has_value()) {
969 options.push_back(static_cast<uint32_t>(valueColor.value().GetValue()));
970 } else {
971 options.push_back(0);
972 }
973 }
ParseOuterBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<uint32_t> & values,int32_t argsIndex,bool needLocalized=false)974 void ParseOuterBorderColor(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<uint32_t>& values,
975 int32_t argsIndex, bool needLocalized = false)
976 {
977 Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(argsIndex);
978 Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
979 Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
980 Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
981
982 std::optional<Color> leftColor;
983 std::optional<Color> rightColor;
984 std::optional<Color> topColor;
985 std::optional<Color> bottomColor;
986 std::optional<Color> startColor;
987 std::optional<Color> endColor;
988
989 Color left;
990 if (!leftArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, leftArg, left)) {
991 leftColor = left;
992 }
993 Color right;
994 if (!rightArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, rightArg, right)) {
995 rightColor = right;
996 }
997 Color top;
998 if (!topArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, topArg, top)) {
999 topColor = top;
1000 }
1001 Color bottom;
1002 if (!bottomArg->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, bottomArg, bottom)) {
1003 bottomColor = bottom;
1004 }
1005 if (needLocalized) {
1006 Local<JSValueRef> startArgs = runtimeCallInfo->GetCallArgRef(27); // 27: index of BorderColor.startColor
1007 Local<JSValueRef> endArgs = runtimeCallInfo->GetCallArgRef(28); // 28: index of BorderColor.endColor
1008 Color start;
1009 if (!startArgs->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, startArgs, start)) {
1010 startColor = start;
1011 }
1012 Color end;
1013 if (!endArgs->IsUndefined() && ArkTSUtils::ParseJsColorAlpha(vm, endArgs, end)) {
1014 endColor = end;
1015 }
1016 }
1017 if (startColor.has_value() || endColor.has_value()) {
1018 PushOuterBorderColorVector(startColor, values);
1019 PushOuterBorderColorVector(endColor, values);
1020 } else {
1021 PushOuterBorderColorVector(leftColor, values);
1022 PushOuterBorderColorVector(rightColor, values);
1023 }
1024 PushOuterBorderColorVector(topColor, values);
1025 PushOuterBorderColorVector(bottomColor, values);
1026 }
1027
ParseLocalizedBorderRadius(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & result)1028 bool ParseLocalizedBorderRadius(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& result)
1029 {
1030 if (ArkTSUtils::ParseJsLengthMetrics(vm, value, result)) {
1031 if (result.IsNegative()) {
1032 result.Reset();
1033 }
1034 return true;
1035 }
1036 return false;
1037 }
1038
ParseOuterBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values,int32_t argsIndex,bool needLocalized=false)1039 void ParseOuterBorderRadius(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<ArkUI_Float32>& values,
1040 int32_t argsIndex, bool needLocalized = false)
1041 {
1042 Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(argsIndex);
1043 Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
1044 Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
1045 Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
1046 if (needLocalized) {
1047 Local<JSValueRef> topStartArgs = runtimeCallInfo->GetCallArgRef(29); // 29: index of BorderRadius.topStart
1048 Local<JSValueRef> topEndArgs = runtimeCallInfo->GetCallArgRef(30); // 30: index of BorderRadius.topEnd
1049 Local<JSValueRef> bottomStartArgs = runtimeCallInfo->GetCallArgRef(31); // 31: index of BorderRadius.bottomStart
1050 Local<JSValueRef> bottomEndArgs = runtimeCallInfo->GetCallArgRef(32); // 32: index of BorderRadius.bottomEnd
1051 // 35: index of is LocalizedBorderRadius or not
1052 Local<JSValueRef> isLocalizedBorderRadiusArg = runtimeCallInfo->GetCallArgRef(35);
1053 bool isLocalizedBorderRadius =
1054 (isLocalizedBorderRadiusArg->IsBoolean()) ? isLocalizedBorderRadiusArg->ToBoolean(vm)->Value() : false;
1055 if (isLocalizedBorderRadius) {
1056 CalcDimension topStartOptional;
1057 CalcDimension topEndOptional;
1058 CalcDimension bottomStartOptional;
1059 CalcDimension bottomEndOptional;
1060 ParseLocalizedBorderRadius(vm, topStartArgs, topStartOptional);
1061 ParseLocalizedBorderRadius(vm, topEndArgs, topEndOptional);
1062 ParseLocalizedBorderRadius(vm, bottomStartArgs, bottomStartOptional);
1063 ParseLocalizedBorderRadius(vm, bottomEndArgs, bottomEndOptional);
1064 PushOuterBorderDimensionVector(topStartOptional, values);
1065 PushOuterBorderDimensionVector(topEndOptional, values);
1066 PushOuterBorderDimensionVector(bottomStartOptional, values);
1067 PushOuterBorderDimensionVector(bottomEndOptional, values);
1068 return;
1069 }
1070 }
1071
1072 std::optional<CalcDimension> topLeftOptional;
1073 std::optional<CalcDimension> topRightOptional;
1074 std::optional<CalcDimension> bottomLeftOptional;
1075 std::optional<CalcDimension> bottomRightOptional;
1076
1077 ArkTSUtils::ParseOuterBorder(vm, topLeftArgs, topLeftOptional);
1078 ArkTSUtils::ParseOuterBorder(vm, topRightArgs, topRightOptional);
1079 ArkTSUtils::ParseOuterBorder(vm, bottomLeftArgs, bottomLeftOptional);
1080 ArkTSUtils::ParseOuterBorder(vm, bottomRightArgs, bottomRightOptional);
1081
1082 PushOuterBorderDimensionVector(topLeftOptional, values);
1083 PushOuterBorderDimensionVector(topRightOptional, values);
1084 PushOuterBorderDimensionVector(bottomLeftOptional, values);
1085 PushOuterBorderDimensionVector(bottomRightOptional, values);
1086 }
1087
PushOuterBorderStyleVector(const std::optional<BorderStyle> & value,std::vector<uint32_t> & options)1088 void PushOuterBorderStyleVector(const std::optional<BorderStyle>& value, std::vector<uint32_t> &options)
1089 {
1090 options.push_back(static_cast<uint32_t>(value.has_value()));
1091 if (value.has_value()) {
1092 options.push_back(static_cast<uint32_t>(value.value()));
1093 } else {
1094 options.push_back(0);
1095 }
1096 }
1097
ParseOuterBorderStyle(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<uint32_t> & values,int32_t argsIndex)1098 void ParseOuterBorderStyle(
1099 ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<uint32_t>& values, int32_t argsIndex)
1100 {
1101 std::optional<BorderStyle> styleLeft;
1102 std::optional<BorderStyle> styleRight;
1103 std::optional<BorderStyle> styleTop;
1104 std::optional<BorderStyle> styleBottom;
1105
1106 auto topArg = runtimeCallInfo->GetCallArgRef(argsIndex);
1107 auto rightArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
1108 auto bottomArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
1109 auto leftArg = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
1110
1111 if (!topArg->IsUndefined() && topArg->IsNumber()) {
1112 styleTop = ConvertBorderStyle(topArg->Int32Value(vm));
1113 }
1114 if (!rightArg->IsUndefined() && rightArg->IsNumber()) {
1115 styleRight = ConvertBorderStyle(rightArg->Int32Value(vm));
1116 }
1117 if (!bottomArg->IsUndefined() && bottomArg->IsNumber()) {
1118 styleBottom = ConvertBorderStyle(bottomArg->Int32Value(vm));
1119 }
1120 if (!leftArg->IsUndefined() && leftArg->IsNumber()) {
1121 styleLeft = ConvertBorderStyle(leftArg->Int32Value(vm));
1122 }
1123
1124 PushOuterBorderStyleVector(styleLeft, values);
1125 PushOuterBorderStyleVector(styleRight, values);
1126 PushOuterBorderStyleVector(styleTop, values);
1127 PushOuterBorderStyleVector(styleBottom, values);
1128 }
1129
ParseOuterBorderDashParam(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values,int32_t argsIndex)1130 void ParseOuterBorderDashParam(ArkUIRuntimeCallInfo *runtimeCallInfo, EcmaVM *vm, std::vector<ArkUI_Float32> &values,
1131 int32_t argsIndex)
1132 {
1133 Local<JSValueRef> leftArgs = runtimeCallInfo->GetCallArgRef(argsIndex);
1134 Local<JSValueRef> rightArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_1);
1135 Local<JSValueRef> topArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_2);
1136 Local<JSValueRef> bottomArgs = runtimeCallInfo->GetCallArgRef(argsIndex + NUM_3);
1137 std::optional<CalcDimension> leftDim;
1138 std::optional<CalcDimension> rightDim;
1139 std::optional<CalcDimension> topDim;
1140 std::optional<CalcDimension> bottomDim;
1141
1142 ArkTSUtils::ParseOuterBorderForDashParams(vm, leftArgs, leftDim);
1143 ArkTSUtils::ParseOuterBorderForDashParams(vm, rightArgs, rightDim);
1144 ArkTSUtils::ParseOuterBorderForDashParams(vm, topArgs, topDim);
1145 ArkTSUtils::ParseOuterBorderForDashParams(vm, bottomArgs, bottomDim);
1146
1147 PushOuterBorderDimensionVector(leftDim, values);
1148 PushOuterBorderDimensionVector(rightDim, values);
1149 PushOuterBorderDimensionVector(topDim, values);
1150 PushOuterBorderDimensionVector(bottomDim, values);
1151 }
1152
SetBackgroundImagePositionAlign(double & value,DimensionUnit & type,double valueContent,const DimensionUnit & typeContent)1153 void SetBackgroundImagePositionAlign(double &value, DimensionUnit &type, double valueContent,
1154 const DimensionUnit &typeContent)
1155 {
1156 value = valueContent;
1157 type = typeContent;
1158 }
1159
ParseBackgroundImagePositionAlign(const int32_t align,double & valueX,double & valueY,DimensionUnit & typeX,DimensionUnit & typeY)1160 void ParseBackgroundImagePositionAlign(const int32_t align, double &valueX, double &valueY, DimensionUnit &typeX,
1161 DimensionUnit &typeY)
1162 {
1163 switch (align) {
1164 case NUM_0:
1165 SetBackgroundImagePositionAlign(valueX, typeX, 0.0, DimensionUnit::PERCENT);
1166 SetBackgroundImagePositionAlign(valueY, typeY, 0.0, DimensionUnit::PERCENT);
1167 break;
1168 case NUM_1:
1169 SetBackgroundImagePositionAlign(valueX, typeX, HALF_DIMENSION, DimensionUnit::PERCENT);
1170 SetBackgroundImagePositionAlign(valueY, typeY, 0.0, DimensionUnit::PERCENT);
1171 break;
1172 case NUM_2:
1173 SetBackgroundImagePositionAlign(valueX, typeX, FULL_DIMENSION, DimensionUnit::PERCENT);
1174 SetBackgroundImagePositionAlign(valueY, typeY, 0.0, DimensionUnit::PERCENT);
1175 break;
1176 case NUM_3:
1177 SetBackgroundImagePositionAlign(valueX, typeX, 0.0, DimensionUnit::PERCENT);
1178 SetBackgroundImagePositionAlign(valueY, typeY, HALF_DIMENSION, DimensionUnit::PERCENT);
1179 break;
1180 case NUM_4:
1181 SetBackgroundImagePositionAlign(valueX, typeX, HALF_DIMENSION, DimensionUnit::PERCENT);
1182 SetBackgroundImagePositionAlign(valueY, typeY, HALF_DIMENSION, DimensionUnit::PERCENT);
1183 break;
1184 case NUM_5:
1185 SetBackgroundImagePositionAlign(valueX, typeX, FULL_DIMENSION, DimensionUnit::PERCENT);
1186 SetBackgroundImagePositionAlign(valueY, typeY, HALF_DIMENSION, DimensionUnit::PERCENT);
1187 break;
1188 case NUM_6:
1189 SetBackgroundImagePositionAlign(valueX, typeX, 0.0, DimensionUnit::PERCENT);
1190 SetBackgroundImagePositionAlign(valueY, typeY, FULL_DIMENSION, DimensionUnit::PERCENT);
1191 break;
1192 case NUM_7:
1193 SetBackgroundImagePositionAlign(valueX, typeX, HALF_DIMENSION, DimensionUnit::PERCENT);
1194 SetBackgroundImagePositionAlign(valueY, typeY, FULL_DIMENSION, DimensionUnit::PERCENT);
1195 break;
1196 case NUM_8:
1197 SetBackgroundImagePositionAlign(valueX, typeX, FULL_DIMENSION, DimensionUnit::PERCENT);
1198 SetBackgroundImagePositionAlign(valueY, typeY, FULL_DIMENSION, DimensionUnit::PERCENT);
1199 break;
1200 default:
1201 break;
1202 }
1203 }
1204
ParseAxisDimensionVp(const EcmaVM * vm,const Local<JSValueRef> & jsValue,CalcDimension & result,bool checkIllegal=false)1205 bool ParseAxisDimensionVp(const EcmaVM *vm, const Local<JSValueRef> &jsValue, CalcDimension &result,
1206 bool checkIllegal = false)
1207 {
1208 if (jsValue->IsNumber()) {
1209 result = Dimension(jsValue->ToNumber(vm)->Value(), DimensionUnit::VP);
1210 return true;
1211 }
1212 if (jsValue->IsString(vm)) {
1213 if (checkIllegal) {
1214 return StringUtils::StringToDimensionWithUnitNG(jsValue->ToString(vm)->ToString(vm), result,
1215 DimensionUnit::VP);
1216 }
1217 result = StringUtils::StringToCalcDimension(jsValue->ToString(vm)->ToString(vm), false, DimensionUnit::VP);
1218 return true;
1219 }
1220 return false;
1221 }
1222
ParseDirection(EcmaVM * vm,const Local<JSValueRef> & directionArg,float & value)1223 void ParseDirection(EcmaVM *vm, const Local<JSValueRef> &directionArg, float &value)
1224 {
1225 if (directionArg->IsNumber()) {
1226 value = directionArg->ToNumber(vm)->Value();
1227 }
1228 }
1229
GetJsAngle(const EcmaVM * vm,const Local<JSValueRef> & angleArg,std::optional<float> & angle)1230 void GetJsAngle(const EcmaVM* vm, const Local<JSValueRef>& angleArg, std::optional<float>& angle)
1231 {
1232 if (angleArg->IsString(vm)) {
1233 angle = static_cast<float>(StringUtils::StringToDegree(angleArg->ToString(vm)->ToString(vm)));
1234 } else if (angleArg->IsNumber()) {
1235 angle = static_cast<float>(angleArg->ToNumber(vm)->Value());
1236 } else {
1237 LOGE("Invalid value type");
1238 }
1239 }
1240
ParseCenterDimension(const EcmaVM * vm,const Local<JSValueRef> & centerArg,CalcDimension & centerDimension)1241 void ParseCenterDimension(const EcmaVM* vm, const Local<JSValueRef>& centerArg, CalcDimension& centerDimension)
1242 {
1243 if (!ArkTSUtils::ParseJsDimensionVp(vm, centerArg, centerDimension, false)) {
1244 centerDimension = Dimension(0.5f, DimensionUnit::PERCENT);
1245 }
1246 }
1247
ParseRotate(ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUI_Float32 values[],int units[],int valuesLength,int unitsLength)1248 bool ParseRotate(ArkUIRuntimeCallInfo *runtimeCallInfo, ArkUI_Float32 values[], int units[],
1249 int valuesLength, int unitsLength)
1250 {
1251 if (valuesLength != SIZE_OF_EIGHT || unitsLength != SIZE_OF_THREE) {
1252 return false;
1253 }
1254 EcmaVM *vm = runtimeCallInfo->GetVM();
1255 Local<JSValueRef> xDirectionArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1256 Local<JSValueRef> yDirectionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1257 Local<JSValueRef> zDirectionArg = runtimeCallInfo->GetCallArgRef(NUM_3);
1258 Local<JSValueRef> angleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
1259 Local<JSValueRef> centerXArg = runtimeCallInfo->GetCallArgRef(NUM_5);
1260 Local<JSValueRef> centerYArg = runtimeCallInfo->GetCallArgRef(NUM_6);
1261 Local<JSValueRef> centerZArg = runtimeCallInfo->GetCallArgRef(NUM_7);
1262 Local<JSValueRef> perspectiveArg = runtimeCallInfo->GetCallArgRef(NUM_8);
1263 float xDirection = 0.0f;
1264 float yDirection = 0.0f;
1265 float zDirection = 0.0f;
1266 float angle = 0.0f;
1267 std::optional<float> angleOptional;
1268 CalcDimension centerX = 0.5_pct;
1269 CalcDimension centerY = 0.5_pct;
1270 CalcDimension centerZ = CalcDimension(0.0f, DimensionUnit::VP);
1271 GetJsAngle(vm, angleArg, angleOptional);
1272 if (!angleOptional) {
1273 return false;
1274 }
1275 angle = angleOptional.value();
1276 double perspective = 0.0;
1277 if (!xDirectionArg->IsNumber() && !yDirectionArg->IsNumber() && !zDirectionArg->IsNumber()) {
1278 zDirection = 1.0f;
1279 }
1280 ParseDirection(vm, xDirectionArg, xDirection);
1281 ParseDirection(vm, yDirectionArg, yDirection);
1282 ParseDirection(vm, zDirectionArg, zDirection);
1283 ParseCenterDimension(vm, centerXArg, centerX);
1284 ParseCenterDimension(vm, centerYArg, centerY);
1285 ParseCenterDimension(vm, centerZArg, centerZ);
1286 ArkTSUtils::ParseJsDouble(vm, perspectiveArg, perspective);
1287 values[NUM_0] = static_cast<ArkUI_Float32>(centerX.Value());
1288 units[NUM_0] = static_cast<int>(centerX.Unit());
1289 values[NUM_1] = static_cast<ArkUI_Float32>(centerY.Value());
1290 units[NUM_1] = static_cast<int>(centerY.Unit());
1291 values[NUM_2] = static_cast<ArkUI_Float32>(centerZ.Value());
1292 units[NUM_2] = static_cast<int>(centerZ.Unit());
1293 values[NUM_3] = static_cast<ArkUI_Float32>(xDirection);
1294 values[NUM_4] = static_cast<ArkUI_Float32>(yDirection);
1295 values[NUM_5] = static_cast<ArkUI_Float32>(zDirection);
1296 values[NUM_6] = static_cast<ArkUI_Float32>(angle);
1297 values[NUM_7] = static_cast<ArkUI_Float32>(perspective);
1298 return true;
1299 }
1300
ParseBlurOption(const EcmaVM * vm,const Local<JSValueRef> blurOptionsArg,BlurOption & blurOption)1301 void ParseBlurOption(const EcmaVM* vm, const Local<JSValueRef> blurOptionsArg, BlurOption& blurOption)
1302 {
1303 if (blurOptionsArg->IsArray(vm)) {
1304 Local<panda::ArrayRef> params = static_cast<Local<panda::ArrayRef>>(blurOptionsArg);
1305 auto grey1 = params->GetValueAt(vm, blurOptionsArg, 0)->Uint32Value(vm);
1306 auto grey2 = params->GetValueAt(vm, blurOptionsArg, 1)->Uint32Value(vm);
1307 std::vector<float> greyVec(2);
1308 greyVec[0] = grey1;
1309 greyVec[1] = grey2;
1310 blurOption.grayscale = greyVec;
1311 }
1312 }
1313
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)1314 void ParseDynamicBrightnessOption(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm,
1315 ArkUI_Float32& rate, ArkUI_Float32& lightUpDegree, ArkUI_Float32& cubicCoeff, ArkUI_Float32& quadCoeff,
1316 ArkUI_Float32& saturation, std::vector<float>& posRGB, std::vector<float>& negRGB, ArkUI_Float32& fraction)
1317 {
1318 Local<JSValueRef> rateArg = runtimeCallInfo->GetCallArgRef(1);
1319 Local<JSValueRef> lightUpDegreeArg = runtimeCallInfo->GetCallArgRef(2);
1320 Local<JSValueRef> cubicCoeffArg = runtimeCallInfo->GetCallArgRef(3);
1321 Local<JSValueRef> quadCoeffArg = runtimeCallInfo->GetCallArgRef(4);
1322 Local<JSValueRef> saturationArg = runtimeCallInfo->GetCallArgRef(5);
1323 Local<JSValueRef> posRGBArg = runtimeCallInfo->GetCallArgRef(6);
1324 Local<JSValueRef> negRGBArg = runtimeCallInfo->GetCallArgRef(7);
1325 Local<JSValueRef> fractionArg = runtimeCallInfo->GetCallArgRef(8);
1326 if (rateArg->IsNumber()) {
1327 rate = rateArg->ToNumber(vm)->Value();
1328 }
1329 if (lightUpDegreeArg->IsNumber()) {
1330 lightUpDegree = lightUpDegreeArg->ToNumber(vm)->Value();
1331 }
1332 if (cubicCoeffArg->IsNumber()) {
1333 cubicCoeff = cubicCoeffArg->ToNumber(vm)->Value();
1334 }
1335 if (quadCoeffArg->IsNumber()) {
1336 quadCoeff = quadCoeffArg->ToNumber(vm)->Value();
1337 }
1338 if (saturationArg->IsNumber()) {
1339 saturation = saturationArg->ToNumber(vm)->Value();
1340 }
1341 if (posRGBArg->IsArray(vm)) {
1342 Local<panda::ArrayRef> params = static_cast<Local<panda::ArrayRef>>(posRGBArg);
1343 auto r = params->GetValueAt(vm, posRGBArg, 0)->Uint32Value(vm);
1344 auto g = params->GetValueAt(vm, posRGBArg, 1)->Uint32Value(vm);
1345 auto b = params->GetValueAt(vm, posRGBArg, 2)->Uint32Value(vm);
1346 posRGB[0] = r;
1347 posRGB[1] = g;
1348 posRGB[2] = b;
1349 }
1350 if (negRGBArg->IsArray(vm)) {
1351 Local<panda::ArrayRef> params = static_cast<Local<panda::ArrayRef>>(negRGBArg);
1352 auto r = params->GetValueAt(vm, negRGBArg, 0)->Uint32Value(vm);
1353 auto g = params->GetValueAt(vm, negRGBArg, 1)->Uint32Value(vm);
1354 auto b = params->GetValueAt(vm, negRGBArg, 2)->Uint32Value(vm);
1355 negRGB[0] = r;
1356 negRGB[1] = g;
1357 negRGB[2] = b;
1358 }
1359 if (fractionArg->IsNumber()) {
1360 fraction = fractionArg->ToNumber(vm)->Value();
1361 }
1362 }
1363
ParseCalcDimension(const EcmaVM * vm,ArkUINodeHandle node,const Local<JSValueRef> & value,CalcDimension & result,bool isWidth)1364 bool ParseCalcDimension(const EcmaVM* vm,
1365 ArkUINodeHandle node, const Local<JSValueRef>& value, CalcDimension& result, bool isWidth)
1366 {
1367 CHECK_NULL_RETURN(vm, false);
1368 bool undefined = value->IsUndefined();
1369 if (undefined) {
1370 GetArkUINodeModifiers()->getCommonModifier()->clearWidthOrHeight(node, isWidth);
1371 return true;
1372 }
1373 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
1374 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, value, result)) {
1375 GetArkUINodeModifiers()->getCommonModifier()->clearWidthOrHeight(node, isWidth);
1376 return false;
1377 }
1378 } else if (!ArkTSUtils::ParseJsDimensionVp(vm, value, result)) {
1379 return false;
1380 }
1381
1382 if (LessNotEqual(result.Value(), 0.0)) {
1383 result.SetValue(0.0);
1384 }
1385 std::string calc = result.CalcValue();
1386 if (isWidth) {
1387 GetArkUINodeModifiers()->getCommonModifier()->setWidth(
1388 node, result.Value(), static_cast<int32_t>(result.Unit()), calc.c_str());
1389 } else {
1390 GetArkUINodeModifiers()->getCommonModifier()->setHeight(
1391 node, result.Value(), static_cast<int32_t>(result.Unit()), calc.c_str());
1392 }
1393 return true;
1394 }
1395
ParseResizableCalcDimensions(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count,std::vector<std::optional<CalcDimension>> & results,const CalcDimension & defValue)1396 void ParseResizableCalcDimensions(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count,
1397 std::vector<std::optional<CalcDimension>>& results, const CalcDimension& defValue)
1398 {
1399 auto end = offset + count;
1400 auto argsNumber = runtimeCallInfo->GetArgsNumber();
1401 if (end > argsNumber) {
1402 return;
1403 }
1404 CalcDimension defaultDimension(defValue);
1405 EcmaVM* vm = runtimeCallInfo->GetVM();
1406 for (uint32_t index = offset; index < end; index++) {
1407 auto arg = runtimeCallInfo->GetCallArgRef(index);
1408 std::optional<CalcDimension> optCalcDimension;
1409 CalcDimension dimension(defValue);
1410 if (ArkTSUtils::ParseJsDimensionVp(vm, arg, dimension, false)) {
1411 optCalcDimension = dimension;
1412 } else {
1413 optCalcDimension = defaultDimension;
1414 }
1415 results.push_back(optCalcDimension);
1416 }
1417 }
1418
ParseJsAlignRule(const EcmaVM * vm,const Local<JSValueRef> & arg,std::string & anchor,ArkUI_Int32 & direction)1419 bool ParseJsAlignRule(const EcmaVM* vm, const Local<JSValueRef> &arg, std::string& anchor, ArkUI_Int32 &direction)
1420 {
1421 if (arg->IsString(vm)) {
1422 std::string directionString = arg->ToString(vm)->ToString(vm);
1423 if (directionString.empty()) {
1424 return false;
1425 }
1426 size_t pos = directionString.find('|');
1427 if (pos == std::string::npos) {
1428 return false;
1429 }
1430 char* endPtr = nullptr;
1431 long alignValue = std::strtol(directionString.substr(0, pos).c_str(), &endPtr, 10);
1432 direction = static_cast<int8_t>(alignValue);
1433 anchor = directionString.substr(pos + 1);
1434 return true;
1435 }
1436 return false;
1437 }
1438
ParseResponseRegion(const EcmaVM * vm,const Local<JSValueRef> & jsValue,ArkUI_Float32 regionValues[],int32_t regionUnits[],int32_t length)1439 bool ParseResponseRegion(const EcmaVM* vm, const Local<JSValueRef>& jsValue, ArkUI_Float32 regionValues[],
1440 int32_t regionUnits[], int32_t length)
1441 {
1442 if (jsValue->IsUndefined() || !jsValue->IsArray(vm)) {
1443 return false;
1444 }
1445
1446 Local<panda::ArrayRef> transArray = static_cast<Local<panda::ArrayRef>>(jsValue);
1447 for (int32_t i = 0; i < length; i = i + NUM_4) {
1448 Local<JSValueRef> x = transArray->GetValueAt(vm, jsValue, i + NUM_0);
1449 Local<JSValueRef> y = transArray->GetValueAt(vm, jsValue, i + NUM_1);
1450 Local<JSValueRef> width = transArray->GetValueAt(vm, jsValue, i + NUM_2);
1451 Local<JSValueRef> height = transArray->GetValueAt(vm, jsValue, i + NUM_3);
1452 CalcDimension xDimen = CalcDimension(0.0, DimensionUnit::VP);
1453 CalcDimension yDimen = CalcDimension(0.0, DimensionUnit::VP);
1454 CalcDimension widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
1455 CalcDimension heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
1456 auto s1 = width->ToString(vm)->ToString(vm);
1457 auto s2 = height->ToString(vm)->ToString(vm);
1458 if (s1.find('-') != std::string::npos) {
1459 width = ToJSValue("100%");
1460 }
1461 if (s2.find('-') != std::string::npos) {
1462 height = ToJSValue("100%");
1463 }
1464 if (!ArkTSUtils::ParseJsDimensionNG(vm, x, xDimen, DimensionUnit::VP)) {
1465 xDimen = CalcDimension(0.0, DimensionUnit::VP);
1466 }
1467 if (!ArkTSUtils::ParseJsDimensionNG(vm, y, yDimen, DimensionUnit::VP)) {
1468 yDimen = CalcDimension(0.0, DimensionUnit::VP);
1469 }
1470 if (!ArkTSUtils::ParseJsDimensionNG(vm, width, widthDimen, DimensionUnit::VP)) {
1471 widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
1472 }
1473 if (!ArkTSUtils::ParseJsDimensionNG(vm, height, heightDimen, DimensionUnit::VP)) {
1474 heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
1475 }
1476 regionValues[i + NUM_0] = static_cast<ArkUI_Float32>(xDimen.Value());
1477 regionUnits[i + NUM_0] = static_cast<int32_t>(xDimen.Unit());
1478 regionValues[i + NUM_1] = static_cast<ArkUI_Float32>(yDimen.Value());
1479 regionUnits[i + NUM_1] = static_cast<int32_t>(yDimen.Unit());
1480 regionValues[i + NUM_2] = static_cast<ArkUI_Float32>(widthDimen.Value());
1481 regionUnits[i + NUM_2] = static_cast<int32_t>(widthDimen.Unit());
1482 regionValues[i + NUM_3] = static_cast<ArkUI_Float32>(heightDimen.Value());
1483 regionUnits[i + NUM_3] = static_cast<int32_t>(heightDimen.Unit());
1484 }
1485 return true;
1486 }
1487
ParseTransitionCallback(const JSRef<JSFunc> & jsFunc,const JSExecutionContext & context,FrameNode * node)1488 std::function<void(bool)> ParseTransitionCallback(
1489 const JSRef<JSFunc>& jsFunc, const JSExecutionContext& context, FrameNode* node)
1490 {
1491 auto jsFuncFinish = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(jsFunc));
1492 auto targetNode = AceType::WeakClaim(node);
1493 auto finishCallback = [execCtx = context, jsFuncFinish, targetNode](bool isTransitionIn) {
1494 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
1495 NG::PipelineContext::SetCallBackNode(targetNode);
1496 JSRef<JSVal> newJSVal = JSRef<JSVal>::Make(ToJSValue(isTransitionIn));
1497 jsFuncFinish->ExecuteJS(1, &newJSVal);
1498 };
1499 return finishCallback;
1500 }
1501
ParseColorMetricsToColor(const EcmaVM * vm,const Local<JSValueRef> & jsValue,Color & result)1502 bool ParseColorMetricsToColor(const EcmaVM *vm, const Local<JSValueRef> &jsValue, Color& result)
1503 {
1504 if (!jsValue->IsObject(vm)) {
1505 return false;
1506 }
1507 auto obj = jsValue->ToObject(vm);
1508 auto toNumericProp = obj->Get(vm, "toNumeric");
1509 if (toNumericProp->IsFunction(vm)) {
1510 panda::Local<panda::FunctionRef> func = toNumericProp;
1511 auto colorVal = func->Call(vm, obj, nullptr, 0);
1512 result.SetValue(colorVal->Uint32Value(vm));
1513 return true;
1514 }
1515 return false;
1516 }
1517
1518 const std::vector<AccessibilitySamePageMode> PAGE_MODE_TYPE = { AccessibilitySamePageMode::SEMI_SILENT,
1519 AccessibilitySamePageMode::FULL_SILENT };
1520 const std::vector<FocusDrawLevel> FOCUS_DRAW_LEVEL = { FocusDrawLevel::SELF, FocusDrawLevel::TOP };
1521 } // namespace
1522
SetBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1523 ArkUINativeModuleValue CommonBridge::SetBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1524 {
1525 EcmaVM *vm = runtimeCallInfo->GetVM();
1526 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1527 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1528 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
1529 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1530 Color color;
1531 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
1532 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundColor(nativeNode);
1533 } else {
1534 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundColor(nativeNode, color.GetValue());
1535 }
1536 return panda::JSValueRef::Undefined(vm);
1537 }
1538
ResetBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1539 ArkUINativeModuleValue CommonBridge::ResetBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1540 {
1541 EcmaVM *vm = runtimeCallInfo->GetVM();
1542 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1543 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1544 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1545 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundColor(nativeNode);
1546 return panda::JSValueRef::Undefined(vm);
1547 }
1548
SetBorderWidthArray(const EcmaVM * vm,const Local<JSValueRef> & args,ArkUI_Float32 values[],int units[],int index)1549 void SetBorderWidthArray(const EcmaVM* vm, const Local<JSValueRef>& args, ArkUI_Float32 values[],
1550 int units[], int index)
1551 {
1552 CalcDimension borderDimension;
1553 if (!args->IsUndefined()) {
1554 if (ArkTSUtils::ParseAllBorder(vm, args, borderDimension)) {
1555 values[index] = borderDimension.Value();
1556 units[index] = static_cast<int>(borderDimension.Unit());
1557 } else {
1558 values[index] = 0;
1559 units[index] = static_cast<int>(DimensionUnit::VP);
1560 }
1561 } else {
1562 values[index] = -1;
1563 units[index] = static_cast<int>(DimensionUnit::INVALID);
1564 }
1565 }
1566
ParseLocalizedBorderWidth(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen)1567 bool ParseLocalizedBorderWidth(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen)
1568 {
1569 if (ArkTSUtils::ParseJsLengthMetrics(vm, value, dimen)) {
1570 if (LessOrEqual(dimen.Value(), 0.0)) {
1571 dimen.SetValue(0.0);
1572 dimen.SetUnit(DimensionUnit::VP);
1573 }
1574 return true;
1575 }
1576 return false;
1577 }
1578
SetBorderWidthArrayByDimen(CalcDimension & borderDimension,ArkUI_Float32 values[],int units[],int index)1579 void SetBorderWidthArrayByDimen(CalcDimension& borderDimension, ArkUI_Float32 values[], int units[], int index)
1580 {
1581 values[index] = borderDimension.Value();
1582 units[index] = static_cast<int>(borderDimension.Unit());
1583 }
1584
SetBorderWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1585 ArkUINativeModuleValue CommonBridge::SetBorderWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1586 {
1587 EcmaVM* vm = runtimeCallInfo->GetVM();
1588 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1589 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1590 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1591 Local<JSValueRef> topArgs = runtimeCallInfo->GetCallArgRef(NUM_1);
1592 Local<JSValueRef> rightArgs = runtimeCallInfo->GetCallArgRef(NUM_2);
1593 Local<JSValueRef> bottomArgs = runtimeCallInfo->GetCallArgRef(NUM_3);
1594 Local<JSValueRef> leftArgs = runtimeCallInfo->GetCallArgRef(NUM_4);
1595 if (leftArgs->IsUndefined() && rightArgs->IsUndefined() && topArgs->IsUndefined() && bottomArgs->IsUndefined()) {
1596 GetArkUINodeModifiers()->getCommonModifier()->resetBorderWidth(nativeNode);
1597 return panda::JSValueRef::Undefined(vm);
1598 }
1599
1600 CalcDimension top;
1601 CalcDimension right;
1602 CalcDimension bottom;
1603 CalcDimension left;
1604 bool isLengthMetrics = false;
1605
1606 if (topArgs->IsObject(vm)) {
1607 isLengthMetrics |= ParseLocalizedBorderWidth(vm, topArgs, top);
1608 }
1609 if (rightArgs->IsObject(vm)) {
1610 isLengthMetrics |= ParseLocalizedBorderWidth(vm, rightArgs, right);
1611 }
1612 if (bottomArgs->IsObject(vm)) {
1613 isLengthMetrics |= ParseLocalizedBorderWidth(vm, bottomArgs, bottom);
1614 }
1615 if (leftArgs->IsObject(vm)) {
1616 isLengthMetrics |= ParseLocalizedBorderWidth(vm, leftArgs, left);
1617 }
1618
1619 uint32_t size = SIZE_OF_FOUR;
1620 ArkUI_Float32 values[size];
1621 int units[size];
1622
1623 if (isLengthMetrics) {
1624 auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
1625 SetBorderWidthArrayByDimen(top, values, units, NUM_0);
1626 SetBorderWidthArrayByDimen(isRightToLeft ? left : right, values, units, NUM_1);
1627 SetBorderWidthArrayByDimen(bottom, values, units, NUM_2);
1628 SetBorderWidthArrayByDimen(isRightToLeft ? right : left, values, units, NUM_3);
1629 } else {
1630 SetBorderWidthArray(vm, topArgs, values, units, NUM_0);
1631 SetBorderWidthArray(vm, rightArgs, values, units, NUM_1);
1632 SetBorderWidthArray(vm, bottomArgs, values, units, NUM_2);
1633 SetBorderWidthArray(vm, leftArgs, values, units, NUM_3);
1634 }
1635
1636 GetArkUINodeModifiers()->getCommonModifier()->setBorderWidth(nativeNode, values, units, size);
1637 return panda::JSValueRef::Undefined(vm);
1638 }
1639
ResetBorderWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1640 ArkUINativeModuleValue CommonBridge::ResetBorderWidth(ArkUIRuntimeCallInfo *runtimeCallInfo)
1641 {
1642 EcmaVM *vm = runtimeCallInfo->GetVM();
1643 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1644 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1645 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1646 GetArkUINodeModifiers()->getCommonModifier()->resetBorderWidth(nativeNode);
1647 return panda::JSValueRef::Undefined(vm);
1648 }
1649
ParseMirrorDimen(ArkUI_Float32 values[],int units[],int idx,CalcDimension & calcDimen)1650 void ParseMirrorDimen(ArkUI_Float32 values[], int units[], int idx, CalcDimension& calcDimen)
1651 {
1652 values[idx] = calcDimen.Value();
1653 units[idx] = static_cast<int>(calcDimen.Unit());
1654 }
1655
SetBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1656 ArkUINativeModuleValue CommonBridge::SetBorderRadius(ArkUIRuntimeCallInfo *runtimeCallInfo)
1657 {
1658 EcmaVM *vm = runtimeCallInfo->GetVM();
1659 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1660 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1661 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1662 Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(NUM_1);
1663 Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(NUM_2);
1664 Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(NUM_3);
1665 Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(NUM_4);
1666 if (topLeftArgs->IsUndefined() && topRightArgs->IsUndefined() && bottomLeftArgs->IsUndefined() &&
1667 bottomRightArgs->IsUndefined()) {
1668 GetArkUINodeModifiers()->getCommonModifier()->resetBorderRadius(nativeNode);
1669 return panda::JSValueRef::Undefined(vm);
1670 }
1671 CalcDimension topLeft;
1672 CalcDimension topRight;
1673 CalcDimension bottomLeft;
1674 CalcDimension bottomRight;
1675 bool isLengthMetrics = false;
1676 if (topLeftArgs->IsObject(vm)) {
1677 isLengthMetrics |= ParseLocalizedBorderRadius(vm, topLeftArgs, topLeft);
1678 }
1679 if (topRightArgs->IsObject(vm)) {
1680 isLengthMetrics |= ParseLocalizedBorderRadius(vm, topRightArgs, topRight);
1681 }
1682 if (bottomLeftArgs->IsObject(vm)) {
1683 isLengthMetrics |= ParseLocalizedBorderRadius(vm, bottomLeftArgs, bottomLeft);
1684 }
1685 if (bottomRightArgs->IsObject(vm)) {
1686 isLengthMetrics |= ParseLocalizedBorderRadius(vm, bottomRightArgs, bottomRight);
1687 }
1688 if (!isLengthMetrics) {
1689 ArkTSUtils::ParseAllBorder(vm, topLeftArgs, topLeft);
1690 ArkTSUtils::ParseAllBorder(vm, topRightArgs, topRight);
1691 ArkTSUtils::ParseAllBorder(vm, bottomLeftArgs, bottomLeft);
1692 ArkTSUtils::ParseAllBorder(vm, bottomRightArgs, bottomRight);
1693 }
1694 ArkUI_Float32 values[SIZE_OF_FOUR];
1695 int units[SIZE_OF_FOUR];
1696 bool isMirror = isLengthMetrics && AceApplicationInfo::GetInstance().IsRightToLeft();
1697 ParseMirrorDimen(values, units, NUM_0, isMirror ? topRight : topLeft);
1698 ParseMirrorDimen(values, units, NUM_1, isMirror ? topLeft : topRight);
1699 ParseMirrorDimen(values, units, NUM_2, isMirror ? bottomRight : bottomLeft);
1700 ParseMirrorDimen(values, units, NUM_3, isMirror ? bottomLeft : bottomRight);
1701 GetArkUINodeModifiers()->getCommonModifier()->setBorderRadius(nativeNode, values, units, SIZE_OF_FOUR);
1702 return panda::JSValueRef::Undefined(vm);
1703 }
1704
ResetBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1705 ArkUINativeModuleValue CommonBridge::ResetBorderRadius(ArkUIRuntimeCallInfo *runtimeCallInfo)
1706 {
1707 EcmaVM *vm = runtimeCallInfo->GetVM();
1708 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1709 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1710 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1711 GetArkUINodeModifiers()->getCommonModifier()->resetBorderRadius(nativeNode);
1712 return panda::JSValueRef::Undefined(vm);
1713 }
1714
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1715 ArkUINativeModuleValue CommonBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1716 {
1717 EcmaVM* vm = runtimeCallInfo->GetVM();
1718 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1719 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1720 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1721 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
1722
1723 CalcDimension width;
1724 std::string calcStr;
1725 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, width)) {
1726 GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
1727 } else {
1728 if (LessNotEqual(width.Value(), 0.0)) {
1729 if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
1730 GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
1731 return panda::JSValueRef::Undefined(vm);
1732 }
1733 width.SetValue(0.0);
1734 }
1735
1736 if (width.Unit() == DimensionUnit::CALC) {
1737 GetArkUINodeModifiers()->getCommonModifier()->setWidth(
1738 nativeNode, 0, static_cast<int32_t>(width.Unit()), width.CalcValue().c_str());
1739 } else {
1740 GetArkUINodeModifiers()->getCommonModifier()->setWidth(
1741 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()), calcStr.c_str());
1742 }
1743 }
1744 return panda::JSValueRef::Undefined(vm);
1745 }
1746
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1747 ArkUINativeModuleValue CommonBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1748 {
1749 EcmaVM* vm = runtimeCallInfo->GetVM();
1750 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1751 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1752 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1753 GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
1754 return panda::JSValueRef::Undefined(vm);
1755 }
1756
SetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)1757 ArkUINativeModuleValue CommonBridge::SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
1758 {
1759 EcmaVM* vm = runtimeCallInfo->GetVM();
1760 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1761 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1762 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1763 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
1764 CalcDimension height;
1765 std::string calcStr;
1766 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height)) {
1767 GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
1768 } else {
1769 if (LessNotEqual(height.Value(), 0.0)) {
1770 if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
1771 GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
1772 return panda::JSValueRef::Undefined(vm);
1773 }
1774 height.SetValue(0.0);
1775 }
1776 if (height.Unit() == DimensionUnit::CALC) {
1777 GetArkUINodeModifiers()->getCommonModifier()->setHeight(
1778 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), height.CalcValue().c_str());
1779 } else {
1780 GetArkUINodeModifiers()->getCommonModifier()->setHeight(
1781 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), calcStr.c_str());
1782 }
1783 }
1784 return panda::JSValueRef::Undefined(vm);
1785 }
1786
ResetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)1787 ArkUINativeModuleValue CommonBridge::ResetHeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
1788 {
1789 EcmaVM *vm = runtimeCallInfo->GetVM();
1790 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1791 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1792 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1793 GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
1794 return panda::JSValueRef::Undefined(vm);
1795 }
1796
SetPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)1797 ArkUINativeModuleValue CommonBridge::SetPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
1798 {
1799 EcmaVM* vm = runtimeCallInfo->GetVM();
1800 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1801 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1802 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1803 bool useEdges = runtimeCallInfo->GetCallArgRef(NUM_1)->ToBoolean(vm)->Value();
1804 std::vector<ArkUIStringAndFloat> options;
1805 std::vector<std::optional<CalcDimension>> edges;
1806
1807 if (useEdges) {
1808 ParseResult res = ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_4, edges, CalcDimension(0.0));
1809 if (res == ParseResult::LENGTHMETRICS_SUCCESS && AceApplicationInfo::GetInstance().IsRightToLeft()) {
1810 // Swap left and right
1811 std::swap(edges[NUM_1], edges[NUM_3]);
1812 }
1813 PushDimensionsToVector(options, edges);
1814 GetArkUINodeModifiers()->getCommonModifier()->setPositionEdges(nativeNode, useEdges, options.data());
1815 } else {
1816 ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_2, edges, CalcDimension(0.0));
1817 PushDimensionsToVector(options, edges);
1818 GetArkUINodeModifiers()->getCommonModifier()->setPositionEdges(nativeNode, useEdges, options.data());
1819 }
1820 return panda::JSValueRef::Undefined(vm);
1821 }
1822
ResetPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)1823 ArkUINativeModuleValue CommonBridge::ResetPosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
1824 {
1825 EcmaVM *vm = runtimeCallInfo->GetVM();
1826 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1827 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1828 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1829 GetArkUINodeModifiers()->getCommonModifier()->resetPositionEdges(nativeNode);
1830 return panda::JSValueRef::Undefined(vm);
1831 }
1832
SetTransform(ArkUIRuntimeCallInfo * runtimeCallInfo)1833 ArkUINativeModuleValue CommonBridge::SetTransform(ArkUIRuntimeCallInfo *runtimeCallInfo)
1834 {
1835 EcmaVM *vm = runtimeCallInfo->GetVM();
1836 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1837 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1838 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1839 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
1840
1841 if (!jsValue->IsArray(vm)) {
1842 GetArkUINodeModifiers()->getCommonModifier()->resetTransform(nativeNode);
1843 return panda::JSValueRef::Undefined(vm);
1844 }
1845
1846 const auto matrix4Len = Matrix4::DIMENSION * Matrix4::DIMENSION;
1847 float matrix[matrix4Len];
1848 Local<panda::ArrayRef> transArray = static_cast<Local<panda::ArrayRef>>(jsValue);
1849 for (size_t i = 0; i < transArray->Length(vm); i++) {
1850 Local<JSValueRef> value = transArray->GetValueAt(vm, jsValue, i);
1851 matrix[i] = value->ToNumber(vm)->Value();
1852 }
1853 GetArkUINodeModifiers()->getCommonModifier()->setTransform(nativeNode, matrix, matrix4Len);
1854 return panda::JSValueRef::Undefined(vm);
1855 }
1856
ResetTransform(ArkUIRuntimeCallInfo * runtimeCallInfo)1857 ArkUINativeModuleValue CommonBridge::ResetTransform(ArkUIRuntimeCallInfo *runtimeCallInfo)
1858 {
1859 EcmaVM *vm = runtimeCallInfo->GetVM();
1860 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1861 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1862 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1863
1864 GetArkUINodeModifiers()->getCommonModifier()->resetTransform(nativeNode);
1865 return panda::JSValueRef::Undefined(vm);
1866 }
1867
SetBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1868 ArkUINativeModuleValue CommonBridge::SetBorderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1869 {
1870 EcmaVM *vm = runtimeCallInfo->GetVM();
1871 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1872 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
1873 Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(NUM_1);
1874 Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
1875 Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(NUM_3);
1876 Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(NUM_4);
1877 Local<JSValueRef> isLocalizedArg = runtimeCallInfo->GetCallArgRef(NUM_5);
1878 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1879 auto isLocalized = (isLocalizedArg->IsBoolean()) ? isLocalizedArg->ToBoolean(vm)->Value() : false;
1880
1881 Color topColor;
1882 Color rightColor;
1883 Color bottomColor;
1884 Color leftColor;
1885
1886 if (!ArkTSUtils::ParseJsColorAlpha(vm, topArg, topColor)) {
1887 topColor.SetValue(COLOR_ALPHA_VALUE);
1888 }
1889 if (!ArkTSUtils::ParseJsColorAlpha(vm, rightArg, rightColor)) {
1890 rightColor.SetValue(COLOR_ALPHA_VALUE);
1891 }
1892 if (!ArkTSUtils::ParseJsColorAlpha(vm, bottomArg, bottomColor)) {
1893 bottomColor.SetValue(COLOR_ALPHA_VALUE);
1894 }
1895 if (!ArkTSUtils::ParseJsColorAlpha(vm, leftArg, leftColor)) {
1896 leftColor.SetValue(COLOR_ALPHA_VALUE);
1897 }
1898 auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
1899 GetArkUINodeModifiers()->getCommonModifier()->setBorderColor(nativeNode,
1900 topColor.GetValue(),
1901 (isRightToLeft && isLocalized) ? leftColor.GetValue() : rightColor.GetValue(),
1902 bottomColor.GetValue(),
1903 (isRightToLeft && isLocalized) ? rightColor.GetValue() : leftColor.GetValue());
1904 return panda::JSValueRef::Undefined(vm);
1905 }
1906
ResetBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1907 ArkUINativeModuleValue CommonBridge::ResetBorderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
1908 {
1909 EcmaVM *vm = runtimeCallInfo->GetVM();
1910 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1911 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1912 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1913 GetArkUINodeModifiers()->getCommonModifier()->resetBorderColor(nativeNode);
1914 return panda::JSValueRef::Undefined(vm);
1915 }
1916
SetOutlineColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1917 ArkUINativeModuleValue CommonBridge::SetOutlineColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
1918 {
1919 EcmaVM* vm = runtimeCallInfo->GetVM();
1920 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1921 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1922 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1923 std::vector<uint32_t> colorOptions;
1924 ParseOuterBorderColor(runtimeCallInfo, vm, colorOptions, NUM_1);
1925 GetArkUINodeModifiers()->getCommonModifier()->setOutlineColor(
1926 nativeNode, colorOptions.data(), colorOptions.size());
1927 return panda::JSValueRef::Undefined(vm);
1928 }
1929
ResetOutlineColor(ArkUIRuntimeCallInfo * runtimeCallInfo)1930 ArkUINativeModuleValue CommonBridge::ResetOutlineColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
1931 {
1932 EcmaVM* vm = runtimeCallInfo->GetVM();
1933 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1934 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1935 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1936 GetArkUINodeModifiers()->getCommonModifier()->resetOutlineColor(nativeNode);
1937 return panda::JSValueRef::Undefined(vm);
1938 }
1939
SetOutlineRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1940 ArkUINativeModuleValue CommonBridge::SetOutlineRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
1941 {
1942 EcmaVM* vm = runtimeCallInfo->GetVM();
1943 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1944 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1945 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1946 std::vector<ArkUI_Float32> radiusOptions;
1947 ParseOuterBorderRadius(runtimeCallInfo, vm, radiusOptions, NUM_1);
1948 GetArkUINodeModifiers()->getCommonModifier()->setOutlineRadius(
1949 nativeNode, radiusOptions.data(), radiusOptions.size());
1950 return panda::JSValueRef::Undefined(vm);
1951 }
1952
ResetOutlineRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)1953 ArkUINativeModuleValue CommonBridge::ResetOutlineRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
1954 {
1955 EcmaVM* vm = runtimeCallInfo->GetVM();
1956 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1957 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1958 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1959 GetArkUINodeModifiers()->getCommonModifier()->resetOutlineRadius(nativeNode);
1960 return panda::JSValueRef::Undefined(vm);
1961 }
1962
SetOutlineWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1963 ArkUINativeModuleValue CommonBridge::SetOutlineWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1964 {
1965 EcmaVM* vm = runtimeCallInfo->GetVM();
1966 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1967 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1968 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1969 std::vector<ArkUI_Float32> widthOptions;
1970 ParseOuterBorderWidth(runtimeCallInfo, vm, widthOptions);
1971 GetArkUINodeModifiers()->getCommonModifier()->setOutlineWidth(
1972 nativeNode, widthOptions.data(), widthOptions.size());
1973 return panda::JSValueRef::Undefined(vm);
1974 }
1975
ResetOutlineWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)1976 ArkUINativeModuleValue CommonBridge::ResetOutlineWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
1977 {
1978 EcmaVM* vm = runtimeCallInfo->GetVM();
1979 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1980 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1981 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1982 GetArkUINodeModifiers()->getCommonModifier()->resetOutlineWidth(nativeNode);
1983 return panda::JSValueRef::Undefined(vm);
1984 }
1985
SetOutlineStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)1986 ArkUINativeModuleValue CommonBridge::SetOutlineStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
1987 {
1988 EcmaVM* vm = runtimeCallInfo->GetVM();
1989 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1990 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1991 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1992 std::vector<uint32_t> styleOptions;
1993 ParseOuterBorderStyle(runtimeCallInfo, vm, styleOptions, NUM_1);
1994 GetArkUINodeModifiers()->getCommonModifier()->setOutlineStyle(
1995 nativeNode, styleOptions.data(), styleOptions.size());
1996 return panda::JSValueRef::Undefined(vm);
1997 }
1998
ResetOutlineStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)1999 ArkUINativeModuleValue CommonBridge::ResetOutlineStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
2000 {
2001 EcmaVM* vm = runtimeCallInfo->GetVM();
2002 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2003 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2004 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2005 GetArkUINodeModifiers()->getCommonModifier()->resetOutlineStyle(nativeNode);
2006 return panda::JSValueRef::Undefined(vm);
2007 }
2008
SetOutline(ArkUIRuntimeCallInfo * runtimeCallInfo)2009 ArkUINativeModuleValue CommonBridge::SetOutline(ArkUIRuntimeCallInfo* runtimeCallInfo)
2010 {
2011 EcmaVM* vm = runtimeCallInfo->GetVM();
2012 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2013 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2014 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2015 std::vector<ArkUI_Float32> options;
2016 ParseOuterBorderWidth(runtimeCallInfo, vm, options); // Outline Width args start index from 1
2017 ParseOuterBorderRadius(runtimeCallInfo, vm, options, NUM_9); // Outline Radius args start index
2018
2019 std::vector<uint32_t> colorAndStyleOptions;
2020 ParseOuterBorderColor(runtimeCallInfo, vm, colorAndStyleOptions, NUM_5); // Outline Color args start index
2021 ParseOuterBorderStyle(runtimeCallInfo, vm, colorAndStyleOptions, NUM_13); // Outline Style args start index
2022
2023 GetArkUINodeModifiers()->getCommonModifier()->setOutline(
2024 nativeNode, options.data(), options.size(), colorAndStyleOptions.data(), colorAndStyleOptions.size());
2025 return panda::JSValueRef::Undefined(vm);
2026 }
2027
ResetOutline(ArkUIRuntimeCallInfo * runtimeCallInfo)2028 ArkUINativeModuleValue CommonBridge::ResetOutline(ArkUIRuntimeCallInfo* runtimeCallInfo)
2029 {
2030 EcmaVM* vm = runtimeCallInfo->GetVM();
2031 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2032 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2033 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2034 GetArkUINodeModifiers()->getCommonModifier()->resetOutline(nativeNode);
2035 return panda::JSValueRef::Undefined(vm);
2036 }
2037
SetBorderStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2038 ArkUINativeModuleValue CommonBridge::SetBorderStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2039 {
2040 EcmaVM *vm = runtimeCallInfo->GetVM();
2041 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2042 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2043 auto typeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2044 auto styleArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2045 auto topArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2046 auto rightArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2047 auto bottomArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2048 auto leftArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2049 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2050 if ((!typeArg->IsBoolean()) || (!typeArg->BooleaValue(vm))) {
2051 int32_t styles[] = { static_cast<int32_t>(BorderStyle::SOLID) };
2052 GetArkUINodeModifiers()->getCommonModifier()->setBorderStyle(nativeNode, styles,
2053 (sizeof(styles) / sizeof(styles[NUM_0])));
2054 return panda::JSValueRef::Undefined(vm);
2055 }
2056 if (styleArg->IsInt()) {
2057 int32_t styles[] = { styleArg->Int32Value(vm) };
2058 GetArkUINodeModifiers()->getCommonModifier()->setBorderStyle(nativeNode, styles,
2059 (sizeof(styles) / sizeof(styles[NUM_0])));
2060 return panda::JSValueRef::Undefined(vm);
2061 }
2062 int32_t styles[] = { -1, -1, -1, -1 };
2063 if (topArg->IsInt()) {
2064 styles[NUM_0] = topArg->Int32Value(vm);
2065 }
2066 if (rightArg->IsInt()) {
2067 styles[NUM_1] = rightArg->Int32Value(vm);
2068 }
2069 if (bottomArg->IsInt()) {
2070 styles[NUM_2] = bottomArg->Int32Value(vm);
2071 }
2072 if (leftArg->IsInt()) {
2073 styles[NUM_3] = leftArg->Int32Value(vm);
2074 }
2075 GetArkUINodeModifiers()->getCommonModifier()->setBorderStyle(nativeNode, styles,
2076 (sizeof(styles) / sizeof(styles[NUM_0])));
2077 return panda::JSValueRef::Undefined(vm);
2078 }
2079
ResetBorderStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2080 ArkUINativeModuleValue CommonBridge::ResetBorderStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2081 {
2082 EcmaVM *vm = runtimeCallInfo->GetVM();
2083 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2084 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2085 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2086 GetArkUINodeModifiers()->getCommonModifier()->resetBorderStyle(nativeNode);
2087 return panda::JSValueRef::Undefined(vm);
2088 }
2089
SetShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)2090 ArkUINativeModuleValue CommonBridge::SetShadow(ArkUIRuntimeCallInfo *runtimeCallInfo)
2091 {
2092 EcmaVM *vm = runtimeCallInfo->GetVM();
2093 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2094 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2095 auto styleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2096 auto radiusArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2097 auto typeArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2098 auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2099 auto offsetXArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2100 auto offsetYArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2101 auto fillArg = runtimeCallInfo->GetCallArgRef(NUM_7);
2102 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2103 int32_t shadowStyle = 0;
2104 if (ArkTSUtils::ParseJsInteger(vm, styleArg, shadowStyle)) {
2105 ArkUIInt32orFloat32 shadows[] = { {.i32 = shadowStyle} };
2106 GetArkUINodeModifiers()->getCommonModifier()->setBackShadow(nativeNode, shadows,
2107 (sizeof(shadows) / sizeof(shadows[NUM_0])));
2108 return panda::JSValueRef::Undefined(vm);
2109 }
2110 ArkUIInt32orFloat32 shadows[] = { { 0.0 }, { .i32 = 0 }, { 0.0 }, { 0.0 },
2111 { .i32 = static_cast<ArkUI_Int32>(ShadowType::COLOR) }, { .u32 = 0 }, { .i32 = 0 } };
2112 double radius;
2113 ArkTSUtils::ParseJsDouble(vm, radiusArg, radius);
2114 shadows[NUM_0].f32 = radius;
2115
2116 shadows[NUM_0].f32 = (LessNotEqual(shadows[NUM_0].f32, 0.0)) ? 0.0 : shadows[NUM_0].f32;
2117 CalcDimension offsetX;
2118 if (ParseJsShadowDimension(vm, offsetXArg, offsetX)) {
2119 shadows[NUM_2].f32 = offsetX.Value();
2120 }
2121 CalcDimension offsetY;
2122 if (ParseJsShadowDimension(vm, offsetYArg, offsetY)) {
2123 shadows[NUM_3].f32 = offsetY.Value();
2124 }
2125 if (typeArg->IsInt()) {
2126 uint32_t shadowType = typeArg->Uint32Value(vm);
2127 shadows[NUM_4].i32 =
2128 std::clamp(shadowType, static_cast<uint32_t>(ShadowType::COLOR), static_cast<uint32_t>(ShadowType::BLUR));
2129 }
2130 int32_t type = 0;
2131 uint32_t color = 0;
2132 if (ParseJsShadowColor(vm, colorArg, type, color)) {
2133 shadows[NUM_1].i32 = type;
2134 shadows[NUM_5].u32 = color;
2135 }
2136 shadows[NUM_6].i32 = fillArg->IsBoolean() ? fillArg->BooleaValue(vm) : false;
2137 GetArkUINodeModifiers()->getCommonModifier()->setBackShadow(nativeNode, shadows,
2138 (sizeof(shadows) / sizeof(shadows[NUM_0])));
2139 return panda::JSValueRef::Undefined(vm);
2140 }
2141
ResetShadow(ArkUIRuntimeCallInfo * runtimeCallInfo)2142 ArkUINativeModuleValue CommonBridge::ResetShadow(ArkUIRuntimeCallInfo *runtimeCallInfo)
2143 {
2144 EcmaVM *vm = runtimeCallInfo->GetVM();
2145 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2146 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2147 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2148 GetArkUINodeModifiers()->getCommonModifier()->resetBackShadow(nativeNode);
2149 return panda::JSValueRef::Undefined(vm);
2150 }
2151
SetHitTestBehavior(ArkUIRuntimeCallInfo * runtimeCallInfo)2152 ArkUINativeModuleValue CommonBridge::SetHitTestBehavior(ArkUIRuntimeCallInfo *runtimeCallInfo)
2153 {
2154 EcmaVM *vm = runtimeCallInfo->GetVM();
2155 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2156 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2157 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
2158 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2159 if (secondArg->IsNumber()) {
2160 uint32_t hitTestModeNG = secondArg->Uint32Value(vm);
2161 GetArkUINodeModifiers()->getCommonModifier()->setHitTestBehavior(nativeNode, hitTestModeNG);
2162 } else {
2163 GetArkUINodeModifiers()->getCommonModifier()->resetHitTestBehavior(nativeNode);
2164 }
2165 return panda::JSValueRef::Undefined(vm);
2166 }
2167
ResetHitTestBehavior(ArkUIRuntimeCallInfo * runtimeCallInfo)2168 ArkUINativeModuleValue CommonBridge::ResetHitTestBehavior(ArkUIRuntimeCallInfo *runtimeCallInfo)
2169 {
2170 EcmaVM *vm = runtimeCallInfo->GetVM();
2171 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2172 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2173 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2174 GetArkUINodeModifiers()->getCommonModifier()->resetHitTestBehavior(nativeNode);
2175 return panda::JSValueRef::Undefined(vm);
2176 }
2177
SetZIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)2178 ArkUINativeModuleValue CommonBridge::SetZIndex(ArkUIRuntimeCallInfo *runtimeCallInfo)
2179 {
2180 EcmaVM *vm = runtimeCallInfo->GetVM();
2181 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2182 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2183 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
2184 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2185 if (secondArg->IsNumber()) {
2186 int32_t value = secondArg->Int32Value(vm);
2187 GetArkUINodeModifiers()->getCommonModifier()->setZIndex(nativeNode, value);
2188 } else {
2189 GetArkUINodeModifiers()->getCommonModifier()->resetZIndex(nativeNode);
2190 }
2191 return panda::JSValueRef::Undefined(vm);
2192 }
2193
ResetZIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)2194 ArkUINativeModuleValue CommonBridge::ResetZIndex(ArkUIRuntimeCallInfo *runtimeCallInfo)
2195 {
2196 EcmaVM *vm = runtimeCallInfo->GetVM();
2197 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2198 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2199 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2200 GetArkUINodeModifiers()->getCommonModifier()->resetZIndex(nativeNode);
2201 return panda::JSValueRef::Undefined(vm);
2202 }
2203
SetOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)2204 ArkUINativeModuleValue CommonBridge::SetOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
2205 {
2206 EcmaVM *vm = runtimeCallInfo->GetVM();
2207 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2208 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2209 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
2210 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2211 double opacity;
2212 if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity)) {
2213 GetArkUINodeModifiers()->getCommonModifier()->resetOpacity(nativeNode);
2214 } else {
2215 GetArkUINodeModifiers()->getCommonModifier()->setOpacity(nativeNode, opacity);
2216 }
2217 return panda::JSValueRef::Undefined(vm);
2218 }
2219
ResetOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)2220 ArkUINativeModuleValue CommonBridge::ResetOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
2221 {
2222 EcmaVM *vm = runtimeCallInfo->GetVM();
2223 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2224 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2225 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2226 GetArkUINodeModifiers()->getCommonModifier()->resetOpacity(nativeNode);
2227 return panda::JSValueRef::Undefined(vm);
2228 }
2229
SetAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)2230 ArkUINativeModuleValue CommonBridge::SetAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
2231 {
2232 EcmaVM *vm = runtimeCallInfo->GetVM();
2233 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2234 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2235 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2236 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2237 if (secondArg->IsNumber()) {
2238 GetArkUINodeModifiers()->getCommonModifier()->setAlign(nativeNode, secondArg->ToNumber(vm)->Value());
2239 } else {
2240 GetArkUINodeModifiers()->getCommonModifier()->resetAlign(nativeNode);
2241 }
2242 return panda::JSValueRef::Undefined(vm);
2243 }
2244
ResetAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)2245 ArkUINativeModuleValue CommonBridge::ResetAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
2246 {
2247 EcmaVM *vm = runtimeCallInfo->GetVM();
2248 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2249 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2250 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2251 GetArkUINodeModifiers()->getCommonModifier()->resetAlign(nativeNode);
2252 return panda::JSValueRef::Undefined(vm);
2253 }
2254
SetBackdropBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2255 ArkUINativeModuleValue CommonBridge::SetBackdropBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2256 {
2257 EcmaVM *vm = runtimeCallInfo->GetVM();
2258 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2259 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2260 Local<JSValueRef> blurArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2261 Local<JSValueRef> blurOptionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2262 Local<JSValueRef> disableSystemAdaptationArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2263 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2264
2265 double blur = 0.0;
2266 if (!ArkTSUtils::ParseJsDouble(vm, blurArg, blur)) {
2267 GetArkUINodeModifiers()->getCommonModifier()->resetBackdropBlur(nativeNode);
2268 return panda::JSValueRef::Undefined(vm);
2269 }
2270 BlurOption blurOption;
2271 if (blurOptionArg->IsArray(vm)) {
2272 ParseBlurOption(vm, blurOptionArg, blurOption);
2273 }
2274 bool disableSystemAdaptation = false;
2275 if (disableSystemAdaptationArg->IsBoolean()) {
2276 disableSystemAdaptation = disableSystemAdaptationArg->ToBoolean(vm)->Value();
2277 }
2278 GetArkUINodeModifiers()->getCommonModifier()->setBackdropBlur(
2279 nativeNode, blur, blurOption.grayscale.data(), blurOption.grayscale.size(), disableSystemAdaptation);
2280 return panda::JSValueRef::Undefined(vm);
2281 }
2282
ResetBackdropBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2283 ArkUINativeModuleValue CommonBridge::ResetBackdropBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2284 {
2285 EcmaVM *vm = runtimeCallInfo->GetVM();
2286 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2287 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2288 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2289 GetArkUINodeModifiers()->getCommonModifier()->resetBackdropBlur(nativeNode);
2290 return panda::JSValueRef::Undefined(vm);
2291 }
2292
SetHueRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)2293 ArkUINativeModuleValue CommonBridge::SetHueRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2294 {
2295 EcmaVM *vm = runtimeCallInfo->GetVM();
2296 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2297 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2298 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2299 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2300 std::optional<float> degree;
2301 if (secondArg->IsString(vm)) {
2302 degree = static_cast<float>(StringUtils::StringToDegree(secondArg->ToString(vm)->ToString(vm)));
2303 } else if (secondArg->IsNumber()) {
2304 degree = static_cast<float>(secondArg->ToNumber(vm)->Value());
2305 } else {
2306 GetArkUINodeModifiers()->getCommonModifier()->resetHueRotate(nativeNode);
2307 return panda::JSValueRef::Undefined(vm);
2308 }
2309
2310 float deg = 0.0f;
2311 if (degree) {
2312 deg = degree.value();
2313 degree.reset();
2314 }
2315 GetArkUINodeModifiers()->getCommonModifier()->setHueRotate(nativeNode, deg);
2316 return panda::JSValueRef::Undefined(vm);
2317 }
2318
ResetHueRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)2319 ArkUINativeModuleValue CommonBridge::ResetHueRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2320 {
2321 EcmaVM *vm = runtimeCallInfo->GetVM();
2322 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2323 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2324 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2325 GetArkUINodeModifiers()->getCommonModifier()->resetHueRotate(nativeNode);
2326 return panda::JSValueRef::Undefined(vm);
2327 }
2328
SetInvert(ArkUIRuntimeCallInfo * runtimeCallInfo)2329 ArkUINativeModuleValue CommonBridge::SetInvert(ArkUIRuntimeCallInfo *runtimeCallInfo)
2330 {
2331 EcmaVM* vm = runtimeCallInfo->GetVM();
2332 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2333 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2334 Local<JSValueRef> invertValueArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2335 Local<JSValueRef> optionLowArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2336 Local<JSValueRef> optionHighArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2337 Local<JSValueRef> optionThresholdArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2338 Local<JSValueRef> optionThresholdRangeArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2339 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2340
2341 if (!invertValueArg->IsUndefined()) {
2342 double invertValue = 0.0;
2343 if (ArkTSUtils::ParseJsDouble(vm, invertValueArg, invertValue)) {
2344 ArkUI_Float32 invert[] = { invertValue };
2345 GetArkUINodeModifiers()->getCommonModifier()->setInvert(nativeNode, invert, NUM_1);
2346 } else {
2347 GetArkUINodeModifiers()->getCommonModifier()->resetInvert(nativeNode);
2348 }
2349 } else {
2350 ArkUI_Float32 invert[] = { 0.0, 0.0, 0.0, 0.0 };
2351 double low = 0.0;
2352 double high = 0.0;
2353 double threshold = 0.0;
2354 double thresholdRange = 0.0;
2355 if (ArkTSUtils::ParseJsDouble(vm, optionLowArg, low)) {
2356 invert[NUM_0] = std::clamp(low, 0.0, 1.0);
2357 }
2358 if (ArkTSUtils::ParseJsDouble(vm, optionHighArg, high)) {
2359 invert[NUM_1] = std::clamp(high, 0.0, 1.0);
2360 }
2361 if (ArkTSUtils::ParseJsDouble(vm, optionThresholdArg, threshold)) {
2362 invert[NUM_2] = std::clamp(threshold, 0.0, 1.0);
2363 }
2364 if (ArkTSUtils::ParseJsDouble(vm, optionThresholdRangeArg, thresholdRange)) {
2365 invert[NUM_3] = std::clamp(thresholdRange, 0.0, 1.0);
2366 }
2367 GetArkUINodeModifiers()->getCommonModifier()->setInvert(nativeNode, invert, NUM_4);
2368 }
2369
2370 return panda::JSValueRef::Undefined(vm);
2371 }
2372
ResetInvert(ArkUIRuntimeCallInfo * runtimeCallInfo)2373 ArkUINativeModuleValue CommonBridge::ResetInvert(ArkUIRuntimeCallInfo *runtimeCallInfo)
2374 {
2375 EcmaVM *vm = runtimeCallInfo->GetVM();
2376 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2377 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2378 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2379 GetArkUINodeModifiers()->getCommonModifier()->resetInvert(nativeNode);
2380 return panda::JSValueRef::Undefined(vm);
2381 }
2382
SetSepia(ArkUIRuntimeCallInfo * runtimeCallInfo)2383 ArkUINativeModuleValue CommonBridge::SetSepia(ArkUIRuntimeCallInfo *runtimeCallInfo)
2384 {
2385 EcmaVM *vm = runtimeCallInfo->GetVM();
2386 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2387 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2388 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2389 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2390 if (secondArg->IsNumber()) {
2391 GetArkUINodeModifiers()->getCommonModifier()->setSepia(nativeNode, secondArg->ToNumber(vm)->Value());
2392 } else {
2393 GetArkUINodeModifiers()->getCommonModifier()->resetSepia(nativeNode);
2394 }
2395 return panda::JSValueRef::Undefined(vm);
2396 }
2397
ResetSepia(ArkUIRuntimeCallInfo * runtimeCallInfo)2398 ArkUINativeModuleValue CommonBridge::ResetSepia(ArkUIRuntimeCallInfo *runtimeCallInfo)
2399 {
2400 EcmaVM *vm = runtimeCallInfo->GetVM();
2401 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2402 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2403 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2404 GetArkUINodeModifiers()->getCommonModifier()->resetSepia(nativeNode);
2405 return panda::JSValueRef::Undefined(vm);
2406 }
2407
SetSaturate(ArkUIRuntimeCallInfo * runtimeCallInfo)2408 ArkUINativeModuleValue CommonBridge::SetSaturate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2409 {
2410 EcmaVM *vm = runtimeCallInfo->GetVM();
2411 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2412 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2413 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2414 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2415 if (secondArg->IsNumber()) {
2416 GetArkUINodeModifiers()->getCommonModifier()->setSaturate(nativeNode, secondArg->ToNumber(vm)->Value());
2417 } else {
2418 GetArkUINodeModifiers()->getCommonModifier()->resetSaturate(nativeNode);
2419 }
2420 return panda::JSValueRef::Undefined(vm);
2421 }
2422
ResetSaturate(ArkUIRuntimeCallInfo * runtimeCallInfo)2423 ArkUINativeModuleValue CommonBridge::ResetSaturate(ArkUIRuntimeCallInfo *runtimeCallInfo)
2424 {
2425 EcmaVM *vm = runtimeCallInfo->GetVM();
2426 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2427 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2428 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2429 GetArkUINodeModifiers()->getCommonModifier()->resetSaturate(nativeNode);
2430 return panda::JSValueRef::Undefined(vm);
2431 }
2432
SetColorBlend(ArkUIRuntimeCallInfo * runtimeCallInfo)2433 ArkUINativeModuleValue CommonBridge::SetColorBlend(ArkUIRuntimeCallInfo *runtimeCallInfo)
2434 {
2435 EcmaVM *vm = runtimeCallInfo->GetVM();
2436 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2437 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2438 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2439 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2440 Color color;
2441 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
2442 GetArkUINodeModifiers()->getCommonModifier()->resetColorBlend(nativeNode);
2443 } else {
2444 GetArkUINodeModifiers()->getCommonModifier()->setColorBlend(nativeNode, color.GetValue());
2445 }
2446 return panda::JSValueRef::Undefined(vm);
2447 }
2448
ResetColorBlend(ArkUIRuntimeCallInfo * runtimeCallInfo)2449 ArkUINativeModuleValue CommonBridge::ResetColorBlend(ArkUIRuntimeCallInfo *runtimeCallInfo)
2450 {
2451 EcmaVM *vm = runtimeCallInfo->GetVM();
2452 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2453 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2454 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2455 GetArkUINodeModifiers()->getCommonModifier()->resetColorBlend(nativeNode);
2456 return panda::JSValueRef::Undefined(vm);
2457 }
2458
SetGrayscale(ArkUIRuntimeCallInfo * runtimeCallInfo)2459 ArkUINativeModuleValue CommonBridge::SetGrayscale(ArkUIRuntimeCallInfo *runtimeCallInfo)
2460 {
2461 EcmaVM *vm = runtimeCallInfo->GetVM();
2462 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2463 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2464 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2465 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2466 if (secondArg->IsNumber()) {
2467 GetArkUINodeModifiers()->getCommonModifier()->setGrayscale(nativeNode, secondArg->ToNumber(vm)->Value());
2468 } else {
2469 GetArkUINodeModifiers()->getCommonModifier()->resetGrayscale(nativeNode);
2470 }
2471 return panda::JSValueRef::Undefined(vm);
2472 }
2473
ResetGrayscale(ArkUIRuntimeCallInfo * runtimeCallInfo)2474 ArkUINativeModuleValue CommonBridge::ResetGrayscale(ArkUIRuntimeCallInfo *runtimeCallInfo)
2475 {
2476 EcmaVM *vm = runtimeCallInfo->GetVM();
2477 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2478 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2479 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2480 GetArkUINodeModifiers()->getCommonModifier()->resetGrayscale(nativeNode);
2481 return panda::JSValueRef::Undefined(vm);
2482 }
2483
SetContrast(ArkUIRuntimeCallInfo * runtimeCallInfo)2484 ArkUINativeModuleValue CommonBridge::SetContrast(ArkUIRuntimeCallInfo *runtimeCallInfo)
2485 {
2486 EcmaVM *vm = runtimeCallInfo->GetVM();
2487 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2488 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2489 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2490 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2491 if (secondArg->IsNumber()) {
2492 GetArkUINodeModifiers()->getCommonModifier()->setContrast(nativeNode, secondArg->ToNumber(vm)->Value());
2493 } else {
2494 GetArkUINodeModifiers()->getCommonModifier()->resetContrast(nativeNode);
2495 }
2496 return panda::JSValueRef::Undefined(vm);
2497 }
2498
ResetContrast(ArkUIRuntimeCallInfo * runtimeCallInfo)2499 ArkUINativeModuleValue CommonBridge::ResetContrast(ArkUIRuntimeCallInfo *runtimeCallInfo)
2500 {
2501 EcmaVM *vm = runtimeCallInfo->GetVM();
2502 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2503 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2504 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2505 GetArkUINodeModifiers()->getCommonModifier()->resetContrast(nativeNode);
2506 return panda::JSValueRef::Undefined(vm);
2507 }
2508
SetBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)2509 ArkUINativeModuleValue CommonBridge::SetBrightness(ArkUIRuntimeCallInfo *runtimeCallInfo)
2510 {
2511 EcmaVM *vm = runtimeCallInfo->GetVM();
2512 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2513 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2514 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2515 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2516 if (secondArg->IsNumber()) {
2517 GetArkUINodeModifiers()->getCommonModifier()->setBrightness(nativeNode, secondArg->ToNumber(vm)->Value());
2518 } else {
2519 GetArkUINodeModifiers()->getCommonModifier()->resetBrightness(nativeNode);
2520 }
2521 return panda::JSValueRef::Undefined(vm);
2522 }
2523
ResetBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)2524 ArkUINativeModuleValue CommonBridge::ResetBrightness(ArkUIRuntimeCallInfo *runtimeCallInfo)
2525 {
2526 EcmaVM *vm = runtimeCallInfo->GetVM();
2527 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2528 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2529 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2530 GetArkUINodeModifiers()->getCommonModifier()->resetBrightness(nativeNode);
2531 return panda::JSValueRef::Undefined(vm);
2532 }
2533
SetBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2534 ArkUINativeModuleValue CommonBridge::SetBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2535 {
2536 EcmaVM *vm = runtimeCallInfo->GetVM();
2537 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2538 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2539 Local<JSValueRef> blurArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2540 Local<JSValueRef> blurOptionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2541 Local<JSValueRef> disableSystemAdaptationArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2542 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2543 double blur = 0.0;
2544 if (!ArkTSUtils::ParseJsDouble(vm, blurArg, blur)) {
2545 GetArkUINodeModifiers()->getCommonModifier()->resetBlur(nativeNode);
2546 return panda::JSValueRef::Undefined(vm);
2547 }
2548 BlurOption blurOption;
2549 if (blurOptionArg->IsArray(vm)) {
2550 ParseBlurOption(vm, blurOptionArg, blurOption);
2551 }
2552 bool disableSystemAdaptation = false;
2553 if (disableSystemAdaptationArg->IsBoolean()) {
2554 disableSystemAdaptation = disableSystemAdaptationArg->ToBoolean(vm)->Value();
2555 }
2556 GetArkUINodeModifiers()->getCommonModifier()->setBlur(
2557 nativeNode, blur, blurOption.grayscale.data(), blurOption.grayscale.size(), disableSystemAdaptation);
2558
2559 return panda::JSValueRef::Undefined(vm);
2560 }
2561
ResetBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2562 ArkUINativeModuleValue CommonBridge::ResetBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2563 {
2564 EcmaVM *vm = runtimeCallInfo->GetVM();
2565 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2566 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
2567 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2568 GetArkUINodeModifiers()->getCommonModifier()->resetBlur(nativeNode);
2569 return panda::JSValueRef::Undefined(vm);
2570 }
2571
SetLinearGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2572 ArkUINativeModuleValue CommonBridge::SetLinearGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2573 {
2574 EcmaVM *vm = runtimeCallInfo->GetVM();
2575 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2576 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2577 auto angleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2578 auto directionArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2579 auto colorsArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2580 auto repeatingArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2581 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2582
2583 std::vector<ArkUIInt32orFloat32> values;
2584 ParseGradientAngle(vm, angleArg, values);
2585 int32_t direction = static_cast<int32_t>(GradientDirection::NONE);
2586 ParseJsInt32(vm, directionArg, direction);
2587 values.push_back({.i32 = static_cast<ArkUI_Float32>(direction)});
2588
2589 std::vector<ArkUIInt32orFloat32> colors;
2590 ParseGradientColorStops(vm, colorsArg, colors);
2591 auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(vm) : false;
2592 values.push_back({.i32 = static_cast<ArkUI_Float32>(repeating)});
2593 GetArkUINodeModifiers()->getCommonModifier()->setLinearGradient(nativeNode, values.data(), values.size(),
2594 colors.data(), colors.size());
2595 return panda::JSValueRef::Undefined(vm);
2596 }
2597
ResetLinearGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2598 ArkUINativeModuleValue CommonBridge::ResetLinearGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2599 {
2600 EcmaVM *vm = runtimeCallInfo->GetVM();
2601 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2602 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2603 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2604 GetArkUINodeModifiers()->getCommonModifier()->resetLinearGradient(nativeNode);
2605 return panda::JSValueRef::Undefined(vm);
2606 }
2607
SetSweepGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2608 ArkUINativeModuleValue CommonBridge::SetSweepGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2609 {
2610 EcmaVM *vm = runtimeCallInfo->GetVM();
2611 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2612 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2613 auto centerArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2614 auto startArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2615 auto endArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2616 auto rotationArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2617 auto colorsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2618 auto repeatingArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2619 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2620 std::vector<ArkUIInt32orFloat32> values;
2621 ParseGradientCenter(vm, centerArg, values);
2622 ParseGradientAngle(vm, startArg, values);
2623 ParseGradientAngle(vm, endArg, values);
2624 ParseGradientAngle(vm, rotationArg, values);
2625 std::vector<ArkUIInt32orFloat32> colors;
2626 ParseGradientColorStops(vm, colorsArg, colors);
2627 auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(vm) : false;
2628 values.push_back({.i32 = static_cast<ArkUI_Int32>(repeating)});
2629 GetArkUINodeModifiers()->getCommonModifier()->setSweepGradient(nativeNode, values.data(), values.size(),
2630 colors.data(), colors.size());
2631 return panda::JSValueRef::Undefined(vm);
2632 }
2633
ResetSweepGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2634 ArkUINativeModuleValue CommonBridge::ResetSweepGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2635 {
2636 EcmaVM *vm = runtimeCallInfo->GetVM();
2637 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2638 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2639 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2640 GetArkUINodeModifiers()->getCommonModifier()->resetSweepGradient(nativeNode);
2641 return panda::JSValueRef::Undefined(vm);
2642 }
2643
SetRadialGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2644 ArkUINativeModuleValue CommonBridge::SetRadialGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2645 {
2646 EcmaVM *vm = runtimeCallInfo->GetVM();
2647 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2648 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2649 auto centerArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2650 auto radiusArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2651 auto colorsArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2652 auto repeatingArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2653 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2654 std::vector<ArkUIInt32orFloat32> values;
2655 ParseGradientCenter(vm, centerArg, values);
2656 CalcDimension radius;
2657 auto hasRadius = ArkTSUtils::ParseJsDimensionVp(vm, radiusArg, radius, false);
2658 values.push_back({.i32 = static_cast<ArkUI_Int32>(hasRadius)});
2659 values.push_back({.f32 = static_cast<ArkUI_Float32>(radius.Value())});
2660 values.push_back({.i32 = static_cast<ArkUI_Int32>(radius.Unit())});
2661 std::vector<ArkUIInt32orFloat32> colors;
2662 ParseGradientColorStops(vm, colorsArg, colors);
2663 auto repeating = repeatingArg->IsBoolean() ? repeatingArg->BooleaValue(vm) : false;
2664 values.push_back({.i32 = static_cast<ArkUI_Int32>(repeating)});
2665 GetArkUINodeModifiers()->getCommonModifier()->setRadialGradient(nativeNode, values.data(), values.size(),
2666 colors.data(), colors.size());
2667 return panda::JSValueRef::Undefined(vm);
2668 }
2669
ResetRadialGradient(ArkUIRuntimeCallInfo * runtimeCallInfo)2670 ArkUINativeModuleValue CommonBridge::ResetRadialGradient(ArkUIRuntimeCallInfo *runtimeCallInfo)
2671 {
2672 EcmaVM *vm = runtimeCallInfo->GetVM();
2673 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2674 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2675 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2676 GetArkUINodeModifiers()->getCommonModifier()->resetRadialGradient(nativeNode);
2677 return panda::JSValueRef::Undefined(vm);
2678 }
2679
SetOverlay(ArkUIRuntimeCallInfo * runtimeCallInfo)2680 ArkUINativeModuleValue CommonBridge::SetOverlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
2681 {
2682 EcmaVM* vm = runtimeCallInfo->GetVM();
2683 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2684 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2685 auto valueArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2686 auto alignArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2687 auto offsetXArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2688 auto offsetYArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2689 auto hasOptionsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2690 auto hasOffsetArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2691 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2692
2693 std::optional<std::string> text;
2694 if (valueArg->IsString(vm)) {
2695 text = valueArg->ToString(vm)->ToString(vm);
2696 }
2697 int32_t align = ALIGNMENT_TOP_LEFT;
2698 auto hasAlign = ArkTSUtils::ParseJsInteger(vm, alignArg, align);
2699 std::optional<CalcDimension> offsetX = CalcDimension(0);
2700 std::optional<CalcDimension> offsetY = CalcDimension(0);
2701 CalcDimension dimensionX;
2702 if (ArkTSUtils::ParseJsDimensionVp(vm, offsetXArg, dimensionX, false)) {
2703 offsetX = dimensionX;
2704 }
2705 CalcDimension dimensionY;
2706 if (ArkTSUtils::ParseJsDimensionVp(vm, offsetYArg, dimensionY, false)) {
2707 offsetY = dimensionY;
2708 }
2709 auto hasOptions = (hasOptionsArg->IsBoolean()) ? hasOptionsArg->ToBoolean(vm)->Value(): false;
2710 auto hasOffset = (hasOffsetArg->IsBoolean()) ? hasOffsetArg->ToBoolean(vm)->Value(): false;
2711 std::vector<ArkUI_Float32> options;
2712 options.push_back(static_cast<ArkUI_Float32>(hasAlign));
2713 options.push_back(static_cast<ArkUI_Float32>(align));
2714 options.push_back(static_cast<ArkUI_Float32>(offsetX.has_value()));
2715 options.push_back(static_cast<ArkUI_Float32>(offsetX.value().Value()));
2716 options.push_back(static_cast<ArkUI_Float32>(offsetX.value().Unit()));
2717 options.push_back(static_cast<ArkUI_Float32>(offsetY.has_value()));
2718 options.push_back(static_cast<ArkUI_Float32>(offsetY.value().Value()));
2719 options.push_back(static_cast<ArkUI_Float32>(offsetY.value().Unit()));
2720 options.push_back(static_cast<ArkUI_Float32>(hasOptions));
2721 options.push_back(static_cast<ArkUI_Float32>(hasOffset));
2722 auto textPtr = (text.has_value()) ? text.value().c_str() : nullptr;
2723 GetArkUINodeModifiers()->getCommonModifier()->setOverlay(nativeNode, textPtr, options.data(), options.size());
2724 return panda::JSValueRef::Undefined(vm);
2725 }
2726
ResetOverlay(ArkUIRuntimeCallInfo * runtimeCallInfo)2727 ArkUINativeModuleValue CommonBridge::ResetOverlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
2728 {
2729 EcmaVM* vm = runtimeCallInfo->GetVM();
2730 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2731 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2732 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2733 GetArkUINodeModifiers()->getCommonModifier()->resetOverlay(nativeNode);
2734 return panda::JSValueRef::Undefined(vm);
2735 }
2736
SetBorderImage(ArkUIRuntimeCallInfo * runtimeCallInfo)2737 ArkUINativeModuleValue CommonBridge::SetBorderImage(ArkUIRuntimeCallInfo* runtimeCallInfo)
2738 {
2739 EcmaVM* vm = runtimeCallInfo->GetVM();
2740 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2741 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2742 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2743 auto argsNumber = runtimeCallInfo->GetArgsNumber();
2744 if (IsArgsUndefined(runtimeCallInfo, NUM_1, argsNumber - NUM_1)) {
2745 return panda::JSValueRef::Undefined(vm);
2746 }
2747 std::string src;
2748 std::vector<ArkUIStringAndFloat> options;
2749 uint8_t bitsets = 0;
2750 uint32_t offset = NUM_1;
2751 std::vector<std::optional<CalcDimension>> sliceDimensions;
2752 ParseBorderImageSlice(runtimeCallInfo, offset, sliceDimensions, bitsets); // use 4 args
2753 PushDimensionsToVector(options, sliceDimensions);
2754 ParseBorderImageRepeat(runtimeCallInfo, offset, options, bitsets); // use 1 args
2755 if (!ParseBorderImageSource(runtimeCallInfo, offset, nativeNode, src, bitsets)) { // use 5 args
2756 return panda::JSValueRef::Undefined(vm);
2757 }
2758 std::vector<std::optional<CalcDimension>> widthDimensions;
2759 ParseBorderImageWidth(runtimeCallInfo, offset, widthDimensions, bitsets); // use 4 args
2760 PushDimensionsToVector(options, widthDimensions);
2761 std::vector<std::optional<CalcDimension>> outsetDimensions;
2762 ParseBorderImageOutset(runtimeCallInfo, offset, outsetDimensions, bitsets); // use 4 args
2763 PushDimensionsToVector(options, outsetDimensions);
2764 ParseBorderImageFill(runtimeCallInfo, offset, options); // use 1 args
2765 options.push_back(ArkUIStringAndFloat { static_cast<double>(bitsets), nullptr });
2766 GetArkUINodeModifiers()->getCommonModifier()->setBorderImage(nativeNode,
2767 src.c_str(), options.data(), options.size());
2768 ResetCalcDimensions(sliceDimensions);
2769 ResetCalcDimensions(widthDimensions);
2770 ResetCalcDimensions(outsetDimensions);
2771 return panda::JSValueRef::Undefined(vm);
2772 }
2773
ResetBorderImage(ArkUIRuntimeCallInfo * runtimeCallInfo)2774 ArkUINativeModuleValue CommonBridge::ResetBorderImage(ArkUIRuntimeCallInfo* runtimeCallInfo)
2775 {
2776 EcmaVM* vm = runtimeCallInfo->GetVM();
2777 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2778 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2779 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2780 GetArkUINodeModifiers()->getCommonModifier()->resetBorderImage(nativeNode);
2781 return panda::JSValueRef::Undefined(vm);
2782 }
2783
SetForegroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2784 ArkUINativeModuleValue CommonBridge::SetForegroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2785 {
2786 EcmaVM *vm = runtimeCallInfo->GetVM();
2787 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2788 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2789 auto blurStyleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2790 auto colorModeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2791 auto adaptiveColorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2792 auto scaleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2793 auto blurOptionsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2794 auto disableSystemAdaptationArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2795 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2796 int32_t blurStyle = -1;
2797 if (blurStyleArg->IsNumber()) {
2798 blurStyle = blurStyleArg->Int32Value(vm);
2799 }
2800 bool isHasOptions = !(colorModeArg->IsUndefined() && adaptiveColorArg->IsUndefined() && scaleArg->IsUndefined() &&
2801 blurOptionsArg->IsUndefined());
2802 int32_t colorMode = static_cast<int32_t>(ThemeColorMode::SYSTEM);
2803 int32_t adaptiveColor = static_cast<int32_t>(AdaptiveColor::DEFAULT);
2804 double scale = 1.0;
2805 BlurOption blurOption;
2806 if (isHasOptions) {
2807 ParseJsInt32(vm, colorModeArg, colorMode);
2808 ParseJsInt32(vm, adaptiveColorArg, adaptiveColor);
2809 if (scaleArg->IsNumber()) {
2810 scale = scaleArg->ToNumber(vm)->Value();
2811 }
2812 if (blurOptionsArg->IsArray(vm)) {
2813 ParseBlurOption(vm, blurOptionsArg, blurOption);
2814 }
2815 }
2816 int32_t intArray[NUM_3];
2817 intArray[NUM_0] = blurStyle;
2818 intArray[NUM_1] = colorMode;
2819 intArray[NUM_2] = adaptiveColor;
2820 bool disableSystemAdaptation = false;
2821 if (disableSystemAdaptationArg->IsBoolean()) {
2822 disableSystemAdaptation = disableSystemAdaptationArg->ToBoolean(vm)->Value();
2823 }
2824 GetArkUINodeModifiers()->getCommonModifier()->setForegroundBlurStyle(nativeNode, &intArray, scale,
2825 blurOption.grayscale.data(), blurOption.grayscale.size(), disableSystemAdaptation);
2826 return panda::JSValueRef::Undefined(vm);
2827 }
2828
ResetForegroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2829 ArkUINativeModuleValue CommonBridge::ResetForegroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2830 {
2831 EcmaVM *vm = runtimeCallInfo->GetVM();
2832 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2833 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2834 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2835 GetArkUINodeModifiers()->getCommonModifier()->resetForegroundBlurStyle(nativeNode);
2836 return panda::JSValueRef::Undefined(vm);
2837 }
2838
SetLinearGradientBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2839 ArkUINativeModuleValue CommonBridge::SetLinearGradientBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2840 {
2841 EcmaVM *vm = runtimeCallInfo->GetVM();
2842 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2843 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2844 auto blurRadiusArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2845 auto fractionStopsArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2846 auto directionArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2847 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2848 double blurRadius = 0.0;
2849 ParseJsDouble(vm, blurRadiusArg, blurRadius);
2850 auto direction = static_cast<int32_t>(GradientDirection::BOTTOM);
2851 if (directionArg->IsInt()) {
2852 direction = directionArg->Int32Value(vm);
2853 }
2854 std::vector<ArkUI_Float32> fractionStops;
2855 if (fractionStopsArg->IsArray(vm)) {
2856 auto array = panda::Local<panda::ArrayRef>(fractionStopsArg);
2857 auto length = array->Length(vm);
2858 for (uint32_t index = 0; index < length; index++) {
2859 auto fractionStop = panda::ArrayRef::GetValueAt(vm, array, index);
2860 ArkUI_Float32 first = 0.0;
2861 ArkUI_Float32 second = 0.0;
2862 if (!ParseJsDoublePair(vm, fractionStop, first, second)) {
2863 continue;
2864 }
2865 fractionStops.push_back(first);
2866 fractionStops.push_back(second);
2867 }
2868 }
2869 GetArkUINodeModifiers()->getCommonModifier()->setLinearGradientBlur(nativeNode, blurRadius, fractionStops.data(),
2870 fractionStops.size(), direction);
2871 return panda::JSValueRef::Undefined(vm);
2872 }
2873
ResetLinearGradientBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)2874 ArkUINativeModuleValue CommonBridge::ResetLinearGradientBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
2875 {
2876 EcmaVM *vm = runtimeCallInfo->GetVM();
2877 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2878 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2879 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2880 GetArkUINodeModifiers()->getCommonModifier()->resetLinearGradientBlur(nativeNode);
2881 return panda::JSValueRef::Undefined(vm);
2882 }
2883
SetBackgroundBlurStyleParam(ArkUIRuntimeCallInfo * runtimeCallInfo,bool & isValidColor,Color & inactiveColor,int32_t & policy,int32_t & blurType)2884 void SetBackgroundBlurStyleParam(
2885 ArkUIRuntimeCallInfo* runtimeCallInfo, bool& isValidColor, Color& inactiveColor, int32_t& policy, int32_t& blurType)
2886 {
2887 EcmaVM *vm = runtimeCallInfo->GetVM();
2888 auto policyArg = runtimeCallInfo->GetCallArgRef(NUM_6);
2889 auto inactiveColorArg = runtimeCallInfo->GetCallArgRef(NUM_7);
2890 auto typeArg = runtimeCallInfo->GetCallArgRef(NUM_8);
2891 if (ArkTSUtils::ParseJsColor(vm, inactiveColorArg, inactiveColor)) {
2892 isValidColor = true;
2893 }
2894 ParseJsInt32(vm, policyArg, policy);
2895 if (policy < static_cast<int32_t>(BlurStyleActivePolicy::FOLLOWS_WINDOW_ACTIVE_STATE) ||
2896 policy > static_cast<int32_t>(BlurStyleActivePolicy::ALWAYS_INACTIVE)) {
2897 policy = static_cast<int32_t>(BlurStyleActivePolicy::ALWAYS_ACTIVE);
2898 }
2899 ParseJsInt32(vm, typeArg, blurType);
2900 if (blurType < static_cast<int32_t>(BlurType::WITHIN_WINDOW) ||
2901 blurType > static_cast<int32_t>(BlurType::BEHIND_WINDOW)) {
2902 blurType = static_cast<int32_t>(BlurType::WITHIN_WINDOW);
2903 }
2904 }
2905
SetBackgroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2906 ArkUINativeModuleValue CommonBridge::SetBackgroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2907 {
2908 EcmaVM *vm = runtimeCallInfo->GetVM();
2909 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2910 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2911 auto blurStyleArg = runtimeCallInfo->GetCallArgRef(NUM_1);
2912 auto colorModeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
2913 auto adaptiveColorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
2914 auto scaleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
2915 auto blurOptionsArg = runtimeCallInfo->GetCallArgRef(NUM_5);
2916 auto disableSystemAdaptationArg = runtimeCallInfo->GetCallArgRef(NUM_9);
2917 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2918 int32_t blurStyle = -1;
2919 if (blurStyleArg->IsNumber()) {
2920 blurStyle = blurStyleArg->Int32Value(vm);
2921 }
2922 bool isHasOptions = !(colorModeArg->IsUndefined() && adaptiveColorArg->IsUndefined() && scaleArg->IsUndefined() &&
2923 blurOptionsArg->IsUndefined());
2924 int32_t colorMode = -1;
2925 int32_t adaptiveColor = -1;
2926 double scale = -1.0;
2927 BlurOption blurOption;
2928 if (isHasOptions) {
2929 colorMode = static_cast<int32_t>(ThemeColorMode::SYSTEM);
2930 ParseJsInt32(vm, colorModeArg, colorMode);
2931 adaptiveColor = static_cast<int32_t>(AdaptiveColor::DEFAULT);
2932 ParseJsInt32(vm, adaptiveColorArg, adaptiveColor);
2933 scale = 1.0;
2934 if (scaleArg->IsNumber()) {
2935 scale = scaleArg->ToNumber(vm)->Value();
2936 }
2937 if (blurOptionsArg->IsArray(vm)) {
2938 ParseBlurOption(vm, blurOptionsArg, blurOption);
2939 }
2940 }
2941 bool isValidColor = false;
2942 Color inactiveColor = Color::TRANSPARENT;
2943 auto policy = static_cast<int32_t>(BlurStyleActivePolicy::ALWAYS_ACTIVE);
2944 auto blurType = static_cast<int32_t>(BlurType::WITHIN_WINDOW);
2945 SetBackgroundBlurStyleParam(runtimeCallInfo, isValidColor, inactiveColor, policy, blurType);
2946 int32_t intArray[NUM_5];
2947 intArray[NUM_0] = blurStyle;
2948 intArray[NUM_1] = colorMode;
2949 intArray[NUM_2] = adaptiveColor;
2950 intArray[NUM_3] = policy;
2951 intArray[NUM_4] = blurType;
2952 bool disableSystemAdaptation = false;
2953 if (disableSystemAdaptationArg->IsBoolean()) {
2954 disableSystemAdaptation = disableSystemAdaptationArg->ToBoolean(vm)->Value();
2955 }
2956 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundBlurStyle(
2957 nativeNode, &intArray, scale, blurOption.grayscale.data(), blurOption.grayscale.size(),
2958 isValidColor, inactiveColor.GetValue(), disableSystemAdaptation);
2959 return panda::JSValueRef::Undefined(vm);
2960 }
2961
ResetBackgroundBlurStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)2962 ArkUINativeModuleValue CommonBridge::ResetBackgroundBlurStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
2963 {
2964 EcmaVM *vm = runtimeCallInfo->GetVM();
2965 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2966 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2967 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2968 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundBlurStyle(nativeNode);
2969 return panda::JSValueRef::Undefined(vm);
2970 }
2971
SetBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)2972 ArkUINativeModuleValue CommonBridge::SetBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
2973 {
2974 EcmaVM *vm = runtimeCallInfo->GetVM();
2975 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2976 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2977 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2978
2979 std::vector<ArkUI_Float32> options;
2980 ParseOuterBorderWidth(runtimeCallInfo, vm, options); // Border Width args start index from 1
2981 ParseOuterBorderRadius(runtimeCallInfo, vm, options, NUM_9); // Border Radius args start index
2982
2983 std::vector<uint32_t> colorAndStyleOptions;
2984 ParseOuterBorderColor(runtimeCallInfo, vm, colorAndStyleOptions, NUM_5); // Border Color args start index
2985 ParseOuterBorderStyle(runtimeCallInfo, vm, colorAndStyleOptions, NUM_13); // Border Style args start index
2986
2987 GetArkUINodeModifiers()->getCommonModifier()->setBorder(nativeNode, options.data(), options.size(),
2988 colorAndStyleOptions.data(), colorAndStyleOptions.size(), false, false, false);
2989 return panda::JSValueRef::Undefined(vm);
2990 }
2991
SetLocalizedBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)2992 ArkUINativeModuleValue CommonBridge::SetLocalizedBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
2993 {
2994 EcmaVM *vm = runtimeCallInfo->GetVM();
2995 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
2996 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
2997 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::NativePointerRef::New(vm, nullptr));
2998 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
2999
3000 std::vector<ArkUI_Float32> options;
3001 ParseOuterBorderWidth(runtimeCallInfo, vm, options, true); // Border Width args start index from 1
3002 ParseOuterBorderRadius(runtimeCallInfo, vm, options, NUM_9, true); // Border Radius args start index
3003
3004 std::vector<uint32_t> colorAndStyleOptions;
3005 ParseOuterBorderColor(runtimeCallInfo, vm, colorAndStyleOptions, NUM_5, true); // Border Color args start index
3006 ParseOuterBorderStyle(runtimeCallInfo, vm, colorAndStyleOptions, NUM_13); // Border Style args start index
3007
3008 int32_t isLocalizedBorderWidth = 0;
3009 int32_t isLocalizedBorderColor = 0;
3010 int32_t isLocalizedBorderRadius = 0;
3011 ParseLocalizedBorder(runtimeCallInfo, isLocalizedBorderWidth, isLocalizedBorderColor, isLocalizedBorderRadius);
3012
3013 GetArkUINodeModifiers()->getCommonModifier()->setBorder(nativeNode, options.data(), options.size(),
3014 colorAndStyleOptions.data(), colorAndStyleOptions.size(), isLocalizedBorderWidth, isLocalizedBorderColor,
3015 isLocalizedBorderRadius);
3016 return panda::JSValueRef::Undefined(vm);
3017 }
3018
ParseLocalizedBorder(ArkUIRuntimeCallInfo * runtimeCallInfo,int & isLocalizedBorderWidth,int & isLocalizedBorderColor,int & isLocalizedBorderRadius)3019 void CommonBridge::ParseLocalizedBorder(ArkUIRuntimeCallInfo* runtimeCallInfo, int& isLocalizedBorderWidth,
3020 int& isLocalizedBorderColor, int& isLocalizedBorderRadius)
3021 {
3022 EcmaVM* vm = runtimeCallInfo->GetVM();
3023 CHECK_NULL_VOID(vm);
3024 Local<JSValueRef> isLocalizedBorderWidthArg =
3025 runtimeCallInfo->GetCallArgRef(33); // 33: index of is LocalizedBorderWidth or not
3026 Local<JSValueRef> isLocalizedBorderColorArg =
3027 runtimeCallInfo->GetCallArgRef(34); // 34: index of is LocalizedBorderColor or not
3028 Local<JSValueRef> isLocalizedBorderRadiusArg =
3029 runtimeCallInfo->GetCallArgRef(35); // 35: index of is LocalizedBorderRadius or not
3030 isLocalizedBorderWidth =
3031 (isLocalizedBorderWidthArg->IsBoolean()) ? isLocalizedBorderWidthArg->ToBoolean(vm)->Value() : false;
3032 isLocalizedBorderColor =
3033 (isLocalizedBorderColorArg->IsBoolean()) ? isLocalizedBorderColorArg->ToBoolean(vm)->Value() : false;
3034 isLocalizedBorderRadius =
3035 (isLocalizedBorderRadiusArg->IsBoolean()) ? isLocalizedBorderRadiusArg->ToBoolean(vm)->Value() : false;
3036 }
3037
SetBorderWithDashParams(ArkUIRuntimeCallInfo * runtimeCallInfo)3038 ArkUINativeModuleValue CommonBridge::SetBorderWithDashParams(ArkUIRuntimeCallInfo* runtimeCallInfo)
3039 {
3040 int32_t isLocalizedBorderWidth = 0;
3041 int32_t isLocalizedBorderColor = 0;
3042 int32_t isLocalizedBorderRadius = 0;
3043 ParseLocalizedBorder(runtimeCallInfo, isLocalizedBorderWidth, isLocalizedBorderColor, isLocalizedBorderRadius);
3044 if (isLocalizedBorderWidth || isLocalizedBorderColor || isLocalizedBorderRadius) {
3045 CommonBridge::SetLocalizedBorder(runtimeCallInfo);
3046 } else {
3047 CommonBridge::SetBorder(runtimeCallInfo);
3048 }
3049
3050 EcmaVM *vm = runtimeCallInfo->GetVM();
3051 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3052 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3053 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3054
3055 std::vector<ArkUI_Float32> dashOptions;
3056 ParseOuterBorderDashParam(runtimeCallInfo, vm, dashOptions, 17); // Border DashGap args start index from 17
3057 Local<JSValueRef> startDashGap = runtimeCallInfo->GetCallArgRef(36); // Border DashGap args start index from 36
3058 Local<JSValueRef> endDashGap = runtimeCallInfo->GetCallArgRef(37); // Border DashGap args end index from 37
3059 std::optional<CalcDimension> startDashGapDim;
3060 std::optional<CalcDimension> endDashGapDim;
3061 ArkTSUtils::ParseOuterBorderForDashParams(vm, startDashGap, startDashGapDim);
3062 ArkTSUtils::ParseOuterBorderForDashParams(vm, endDashGap, endDashGapDim);
3063 ArkTSUtils::PushOuterBorderDimensionVector(startDashGapDim, dashOptions);
3064 ArkTSUtils::PushOuterBorderDimensionVector(endDashGapDim, dashOptions);
3065
3066 ParseOuterBorderDashParam(runtimeCallInfo, vm, dashOptions, 21); // Border DashWidth args start index from 21
3067 Local<JSValueRef> startDashWidth = runtimeCallInfo->GetCallArgRef(38); // Border DashWidth args start index from 38
3068 Local<JSValueRef> endDashWidth = runtimeCallInfo->GetCallArgRef(39); // Border DashWidth args end index from 39
3069 std::optional<CalcDimension> startDashWidthDim;
3070 std::optional<CalcDimension> endDashWidthDim;
3071 ArkTSUtils::ParseOuterBorderForDashParams(vm, startDashWidth, startDashWidthDim);
3072 ArkTSUtils::ParseOuterBorderForDashParams(vm, endDashWidth, endDashWidthDim);
3073 ArkTSUtils::PushOuterBorderDimensionVector(startDashWidthDim, dashOptions);
3074 ArkTSUtils::PushOuterBorderDimensionVector(endDashWidthDim, dashOptions);
3075
3076 GetArkUINodeModifiers()->getCommonModifier()->setBorderDashParams(nativeNode, dashOptions.data(),
3077 dashOptions.size());
3078 return panda::JSValueRef::Undefined(vm);
3079 }
3080
ResetBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)3081 ArkUINativeModuleValue CommonBridge::ResetBorder(ArkUIRuntimeCallInfo *runtimeCallInfo)
3082 {
3083 EcmaVM *vm = runtimeCallInfo->GetVM();
3084 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3085 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3086 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3087 GetArkUINodeModifiers()->getCommonModifier()->resetBorder(nativeNode);
3088 return panda::JSValueRef::Undefined(vm);
3089 }
3090
SetBackgroundImagePosition(ArkUIRuntimeCallInfo * runtimeCallInfo)3091 ArkUINativeModuleValue CommonBridge::SetBackgroundImagePosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
3092 {
3093 EcmaVM *vm = runtimeCallInfo->GetVM();
3094 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3095 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3096 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3097 Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3098 Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3099 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3100 double valueX = 0.0;
3101 double valueY = 0.0;
3102 DimensionUnit typeX = DimensionUnit::PX;
3103 DimensionUnit typeY = DimensionUnit::PX;
3104 bool isAlign = false;
3105
3106 if (secondArg->IsNumber()) {
3107 int32_t align = secondArg->ToNumber(vm)->Value();
3108 ParseBackgroundImagePositionAlign(align, valueX, valueY, typeX, typeY);
3109 isAlign = true;
3110 } else {
3111 CalcDimension x(0, DimensionUnit::VP);
3112 CalcDimension y(0, DimensionUnit::VP);
3113 ArkTSUtils::ParseJsDimensionVp(vm, xArg, x);
3114 ArkTSUtils::ParseJsDimensionVp(vm, yArg, y);
3115 valueX = x.ConvertToPx();
3116 valueY = y.ConvertToPx();
3117 if (x.Unit() == DimensionUnit::PERCENT) {
3118 valueX = x.Value();
3119 typeX = DimensionUnit::PERCENT;
3120 }
3121 if (y.Unit() == DimensionUnit::PERCENT) {
3122 valueY = y.Value();
3123 typeY = DimensionUnit::PERCENT;
3124 }
3125 }
3126
3127 ArkUI_Float32 values[SIZE_OF_TWO];
3128 int32_t types[SIZE_OF_TWO];
3129 values[NUM_0] = static_cast<ArkUI_Float32>(valueX);
3130 types[NUM_0] = static_cast<int32_t>(typeX);
3131 values[NUM_1] = static_cast<ArkUI_Float32>(valueY);
3132 types[NUM_1] = static_cast<int32_t>(typeY);
3133
3134 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImagePosition(nativeNode, values, types, isAlign,
3135 SIZE_OF_TWO);
3136 return panda::JSValueRef::Undefined(vm);
3137 }
3138
ResetBackgroundImagePosition(ArkUIRuntimeCallInfo * runtimeCallInfo)3139 ArkUINativeModuleValue CommonBridge::ResetBackgroundImagePosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
3140 {
3141 EcmaVM *vm = runtimeCallInfo->GetVM();
3142 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3143 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3144 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3145 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImagePosition(nativeNode);
3146 return panda::JSValueRef::Undefined(vm);
3147 }
3148
SetBackgroundImageResizable(ArkUIRuntimeCallInfo * runtimeCallInfo)3149 ArkUINativeModuleValue CommonBridge::SetBackgroundImageResizable(ArkUIRuntimeCallInfo *runtimeCallInfo)
3150 {
3151 EcmaVM* vm = runtimeCallInfo->GetVM();
3152 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3153 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3154
3155 std::vector<ArkUIStringAndFloat> options;
3156 std::vector<std::optional<CalcDimension>> sliceDimensions;
3157 ParseResizableCalcDimensions(runtimeCallInfo, NUM_1, NUM_4, sliceDimensions, CalcDimension(0.0));
3158 PushDimensionsToVector(options, sliceDimensions);
3159
3160 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImageResizable(nativeNode, options.data());
3161 return panda::JSValueRef::Undefined(vm);
3162 }
3163
ResetBackgroundImageResizable(ArkUIRuntimeCallInfo * runtimeCallInfo)3164 ArkUINativeModuleValue CommonBridge::ResetBackgroundImageResizable(ArkUIRuntimeCallInfo *runtimeCallInfo)
3165 {
3166 EcmaVM* vm = runtimeCallInfo->GetVM();
3167 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3168 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3169 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImageResizable(nativeNode);
3170 return panda::JSValueRef::Undefined(vm);
3171 }
3172
SetBackgroundImageSize(ArkUIRuntimeCallInfo * runtimeCallInfo)3173 ArkUINativeModuleValue CommonBridge::SetBackgroundImageSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
3174 {
3175 EcmaVM *vm = runtimeCallInfo->GetVM();
3176 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3177 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3178 Local<JSValueRef> imageSizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3179 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3180 Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3181 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3182
3183 OHOS::Ace::BackgroundImageSizeType typeWidth = OHOS::Ace::BackgroundImageSizeType::AUTO;
3184 double valueWidth = 0.0;
3185 OHOS::Ace::BackgroundImageSizeType typeHeight = OHOS::Ace::BackgroundImageSizeType::AUTO;
3186 double valueHeight = 0.0;
3187
3188 if (imageSizeArg->IsNumber()) {
3189 auto sizeType = imageSizeArg->ToNumber(vm)->Value();
3190 if (sizeType < static_cast<uint32_t>(BackgroundImageSizeType::CONTAIN) ||
3191 sizeType > static_cast<uint32_t>(BackgroundImageSizeType::FILL)) {
3192 sizeType = static_cast<uint32_t>(BackgroundImageSizeType::AUTO);
3193 }
3194 typeWidth = static_cast<OHOS::Ace::BackgroundImageSizeType>(sizeType);
3195 typeHeight = static_cast<OHOS::Ace::BackgroundImageSizeType>(sizeType);
3196 } else {
3197 CalcDimension width;
3198 CalcDimension height;
3199 ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width);
3200 ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height);
3201
3202 valueWidth = width.ConvertToPx();
3203 valueHeight = height.ConvertToPx();
3204 typeWidth = BackgroundImageSizeType::LENGTH;
3205 typeHeight = BackgroundImageSizeType::LENGTH;
3206 if (width.Unit() == DimensionUnit::PERCENT) {
3207 typeWidth = BackgroundImageSizeType::PERCENT;
3208 valueWidth = width.Value() * FULL_DIMENSION;
3209 }
3210 if (height.Unit() == DimensionUnit::PERCENT) {
3211 typeHeight = BackgroundImageSizeType::PERCENT;
3212 valueHeight = height.Value() * FULL_DIMENSION;
3213 }
3214 }
3215 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImageSize(
3216 nativeNode, valueWidth, valueHeight, static_cast<int32_t>(typeWidth), static_cast<int32_t>(typeHeight));
3217 return panda::JSValueRef::Undefined(vm);
3218 }
3219
ResetBackgroundImageSize(ArkUIRuntimeCallInfo * runtimeCallInfo)3220 ArkUINativeModuleValue CommonBridge::ResetBackgroundImageSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
3221 {
3222 EcmaVM *vm = runtimeCallInfo->GetVM();
3223 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3224 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3225 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3226 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImageSize(nativeNode);
3227 return panda::JSValueRef::Undefined(vm);
3228 }
3229
ParseJsBackgroundImageOptions(const EcmaVM * vm,const Local<JSValueRef> & value,int32_t & repeatIndex,bool & syncMode)3230 bool ParseJsBackgroundImageOptions(
3231 const EcmaVM* vm, const Local<JSValueRef>& value, int32_t& repeatIndex, bool& syncMode)
3232 {
3233 if (!value->IsObject(vm)) {
3234 return false;
3235 }
3236 auto jsObj = value->ToObject(vm);
3237 auto repeat = jsObj->Get(vm, panda::StringRef::NewFromUtf8(vm, "repeat"));
3238 if (repeat->IsNumber()) {
3239 repeatIndex = repeat->ToNumber(vm)->Value();
3240 }
3241 auto syncLoad = jsObj->Get(vm, panda::StringRef::NewFromUtf8(vm, "syncLoad"));
3242 if (syncLoad->IsBoolean()) {
3243 syncMode = syncLoad->ToBoolean(vm)->Value();
3244 }
3245 return true;
3246 }
3247
SetBackgroundImage(ArkUIRuntimeCallInfo * runtimeCallInfo)3248 ArkUINativeModuleValue CommonBridge::SetBackgroundImage(ArkUIRuntimeCallInfo *runtimeCallInfo)
3249 {
3250 EcmaVM *vm = runtimeCallInfo->GetVM();
3251 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3252 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3253 Local<JSValueRef> srcArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3254 Local<JSValueRef> repeatArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3255 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3256 std::string src;
3257 std::string bundle;
3258 std::string module;
3259 int32_t repeatIndex = 0;
3260 bool syncMode = false;
3261 RefPtr<PixelMap> pixmap = nullptr;
3262 if (repeatArg->IsNumber()) {
3263 repeatIndex = repeatArg->ToNumber(vm)->Value();
3264 }
3265 if (ParseJsBackgroundImageOptions(vm, repeatArg, repeatIndex, syncMode)) {
3266 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImageSyncMode(nativeNode, syncMode);
3267 } else {
3268 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImageSyncMode(nativeNode);
3269 }
3270 if (srcArg->IsString(vm)) {
3271 src = srcArg->ToString(vm)->ToString(vm);
3272 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImage(
3273 nativeNode, src.c_str(), bundle.c_str(), module.c_str(), repeatIndex);
3274 } else if (ArkTSUtils::ParseJsMedia(vm, srcArg, src)) {
3275 ArkTSUtils::GetJsMediaBundleInfo(vm, srcArg, bundle, module);
3276 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImage(
3277 nativeNode, src.c_str(), bundle.c_str(), module.c_str(), repeatIndex);
3278 } else {
3279 #if defined(PIXEL_MAP_SUPPORTED)
3280 if (ArkTSUtils::IsDrawable(vm, srcArg)) {
3281 pixmap = ArkTSUtils::GetDrawablePixmap(vm, srcArg);
3282 } else {
3283 pixmap = ArkTSUtils::CreatePixelMapFromNapiValue(vm, srcArg);
3284 }
3285 #endif
3286 if (pixmap) {
3287 auto pixelMapSharedPtr = pixmap->GetPixelMapSharedPtr();
3288 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundImagePixelMapByPixelMapPtr(
3289 nativeNode, &pixelMapSharedPtr, repeatIndex);
3290 } else {
3291 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImage(nativeNode);
3292 }
3293 }
3294 return panda::JSValueRef::Undefined(vm);
3295 }
3296
ResetBackgroundImage(ArkUIRuntimeCallInfo * runtimeCallInfo)3297 ArkUINativeModuleValue CommonBridge::ResetBackgroundImage(ArkUIRuntimeCallInfo *runtimeCallInfo)
3298 {
3299 EcmaVM *vm = runtimeCallInfo->GetVM();
3300 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3301 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3302 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3303 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImageSyncMode(nativeNode);
3304 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundImage(nativeNode);
3305 return panda::JSValueRef::Undefined(vm);
3306 }
3307
SetTranslate(ArkUIRuntimeCallInfo * runtimeCallInfo)3308 ArkUINativeModuleValue CommonBridge::SetTranslate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3309 {
3310 EcmaVM *vm = runtimeCallInfo->GetVM();
3311 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3312 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3313 Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3314 Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3315 Local<JSValueRef> zArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3316 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3317 if (!xArg->IsNumber() && !xArg->IsString(vm) && !yArg->IsNumber() && !yArg->IsString(vm) && !zArg->IsNumber() &&
3318 !zArg->IsString(vm)) {
3319 GetArkUINodeModifiers()->getCommonModifier()->resetTranslate(nativeNode);
3320 } else {
3321 auto translateX = CalcDimension(0.0);
3322 auto translateY = CalcDimension(0.0);
3323 auto translateZ = CalcDimension(0.0);
3324 bool hasX = ParseAxisDimensionVp(vm, xArg, translateX, true);
3325 bool hasY = ParseAxisDimensionVp(vm, yArg, translateY, true);
3326 bool hasZ = ParseAxisDimensionVp(vm, zArg, translateZ, true);
3327 if (hasX || hasY || hasZ) {
3328 uint32_t size = SIZE_OF_THREE;
3329 ArkUI_Float32 values[size];
3330 int units[size];
3331
3332 values[NUM_0] = static_cast<ArkUI_Float32>(translateX.Value());
3333 units[NUM_0] = static_cast<int>(translateX.Unit());
3334 values[NUM_1] = static_cast<ArkUI_Float32>(translateY.Value());
3335 units[NUM_1] = static_cast<int>(translateY.Unit());
3336 values[NUM_2] = static_cast<ArkUI_Float32>(translateZ.Value());
3337 units[NUM_2] = static_cast<int>(translateZ.Unit());
3338 GetArkUINodeModifiers()->getCommonModifier()->setTranslate(nativeNode, values, units, size);
3339 } else {
3340 GetArkUINodeModifiers()->getCommonModifier()->resetTranslate(nativeNode);
3341 }
3342 }
3343 return panda::JSValueRef::Undefined(vm);
3344 }
3345
ResetTranslate(ArkUIRuntimeCallInfo * runtimeCallInfo)3346 ArkUINativeModuleValue CommonBridge::ResetTranslate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3347 {
3348 EcmaVM *vm = runtimeCallInfo->GetVM();
3349 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3350 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3351 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3352 GetArkUINodeModifiers()->getCommonModifier()->resetTranslate(nativeNode);
3353 return panda::JSValueRef::Undefined(vm);
3354 }
3355
SetScale(ArkUIRuntimeCallInfo * runtimeCallInfo)3356 ArkUINativeModuleValue CommonBridge::SetScale(ArkUIRuntimeCallInfo *runtimeCallInfo)
3357 {
3358 EcmaVM *vm = runtimeCallInfo->GetVM();
3359 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3360 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3361 Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3362 Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3363 Local<JSValueRef> zArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3364 Local<JSValueRef> centerXArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3365 Local<JSValueRef> centerYArg = runtimeCallInfo->GetCallArgRef(NUM_5);
3366 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3367 if (xArg->IsNumber() || yArg->IsNumber() || zArg->IsNumber()) {
3368 auto scaleX = 1.0f;
3369 auto scaleY = 1.0f;
3370 auto scaleZ = 1.0f;
3371
3372 CalcDimension centerX = 0.5_pct;
3373 CalcDimension centerY = 0.5_pct;
3374
3375 if (xArg->IsNumber()) {
3376 scaleX = xArg->ToNumber(vm)->Value();
3377 }
3378 if (yArg->IsNumber()) {
3379 scaleY = yArg->ToNumber(vm)->Value();
3380 }
3381 if (zArg->IsNumber()) {
3382 scaleZ = zArg->ToNumber(vm)->Value();
3383 }
3384 if (centerXArg->IsNumber() || centerXArg->IsString(vm)) {
3385 ParseAxisDimensionVp(vm, centerXArg, centerX, true);
3386 }
3387 if (centerYArg->IsNumber() || centerYArg->IsString(vm)) {
3388 ParseAxisDimensionVp(vm, centerYArg, centerY, true);
3389 }
3390
3391 ArkUI_Float32 values[SIZE_OF_FIVE];
3392 int units[SIZE_OF_TWO];
3393
3394 values[NUM_0] = static_cast<ArkUI_Float32>(scaleX);
3395 values[NUM_1] = static_cast<ArkUI_Float32>(scaleY);
3396 values[NUM_2] = static_cast<ArkUI_Float32>(scaleZ);
3397 values[NUM_3] = static_cast<ArkUI_Float32>(centerX.Value());
3398 values[NUM_4] = static_cast<ArkUI_Float32>(centerY.Value());
3399 units[NUM_0] = static_cast<int>(centerX.Unit());
3400 units[NUM_1] = static_cast<int>(centerY.Unit());
3401 GetArkUINodeModifiers()->getCommonModifier()->setScale(nativeNode, values, SIZE_OF_FIVE, units, SIZE_OF_TWO);
3402 } else {
3403 GetArkUINodeModifiers()->getCommonModifier()->resetScale(nativeNode);
3404 }
3405
3406 return panda::JSValueRef::Undefined(vm);
3407 }
3408
ResetScale(ArkUIRuntimeCallInfo * runtimeCallInfo)3409 ArkUINativeModuleValue CommonBridge::ResetScale(ArkUIRuntimeCallInfo *runtimeCallInfo)
3410 {
3411 EcmaVM *vm = runtimeCallInfo->GetVM();
3412 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3413 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3414 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3415 GetArkUINodeModifiers()->getCommonModifier()->resetScale(nativeNode);
3416 return panda::JSValueRef::Undefined(vm);
3417 }
3418
SetRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)3419 ArkUINativeModuleValue CommonBridge::SetRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3420 {
3421 EcmaVM *vm = runtimeCallInfo->GetVM();
3422 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3423 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3424 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3425
3426 ArkUI_Float32 values[SIZE_OF_EIGHT];
3427 int units[SIZE_OF_THREE];
3428
3429 if (ParseRotate(runtimeCallInfo, values, units, SIZE_OF_EIGHT, SIZE_OF_THREE)) {
3430 GetArkUINodeModifiers()->getCommonModifier()->setRotate(
3431 nativeNode, values, SIZE_OF_EIGHT, units, SIZE_OF_THREE);
3432 } else {
3433 GetArkUINodeModifiers()->getCommonModifier()->resetRotate(nativeNode);
3434 }
3435 return panda::JSValueRef::Undefined(vm);
3436 }
3437
ResetRotate(ArkUIRuntimeCallInfo * runtimeCallInfo)3438 ArkUINativeModuleValue CommonBridge::ResetRotate(ArkUIRuntimeCallInfo *runtimeCallInfo)
3439 {
3440 EcmaVM *vm = runtimeCallInfo->GetVM();
3441 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3442 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3443 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3444 GetArkUINodeModifiers()->getCommonModifier()->resetRotate(nativeNode);
3445 return panda::JSValueRef::Undefined(vm);
3446 }
3447
SetGeometryTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)3448 ArkUINativeModuleValue CommonBridge::SetGeometryTransition(ArkUIRuntimeCallInfo *runtimeCallInfo)
3449 {
3450 EcmaVM *vm = runtimeCallInfo->GetVM();
3451 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3452 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3453 Local<JSValueRef> idArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3454 Local<JSValueRef> followArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3455 Local<JSValueRef> hierarchyStrategyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3456 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3457 if (idArg->IsUndefined() || idArg->IsNull() || !idArg->IsString(vm)) {
3458 GetArkUINodeModifiers()->getCommonModifier()->resetGeometryTransition(nativeNode);
3459 return panda::JSValueRef::Undefined(vm);
3460 }
3461 std::string id = idArg->ToString(vm)->ToString(vm);
3462 ArkUIGeometryTransitionOptions options = {false, static_cast<int32_t>(TransitionHierarchyStrategy::ADAPTIVE)};
3463 if (followArg->IsBoolean()) {
3464 options.follow = followArg->ToBoolean(vm)->Value();
3465 }
3466 if (hierarchyStrategyArg->IsInt()) {
3467 options.hierarchyStrategy = hierarchyStrategyArg->Int32Value(vm);
3468 if (options.hierarchyStrategy < static_cast<int32_t>(TransitionHierarchyStrategy::NONE) ||
3469 options.hierarchyStrategy > static_cast<int32_t>(TransitionHierarchyStrategy::ADAPTIVE)) {
3470 options.hierarchyStrategy = static_cast<int32_t>(TransitionHierarchyStrategy::ADAPTIVE);
3471 }
3472 }
3473 GetArkUINodeModifiers()->getCommonModifier()->setGeometryTransition(nativeNode, id.c_str(), &options);
3474 return panda::JSValueRef::Undefined(vm);
3475 }
3476
ResetGeometryTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)3477 ArkUINativeModuleValue CommonBridge::ResetGeometryTransition(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 GetArkUINodeModifiers()->getCommonModifier()->resetGeometryTransition(nativeNode);
3484 return panda::JSValueRef::Undefined(vm);
3485 }
3486
SetBindMenu(ArkUIRuntimeCallInfo * runtimeCallInfo)3487 ArkUINativeModuleValue CommonBridge::SetBindMenu(ArkUIRuntimeCallInfo* runtimeCallInfo)
3488 {
3489 EcmaVM* vm = runtimeCallInfo->GetVM();
3490 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3491 Framework::JSCallbackInfo info = Framework::JSCallbackInfo(runtimeCallInfo);
3492 NG::MenuParam menuParam;
3493 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
3494 menuParam.placement = Placement::BOTTOM_LEFT;
3495 }
3496 size_t builderIndex = NUM_1;
3497 JSViewPopups::GetMenuShowInSubwindow(menuParam);
3498 if (info.Length() > PARAMETER_LENGTH_SECOND) {
3499 auto jsVal = info[builderIndex];
3500 if (jsVal->IsBoolean()) {
3501 menuParam.isShow = jsVal->ToBoolean();
3502 menuParam.setShow = true;
3503 builderIndex = NUM_2;
3504 if (info.Length() > PARAMETER_LENGTH_THIRD) {
3505 JSViewPopups::ParseBindOptionParam(info, menuParam, builderIndex + 1);
3506 }
3507 } else if (jsVal->IsUndefined()) {
3508 menuParam.setShow = true;
3509 menuParam.isShow = false;
3510 builderIndex = NUM_2;
3511 if (info.Length() > PARAMETER_LENGTH_THIRD) {
3512 JSViewPopups::ParseBindOptionParam(info, menuParam, builderIndex + 1);
3513 }
3514 } else if (jsVal->IsObject()) {
3515 JSRef<JSObject> callbackObj = JSRef<JSObject>::Cast(jsVal);
3516 menuParam.onStateChange = JSViewPopups::ParseDoubleBindCallback(info, callbackObj, "$value");
3517 auto isShowObj = callbackObj->GetProperty(static_cast<int32_t>(ArkUIIndex::VALUE));
3518 if (isShowObj->IsBoolean()) {
3519 menuParam.isShow = isShowObj->ToBoolean();
3520 menuParam.setShow = true;
3521 builderIndex = NUM_2;
3522 if (info.Length() > PARAMETER_LENGTH_THIRD) {
3523 JSViewPopups::ParseBindOptionParam(info, menuParam, builderIndex + 1);
3524 }
3525 } else {
3526 JSViewPopups::ParseBindOptionParam(info, menuParam, builderIndex + 1);
3527 }
3528 }
3529 }
3530 if (info[builderIndex]->IsArray()) {
3531 std::vector<NG::OptionParam> optionsParam = JSViewPopups::ParseBindOptionParam(info, builderIndex);
3532 ViewAbstractModel::GetInstance()->BindMenu(std::move(optionsParam), nullptr, menuParam);
3533 }
3534 return panda::JSValueRef::Undefined(vm);
3535 }
3536
SetBindTips(ArkUIRuntimeCallInfo * runtimeCallInfo)3537 ArkUINativeModuleValue CommonBridge::SetBindTips(ArkUIRuntimeCallInfo* runtimeCallInfo)
3538 {
3539 EcmaVM* vm = runtimeCallInfo->GetVM();
3540 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3541 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3542 Local<JSValueRef> messageArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3543 Local<JSValueRef> appearingTimeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3544 Local<JSValueRef> disappearingTimeArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3545 Local<JSValueRef> appearingTimeWithContinuousOperationArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3546 Local<JSValueRef> disappearingTimeWithContinuousOperationArg = runtimeCallInfo->GetCallArgRef(NUM_5);
3547 Local<JSValueRef> enableArrowArg = runtimeCallInfo->GetCallArgRef(NUM_6);
3548 Local<JSValueRef> arrowPointPositionArg = runtimeCallInfo->GetCallArgRef(NUM_7);
3549 Local<JSValueRef> arrowWidthArg = runtimeCallInfo->GetCallArgRef(NUM_8);
3550 Local<JSValueRef> arrowHeightArg = runtimeCallInfo->GetCallArgRef(NUM_9);
3551 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
3552
3553 std::string message = messageArg->ToString(vm)->ToString(vm);
3554
3555 ArkUIBindTipsOptionsTime tipsOptionsTime {
3556 .appearingTime = 700.0f, // 700.0f : Default appearing time for BindTips,
3557 .disappearingTime = 300.0f, // 300.0f : Default disappearing time for BindTips
3558 .appearingTimeWithContinuousOperation =
3559 300.0f, // 300.0f : Default appearing time with continuous operation for BindTips
3560 .disappearingTimeWithContinuousOperation =
3561 0.0f // 0.0f : Default disappearing time with continuous operation for BindTips
3562 };
3563 ParseTipsOptionsTime(vm, tipsOptionsTime, appearingTimeArg, tipsOptionsTime.appearingTime);
3564 ParseTipsOptionsTime(vm, tipsOptionsTime, disappearingTimeArg, tipsOptionsTime.disappearingTime);
3565 ParseTipsOptionsTime(vm, tipsOptionsTime, appearingTimeWithContinuousOperationArg,
3566 tipsOptionsTime.appearingTimeWithContinuousOperation);
3567 ParseTipsOptionsTime(vm, tipsOptionsTime, disappearingTimeWithContinuousOperationArg,
3568 tipsOptionsTime.disappearingTimeWithContinuousOperation);
3569
3570 ArkUIBindTipsOptionsArrow bindTipsOptionsArrow;
3571
3572 bindTipsOptionsArrow.enableArrow = (enableArrowArg->IsBoolean()) ? enableArrowArg->ToBoolean(vm)->Value() : true;
3573
3574 std::string arrowPointPosition;
3575 if (arrowPointPositionArg->IsString(vm)) {
3576 arrowPointPosition = arrowPointPositionArg->ToString(vm)->ToString(vm);
3577 bindTipsOptionsArrow.arrowPointPosition = arrowPointPosition.c_str();
3578 }
3579
3580 ParseTipsOptionsArrowSize(
3581 vm, arrowWidthArg, bindTipsOptionsArrow.arrowWidthValue, bindTipsOptionsArrow.arrowWidthUnit);
3582
3583 ParseTipsOptionsArrowSize(
3584 vm, arrowHeightArg, bindTipsOptionsArrow.arrowHeightValue, bindTipsOptionsArrow.arrowHeightUnit);
3585 GetArkUINodeModifiers()->getCommonModifier()->setBindTips(
3586 nativeNode, message.c_str(), tipsOptionsTime, bindTipsOptionsArrow);
3587 return panda::JSValueRef::Undefined(vm);
3588 }
3589
ResetBindTips(ArkUIRuntimeCallInfo * runtimeCallInfo)3590 ArkUINativeModuleValue CommonBridge::ResetBindTips(ArkUIRuntimeCallInfo *runtimeCallInfo)
3591 {
3592 EcmaVM *vm = runtimeCallInfo->GetVM();
3593 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3594 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3595 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3596 GetArkUINodeModifiers()->getCommonModifier()->resetBindTips(nativeNode);
3597 return panda::JSValueRef::Undefined(vm);
3598 }
3599
ResetClip(ArkUIRuntimeCallInfo * runtimeCallInfo)3600 ArkUINativeModuleValue CommonBridge::ResetClip(ArkUIRuntimeCallInfo *runtimeCallInfo)
3601 {
3602 EcmaVM *vm = runtimeCallInfo->GetVM();
3603 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3604 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3605 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3606 auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3607 ViewAbstract::SetClipEdge(frameNode, false);
3608 return panda::JSValueRef::Undefined(vm);
3609 }
3610
SetClip(ArkUIRuntimeCallInfo * runtimeCallInfo)3611 ArkUINativeModuleValue CommonBridge::SetClip(ArkUIRuntimeCallInfo *runtimeCallInfo)
3612 {
3613 EcmaVM *vm = runtimeCallInfo->GetVM();
3614 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3615 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3616 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3617 auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3618
3619 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
3620 if (info[NUM_1]->IsUndefined()) {
3621 ViewAbstract::SetClipEdge(frameNode, false);
3622 return panda::JSValueRef::Undefined(vm);
3623 }
3624 if (info[NUM_1]->IsObject()) {
3625 Framework::JSShapeAbstract *clipShape =
3626 Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
3627 if (clipShape == nullptr) {
3628 return panda::JSValueRef::Undefined(vm);
3629 }
3630 ViewAbstract::SetClipShape(frameNode, clipShape->GetBasicShape());
3631 } else if (info[NUM_1]->IsBoolean()) {
3632 ViewAbstract::SetClipEdge(frameNode, info[NUM_1]->ToBoolean());
3633 }
3634 return panda::JSValueRef::Undefined(vm);
3635 }
3636
SetClipShape(ArkUIRuntimeCallInfo * runtimeCallInfo)3637 ArkUINativeModuleValue CommonBridge::SetClipShape(ArkUIRuntimeCallInfo *runtimeCallInfo)
3638 {
3639 EcmaVM *vm = runtimeCallInfo->GetVM();
3640 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3641 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3642 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3643 auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3644
3645 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
3646 if (info[NUM_1]->IsObject()) {
3647 Framework::JSShapeAbstract *clipShape =
3648 Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
3649 if (clipShape == nullptr) {
3650 return panda::JSValueRef::Undefined(vm);
3651 }
3652 ViewAbstract::SetClipShape(frameNode, clipShape->GetBasicShape());
3653 }
3654 return panda::JSValueRef::Undefined(vm);
3655 }
3656
ResetClipShape(ArkUIRuntimeCallInfo * runtimeCallInfo)3657 ArkUINativeModuleValue CommonBridge::ResetClipShape(ArkUIRuntimeCallInfo *runtimeCallInfo)
3658 {
3659 EcmaVM *vm = runtimeCallInfo->GetVM();
3660 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3661 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3662 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3663 auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
3664 ViewAbstract::SetClipEdge(frameNode, false);
3665 return panda::JSValueRef::Undefined(vm);
3666 }
3667
SetPixelStretchEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3668 ArkUINativeModuleValue CommonBridge::SetPixelStretchEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3669 {
3670 EcmaVM *vm = runtimeCallInfo->GetVM();
3671 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3672 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3673 auto topArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3674 auto rightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3675 auto bottomArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3676 auto leftArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3677 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3678 CalcDimension left;
3679 ArkTSUtils::ParseJsDimensionVp(vm, leftArg, left);
3680 CalcDimension right;
3681 ArkTSUtils::ParseJsDimensionVp(vm, rightArg, right);
3682 CalcDimension top;
3683 ArkTSUtils::ParseJsDimensionVp(vm, topArg, top);
3684 CalcDimension bottom;
3685 ArkTSUtils::ParseJsDimensionVp(vm, bottomArg, bottom);
3686 ArkUI_Float32 values[] = { left.Value(), top.Value(), right.Value(), bottom.Value() };
3687 int units[] = { static_cast<int>(left.Unit()), static_cast<int>(top.Unit()), static_cast<int>(right.Unit()),
3688 static_cast<int>(bottom.Unit()) };
3689 GetArkUINodeModifiers()->getCommonModifier()->setPixelStretchEffect(nativeNode, values, units,
3690 (sizeof(values) / sizeof(values[NUM_0])));
3691 return panda::JSValueRef::Undefined(vm);
3692 }
3693
ResetPixelStretchEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3694 ArkUINativeModuleValue CommonBridge::ResetPixelStretchEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3695 {
3696 EcmaVM *vm = runtimeCallInfo->GetVM();
3697 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3698 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3699 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3700 GetArkUINodeModifiers()->getCommonModifier()->resetPixelStretchEffect(nativeNode);
3701 return panda::JSValueRef::Undefined(vm);
3702 }
3703
SetLightUpEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3704 ArkUINativeModuleValue CommonBridge::SetLightUpEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3705 {
3706 EcmaVM *vm = runtimeCallInfo->GetVM();
3707 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3708 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3709 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3710 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3711 auto radio = 1.0;
3712 if (secondArg->IsNumber()) {
3713 radio = secondArg->ToNumber(vm)->Value();
3714 }
3715 GetArkUINodeModifiers()->getCommonModifier()->setLightUpEffect(nativeNode, radio);
3716 return panda::JSValueRef::Undefined(vm);
3717 }
3718
ResetLightUpEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3719 ArkUINativeModuleValue CommonBridge::ResetLightUpEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3720 {
3721 EcmaVM *vm = runtimeCallInfo->GetVM();
3722 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3723 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3724 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3725 GetArkUINodeModifiers()->getCommonModifier()->resetLightUpEffect(nativeNode);
3726 return panda::JSValueRef::Undefined(vm);
3727 }
3728
SetSphericalEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3729 ArkUINativeModuleValue CommonBridge::SetSphericalEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3730 {
3731 EcmaVM *vm = runtimeCallInfo->GetVM();
3732 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3733 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3734 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3735 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3736 auto radio = 0.0;
3737 if (secondArg->IsNumber()) {
3738 radio = secondArg->ToNumber(vm)->Value();
3739 }
3740 GetArkUINodeModifiers()->getCommonModifier()->setSphericalEffect(nativeNode, radio);
3741 return panda::JSValueRef::Undefined(vm);
3742 }
3743
ResetSphericalEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3744 ArkUINativeModuleValue CommonBridge::ResetSphericalEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3745 {
3746 EcmaVM *vm = runtimeCallInfo->GetVM();
3747 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3748 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3749 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3750 GetArkUINodeModifiers()->getCommonModifier()->resetSphericalEffect(nativeNode);
3751 return panda::JSValueRef::Undefined(vm);
3752 }
3753
SetRenderGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)3754 ArkUINativeModuleValue CommonBridge::SetRenderGroup(ArkUIRuntimeCallInfo *runtimeCallInfo)
3755 {
3756 EcmaVM *vm = runtimeCallInfo->GetVM();
3757 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3758 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3759 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3760 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3761 auto isRenderGroup = false;
3762 if (secondArg->IsBoolean()) {
3763 isRenderGroup = secondArg->ToBoolean(vm)->Value();
3764 }
3765 GetArkUINodeModifiers()->getCommonModifier()->setRenderGroup(nativeNode, isRenderGroup);
3766 return panda::JSValueRef::Undefined(vm);
3767 }
3768
ResetRenderGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)3769 ArkUINativeModuleValue CommonBridge::ResetRenderGroup(ArkUIRuntimeCallInfo *runtimeCallInfo)
3770 {
3771 EcmaVM *vm = runtimeCallInfo->GetVM();
3772 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3773 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3774 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3775 GetArkUINodeModifiers()->getCommonModifier()->resetRenderGroup(nativeNode);
3776 return panda::JSValueRef::Undefined(vm);
3777 }
3778
SetRenderFit(ArkUIRuntimeCallInfo * runtimeCallInfo)3779 ArkUINativeModuleValue CommonBridge::SetRenderFit(ArkUIRuntimeCallInfo *runtimeCallInfo)
3780 {
3781 EcmaVM *vm = runtimeCallInfo->GetVM();
3782 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3783 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3784 auto fitModeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3785 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3786 auto renderFit = static_cast<int32_t>(RenderFit::TOP_LEFT);
3787 if (fitModeArg->IsNumber()) {
3788 renderFit = fitModeArg->Int32Value(vm);
3789 }
3790 GetArkUINodeModifiers()->getCommonModifier()->setRenderFit(nativeNode, renderFit);
3791 return panda::JSValueRef::Undefined(vm);
3792 }
3793
ResetRenderFit(ArkUIRuntimeCallInfo * runtimeCallInfo)3794 ArkUINativeModuleValue CommonBridge::ResetRenderFit(ArkUIRuntimeCallInfo *runtimeCallInfo)
3795 {
3796 EcmaVM *vm = runtimeCallInfo->GetVM();
3797 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3798 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3799 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3800 GetArkUINodeModifiers()->getCommonModifier()->resetRenderFit(nativeNode);
3801 return panda::JSValueRef::Undefined(vm);
3802 }
3803
SetUseEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3804 ArkUINativeModuleValue CommonBridge::SetUseEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3805 {
3806 EcmaVM *vm = runtimeCallInfo->GetVM();
3807 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3808 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3809 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3810 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3811 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3812 auto useEffect = false;
3813 if (secondArg->IsBoolean()) {
3814 useEffect = secondArg->ToBoolean(vm)->Value();
3815 }
3816 auto effectTypeDefault = EffectType::DEFAULT;
3817 auto effectTypeParam = effectTypeDefault;
3818 auto effectTypeValue = static_cast<int32_t>(effectTypeDefault);
3819
3820 if (thirdArg->IsNumber()) {
3821 effectTypeValue = thirdArg->Int32Value(vm);
3822 if (effectTypeValue >= static_cast<int32_t>(effectTypeDefault) &&
3823 effectTypeValue <= static_cast<int32_t>(EffectType::WINDOW_EFFECT)) {
3824 effectTypeParam = static_cast<EffectType>(effectTypeValue);
3825 }
3826 }
3827 auto effectType = static_cast<ArkUI_Int32>(effectTypeParam);
3828 GetArkUINodeModifiers()->getCommonModifier()->setUseEffect(nativeNode, useEffect, effectType);
3829 return panda::JSValueRef::Undefined(vm);
3830 }
3831
ResetUseEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)3832 ArkUINativeModuleValue CommonBridge::ResetUseEffect(ArkUIRuntimeCallInfo *runtimeCallInfo)
3833 {
3834 EcmaVM *vm = runtimeCallInfo->GetVM();
3835 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3836 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3837 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3838 GetArkUINodeModifiers()->getCommonModifier()->resetUseEffect(nativeNode);
3839 return panda::JSValueRef::Undefined(vm);
3840 }
3841
SetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)3842 ArkUINativeModuleValue CommonBridge::SetForegroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
3843 {
3844 EcmaVM *vm = runtimeCallInfo->GetVM();
3845 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3846 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3847 auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3848 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3849 if (colorArg->IsString(vm)) {
3850 std::string colorStr = colorArg->ToString(vm)->ToString(vm);
3851 colorStr.erase(std::remove(colorStr.begin(), colorStr.end(), ' '), colorStr.end());
3852 std::transform(colorStr.begin(), colorStr.end(), colorStr.begin(), ::tolower);
3853 if (colorStr.compare("invert") == 0) {
3854 auto strategy = static_cast<uint32_t>(ForegroundColorStrategy::INVERT);
3855 GetArkUINodeModifiers()->getCommonModifier()->setForegroundColor(nativeNode, false, strategy);
3856 return panda::JSValueRef::Undefined(vm);
3857 }
3858 }
3859 Color foregroundColor = Color::TRANSPARENT;
3860 ArkTSUtils::ParseJsColorAlpha(vm, colorArg, foregroundColor);
3861 GetArkUINodeModifiers()->getCommonModifier()->setForegroundColor(nativeNode, true, foregroundColor.GetValue());
3862 return panda::JSValueRef::Undefined(vm);
3863 }
3864
ResetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)3865 ArkUINativeModuleValue CommonBridge::ResetForegroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
3866 {
3867 EcmaVM *vm = runtimeCallInfo->GetVM();
3868 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3869 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3870 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3871 GetArkUINodeModifiers()->getCommonModifier()->resetForegroundColor(nativeNode);
3872 return panda::JSValueRef::Undefined(vm);
3873 }
3874
SetMotionPath(ArkUIRuntimeCallInfo * runtimeCallInfo)3875 ArkUINativeModuleValue CommonBridge::SetMotionPath(ArkUIRuntimeCallInfo *runtimeCallInfo)
3876 {
3877 EcmaVM *vm = runtimeCallInfo->GetVM();
3878 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3879 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3880 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3881 auto pathArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3882 auto fromArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3883 auto toArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3884 auto rotatableArg = runtimeCallInfo->GetCallArgRef(NUM_4);
3885 std::string pathStringValue;
3886 if (pathArg->IsString(vm)) {
3887 pathStringValue = pathArg->ToString(vm)->ToString(vm);
3888 }
3889 float fromValue = (fromArg->IsNumber()) ? fromArg->ToNumber(vm)->Value() : 0.0f;
3890 float toValue = (toArg->IsNumber()) ? toArg->ToNumber(vm)->Value() : 1.0f;
3891 if (fromValue > 1.0f || fromValue < 0.0f) {
3892 fromValue = 0.0f;
3893 }
3894 if (toValue > 1.0f || toValue < 0.0f) {
3895 toValue = 1.0f;
3896 } else if (toValue < fromValue) {
3897 toValue = fromValue;
3898 }
3899 bool rotatableValue = (rotatableArg->IsBoolean()) ? rotatableArg->ToBoolean(vm)->Value() : false;
3900 GetArkUINodeModifiers()->getCommonModifier()->setMotionPath(nativeNode, pathStringValue.c_str(), fromValue,
3901 toValue, rotatableValue);
3902 return panda::JSValueRef::Undefined(vm);
3903 }
3904
ResetMotionPath(ArkUIRuntimeCallInfo * runtimeCallInfo)3905 ArkUINativeModuleValue CommonBridge::ResetMotionPath(ArkUIRuntimeCallInfo *runtimeCallInfo)
3906 {
3907 EcmaVM *vm = runtimeCallInfo->GetVM();
3908 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3909 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3910 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3911 GetArkUINodeModifiers()->getCommonModifier()->resetMotionPath(nativeNode);
3912 return panda::JSValueRef::Undefined(vm);
3913 }
3914
3915
SetMotionBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)3916 ArkUINativeModuleValue CommonBridge::SetMotionBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
3917 {
3918 EcmaVM *vm = runtimeCallInfo->GetVM();
3919 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3920 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
3921 Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(NUM_1);
3922 Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_2);
3923 Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_3);
3924 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3925 double radius = 0.0;
3926 if (!ArkTSUtils::ParseJsDouble(vm, radiusArg, radius) || LessNotEqual(radius, 0.0)) {
3927 radius = 0.0;
3928 }
3929 double x = 0.0;
3930 double y = 0.0;
3931 if (!ArkTSUtils::ParseJsDouble(vm, xArg, x) || LessNotEqual(x, 0.0)) {
3932 x = 0.0;
3933 }
3934 if (!ArkTSUtils::ParseJsDouble(vm, yArg, y) || LessNotEqual(y, 0.0)) {
3935 y = 0.0;
3936 }
3937 x = std::clamp(x, 0.0, 1.0);
3938 y = std::clamp(y, 0.0, 1.0);
3939 GetArkUINodeModifiers()->getCommonModifier()->setMotionBlur(nativeNode, radius, x, y);
3940 return panda::JSValueRef::Undefined(vm);
3941 }
3942
ResetMotionBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)3943 ArkUINativeModuleValue CommonBridge::ResetMotionBlur(ArkUIRuntimeCallInfo *runtimeCallInfo)
3944 {
3945 EcmaVM *vm = runtimeCallInfo->GetVM();
3946 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3947 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3948 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3949 GetArkUINodeModifiers()->getCommonModifier()->resetMotionBlur(nativeNode);
3950 return panda::JSValueRef::Undefined(vm);
3951 }
3952
SetGroupDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)3953 ArkUINativeModuleValue CommonBridge::SetGroupDefaultFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
3954 {
3955 EcmaVM *vm = runtimeCallInfo->GetVM();
3956 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3957 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3958 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3959 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3960 if (secondArg->IsBoolean()) {
3961 bool groupDefaultFocus = secondArg->ToBoolean(vm)->Value();
3962 GetArkUINodeModifiers()->getCommonModifier()->setGroupDefaultFocus(nativeNode, groupDefaultFocus);
3963 } else {
3964 GetArkUINodeModifiers()->getCommonModifier()->resetGroupDefaultFocus(nativeNode);
3965 }
3966 return panda::JSValueRef::Undefined(vm);
3967 }
3968
ResetGroupDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)3969 ArkUINativeModuleValue CommonBridge::ResetGroupDefaultFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
3970 {
3971 EcmaVM *vm = runtimeCallInfo->GetVM();
3972 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3973 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3974 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3975 GetArkUINodeModifiers()->getCommonModifier()->resetGroupDefaultFocus(nativeNode);
3976 return panda::JSValueRef::Undefined(vm);
3977 }
3978
SetFocusOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)3979 ArkUINativeModuleValue CommonBridge::SetFocusOnTouch(ArkUIRuntimeCallInfo *runtimeCallInfo)
3980 {
3981 EcmaVM *vm = runtimeCallInfo->GetVM();
3982 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3983 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
3984 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
3985 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
3986 if (secondArg->IsBoolean()) {
3987 bool focusOnTouch = secondArg->ToBoolean(vm)->Value();
3988 GetArkUINodeModifiers()->getCommonModifier()->setFocusOnTouch(nativeNode, focusOnTouch);
3989 } else {
3990 GetArkUINodeModifiers()->getCommonModifier()->resetFocusOnTouch(nativeNode);
3991 }
3992 return panda::JSValueRef::Undefined(vm);
3993 }
3994
ResetFocusOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)3995 ArkUINativeModuleValue CommonBridge::ResetFocusOnTouch(ArkUIRuntimeCallInfo *runtimeCallInfo)
3996 {
3997 EcmaVM *vm = runtimeCallInfo->GetVM();
3998 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
3999 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4000 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4001 GetArkUINodeModifiers()->getCommonModifier()->resetFocusOnTouch(nativeNode);
4002 return panda::JSValueRef::Undefined(vm);
4003 }
4004
SetFocusable(ArkUIRuntimeCallInfo * runtimeCallInfo)4005 ArkUINativeModuleValue CommonBridge::SetFocusable(ArkUIRuntimeCallInfo* runtimeCallInfo)
4006 {
4007 EcmaVM* vm = runtimeCallInfo->GetVM();
4008 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4009 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4010 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4011 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4012 if (secondArg->IsBoolean()) {
4013 bool focusable = secondArg->ToBoolean(vm)->Value();
4014 GetArkUINodeModifiers()->getCommonModifier()->setFocusable(nativeNode, focusable);
4015 }
4016 return panda::JSValueRef::Undefined(vm);
4017 }
4018
ResetFocusable(ArkUIRuntimeCallInfo * runtimeCallInfo)4019 ArkUINativeModuleValue CommonBridge::ResetFocusable(ArkUIRuntimeCallInfo* runtimeCallInfo)
4020 {
4021 EcmaVM* vm = runtimeCallInfo->GetVM();
4022 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4023 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4024 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4025 GetArkUINodeModifiers()->getCommonModifier()->resetFocusable(nativeNode);
4026 return panda::JSValueRef::Undefined(vm);
4027 }
4028
SetTabStop(ArkUIRuntimeCallInfo * runtimeCallInfo)4029 ArkUINativeModuleValue CommonBridge::SetTabStop(ArkUIRuntimeCallInfo* runtimeCallInfo)
4030 {
4031 EcmaVM* vm = runtimeCallInfo->GetVM();
4032 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4033 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4034 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4035 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4036 if (secondArg->IsBoolean()) {
4037 bool tabStop = secondArg->ToBoolean(vm)->Value();
4038 GetArkUINodeModifiers()->getCommonModifier()->setTabStop(nativeNode, tabStop);
4039 } else {
4040 GetArkUINodeModifiers()->getCommonModifier()->setTabStop(nativeNode, false);
4041 }
4042 return panda::JSValueRef::Undefined(vm);
4043 }
4044
ResetTabStop(ArkUIRuntimeCallInfo * runtimeCallInfo)4045 ArkUINativeModuleValue CommonBridge::ResetTabStop(ArkUIRuntimeCallInfo* runtimeCallInfo)
4046 {
4047 EcmaVM* vm = runtimeCallInfo->GetVM();
4048 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4049 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4050 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4051 GetArkUINodeModifiers()->getCommonModifier()->setTabStop(nativeNode, false);
4052 return panda::JSValueRef::Undefined(vm);
4053 }
4054
SetTouchable(ArkUIRuntimeCallInfo * runtimeCallInfo)4055 ArkUINativeModuleValue CommonBridge::SetTouchable(ArkUIRuntimeCallInfo* runtimeCallInfo)
4056 {
4057 EcmaVM* vm = runtimeCallInfo->GetVM();
4058 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4059 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4060 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4061 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4062 if (secondArg->IsBoolean()) {
4063 bool touchable = secondArg->ToBoolean(vm)->Value();
4064 GetArkUINodeModifiers()->getCommonModifier()->setTouchable(nativeNode, touchable);
4065 } else {
4066 GetArkUINodeModifiers()->getCommonModifier()->resetTouchable(nativeNode);
4067 }
4068 return panda::JSValueRef::Undefined(vm);
4069 }
4070
ResetTouchable(ArkUIRuntimeCallInfo * runtimeCallInfo)4071 ArkUINativeModuleValue CommonBridge::ResetTouchable(ArkUIRuntimeCallInfo* runtimeCallInfo)
4072 {
4073 EcmaVM* vm = runtimeCallInfo->GetVM();
4074 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4075 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4076 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4077 GetArkUINodeModifiers()->getCommonModifier()->resetTouchable(nativeNode);
4078 return panda::JSValueRef::Undefined(vm);
4079 }
4080
SetDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)4081 ArkUINativeModuleValue CommonBridge::SetDefaultFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
4082 {
4083 EcmaVM* vm = runtimeCallInfo->GetVM();
4084 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4085 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4086 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4087 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4088 if (secondArg->IsBoolean()) {
4089 bool defaultFocus = secondArg->ToBoolean(vm)->Value();
4090 GetArkUINodeModifiers()->getCommonModifier()->setDefaultFocus(nativeNode, defaultFocus);
4091 } else {
4092 GetArkUINodeModifiers()->getCommonModifier()->resetDefaultFocus(nativeNode);
4093 }
4094 return panda::JSValueRef::Undefined(vm);
4095 }
4096
ResetDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)4097 ArkUINativeModuleValue CommonBridge::ResetDefaultFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
4098 {
4099 EcmaVM* vm = runtimeCallInfo->GetVM();
4100 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4101 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4102 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4103 GetArkUINodeModifiers()->getCommonModifier()->resetDefaultFocus(nativeNode);
4104 return panda::JSValueRef::Undefined(vm);
4105 }
4106
SetDisplayPriority(ArkUIRuntimeCallInfo * runtimeCallInfo)4107 ArkUINativeModuleValue CommonBridge::SetDisplayPriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
4108 {
4109 EcmaVM* vm = runtimeCallInfo->GetVM();
4110 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4111 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4112 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4113 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4114 if (secondArg->IsNumber()) {
4115 double value = secondArg->ToNumber(vm)->Value();
4116 GetArkUINodeModifiers()->getCommonModifier()->setDisplayPriority(nativeNode, value);
4117 } else {
4118 GetArkUINodeModifiers()->getCommonModifier()->resetDisplayPriority(nativeNode);
4119 }
4120 return panda::JSValueRef::Undefined(vm);
4121 }
4122
ResetDisplayPriority(ArkUIRuntimeCallInfo * runtimeCallInfo)4123 ArkUINativeModuleValue CommonBridge::ResetDisplayPriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
4124 {
4125 EcmaVM* vm = runtimeCallInfo->GetVM();
4126 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4127 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4128 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4129 GetArkUINodeModifiers()->getCommonModifier()->resetDisplayPriority(nativeNode);
4130 return panda::JSValueRef::Undefined(vm);
4131 }
4132
SetAccessibilityLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)4133 ArkUINativeModuleValue CommonBridge::SetAccessibilityLevel(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 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4139 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4140 if (secondArg->IsString(vm)) {
4141 std::string stringValue = secondArg->ToString(vm)->ToString(vm);
4142 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityLevel(nativeNode, stringValue.c_str());
4143 } else {
4144 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityLevel(nativeNode);
4145 }
4146 return panda::JSValueRef::Undefined(vm);
4147 }
4148
ResetAccessibilityLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)4149 ArkUINativeModuleValue CommonBridge::ResetAccessibilityLevel(ArkUIRuntimeCallInfo* runtimeCallInfo)
4150 {
4151 EcmaVM* vm = runtimeCallInfo->GetVM();
4152 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4153 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4154 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4155 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityLevel(nativeNode);
4156 return panda::JSValueRef::Undefined(vm);
4157 }
4158
SetAccessibilityRoleType(ArkUIRuntimeCallInfo * runtimeCallInfo)4159 ArkUINativeModuleValue CommonBridge::SetAccessibilityRoleType(ArkUIRuntimeCallInfo* runtimeCallInfo)
4160 {
4161 EcmaVM* vm = runtimeCallInfo->GetVM();
4162 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4163 if (runtimeCallInfo->GetArgsNumber() < NUM_2) {
4164 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "set role params num is invalid");
4165 return panda::NativePointerRef::New(vm, nullptr);
4166 }
4167 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4168 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4169 if (!firstArg->IsNativePointer(vm)) {
4170 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "set role first param is invalid");
4171 return panda::NativePointerRef::New(vm, nullptr);
4172 }
4173 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4174 if (secondArg->IsInt()) {
4175 auto index = secondArg->Int32Value(vm);
4176 AccessibilityRoleType roleType = static_cast<AccessibilityRoleType>(index);
4177 std::string role = JSAccessibilityAbstract::GetRoleByType(roleType);
4178 if (!role.empty()) {
4179 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityCustomRole(nativeNode, role.c_str());
4180 } else {
4181 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityCustomRole(nativeNode);
4182 }
4183 } else {
4184 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityCustomRole(nativeNode);
4185 }
4186 return panda::JSValueRef::Undefined(vm);
4187 }
4188
ResetAccessibilityRoleType(ArkUIRuntimeCallInfo * runtimeCallInfo)4189 ArkUINativeModuleValue CommonBridge::ResetAccessibilityRoleType(ArkUIRuntimeCallInfo* runtimeCallInfo)
4190 {
4191 EcmaVM* vm = runtimeCallInfo->GetVM();
4192 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4193 if (runtimeCallInfo->GetArgsNumber() < NUM_1) {
4194 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "reset role params num is invalid");
4195 return panda::NativePointerRef::New(vm, nullptr);
4196 }
4197 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4198 if (!firstArg->IsNativePointer(vm)) {
4199 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "reset role first param is invalid");
4200 return panda::NativePointerRef::New(vm, nullptr);
4201 }
4202 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4203 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityCustomRole(nativeNode);
4204 return panda::JSValueRef::Undefined(vm);
4205 }
4206
SetAccessibilityFocusCallback(ArkUIRuntimeCallInfo * runtimeCallInfo)4207 ArkUINativeModuleValue CommonBridge::SetAccessibilityFocusCallback(ArkUIRuntimeCallInfo* runtimeCallInfo)
4208 {
4209 EcmaVM* vm = runtimeCallInfo->GetVM();
4210 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4211 if (runtimeCallInfo->GetArgsNumber() < NUM_2) {
4212 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "set focus callback params num is invalid");
4213 return panda::NativePointerRef::New(vm, nullptr);
4214 }
4215 auto* frameNode = GetFrameNode(runtimeCallInfo);
4216 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
4217 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4218 if (!secondArg->IsFunction(vm)) {
4219 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "set focus callback params is invalid, reset callback");
4220 ViewAbstractModelNG::ResetOnAccessibilityFocus(frameNode);
4221 return panda::JSValueRef::Undefined(vm);
4222 }
4223 auto obj = secondArg->ToObject(vm);
4224 auto containerId = Container::CurrentId();
4225 panda::Local<panda::FunctionRef> func = obj;
4226 auto focusCallback = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
4227 containerId](bool isFocus) {
4228 panda::LocalScope pandaScope(vm);
4229 panda::TryCatch trycatch(vm);
4230 ContainerScope scope(containerId);
4231 PipelineContext::SetCallBackNode(node);
4232 auto newJSVal = panda::BooleanRef::New(vm, isFocus);
4233 panda::Local<panda::JSValueRef> params[] = { newJSVal };
4234 func->Call(vm, func.ToLocal(), params, 1);
4235 };
4236 ViewAbstractModelNG::SetOnAccessibilityFocus(frameNode, std::move(focusCallback));
4237 return panda::JSValueRef::Undefined(vm);
4238 }
4239
ResetAccessibilityFocusCallback(ArkUIRuntimeCallInfo * runtimeCallInfo)4240 ArkUINativeModuleValue CommonBridge::ResetAccessibilityFocusCallback(ArkUIRuntimeCallInfo* runtimeCallInfo)
4241 {
4242 EcmaVM* vm = runtimeCallInfo->GetVM();
4243 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4244 if (runtimeCallInfo->GetArgsNumber() < NUM_1) {
4245 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "reset focus callback params num is invalid");
4246 return panda::NativePointerRef::New(vm, nullptr);
4247 }
4248 auto* frameNode = GetFrameNode(runtimeCallInfo);
4249 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
4250 ViewAbstractModelNG::ResetOnAccessibilityFocus(frameNode);
4251 return panda::JSValueRef::Undefined(vm);
4252 }
4253
SetAccessibilityDescription(ArkUIRuntimeCallInfo * runtimeCallInfo)4254 ArkUINativeModuleValue CommonBridge::SetAccessibilityDescription(ArkUIRuntimeCallInfo* runtimeCallInfo)
4255 {
4256 EcmaVM* vm = runtimeCallInfo->GetVM();
4257 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4258 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4259 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4260 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4261 std::string value;
4262 if (ArkTSUtils::ParseJsString(vm, secondArg, value)) {
4263 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityDescription(nativeNode, value.c_str());
4264 } else {
4265 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityDescription(nativeNode);
4266 }
4267 return panda::JSValueRef::Undefined(vm);
4268 }
4269
ResetAccessibilityDescription(ArkUIRuntimeCallInfo * runtimeCallInfo)4270 ArkUINativeModuleValue CommonBridge::ResetAccessibilityDescription(ArkUIRuntimeCallInfo* runtimeCallInfo)
4271 {
4272 EcmaVM* vm = runtimeCallInfo->GetVM();
4273 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4274 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4275 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4276 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityDescription(nativeNode);
4277 return panda::JSValueRef::Undefined(vm);
4278 }
4279
SetOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)4280 ArkUINativeModuleValue CommonBridge::SetOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
4281 {
4282 EcmaVM* vm = runtimeCallInfo->GetVM();
4283 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4284 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4285 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4286 bool useEdges = runtimeCallInfo->GetCallArgRef(NUM_1)->ToBoolean(vm)->Value();
4287 std::vector<ArkUIStringAndFloat> options;
4288 std::vector<std::optional<CalcDimension>> edges;
4289
4290 if (useEdges) {
4291 ParseResult res = ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_4, edges, CalcDimension(0.0));
4292 if (res == ParseResult::LENGTHMETRICS_SUCCESS && AceApplicationInfo::GetInstance().IsRightToLeft()) {
4293 // Swap left and right
4294 std::swap(edges[NUM_1], edges[NUM_3]);
4295 }
4296 PushDimensionsToVector(options, edges);
4297 GetArkUINodeModifiers()->getCommonModifier()->setOffsetEdges(nativeNode, useEdges, options.data());
4298 } else {
4299 ParseCalcDimensionsNG(runtimeCallInfo, NUM_2, NUM_2, edges, CalcDimension(0.0));
4300 PushDimensionsToVector(options, edges);
4301 GetArkUINodeModifiers()->getCommonModifier()->setOffsetEdges(nativeNode, useEdges, options.data());
4302 }
4303 return panda::JSValueRef::Undefined(vm);
4304 }
4305
ResetOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)4306 ArkUINativeModuleValue CommonBridge::ResetOffset(ArkUIRuntimeCallInfo *runtimeCallInfo)
4307 {
4308 EcmaVM *vm = runtimeCallInfo->GetVM();
4309 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4310 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4311 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4312
4313 GetArkUINodeModifiers()->getCommonModifier()->resetOffset(nativeNode);
4314 return panda::JSValueRef::Undefined(vm);
4315 }
4316
ParsePadding(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)4317 void ParsePadding(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen, ArkUISizeType& result)
4318 {
4319 if (ArkTSUtils::ParseJsDimensionVp(vm, value, dimen)) {
4320 if (LessOrEqual(dimen.Value(), 0.0)) {
4321 dimen.SetValue(0.0);
4322 dimen.SetUnit(DimensionUnit::VP);
4323 }
4324 result.unit = static_cast<int8_t>(dimen.Unit());
4325 if (dimen.CalcValue() != "") {
4326 result.string = dimen.CalcValue().c_str();
4327 } else {
4328 result.value = dimen.Value();
4329 }
4330 }
4331 }
4332
ParseLocalizedPadding(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)4333 bool ParseLocalizedPadding(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen,
4334 ArkUISizeType& result)
4335 {
4336 if (ArkTSUtils::ParseJsLengthMetrics(vm, value, dimen)) {
4337 if (LessOrEqual(dimen.Value(), 0.0)) {
4338 dimen.SetValue(0.0);
4339 dimen.SetUnit(DimensionUnit::VP);
4340 }
4341 result.unit = static_cast<int8_t>(dimen.Unit());
4342 if (dimen.CalcValue() != "") {
4343 result.string = dimen.CalcValue().c_str();
4344 } else {
4345 result.value = dimen.Value();
4346 }
4347 return true;
4348 }
4349 return false;
4350 }
4351
SetPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)4352 ArkUINativeModuleValue CommonBridge::SetPadding(ArkUIRuntimeCallInfo *runtimeCallInfo)
4353 {
4354 EcmaVM *vm = runtimeCallInfo->GetVM();
4355 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4356 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4357 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4358 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4359 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4360 Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
4361 Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
4362
4363 struct ArkUISizeType top = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4364 struct ArkUISizeType right = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4365 struct ArkUISizeType bottom = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4366 struct ArkUISizeType left = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4367
4368 CalcDimension topDimen(0, DimensionUnit::VP);
4369 CalcDimension rightDimen(0, DimensionUnit::VP);
4370 CalcDimension bottomDimen(0, DimensionUnit::VP);
4371 CalcDimension leftDimen(0, DimensionUnit::VP);
4372
4373 bool isLengthMetrics = false;
4374 if (secondArg->IsObject(vm)) {
4375 isLengthMetrics |= ParseLocalizedPadding(vm, secondArg, topDimen, top);
4376 }
4377 if (thirdArg->IsObject(vm)) {
4378 isLengthMetrics |= ParseLocalizedPadding(vm, thirdArg, rightDimen, right);
4379 }
4380 if (forthArg->IsObject(vm)) {
4381 isLengthMetrics |= ParseLocalizedPadding(vm, forthArg, bottomDimen, bottom);
4382 }
4383 if (fifthArg->IsObject(vm)) {
4384 isLengthMetrics |= ParseLocalizedPadding(vm, fifthArg, leftDimen, left);
4385 }
4386
4387 if (isLengthMetrics) {
4388 auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
4389 GetArkUINodeModifiers()->getCommonModifier()->setPadding(nativeNode,
4390 &top,
4391 isRightToLeft ? &left : &right,
4392 &bottom,
4393 isRightToLeft ? &right : &left);
4394 return panda::JSValueRef::Undefined(vm);
4395 }
4396
4397 ParsePadding(vm, secondArg, topDimen, top);
4398 ParsePadding(vm, thirdArg, rightDimen, right);
4399 ParsePadding(vm, forthArg, bottomDimen, bottom);
4400 ParsePadding(vm, fifthArg, leftDimen, left);
4401 GetArkUINodeModifiers()->getCommonModifier()->setPadding(nativeNode, &top, &right, &bottom, &left);
4402
4403 return panda::JSValueRef::Undefined(vm);
4404 }
4405
ResetPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)4406 ArkUINativeModuleValue CommonBridge::ResetPadding(ArkUIRuntimeCallInfo *runtimeCallInfo)
4407 {
4408 EcmaVM *vm = runtimeCallInfo->GetVM();
4409 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4410 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4411 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4412 GetArkUINodeModifiers()->getCommonModifier()->resetPadding(nativeNode);
4413 return panda::JSValueRef::Undefined(vm);
4414 }
4415
ParseLocalizedMargin(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)4416 bool ParseLocalizedMargin(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen, ArkUISizeType& result)
4417 {
4418 if (ArkTSUtils::ParseJsLengthMetrics(vm, value, dimen)) {
4419 result.unit = static_cast<int8_t>(dimen.Unit());
4420 if (dimen.CalcValue() != "") {
4421 result.string = dimen.CalcValue().c_str();
4422 } else {
4423 result.value = dimen.Value();
4424 }
4425 return true;
4426 }
4427 return false;
4428 }
4429
ParseMargin(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dimen,ArkUISizeType & result)4430 void ParseMargin(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dimen, ArkUISizeType& result)
4431 {
4432 if (ArkTSUtils::ParseJsDimensionVp(vm, value, dimen)) {
4433 result.unit = static_cast<int8_t>(dimen.Unit());
4434 if (dimen.CalcValue() != "") {
4435 result.string = dimen.CalcValue().c_str();
4436 } else {
4437 result.value = dimen.Value();
4438 }
4439 }
4440 }
4441
SetMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)4442 ArkUINativeModuleValue CommonBridge::SetMargin(ArkUIRuntimeCallInfo *runtimeCallInfo)
4443 {
4444 EcmaVM *vm = runtimeCallInfo->GetVM();
4445 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4446 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4447 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4448 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4449 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4450 Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
4451 Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
4452 ArkUISizeType top = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4453 ArkUISizeType right = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4454 ArkUISizeType bottom = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4455 ArkUISizeType left = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
4456 CalcDimension topDimen(0, DimensionUnit::VP);
4457 CalcDimension rightDimen(0, DimensionUnit::VP);
4458 CalcDimension bottomDimen(0, DimensionUnit::VP);
4459 CalcDimension leftDimen(0, DimensionUnit::VP);
4460
4461 bool isLengthMetrics = false;
4462 if (secondArg->IsObject(vm)) {
4463 isLengthMetrics |= ParseLocalizedMargin(vm, secondArg, topDimen, top);
4464 }
4465 if (thirdArg->IsObject(vm)) {
4466 isLengthMetrics |= ParseLocalizedMargin(vm, thirdArg, rightDimen, right);
4467 }
4468 if (forthArg->IsObject(vm)) {
4469 isLengthMetrics |= ParseLocalizedMargin(vm, forthArg, bottomDimen, bottom);
4470 }
4471 if (fifthArg->IsObject(vm)) {
4472 isLengthMetrics |= ParseLocalizedMargin(vm, fifthArg, leftDimen, left);
4473 }
4474 if (isLengthMetrics) {
4475 auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
4476 GetArkUINodeModifiers()->getCommonModifier()->setMargin(nativeNode,
4477 &top,
4478 isRightToLeft ? &left : &right,
4479 &bottom,
4480 isRightToLeft ? &right : &left);
4481 return panda::JSValueRef::Undefined(vm);
4482 }
4483 ParseMargin(vm, secondArg, topDimen, top);
4484 ParseMargin(vm, thirdArg, rightDimen, right);
4485 ParseMargin(vm, forthArg, bottomDimen, bottom);
4486 ParseMargin(vm, fifthArg, leftDimen, left);
4487 GetArkUINodeModifiers()->getCommonModifier()->setMargin(nativeNode, &top, &right, &bottom, &left);
4488 return panda::JSValueRef::Undefined(vm);
4489 }
4490
ResetMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)4491 ArkUINativeModuleValue CommonBridge::ResetMargin(ArkUIRuntimeCallInfo *runtimeCallInfo)
4492 {
4493 EcmaVM *vm = runtimeCallInfo->GetVM();
4494 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4495 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4496 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4497 GetArkUINodeModifiers()->getCommonModifier()->resetMargin(nativeNode);
4498 return panda::JSValueRef::Undefined(vm);
4499 }
4500
SetSafeAreaPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)4501 ArkUINativeModuleValue CommonBridge::SetSafeAreaPadding(ArkUIRuntimeCallInfo* runtimeCallInfo)
4502 {
4503 EcmaVM* vm = runtimeCallInfo->GetVM();
4504 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4505 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4506 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4507 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4508 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4509 Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
4510 Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
4511 struct ArkUISizeType top = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4512 struct ArkUISizeType end = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4513 struct ArkUISizeType bottom = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4514 struct ArkUISizeType start = { 0.0, static_cast<int8_t>(DimensionUnit::VP) };
4515 CalcDimension topDimen(0, DimensionUnit::VP);
4516 CalcDimension endDimen(0, DimensionUnit::VP);
4517 CalcDimension bottomDimen(0, DimensionUnit::VP);
4518 CalcDimension startDimen(0, DimensionUnit::VP);
4519 bool isLengthMetrics = false;
4520 if (secondArg->IsObject(vm)) {
4521 isLengthMetrics |= ParseLocalizedPadding(vm, secondArg, topDimen, top);
4522 }
4523 if (thirdArg->IsObject(vm)) {
4524 isLengthMetrics |= ParseLocalizedPadding(vm, thirdArg, endDimen, end);
4525 }
4526 if (forthArg->IsObject(vm)) {
4527 isLengthMetrics |= ParseLocalizedPadding(vm, forthArg, bottomDimen, bottom);
4528 }
4529 if (fifthArg->IsObject(vm)) {
4530 isLengthMetrics |= ParseLocalizedPadding(vm, fifthArg, startDimen, start);
4531 }
4532 if (!isLengthMetrics) {
4533 ParsePadding(vm, secondArg, topDimen, top);
4534 ParsePadding(vm, thirdArg, endDimen, end);
4535 ParsePadding(vm, forthArg, bottomDimen, bottom);
4536 ParsePadding(vm, fifthArg, startDimen, start);
4537 }
4538 struct ArkUIPaddingType localizedPadding;
4539 localizedPadding.top = top;
4540 localizedPadding.end = end;
4541 localizedPadding.bottom = bottom;
4542 localizedPadding.start = start;
4543 GetArkUINodeModifiers()->getCommonModifier()->setSafeAreaPadding(nativeNode, &localizedPadding, isLengthMetrics);
4544 return panda::JSValueRef::Undefined(vm);
4545 }
4546
ResetSafeAreaPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)4547 ArkUINativeModuleValue CommonBridge::ResetSafeAreaPadding(ArkUIRuntimeCallInfo *runtimeCallInfo)
4548 {
4549 EcmaVM *vm = runtimeCallInfo->GetVM();
4550 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4551 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4552 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4553 GetArkUINodeModifiers()->getCommonModifier()->resetSafeAreaPadding(nativeNode);
4554 return panda::JSValueRef::Undefined(vm);
4555 }
4556
SetMarkAnchor(ArkUIRuntimeCallInfo * runtimeCallInfo)4557 ArkUINativeModuleValue CommonBridge::SetMarkAnchor(ArkUIRuntimeCallInfo* runtimeCallInfo)
4558 {
4559 EcmaVM* vm = runtimeCallInfo->GetVM();
4560 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4561 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4562 Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4563 Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4564 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4565 CalcDimension x(0.0, DimensionUnit::VP);
4566 CalcDimension y(0.0, DimensionUnit::VP);
4567 bool useLengthMetrics = ArkTSUtils::ParseJsLengthMetrics(vm, xArg, x);
4568 useLengthMetrics = ArkTSUtils::ParseJsLengthMetrics(vm, yArg, y) || useLengthMetrics;
4569 if (useLengthMetrics && AceApplicationInfo::GetInstance().IsRightToLeft()) {
4570 x.SetValue(-x.Value());
4571 }
4572 bool hasX = useLengthMetrics || ArkTSUtils::ParseJsDimensionNG(vm, xArg, x, DimensionUnit::VP);
4573 bool hasY = useLengthMetrics || ArkTSUtils::ParseJsDimensionNG(vm, yArg, y, DimensionUnit::VP);
4574 if (useLengthMetrics || hasX || hasY) {
4575 GetArkUINodeModifiers()->getCommonModifier()->setMarkAnchor(
4576 nativeNode, x.Value(), static_cast<int32_t>(x.Unit()), y.Value(), static_cast<int32_t>(y.Unit()));
4577 } else {
4578 GetArkUINodeModifiers()->getCommonModifier()->resetMarkAnchor(nativeNode);
4579 }
4580 return panda::JSValueRef::Undefined(vm);
4581 }
4582
ResetMarkAnchor(ArkUIRuntimeCallInfo * runtimeCallInfo)4583 ArkUINativeModuleValue CommonBridge::ResetMarkAnchor(ArkUIRuntimeCallInfo *runtimeCallInfo)
4584 {
4585 EcmaVM *vm = runtimeCallInfo->GetVM();
4586 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4587 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
4588 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4589 GetArkUINodeModifiers()->getCommonModifier()->resetMarkAnchor(nativeNode);
4590 return panda::JSValueRef::Undefined(vm);
4591 }
4592
SetVisibility(ArkUIRuntimeCallInfo * runtimeCallInfo)4593 ArkUINativeModuleValue CommonBridge::SetVisibility(ArkUIRuntimeCallInfo *runtimeCallInfo)
4594 {
4595 EcmaVM *vm = runtimeCallInfo->GetVM();
4596 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4597 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4598 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4599 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4600 int32_t value = 0;
4601 if (secondArg->IsNumber()) {
4602 value = secondArg->Int32Value(vm);
4603 if (value<NUM_0 || value>NUM_2) {
4604 value = 0;
4605 }
4606 }
4607 GetArkUINodeModifiers()->getCommonModifier()->setVisibility(nativeNode, value);
4608 return panda::JSValueRef::Undefined(vm);
4609 }
4610
ResetVisibility(ArkUIRuntimeCallInfo * runtimeCallInfo)4611 ArkUINativeModuleValue CommonBridge::ResetVisibility(ArkUIRuntimeCallInfo *runtimeCallInfo)
4612 {
4613 EcmaVM *vm = runtimeCallInfo->GetVM();
4614 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4615 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4616 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4617 GetArkUINodeModifiers()->getCommonModifier()->resetVisibility(nativeNode);
4618 return panda::JSValueRef::Undefined(vm);
4619 }
4620
SetAccessibilityText(ArkUIRuntimeCallInfo * runtimeCallInfo)4621 ArkUINativeModuleValue CommonBridge::SetAccessibilityText(ArkUIRuntimeCallInfo* runtimeCallInfo)
4622 {
4623 EcmaVM* vm = runtimeCallInfo->GetVM();
4624 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4625 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4626 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
4627 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4628 std::string value;
4629 if (ArkTSUtils::ParseJsString(vm, secondArg, value)) {
4630 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityText(nativeNode, value.c_str());
4631 } else {
4632 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityText(nativeNode);
4633 }
4634 return panda::JSValueRef::Undefined(vm);
4635 }
4636
ResetAccessibilityText(ArkUIRuntimeCallInfo * runtimeCallInfo)4637 ArkUINativeModuleValue CommonBridge::ResetAccessibilityText(ArkUIRuntimeCallInfo* runtimeCallInfo)
4638 {
4639 EcmaVM* vm = runtimeCallInfo->GetVM();
4640 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4641 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4642 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4643 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityText(nativeNode);
4644 return panda::JSValueRef::Undefined(vm);
4645 }
4646
SetConstraintSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4647 ArkUINativeModuleValue CommonBridge::SetConstraintSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4648 {
4649 EcmaVM* vm = runtimeCallInfo->GetVM();
4650 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4651 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4652 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4653 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4654 Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
4655 Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
4656 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4657 CalcDimension minWidth;
4658 CalcDimension maxWidth;
4659 CalcDimension minHeight;
4660 CalcDimension maxHeight;
4661 struct ArkUISizeType minWidthValue = {0.0, 0};
4662 struct ArkUISizeType maxWidthValue = {0.0, 0};
4663 struct ArkUISizeType minHeightValue = {0.0, 0};
4664 struct ArkUISizeType maxHeightValue = {0.0, 0};
4665
4666 bool version10OrLarger = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN);
4667 if (ArkTSUtils::ParseJsDimensionVp(vm, secondArg, minWidth, false)) {
4668 if (minWidth.CalcValue() != "") {
4669 minWidthValue.string = minWidth.CalcValue().c_str();
4670 } else {
4671 minWidthValue.value = minWidth.Value();
4672 minWidthValue.unit = static_cast<int8_t>(minWidth.Unit());
4673 }
4674 GetArkUINodeModifiers()->getCommonModifier()->setMinWidth(nativeNode, &minWidthValue);
4675 } else if (version10OrLarger) {
4676 GetArkUINodeModifiers()->getCommonModifier()->resetMinWidth(nativeNode);
4677 }
4678
4679 if (ArkTSUtils::ParseJsDimensionVp(vm, thirdArg, maxWidth, false)) {
4680 if (maxWidth.CalcValue() != "") {
4681 maxWidthValue.string = maxWidth.CalcValue().c_str();
4682 } else {
4683 maxWidthValue.value = maxWidth.Value();
4684 maxWidthValue.unit = static_cast<int8_t>(maxWidth.Unit());
4685 }
4686 GetArkUINodeModifiers()->getCommonModifier()->setMaxWidth(nativeNode, &maxWidthValue);
4687 } else if (version10OrLarger) {
4688 GetArkUINodeModifiers()->getCommonModifier()->resetMaxWidth(nativeNode);
4689 }
4690
4691 if (ArkTSUtils::ParseJsDimensionVp(vm, forthArg, minHeight, false)) {
4692 if (minHeight.CalcValue() != "") {
4693 minHeightValue.string = minHeight.CalcValue().c_str();
4694 } else {
4695 minHeightValue.value = minHeight.Value();
4696 minHeightValue.unit = static_cast<int8_t>(minHeight.Unit());
4697 }
4698 GetArkUINodeModifiers()->getCommonModifier()->setMinHeight(nativeNode, &minHeightValue);
4699 } else if (version10OrLarger) {
4700 GetArkUINodeModifiers()->getCommonModifier()->resetMinHeight(nativeNode);
4701 }
4702
4703 if (ArkTSUtils::ParseJsDimensionVp(vm, fifthArg, maxHeight, false)) {
4704 if (maxHeight.CalcValue() != "") {
4705 maxHeightValue.string = maxHeight.CalcValue().c_str();
4706 } else {
4707 maxHeightValue.value = maxHeight.Value();
4708 maxHeightValue.unit = static_cast<int8_t>(maxHeight.Unit());
4709 }
4710 GetArkUINodeModifiers()->getCommonModifier()->setMaxHeight(nativeNode, &maxHeightValue);
4711 } else if (version10OrLarger) {
4712 GetArkUINodeModifiers()->getCommonModifier()->resetMaxHeight(nativeNode);
4713 }
4714 return panda::JSValueRef::Undefined(vm);
4715 }
4716
ResetConstraintSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4717 ArkUINativeModuleValue CommonBridge::ResetConstraintSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4718 {
4719 EcmaVM* vm = runtimeCallInfo->GetVM();
4720 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4721 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4722 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4723 GetArkUINodeModifiers()->getCommonModifier()->resetMaxHeight(nativeNode);
4724 GetArkUINodeModifiers()->getCommonModifier()->resetMaxWidth(nativeNode);
4725 GetArkUINodeModifiers()->getCommonModifier()->resetMinHeight(nativeNode);
4726 GetArkUINodeModifiers()->getCommonModifier()->resetMinWidth(nativeNode);
4727 return panda::JSValueRef::Undefined(vm);
4728 }
4729
SetDirection(ArkUIRuntimeCallInfo * runtimeCallInfo)4730 ArkUINativeModuleValue CommonBridge::SetDirection(ArkUIRuntimeCallInfo* runtimeCallInfo)
4731 {
4732 EcmaVM* vm = runtimeCallInfo->GetVM();
4733 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4734 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4735 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4736 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4737 std::string dir;
4738 int32_t direction = NUM_3;
4739 if (secondArg->IsString(vm)) {
4740 dir = secondArg->ToString(vm)->ToString(vm);
4741 if (dir == "Ltr") {
4742 direction = NUM_0;
4743 } else if (dir == "Rtl") {
4744 direction = NUM_1;
4745 } else if (dir == "Auto") {
4746 direction = NUM_3;
4747 } else if (dir == "undefined" && Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
4748 direction = NUM_3;
4749 }
4750 }
4751 GetArkUINodeModifiers()->getCommonModifier()->setDirection(nativeNode, direction);
4752 return panda::JSValueRef::Undefined(vm);
4753 }
4754
ResetDirection(ArkUIRuntimeCallInfo * runtimeCallInfo)4755 ArkUINativeModuleValue CommonBridge::ResetDirection(ArkUIRuntimeCallInfo* runtimeCallInfo)
4756 {
4757 EcmaVM* vm = runtimeCallInfo->GetVM();
4758 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4759 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4760 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4761 GetArkUINodeModifiers()->getCommonModifier()->resetDirection(nativeNode);
4762 return panda::JSValueRef::Undefined(vm);
4763 }
4764
SetLayoutWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)4765 ArkUINativeModuleValue CommonBridge::SetLayoutWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
4766 {
4767 EcmaVM* vm = runtimeCallInfo->GetVM();
4768 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4769 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4770 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4771 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4772 float layoutWeight = 0.0f;
4773 if (secondArg->IsNumber()) {
4774 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE)) {
4775 layoutWeight = secondArg->ToNumber(vm)->Value();
4776 } else {
4777 layoutWeight = secondArg->Int32Value(vm);
4778 }
4779 } else if (secondArg->IsString(vm)) {
4780 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE)) {
4781 layoutWeight = StringUtils::StringToFloat(secondArg->ToString(vm)->ToString(vm));
4782 } else {
4783 layoutWeight = StringUtils::StringToInt(secondArg->ToString(vm)->ToString(vm));
4784 }
4785 }
4786 GetArkUINodeModifiers()->getCommonModifier()->setLayoutWeight(nativeNode, layoutWeight);
4787 return panda::JSValueRef::Undefined(vm);
4788 }
4789
ResetLayoutWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)4790 ArkUINativeModuleValue CommonBridge::ResetLayoutWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
4791 {
4792 EcmaVM* vm = runtimeCallInfo->GetVM();
4793 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4794 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
4795 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4796 GetArkUINodeModifiers()->getCommonModifier()->resetLayoutWeight(nativeNode);
4797 return panda::JSValueRef::Undefined(vm);
4798 }
4799
SetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4800 ArkUINativeModuleValue CommonBridge::SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4801 {
4802 EcmaVM* vm = runtimeCallInfo->GetVM();
4803 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4804 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4805 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4806 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4807 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4808 CalcDimension wVal(0.0, DimensionUnit::VP);
4809 CalcDimension hVal(0.0, DimensionUnit::VP);
4810 ParseCalcDimension(vm, nativeNode, secondArg, wVal, true);
4811 ParseCalcDimension(vm, nativeNode, thirdArg, hVal, false);
4812 return panda::JSValueRef::Undefined(vm);
4813 }
4814
ResetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)4815 ArkUINativeModuleValue CommonBridge::ResetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
4816 {
4817 EcmaVM* vm = runtimeCallInfo->GetVM();
4818 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4819 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4820 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4821 GetArkUINodeModifiers()->getCommonModifier()->resetWidth(nativeNode);
4822 GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
4823 return panda::JSValueRef::Undefined(vm);
4824 }
4825
SetAlignSelf(ArkUIRuntimeCallInfo * runtimeCallInfo)4826 ArkUINativeModuleValue CommonBridge::SetAlignSelf(ArkUIRuntimeCallInfo* runtimeCallInfo)
4827 {
4828 EcmaVM* vm = runtimeCallInfo->GetVM();
4829 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4830 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4831 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4832 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4833
4834 if (secondArg->IsNumber() && secondArg->ToNumber(vm)->Value() >= 0 &&
4835 secondArg->ToNumber(vm)->Value() <= MAX_ALIGN_VALUE) {
4836 GetArkUINodeModifiers()->getCommonModifier()->setAlignSelf(nativeNode, secondArg->Int32Value(vm));
4837 } else {
4838 GetArkUINodeModifiers()->getCommonModifier()->resetAlignSelf(nativeNode);
4839 }
4840 return panda::JSValueRef::Undefined(vm);
4841 }
4842
ResetAlignSelf(ArkUIRuntimeCallInfo * runtimeCallInfo)4843 ArkUINativeModuleValue CommonBridge::ResetAlignSelf(ArkUIRuntimeCallInfo* runtimeCallInfo)
4844 {
4845 EcmaVM* vm = runtimeCallInfo->GetVM();
4846 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4847 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4848 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4849 GetArkUINodeModifiers()->getCommonModifier()->resetAlignSelf(nativeNode);
4850 return panda::JSValueRef::Undefined(vm);
4851 }
4852
SetAspectRatio(ArkUIRuntimeCallInfo * runtimeCallInfo)4853 ArkUINativeModuleValue CommonBridge::SetAspectRatio(ArkUIRuntimeCallInfo* runtimeCallInfo)
4854 {
4855 EcmaVM* vm = runtimeCallInfo->GetVM();
4856 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4857 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4858 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4859 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4860
4861 if (secondArg->IsNumber()) {
4862 double value = secondArg->ToNumber(vm)->Value();
4863 GetArkUINodeModifiers()->getCommonModifier()->setAspectRatio(nativeNode, value);
4864 } else {
4865 GetArkUINodeModifiers()->getCommonModifier()->resetAspectRatio(nativeNode);
4866 }
4867 return panda::JSValueRef::Undefined(vm);
4868 }
4869
ResetAspectRatio(ArkUIRuntimeCallInfo * runtimeCallInfo)4870 ArkUINativeModuleValue CommonBridge::ResetAspectRatio(ArkUIRuntimeCallInfo* runtimeCallInfo)
4871 {
4872 EcmaVM* vm = runtimeCallInfo->GetVM();
4873 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4874 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4875 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4876 GetArkUINodeModifiers()->getCommonModifier()->resetAspectRatio(nativeNode);
4877 return panda::JSValueRef::Undefined(vm);
4878 }
4879
SetFlexGrow(ArkUIRuntimeCallInfo * runtimeCallInfo)4880 ArkUINativeModuleValue CommonBridge::SetFlexGrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
4881 {
4882 EcmaVM* vm = runtimeCallInfo->GetVM();
4883 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4884 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4885 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4886 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4887
4888 if (secondArg->IsNumber()) {
4889 double value = secondArg->ToNumber(vm)->Value();
4890 GetArkUINodeModifiers()->getCommonModifier()->setFlexGrow(nativeNode, value);
4891 } else {
4892 GetArkUINodeModifiers()->getCommonModifier()->resetFlexGrow(nativeNode);
4893 }
4894 return panda::JSValueRef::Undefined(vm);
4895 }
4896
ResetFlexGrow(ArkUIRuntimeCallInfo * runtimeCallInfo)4897 ArkUINativeModuleValue CommonBridge::ResetFlexGrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
4898 {
4899 EcmaVM* vm = runtimeCallInfo->GetVM();
4900 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4901 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4902 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4903 GetArkUINodeModifiers()->getCommonModifier()->resetFlexGrow(nativeNode);
4904 return panda::JSValueRef::Undefined(vm);
4905 }
4906
SetFlexShrink(ArkUIRuntimeCallInfo * runtimeCallInfo)4907 ArkUINativeModuleValue CommonBridge::SetFlexShrink(ArkUIRuntimeCallInfo* runtimeCallInfo)
4908 {
4909 EcmaVM* vm = runtimeCallInfo->GetVM();
4910 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4911 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4912 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4913 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4914
4915 if (secondArg->IsNumber()) {
4916 double value = secondArg->ToNumber(vm)->Value();
4917 GetArkUINodeModifiers()->getCommonModifier()->setFlexShrink(nativeNode, value);
4918 } else {
4919 GetArkUINodeModifiers()->getCommonModifier()->resetFlexShrink(nativeNode);
4920 }
4921 return panda::JSValueRef::Undefined(vm);
4922 }
4923
ResetFlexShrink(ArkUIRuntimeCallInfo * runtimeCallInfo)4924 ArkUINativeModuleValue CommonBridge::ResetFlexShrink(ArkUIRuntimeCallInfo* runtimeCallInfo)
4925 {
4926 EcmaVM* vm = runtimeCallInfo->GetVM();
4927 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4928 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4929 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4930 GetArkUINodeModifiers()->getCommonModifier()->resetFlexShrink(nativeNode);
4931 return panda::JSValueRef::Undefined(vm);
4932 }
4933
SetGridOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)4934 ArkUINativeModuleValue CommonBridge::SetGridOffset(ArkUIRuntimeCallInfo *runtimeCallInfo)
4935 {
4936 EcmaVM* vm = runtimeCallInfo->GetVM();
4937 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4938 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4939 Local<JSValueRef> offsetArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4940 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4941 int32_t offset = 0;
4942 if (offsetArg->IsNumber()) {
4943 offset = offsetArg->Int32Value(vm);
4944 GetArkUINodeModifiers()->getCommonModifier()->setGridOffset(nativeNode, offset);
4945 } else {
4946 GetArkUINodeModifiers()->getCommonModifier()->resetGridOffset(nativeNode);
4947 }
4948 return panda::JSValueRef::Undefined(vm);
4949 }
4950
ResetGridOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)4951 ArkUINativeModuleValue CommonBridge::ResetGridOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
4952 {
4953 EcmaVM* vm = runtimeCallInfo->GetVM();
4954 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4955 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4956 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
4957 GetArkUINodeModifiers()->getCommonModifier()->resetGridOffset(nativeNode);
4958 return panda::JSValueRef::Undefined(vm);
4959 }
4960
SetGridSpan(ArkUIRuntimeCallInfo * runtimeCallInfo)4961 ArkUINativeModuleValue CommonBridge::SetGridSpan(ArkUIRuntimeCallInfo *runtimeCallInfo)
4962 {
4963 EcmaVM* vm = runtimeCallInfo->GetVM();
4964 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4965 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4966 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4967 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4968 int32_t value = 0;
4969 if (secondArg->IsNumber()) {
4970 value = secondArg->Int32Value(vm);
4971 GetArkUINodeModifiers()->getCommonModifier()->setGridSpan(nativeNode, value);
4972 } else {
4973 GetArkUINodeModifiers()->getCommonModifier()->resetGridSpan(nativeNode);
4974 }
4975 return panda::JSValueRef::Undefined(vm);
4976 }
4977
ResetGridSpan(ArkUIRuntimeCallInfo * runtimeCallInfo)4978 ArkUINativeModuleValue CommonBridge::ResetGridSpan(ArkUIRuntimeCallInfo *runtimeCallInfo)
4979 {
4980 EcmaVM* vm = runtimeCallInfo->GetVM();
4981 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4982 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4983 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4984 GetArkUINodeModifiers()->getCommonModifier()->resetGridSpan(nativeNode);
4985 return panda::JSValueRef::Undefined(vm);
4986 }
4987
SetExpandSafeArea(ArkUIRuntimeCallInfo * runtimeCallInfo)4988 ArkUINativeModuleValue CommonBridge::SetExpandSafeArea(ArkUIRuntimeCallInfo *runtimeCallInfo)
4989 {
4990 EcmaVM* vm = runtimeCallInfo->GetVM();
4991 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
4992 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
4993 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
4994 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
4995 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
4996 std::string typeCppStr = "";
4997 std::string edgesCppStr = "";
4998 uint32_t safeAreaType = NG::SAFE_AREA_TYPE_NONE;
4999 uint32_t safeAreaEdge = NG::SAFE_AREA_EDGE_NONE;
5000 if (secondArg->IsString(vm)) {
5001 typeCppStr = secondArg->ToString(vm)->ToString(vm);
5002 safeAreaType = ParseStrToUint(typeCppStr);
5003 } else {
5004 safeAreaType = NG::SAFE_AREA_TYPE_ALL;
5005 }
5006
5007 if (thirdArg->IsString(vm)) {
5008 edgesCppStr = thirdArg->ToString(vm)->ToString(vm);
5009 safeAreaEdge = ParseStrToUint(edgesCppStr);
5010 } else {
5011 safeAreaEdge = NG::SAFE_AREA_EDGE_ALL;
5012 }
5013 GetArkUINodeModifiers()->getCommonModifier()->setExpandSafeArea(nativeNode, safeAreaType, safeAreaEdge);
5014 return panda::JSValueRef::Undefined(vm);
5015 }
5016
ResetExpandSafeArea(ArkUIRuntimeCallInfo * runtimeCallInfo)5017 ArkUINativeModuleValue CommonBridge::ResetExpandSafeArea(ArkUIRuntimeCallInfo* runtimeCallInfo)
5018 {
5019 EcmaVM* vm = runtimeCallInfo->GetVM();
5020 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5021 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5022 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5023 GetArkUINodeModifiers()->getCommonModifier()->resetExpandSafeArea(nativeNode);
5024 return panda::JSValueRef::Undefined(vm);
5025 }
5026
SetAlignRules(ArkUIRuntimeCallInfo * runtimeCallInfo)5027 ArkUINativeModuleValue CommonBridge::SetAlignRules(ArkUIRuntimeCallInfo* runtimeCallInfo)
5028 {
5029 EcmaVM* vm = runtimeCallInfo->GetVM();
5030 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5031 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5032 Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5033 Local<JSValueRef> middleArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5034 Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(NUM_3);
5035 Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(NUM_4);
5036 Local<JSValueRef> centerArg = runtimeCallInfo->GetCallArgRef(NUM_5);
5037 Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(NUM_6);
5038 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5039
5040 auto anchors = std::make_unique<std::string []>(ALIGN_RULES_NUM);
5041 auto direction = std::make_unique<ArkUI_Int32 []>(ALIGN_RULES_NUM);
5042 for (int32_t i = 0; i < ALIGN_RULES_NUM; i++) {
5043 anchors[i] = "";
5044 direction[i] = ALIGN_DIRECTION_DEFAULT;
5045 }
5046 bool leftParseResult = ParseJsAlignRule(vm, leftArg, anchors[0], direction[0]);
5047 bool middleParseResult = ParseJsAlignRule(vm, middleArg, anchors[1], direction[1]);
5048 bool rightParseResult = ParseJsAlignRule(vm, rightArg, anchors[2], direction[2]);
5049 bool topParseResult = ParseJsAlignRule(vm, topArg, anchors[3], direction[3]);
5050 bool centerParseResult = ParseJsAlignRule(vm, centerArg, anchors[4], direction[4]);
5051 bool bottomParseResult = ParseJsAlignRule(vm, bottomArg, anchors[5], direction[5]);
5052 if (!leftParseResult && !middleParseResult && !rightParseResult && !topParseResult && !centerParseResult &&
5053 !bottomParseResult) {
5054 GetArkUINodeModifiers()->getCommonModifier()->resetAlignRules(nativeNode);
5055 return panda::JSValueRef::Undefined(vm);
5056 }
5057 auto realAnchors = std::make_unique<char* []>(ALIGN_RULES_NUM);
5058 for (int32_t i = 0; i < ALIGN_RULES_NUM; i++) {
5059 realAnchors[i] = const_cast<char*>(anchors[i].c_str());
5060 }
5061 GetArkUINodeModifiers()->getCommonModifier()->setAlignRules(nativeNode, realAnchors.get(), direction.get(),
5062 ALIGN_RULES_NUM);
5063 return panda::JSValueRef::Undefined(vm);
5064 }
5065
ResetAlignRules(ArkUIRuntimeCallInfo * runtimeCallInfo)5066 ArkUINativeModuleValue CommonBridge::ResetAlignRules(ArkUIRuntimeCallInfo* runtimeCallInfo)
5067 {
5068 EcmaVM* vm = runtimeCallInfo->GetVM();
5069 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5070 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5071 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5072 GetArkUINodeModifiers()->getCommonModifier()->resetAlignRules(nativeNode);
5073 return panda::JSValueRef::Undefined(vm);
5074 }
5075
SetFlexBasis(ArkUIRuntimeCallInfo * runtimeCallInfo)5076 ArkUINativeModuleValue CommonBridge::SetFlexBasis(ArkUIRuntimeCallInfo* runtimeCallInfo)
5077 {
5078 EcmaVM* vm = runtimeCallInfo->GetVM();
5079 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5080 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5081 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5082 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5083 struct ArkUIStringAndFloat flexBasis { 0.0, nullptr};
5084 std::string tempValueStr = "";
5085 if (secondArg->IsNumber()) {
5086 flexBasis.value = secondArg->ToNumber(vm)->Value();
5087 GetArkUINodeModifiers()->getCommonModifier()->setFlexBasis(nativeNode, &flexBasis);
5088 } else if (secondArg->IsString(vm)) {
5089 tempValueStr = secondArg->ToString(vm)->ToString(vm);
5090 flexBasis.valueStr = tempValueStr.c_str();
5091 GetArkUINodeModifiers()->getCommonModifier()->setFlexBasis(nativeNode, &flexBasis);
5092 } else {
5093 GetArkUINodeModifiers()->getCommonModifier()->resetFlexBasis(nativeNode);
5094 }
5095 return panda::JSValueRef::Undefined(vm);
5096 }
5097
ResetFlexBasis(ArkUIRuntimeCallInfo * runtimeCallInfo)5098 ArkUINativeModuleValue CommonBridge::ResetFlexBasis(ArkUIRuntimeCallInfo* runtimeCallInfo)
5099 {
5100 EcmaVM* vm = runtimeCallInfo->GetVM();
5101 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5102 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5103 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5104 GetArkUINodeModifiers()->getCommonModifier()->resetFlexBasis(nativeNode);
5105 return panda::JSValueRef::Undefined(vm);
5106 }
5107
SetAllowDrop(ArkUIRuntimeCallInfo * runtimeCallInfo)5108 ArkUINativeModuleValue CommonBridge::SetAllowDrop(ArkUIRuntimeCallInfo* runtimeCallInfo)
5109 {
5110 EcmaVM* vm = runtimeCallInfo->GetVM();
5111 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5112 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5113 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
5114 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5115 if (secondArg->IsUndefined()) {
5116 GetArkUINodeModifiers()->getCommonModifier()->resetAllowDrop(nativeNode);
5117 return panda::JSValueRef::Undefined(vm);
5118 }
5119 Local<panda::ArrayRef> allowDropArray = static_cast<Local<panda::ArrayRef>>(secondArg);
5120 auto length = allowDropArray->Length(vm);
5121 if (length <= 0) {
5122 GetArkUINodeModifiers()->getCommonModifier()->resetAllowDrop(nativeNode);
5123 return panda::JSValueRef::Undefined(vm);
5124 }
5125 std::vector<std::string> keepStr(length);
5126 std::vector<const char*> strList;
5127 for (size_t i = 0; i < length; i++) {
5128 Local<JSValueRef> objValue = allowDropArray->GetValueAt(vm, secondArg, i);
5129 keepStr[i] = objValue->ToString(vm)->ToString(vm);
5130 strList.push_back(keepStr[i].c_str());
5131 }
5132 GetArkUINodeModifiers()->getCommonModifier()->setAllowDrop(nativeNode, strList.data(), strList.size());
5133 return panda::JSValueRef::Undefined(vm);
5134 }
5135
ResetAllowDrop(ArkUIRuntimeCallInfo * runtimeCallInfo)5136 ArkUINativeModuleValue CommonBridge::ResetAllowDrop(ArkUIRuntimeCallInfo* runtimeCallInfo)
5137 {
5138 EcmaVM* vm = runtimeCallInfo->GetVM();
5139 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5140 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5141 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5142 GetArkUINodeModifiers()->getCommonModifier()->resetAllowDrop(nativeNode);
5143 return panda::JSValueRef::Undefined(vm);
5144 }
5145
SetId(ArkUIRuntimeCallInfo * runtimeCallInfo)5146 ArkUINativeModuleValue CommonBridge::SetId(ArkUIRuntimeCallInfo* runtimeCallInfo)
5147 {
5148 EcmaVM* vm = runtimeCallInfo->GetVM();
5149 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5150 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5151 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
5152 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5153 if (secondArg->IsString(vm)) {
5154 std::string stringValue = secondArg->ToString(vm)->ToString(vm);
5155 GetArkUINodeModifiers()->getCommonModifier()->setId(nativeNode, stringValue.c_str());
5156 } else {
5157 GetArkUINodeModifiers()->getCommonModifier()->resetId(nativeNode);
5158 }
5159 return panda::JSValueRef::Undefined(vm);
5160 }
5161
ResetId(ArkUIRuntimeCallInfo * runtimeCallInfo)5162 ArkUINativeModuleValue CommonBridge::ResetId(ArkUIRuntimeCallInfo* runtimeCallInfo)
5163 {
5164 EcmaVM* vm = runtimeCallInfo->GetVM();
5165 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5166 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5167 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5168 GetArkUINodeModifiers()->getCommonModifier()->resetId(nativeNode);
5169 return panda::JSValueRef::Undefined(vm);
5170 }
5171
SetKey(ArkUIRuntimeCallInfo * runtimeCallInfo)5172 ArkUINativeModuleValue CommonBridge::SetKey(ArkUIRuntimeCallInfo* runtimeCallInfo)
5173 {
5174 EcmaVM* vm = runtimeCallInfo->GetVM();
5175 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5176 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5177 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
5178 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5179 if (secondArg->IsString(vm)) {
5180 std::string stringValue = secondArg->ToString(vm)->ToString(vm);
5181 GetArkUINodeModifiers()->getCommonModifier()->setKey(nativeNode, stringValue.c_str());
5182 } else {
5183 GetArkUINodeModifiers()->getCommonModifier()->resetKey(nativeNode);
5184 }
5185 return panda::JSValueRef::Undefined(vm);
5186 }
5187
ResetKey(ArkUIRuntimeCallInfo * runtimeCallInfo)5188 ArkUINativeModuleValue CommonBridge::ResetKey(ArkUIRuntimeCallInfo* runtimeCallInfo)
5189 {
5190 EcmaVM* vm = runtimeCallInfo->GetVM();
5191 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5192 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5193 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5194 GetArkUINodeModifiers()->getCommonModifier()->resetKey(nativeNode);
5195 return panda::JSValueRef::Undefined(vm);
5196 }
5197
SetRestoreId(ArkUIRuntimeCallInfo * runtimeCallInfo)5198 ArkUINativeModuleValue CommonBridge::SetRestoreId(ArkUIRuntimeCallInfo* runtimeCallInfo)
5199 {
5200 EcmaVM* vm = runtimeCallInfo->GetVM();
5201 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5202 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5203 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
5204 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5205 if (secondArg->IsNumber()) {
5206 uint32_t value = secondArg->Uint32Value(vm);
5207 GetArkUINodeModifiers()->getCommonModifier()->setRestoreId(nativeNode, value);
5208 } else {
5209 GetArkUINodeModifiers()->getCommonModifier()->resetRestoreId(nativeNode);
5210 }
5211 return panda::JSValueRef::Undefined(vm);
5212 }
5213
ResetRestoreId(ArkUIRuntimeCallInfo * runtimeCallInfo)5214 ArkUINativeModuleValue CommonBridge::ResetRestoreId(ArkUIRuntimeCallInfo* runtimeCallInfo)
5215 {
5216 EcmaVM* vm = runtimeCallInfo->GetVM();
5217 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5218 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5219 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5220 GetArkUINodeModifiers()->getCommonModifier()->resetRestoreId(nativeNode);
5221 return panda::JSValueRef::Undefined(vm);
5222 }
5223
SetTabIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)5224 ArkUINativeModuleValue CommonBridge::SetTabIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
5225 {
5226 EcmaVM* vm = runtimeCallInfo->GetVM();
5227 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5228 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5229 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
5230 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5231 if (secondArg->IsNumber()) {
5232 int32_t index = secondArg->Int32Value(vm);
5233 GetArkUINodeModifiers()->getCommonModifier()->setTabIndex(nativeNode, index);
5234 } else {
5235 GetArkUINodeModifiers()->getCommonModifier()->resetTabIndex(nativeNode);
5236 }
5237 return panda::JSValueRef::Undefined(vm);
5238 }
5239
ResetTabIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)5240 ArkUINativeModuleValue CommonBridge::ResetTabIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
5241 {
5242 EcmaVM* vm = runtimeCallInfo->GetVM();
5243 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5244 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5245 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5246 GetArkUINodeModifiers()->getCommonModifier()->resetTabIndex(nativeNode);
5247 return panda::JSValueRef::Undefined(vm);
5248 }
5249
SetObscured(ArkUIRuntimeCallInfo * runtimeCallInfo)5250 ArkUINativeModuleValue CommonBridge::SetObscured(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 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
5256 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5257
5258 if (secondArg->IsUndefined() || !secondArg->IsArray(vm)) {
5259 GetArkUINodeModifiers()->getCommonModifier()->resetObscured(nativeNode);
5260 return panda::JSValueRef::Undefined(vm);
5261 }
5262 Local<panda::ArrayRef> transArray = static_cast<Local<panda::ArrayRef>>(secondArg);
5263 auto length = transArray->Length(vm);
5264 int32_t reasonArray[length];
5265
5266 for (size_t i = 0; i < length; i++) {
5267 Local<JSValueRef> value = transArray->GetValueAt(vm, secondArg, i);
5268 reasonArray[i] = value->Int32Value(vm);
5269 }
5270 GetArkUINodeModifiers()->getCommonModifier()->setObscured(nativeNode, reasonArray, length);
5271 return panda::JSValueRef::Undefined(vm);
5272 }
5273
ResetObscured(ArkUIRuntimeCallInfo * runtimeCallInfo)5274 ArkUINativeModuleValue CommonBridge::ResetObscured(ArkUIRuntimeCallInfo* runtimeCallInfo)
5275 {
5276 EcmaVM* vm = runtimeCallInfo->GetVM();
5277 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5278 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5279 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5280 GetArkUINodeModifiers()->getCommonModifier()->resetObscured(nativeNode);
5281 return panda::JSValueRef::Undefined(vm);
5282 }
5283
SetForegroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5284 ArkUINativeModuleValue CommonBridge::SetForegroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5285 {
5286 EcmaVM* vm = runtimeCallInfo->GetVM();
5287 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5288 Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(1);
5289 Local<JSValueRef> disableSystemAdaptationArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5290 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5291 CalcDimension radius;
5292 if (!ArkTSUtils::ParseJsDimensionVp(vm, radiusArg, radius) || LessNotEqual(radius.Value(), 0.0f)) {
5293 radius.SetValue(0.0f);
5294 }
5295 ArkUI_Float32 radiusArk = static_cast<ArkUI_Int32>(radius.Value());
5296 bool disableSystemAdaptation = false;
5297 if (disableSystemAdaptationArg->IsBoolean()) {
5298 disableSystemAdaptation = disableSystemAdaptationArg->ToBoolean(vm)->Value();
5299 }
5300 GetArkUINodeModifiers()->getCommonModifier()->setForegroundEffect(nativeNode, radiusArk, disableSystemAdaptation);
5301 return panda::JSValueRef::Undefined(vm);
5302 }
5303
ResetForegroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5304 ArkUINativeModuleValue CommonBridge::ResetForegroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5305 {
5306 EcmaVM* vm = runtimeCallInfo->GetVM();
5307 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5308 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5309 GetArkUINodeModifiers()->getCommonModifier()->resetForegroundEffect(nativeNode);
5310 return panda::JSValueRef::Undefined(vm);
5311 }
5312
SetBackgroundEffectParam(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & policy,int32_t & blurType,Color & inactiveColor,bool & isValidColor)5313 void SetBackgroundEffectParam(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& policy, int32_t& blurType,
5314 Color& inactiveColor, bool& isValidColor)
5315 {
5316 EcmaVM* vm = runtimeCallInfo->GetVM();
5317 Local<JSValueRef> policyArg = runtimeCallInfo->GetCallArgRef(7); // 7:index of parameter policy
5318 Local<JSValueRef> inactiveColorArg = runtimeCallInfo->GetCallArgRef(8); // 8:index of parameter inactiveColor
5319 Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(9); // 9:index of parameter type
5320
5321 ParseJsInt32(vm, policyArg, policy);
5322 if (policy < static_cast<int32_t>(BlurStyleActivePolicy::FOLLOWS_WINDOW_ACTIVE_STATE) ||
5323 policy > static_cast<int32_t>(BlurStyleActivePolicy::ALWAYS_INACTIVE)) {
5324 policy = static_cast<int32_t>(BlurStyleActivePolicy::ALWAYS_ACTIVE);
5325 }
5326 ParseJsInt32(vm, typeArg, blurType);
5327 if (blurType < static_cast<int32_t>(BlurType::WITHIN_WINDOW) ||
5328 blurType > static_cast<int32_t>(BlurType::BEHIND_WINDOW)) {
5329 blurType = static_cast<int32_t>(BlurType::WITHIN_WINDOW);
5330 }
5331 if (ArkTSUtils::ParseJsColor(vm, inactiveColorArg, inactiveColor)) {
5332 isValidColor = true;
5333 }
5334 }
5335
SetAdaptiveColorParam(ArkUIRuntimeCallInfo * runtimeCallInfo,AdaptiveColor & adaptiveColor)5336 void SetAdaptiveColorParam(ArkUIRuntimeCallInfo* runtimeCallInfo, AdaptiveColor& adaptiveColor)
5337 {
5338 EcmaVM* vm = runtimeCallInfo->GetVM();
5339 Local<JSValueRef> adaptiveColorArg = runtimeCallInfo->GetCallArgRef(5); // 5:index of parameter adaptiveColor
5340 auto adaptiveColorValue = static_cast<int32_t>(AdaptiveColor::DEFAULT);
5341 if (adaptiveColorArg->IsNumber()) {
5342 adaptiveColorValue = adaptiveColorArg->Int32Value(vm);
5343 if (adaptiveColorValue >= static_cast<int32_t>(AdaptiveColor::DEFAULT) &&
5344 adaptiveColorValue <= static_cast<int32_t>(AdaptiveColor::AVERAGE)) {
5345 adaptiveColor = static_cast<AdaptiveColor>(adaptiveColorValue);
5346 }
5347 }
5348 }
5349
SetBackgroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5350 ArkUINativeModuleValue CommonBridge::SetBackgroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5351 {
5352 EcmaVM* vm = runtimeCallInfo->GetVM();
5353 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5354 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:index of parameter frameNode
5355 Local<JSValueRef> radiusArg = runtimeCallInfo->GetCallArgRef(1); // 1:index of parameter radius
5356 Local<JSValueRef> saturationArg = runtimeCallInfo->GetCallArgRef(2); // 2:index of parameter saturation
5357 Local<JSValueRef> brightnessArg = runtimeCallInfo->GetCallArgRef(3); // 3:index of parameter brightness
5358 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(4); // 4:index of parameter color
5359 Local<JSValueRef> blurOptionsArg = runtimeCallInfo->GetCallArgRef(6); // 6:index of parameter blurOptions
5360 Local<JSValueRef> disableSystemAdaptationArg = runtimeCallInfo->GetCallArgRef(NUM_10);
5361 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5362 CalcDimension radius;
5363 if (!ArkTSUtils::ParseJsDimensionVp(vm, radiusArg, radius) || LessNotEqual(radius.Value(), 0.0f)) {
5364 radius.SetValue(0.0f);
5365 }
5366 ArkUI_Float32 saturation = 1.0f;
5367 if (saturationArg->IsNumber()) {
5368 saturation = saturationArg->ToNumber(vm)->Value();
5369 saturation = (saturation > 0.0f || NearZero(saturation)) ? saturation : 1.0f;
5370 }
5371 ArkUI_Float32 brightness = 1.0f;
5372 if (brightnessArg->IsNumber()) {
5373 brightness = brightnessArg->ToNumber(vm)->Value();
5374 brightness = (brightness > 0.0f || NearZero(brightness)) ? brightness : 1.0f;
5375 }
5376 Color color = Color::TRANSPARENT;
5377 if (!ArkTSUtils::ParseJsColor(vm, colorArg, color)) {
5378 color.SetValue(Color::TRANSPARENT.GetValue());
5379 }
5380 auto adaptiveColor = AdaptiveColor::DEFAULT;
5381 SetAdaptiveColorParam(runtimeCallInfo, adaptiveColor);
5382 BlurOption blurOption;
5383 if (blurOptionsArg->IsArray(vm)) {
5384 ParseBlurOption(vm, blurOptionsArg, blurOption);
5385 }
5386 auto policy = static_cast<int32_t>(BlurStyleActivePolicy::ALWAYS_ACTIVE);
5387 auto blurType = static_cast<int32_t>(BlurType::WITHIN_WINDOW);
5388 Color inactiveColor = Color::TRANSPARENT;
5389 bool isValidColor = false;
5390 SetBackgroundEffectParam(runtimeCallInfo, policy, blurType, inactiveColor, isValidColor);
5391 bool disableSystemAdaptation = false;
5392 if (disableSystemAdaptationArg->IsBoolean()) {
5393 disableSystemAdaptation = disableSystemAdaptationArg->ToBoolean(vm)->Value();
5394 }
5395 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundEffect(nativeNode,
5396 static_cast<ArkUI_Float32>(radius.Value()), saturation, brightness, color.GetValue(),
5397 static_cast<ArkUI_Int32>(adaptiveColor), blurOption.grayscale.data(), blurOption.grayscale.size(), policy,
5398 blurType, isValidColor, inactiveColor.GetValue(), disableSystemAdaptation);
5399 return panda::JSValueRef::Undefined(vm);
5400 }
5401
ResetBackgroundEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)5402 ArkUINativeModuleValue CommonBridge::ResetBackgroundEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
5403 {
5404 EcmaVM* vm = runtimeCallInfo->GetVM();
5405 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5406 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5407 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5408 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundEffect(nativeNode);
5409 return panda::JSValueRef::Undefined(vm);
5410 }
5411
SetBackgroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)5412 ArkUINativeModuleValue CommonBridge::SetBackgroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
5413 {
5414 EcmaVM* vm = runtimeCallInfo->GetVM();
5415 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5416 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:index of parameter frameNode
5417 Local<JSValueRef> ratedArg = runtimeCallInfo->GetCallArgRef(1); // 1:index of parameter ratedArg
5418 Local<JSValueRef> lightUpDegreeArg = runtimeCallInfo->GetCallArgRef(2); // 2:index of parameter lightUpDegreeArg
5419 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5420 double rate = 0.0;
5421 double lightUpDegree = 0.0;
5422 if (!ArkTSUtils::ParseJsDouble(vm, ratedArg, rate)) {
5423 return panda::JSValueRef::Undefined(vm);
5424 }
5425 if (!ArkTSUtils::ParseJsDouble(vm, lightUpDegreeArg, lightUpDegree)) {
5426 return panda::JSValueRef::Undefined(vm);
5427 }
5428 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundBrightness(nativeNode, rate, lightUpDegree);
5429 return panda::JSValueRef::Undefined(vm);
5430 }
5431
ResetBackgroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)5432 ArkUINativeModuleValue CommonBridge::ResetBackgroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
5433 {
5434 EcmaVM* vm = runtimeCallInfo->GetVM();
5435 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5436 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5437 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5438 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundBrightness(nativeNode);
5439 return panda::JSValueRef::Undefined(vm);
5440 }
5441
SetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo * runtimeCallInfo)5442 ArkUINativeModuleValue CommonBridge::SetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo* runtimeCallInfo)
5443 {
5444 EcmaVM* vm = runtimeCallInfo->GetVM();
5445 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5446 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5447 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5448 ArkUI_Float32 rate = 1.0f;
5449 ArkUI_Float32 lightUpDegree = 0.0f;
5450 ArkUI_Float32 cubicCoeff = 0.0f;
5451 ArkUI_Float32 quadCoeff = 0.0f;
5452 ArkUI_Float32 saturation = 1.0f;
5453 std::vector<float> posRGB(3, 0.0);
5454 std::vector<float> negRGB(3, 0.0);
5455 ArkUI_Float32 fraction = 1.0f;
5456 ParseDynamicBrightnessOption(runtimeCallInfo, vm, rate, lightUpDegree,
5457 cubicCoeff, quadCoeff, saturation, posRGB, negRGB, fraction);
5458 GetArkUINodeModifiers()->getCommonModifier()->setBackgroundBrightnessInternal(
5459 nativeNode, rate, lightUpDegree, cubicCoeff, quadCoeff, saturation,
5460 posRGB.data(), posRGB.size(), negRGB.data(), negRGB.size(), fraction);
5461 return panda::JSValueRef::Undefined(vm);
5462 }
5463
ResetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo * runtimeCallInfo)5464 ArkUINativeModuleValue CommonBridge::ResetBackgroundBrightnessInternal(ArkUIRuntimeCallInfo* runtimeCallInfo)
5465 {
5466 EcmaVM* vm = runtimeCallInfo->GetVM();
5467 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5468 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5469 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5470 GetArkUINodeModifiers()->getCommonModifier()->resetBackgroundBrightnessInternal(nativeNode);
5471 return panda::JSValueRef::Undefined(vm);
5472 }
5473
SetForegroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)5474 ArkUINativeModuleValue CommonBridge::SetForegroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
5475 {
5476 EcmaVM* vm = runtimeCallInfo->GetVM();
5477 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5478 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5479 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5480 ArkUI_Float32 rate = 1.0f;
5481 ArkUI_Float32 lightUpDegree = 0.0f;
5482 ArkUI_Float32 cubicCoeff = 0.0f;
5483 ArkUI_Float32 quadCoeff = 0.0f;
5484 ArkUI_Float32 saturation = 1.0f;
5485 std::vector<float> posRGB(3, 0.0);
5486 std::vector<float> negRGB(3, 0.0);
5487 ArkUI_Float32 fraction = 1.0f;
5488 ParseDynamicBrightnessOption(runtimeCallInfo, vm, rate, lightUpDegree,
5489 cubicCoeff, quadCoeff, saturation, posRGB, negRGB, fraction);
5490 GetArkUINodeModifiers()->getCommonModifier()->setForegroundBrightness(
5491 nativeNode, rate, lightUpDegree, cubicCoeff, quadCoeff, saturation,
5492 posRGB.data(), posRGB.size(), negRGB.data(), negRGB.size(), fraction);
5493 return panda::JSValueRef::Undefined(vm);
5494 }
5495
ResetForegroundBrightness(ArkUIRuntimeCallInfo * runtimeCallInfo)5496 ArkUINativeModuleValue CommonBridge::ResetForegroundBrightness(ArkUIRuntimeCallInfo* runtimeCallInfo)
5497 {
5498 EcmaVM* vm = runtimeCallInfo->GetVM();
5499 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5500 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5501 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5502 GetArkUINodeModifiers()->getCommonModifier()->resetForegroundBrightness(nativeNode);
5503 return panda::JSValueRef::Undefined(vm);
5504 }
5505
ParseDragPreViewOptions(ArkUIRuntimeCallInfo * runtimeCallInfo,Local<JSValueRef> & valueObj,ArkUIDragPreViewOptions & preViewOptions)5506 void ParseDragPreViewOptions(ArkUIRuntimeCallInfo* runtimeCallInfo, Local<JSValueRef>& valueObj,
5507 ArkUIDragPreViewOptions& preViewOptions)
5508 {
5509 EcmaVM* vm = runtimeCallInfo->GetVM();
5510 CHECK_NULL_VOID(vm);
5511 if (!valueObj->IsObject(vm)) {
5512 return;
5513 }
5514 auto obj = valueObj->ToObject(vm);
5515 auto mode = obj->Get(vm, "mode");
5516 if (mode->IsNumber()) {
5517 preViewOptions.isModeArray = false;
5518 preViewOptions.mode = mode->Int32Value(vm);
5519 } else if (mode->IsArray(vm)) {
5520 Local<panda::ArrayRef> modeArray = static_cast<Local<panda::ArrayRef>>(mode);
5521 int32_t arrLength = static_cast<int32_t>(modeArray->Length(vm));
5522 if (arrLength > NUM_4) {
5523 arrLength = NUM_4;
5524 }
5525 preViewOptions.modeArray = new int32_t[arrLength];
5526 for (int32_t i = 0; i < arrLength; i++) {
5527 Local<JSValueRef> objValue = modeArray->GetValueAt(vm, modeArray, i);
5528 preViewOptions.modeArray[i] = objValue->Int32Value(vm);
5529 }
5530 preViewOptions.isModeArray = true;
5531 preViewOptions.modeArrayLength = static_cast<ArkUI_Int32>(arrLength);
5532 }
5533
5534 auto sizeChangeEffect = obj->Get(vm, "sizeChangeEffect");
5535 if (sizeChangeEffect->IsNumber()) {
5536 preViewOptions.sizeChangeEffect = sizeChangeEffect->Int32Value(vm);
5537 }
5538
5539 auto numberBadge = obj->Get(vm, "numberBadge");
5540 if (numberBadge->IsBoolean()) {
5541 preViewOptions.isBadgeNumber = false;
5542 preViewOptions.isShowBadge = numberBadge->ToBoolean(vm)->Value();
5543 } else if (numberBadge->IsNumber()) {
5544 preViewOptions.isBadgeNumber = true;
5545 preViewOptions.badgeNumber = numberBadge->Int32Value(vm);
5546 }
5547 }
5548
ParseDragInteractionOptions(ArkUIRuntimeCallInfo * runtimeCallInfo,Local<JSValueRef> & valueObj,ArkUIDragInteractionOptions & interactionOptions)5549 void ParseDragInteractionOptions(ArkUIRuntimeCallInfo* runtimeCallInfo, Local<JSValueRef>& valueObj,
5550 ArkUIDragInteractionOptions& interactionOptions)
5551 {
5552 EcmaVM* vm = runtimeCallInfo->GetVM();
5553 CHECK_NULL_VOID(vm);
5554 if (!valueObj->IsObject(vm)) {
5555 return;
5556 }
5557 auto obj = valueObj->ToObject(vm);
5558
5559 Local<JSValueRef> isMultiSelectionEnabled = obj->Get(vm, "isMultiSelectionEnabled");
5560 if (isMultiSelectionEnabled->IsBoolean()) {
5561 interactionOptions.isMultiSelectionEnabled = isMultiSelectionEnabled->ToBoolean(vm)->Value();
5562 }
5563 Local<JSValueRef> defaultAnimationBeforeLifting = obj->Get(vm, "defaultAnimationBeforeLifting");
5564 if (defaultAnimationBeforeLifting->IsBoolean()) {
5565 interactionOptions.defaultAnimationBeforeLifting = defaultAnimationBeforeLifting->ToBoolean(vm)->Value();
5566 }
5567 Local<JSValueRef> enableEdgeAutoScroll = obj->Get(vm, "enableEdgeAutoScroll");
5568 if (enableEdgeAutoScroll->IsBoolean()) {
5569 interactionOptions.enableEdgeAutoScroll = enableEdgeAutoScroll->ToBoolean(vm)->Value();
5570 }
5571 Local<JSValueRef> enableHapticFeedback = obj->Get(vm, "enableHapticFeedback");
5572 if (enableHapticFeedback->IsBoolean()) {
5573 interactionOptions.enableHapticFeedback = enableHapticFeedback->ToBoolean(vm)->Value();
5574 }
5575 Local<JSValueRef> isLiftingDisabled = obj->Get(vm, "isLiftingDisabled");
5576 if (isLiftingDisabled->IsBoolean()) {
5577 interactionOptions.isLiftingDisabled = isLiftingDisabled->ToBoolean(vm)->Value();
5578 }
5579 }
5580
SetDragPreviewOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)5581 ArkUINativeModuleValue CommonBridge::SetDragPreviewOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
5582 {
5583 EcmaVM* vm = runtimeCallInfo->GetVM();
5584 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5585 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5586 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5587
5588 Local<JSValueRef> valueObj = runtimeCallInfo->GetCallArgRef(NUM_1);
5589 struct ArkUIDragPreViewOptions preViewOptions = { 1, 0, 0, 0, nullptr, false, true, false };
5590 struct ArkUIDragInteractionOptions interactionOptions = { false, false, true, false, false };
5591 ParseDragPreViewOptions(runtimeCallInfo, valueObj, preViewOptions);
5592 ParseDragInteractionOptions(runtimeCallInfo, valueObj, interactionOptions);
5593
5594 GetArkUINodeModifiers()->getCommonModifier()->setDragPreviewOptions(
5595 nativeNode, preViewOptions, interactionOptions);
5596 delete[] preViewOptions.modeArray;
5597 return panda::JSValueRef::Undefined(vm);
5598 }
5599
ResetDragPreviewOptions(ArkUIRuntimeCallInfo * runtimeCallInfo)5600 ArkUINativeModuleValue CommonBridge::ResetDragPreviewOptions(ArkUIRuntimeCallInfo* runtimeCallInfo)
5601 {
5602 EcmaVM* vm = runtimeCallInfo->GetVM();
5603 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5604 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5605 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5606 GetArkUINodeModifiers()->getCommonModifier()->resetDragPreviewOptions(nativeNode);
5607 return panda::JSValueRef::Undefined(vm);
5608 }
5609
SetDragPreview(ArkUIRuntimeCallInfo * runtimeCallInfo)5610 ArkUINativeModuleValue CommonBridge::SetDragPreview(ArkUIRuntimeCallInfo* runtimeCallInfo)
5611 {
5612 EcmaVM* vm = runtimeCallInfo->GetVM();
5613 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5614 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5615 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5616 Local<JSValueRef> valueObj = runtimeCallInfo->GetCallArgRef(NUM_1);
5617 struct ArkUIDragPreview dragPreview = { "" };
5618 std::string stringValue;
5619 std::string extraInfoValue;
5620 RefPtr<PixelMap> pixmap = nullptr;
5621 if (valueObj->IsObject(vm)) {
5622 auto obj = valueObj->ToObject(vm);
5623 auto inspectorId = obj->Get(vm, "inspetorId");
5624 if (inspectorId->IsString(vm)) {
5625 stringValue = inspectorId->ToString(vm)->ToString(vm);
5626 dragPreview.inspectorId = stringValue.c_str();
5627 }
5628 auto onlyForLifting = obj->Get(vm, "onlyForLifting");
5629 if (onlyForLifting->IsBoolean()) {
5630 dragPreview.onlyForLifting = onlyForLifting->ToBoolean(vm)->Value();
5631 }
5632 auto extraInfo = obj->Get(vm, "extraInfo");
5633 if (extraInfo->IsString(vm)) {
5634 extraInfoValue = extraInfo->ToString(vm)->ToString(vm);
5635 dragPreview.extraInfo = extraInfoValue.c_str();
5636 }
5637 auto pixelMap = obj->Get(vm, "pixelMap");
5638 if (!pixelMap->IsUndefined()) {
5639 #if defined(PIXEL_MAP_SUPPORTED)
5640 pixmap = ArkTSUtils::CreatePixelMapFromNapiValue(vm, pixelMap);
5641 #endif
5642 if (pixmap) {
5643 auto pixelMapSharedPtr = pixmap->GetPixelMapSharedPtr();
5644 dragPreview.pixelMap = static_cast<void*>(&pixelMapSharedPtr);
5645 }
5646 }
5647 }
5648 GetArkUINodeModifiers()->getCommonModifier()->setDragPreview(nativeNode, dragPreview);
5649 return panda::JSValueRef::Undefined(vm);
5650 }
5651
ResetDragPreview(ArkUIRuntimeCallInfo * runtimeCallInfo)5652 ArkUINativeModuleValue CommonBridge::ResetDragPreview(ArkUIRuntimeCallInfo* runtimeCallInfo)
5653 {
5654 EcmaVM* vm = runtimeCallInfo->GetVM();
5655 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5656 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5657 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5658 GetArkUINodeModifiers()->getCommonModifier()->resetDragPreview(nativeNode);
5659 return panda::JSValueRef::Undefined(vm);
5660 }
5661
SetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5662 ArkUINativeModuleValue CommonBridge::SetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5663 {
5664 EcmaVM* vm = runtimeCallInfo->GetVM();
5665 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5666 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5667 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5668 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5669 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5670 int32_t length = thirdArg->Int32Value(vm);
5671 ArkUI_Float32 regionArray[length];
5672 int32_t regionUnits[length];
5673 if (!ParseResponseRegion(vm, secondArg, regionArray, regionUnits, length)) {
5674 GetArkUINodeModifiers()->getCommonModifier()->resetResponseRegion(nativeNode);
5675 return panda::JSValueRef::Undefined(vm);
5676 }
5677 GetArkUINodeModifiers()->getCommonModifier()->setResponseRegion(nativeNode, regionArray, regionUnits, length);
5678 return panda::JSValueRef::Undefined(vm);
5679 }
5680
ResetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5681 ArkUINativeModuleValue CommonBridge::ResetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5682 {
5683 EcmaVM* vm = runtimeCallInfo->GetVM();
5684 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5685 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5686 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5687 GetArkUINodeModifiers()->getCommonModifier()->resetResponseRegion(nativeNode);
5688 return panda::JSValueRef::Undefined(vm);
5689 }
5690
ResetTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5691 ArkUINativeModuleValue CommonBridge::ResetTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5692 {
5693 EcmaVM* vm = runtimeCallInfo->GetVM();
5694 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5695 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5696 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5697 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5698 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5699 ViewAbstract::CleanTransition(frameNode);
5700 ViewAbstract::SetChainedTransition(frameNode, nullptr, nullptr);
5701 return panda::JSValueRef::Undefined(vm);
5702 }
5703
SetTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5704 ArkUINativeModuleValue CommonBridge::SetTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5705 {
5706 EcmaVM* vm = runtimeCallInfo->GetVM();
5707 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5708 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5709 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5710 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5711 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5712 if (!info[1]->IsObject()) {
5713 ViewAbstract::CleanTransition(frameNode);
5714 ViewAbstract::SetChainedTransition(frameNode, nullptr, nullptr);
5715 return panda::JSValueRef::Undefined(vm);
5716 }
5717 auto obj = Framework::JSRef<Framework::JSObject>::Cast(info[1]);
5718 if (!obj->GetProperty("successor_")->IsUndefined()) {
5719 auto chainedEffect = ParseChainedTransition(obj, info.GetExecutionContext());
5720 std::function<void(bool)> finishCallback;
5721 if (info.Length() > 2 && info[2]->IsFunction()) {
5722 finishCallback =
5723 ParseTransitionCallback(JSRef<JSFunc>::Cast(info[2]), info.GetExecutionContext(), frameNode);
5724 }
5725 ViewAbstract::SetChainedTransition(frameNode, chainedEffect, std::move(finishCallback));
5726 return panda::JSValueRef::Undefined(vm);
5727 }
5728 auto options = ParseJsTransition(info[1]);
5729 ViewAbstract::SetTransition(frameNode, options);
5730 return panda::JSValueRef::Undefined(vm);
5731 }
5732
ResetTransitionPassThrough(ArkUIRuntimeCallInfo * runtimeCallInfo)5733 ArkUINativeModuleValue CommonBridge::ResetTransitionPassThrough(ArkUIRuntimeCallInfo* runtimeCallInfo)
5734 {
5735 return CommonBridge::ResetTransition(runtimeCallInfo);
5736 }
5737
SetTransitionPassThrough(ArkUIRuntimeCallInfo * runtimeCallInfo)5738 ArkUINativeModuleValue CommonBridge::SetTransitionPassThrough(ArkUIRuntimeCallInfo* runtimeCallInfo)
5739 {
5740 return CommonBridge::SetTransition(runtimeCallInfo);
5741 }
5742
ResetSharedTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5743 ArkUINativeModuleValue CommonBridge::ResetSharedTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5744 {
5745 EcmaVM* vm = runtimeCallInfo->GetVM();
5746 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5747 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5748 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5749 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5750 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5751 if (!info[1]->IsString() || info[1]->ToString().empty()) {
5752 return panda::JSValueRef::Undefined(vm);
5753 }
5754 auto id = info[1]->ToString();
5755 std::shared_ptr<SharedTransitionOption> sharedOption;
5756 sharedOption = std::make_shared<SharedTransitionOption>();
5757 sharedOption->duration = DEFAULT_DURATION;
5758 sharedOption->delay = NUM_0;
5759 sharedOption->curve = Curves::LINEAR;
5760 sharedOption->zIndex = NUM_0;
5761 sharedOption->type = DEFAULT_SHARED_EFFECT;
5762
5763 ViewAbstract::SetSharedTransition(frameNode, id, sharedOption);
5764 return panda::JSValueRef::Undefined(vm);
5765 }
5766
SetSharedTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)5767 ArkUINativeModuleValue CommonBridge::SetSharedTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
5768 {
5769 EcmaVM* vm = runtimeCallInfo->GetVM();
5770 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5771 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5772 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5773 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5774 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5775 if (!info[NUM_1]->IsString() || info[NUM_1]->ToString().empty()) {
5776 return panda::JSValueRef::Undefined(vm);
5777 }
5778 auto id = info[NUM_1]->ToString();
5779 std::shared_ptr<SharedTransitionOption> sharedOption;
5780 if (info[NUM_2]->IsObject()) {
5781 Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(info[NUM_2]);
5782 sharedOption = std::make_shared<SharedTransitionOption>();
5783 sharedOption->duration = jsObj->GetPropertyValue<int32_t>("duration", DEFAULT_DURATION);
5784 if (sharedOption->duration < 0) {
5785 sharedOption->duration = DEFAULT_DURATION;
5786 }
5787 sharedOption->delay = jsObj->GetPropertyValue<int32_t>("delay", 0);
5788 if (sharedOption->delay < 0) {
5789 sharedOption->delay = 0;
5790 }
5791 RefPtr<Curve> curve;
5792 Framework::JSRef<Framework::JSVal> curveArgs = jsObj->GetProperty("curve");
5793 if (curveArgs->IsString()) {
5794 curve = Framework::CreateCurve(jsObj->GetPropertyValue<std::string>("curve", "linear"), false);
5795 } else if (curveArgs->IsObject()) {
5796 Framework::JSRef<Framework::JSVal> curveString =
5797 Framework::JSRef<Framework::JSObject>::Cast(curveArgs)->GetProperty("__curveString");
5798 if (!curveString->IsString()) {
5799 return panda::JSValueRef::Undefined(vm);
5800 }
5801 curve = Framework::CreateCurve(curveString->ToString(), false);
5802 }
5803 if (!curve) {
5804 curve = Curves::LINEAR;
5805 }
5806 sharedOption->curve = curve;
5807 if (jsObj->HasProperty("motionPath")) {
5808 MotionPathOption motionPathOption;
5809 if (ParseMotionPath(jsObj->GetProperty("motionPath"), motionPathOption)) {
5810 sharedOption->motionPathOption = motionPathOption;
5811 }
5812 }
5813 sharedOption->zIndex = jsObj->GetPropertyValue<int32_t>("zIndex", 0);
5814 int32_t type = jsObj->GetPropertyValue<int32_t>("type", static_cast<int32_t>(DEFAULT_SHARED_EFFECT));
5815 sharedOption->type = static_cast<SharedTransitionEffectType>(type);
5816 }
5817 ViewAbstract::SetSharedTransition(frameNode, id, sharedOption);
5818 return panda::JSValueRef::Undefined(vm);
5819 }
SetMask(ArkUIRuntimeCallInfo * runtimeCallInfo)5820 ArkUINativeModuleValue CommonBridge::SetMask(ArkUIRuntimeCallInfo* runtimeCallInfo)
5821 {
5822 EcmaVM* vm = runtimeCallInfo->GetVM();
5823 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5824 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5825 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5826 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5827
5828 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5829 if (!info[NUM_1]->IsObject()) {
5830 ViewAbstract::SetProgressMask(frameNode, nullptr);
5831 return panda::JSValueRef::Undefined(vm);
5832 }
5833 auto paramObject = Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1]);
5834 Framework::JSRef<Framework::JSVal> typeParam = paramObject->GetProperty("type");
5835 if (!typeParam->IsNull() && !typeParam->IsUndefined() && typeParam->IsString() &&
5836 typeParam->ToString() == "ProgressMask") {
5837 auto progressMask = AceType::MakeRefPtr<NG::ProgressMaskProperty>();
5838 Framework::JSRef<Framework::JSVal> jValue = paramObject->GetProperty("value");
5839 auto value = jValue->IsNumber() ? jValue->ToNumber<float>() : 0.0f;
5840 if (value < 0.0f) {
5841 value = 0.0f;
5842 }
5843 progressMask->SetValue(value);
5844 Framework::JSRef<Framework::JSVal> jTotal = paramObject->GetProperty("total");
5845 auto total = jTotal->IsNumber() ? jTotal->ToNumber<float>() : DEFAULT_PROGRESS_TOTAL;
5846 if (total < 0.0f) {
5847 total = DEFAULT_PROGRESS_TOTAL;
5848 }
5849 progressMask->SetMaxValue(total);
5850 Framework::JSRef<Framework::JSVal> jColor = paramObject->GetProperty("color");
5851 Color colorVal;
5852 if (Framework::JSViewAbstract::ParseJsColor(jColor, colorVal)) {
5853 progressMask->SetColor(colorVal);
5854 } else {
5855 auto theme = Framework::JSShapeAbstract::GetTheme<ProgressTheme>();
5856 progressMask->SetColor(theme->GetMaskColor());
5857 }
5858 ViewAbstract::SetProgressMask(frameNode, progressMask);
5859 } else {
5860 Framework::JSShapeAbstract* maskShape =
5861 Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
5862 if (maskShape == nullptr) {
5863 return panda::JSValueRef::Undefined(vm);
5864 };
5865 ViewAbstract::SetMask(frameNode, maskShape->GetBasicShape());
5866 }
5867 return panda::JSValueRef::Undefined(vm);
5868 }
5869
ResetMask(ArkUIRuntimeCallInfo * runtimeCallInfo)5870 ArkUINativeModuleValue CommonBridge::ResetMask(ArkUIRuntimeCallInfo* runtimeCallInfo)
5871 {
5872 EcmaVM* vm = runtimeCallInfo->GetVM();
5873 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5874 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5875 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5876 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5877 ViewAbstract::SetProgressMask(frameNode, nullptr);
5878 return panda::JSValueRef::Undefined(vm);
5879 }
5880
SetMaskShape(ArkUIRuntimeCallInfo * runtimeCallInfo)5881 ArkUINativeModuleValue CommonBridge::SetMaskShape(ArkUIRuntimeCallInfo* runtimeCallInfo)
5882 {
5883 EcmaVM* vm = runtimeCallInfo->GetVM();
5884 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5885 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5886 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5887 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5888
5889 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
5890 if (!info[NUM_1]->IsObject()) {
5891 return panda::JSValueRef::Undefined(vm);
5892 }
5893
5894 Framework::JSShapeAbstract* maskShape =
5895 Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
5896 if (maskShape == nullptr) {
5897 return panda::JSValueRef::Undefined(vm);
5898 };
5899 ViewAbstract::SetMask(frameNode, maskShape->GetBasicShape());
5900
5901 return panda::JSValueRef::Undefined(vm);
5902 }
5903
ResetMaskShape(ArkUIRuntimeCallInfo * runtimeCallInfo)5904 ArkUINativeModuleValue CommonBridge::ResetMaskShape(ArkUIRuntimeCallInfo* runtimeCallInfo)
5905 {
5906 EcmaVM* vm = runtimeCallInfo->GetVM();
5907 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5908 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5909 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5910 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
5911 ViewAbstract::SetProgressMask(frameNode, nullptr);
5912 return panda::JSValueRef::Undefined(vm);
5913 }
5914
SetMouseResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5915 ArkUINativeModuleValue CommonBridge::SetMouseResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5916 {
5917 EcmaVM* vm = runtimeCallInfo->GetVM();
5918 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5919 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5920 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5921 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
5922 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5923 int32_t length = thirdArg->Int32Value(vm);
5924 ArkUI_Float32 regionArray[length];
5925 int32_t regionUnits[length];
5926 if (!ParseResponseRegion(vm, secondArg, regionArray, regionUnits, length)) {
5927 GetArkUINodeModifiers()->getCommonModifier()->resetMouseResponseRegion(nativeNode);
5928 return panda::JSValueRef::Undefined(vm);
5929 }
5930 GetArkUINodeModifiers()->getCommonModifier()->setMouseResponseRegion(nativeNode, regionArray, regionUnits, length);
5931 return panda::JSValueRef::Undefined(vm);
5932 }
5933
ResetMouseResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)5934 ArkUINativeModuleValue CommonBridge::ResetMouseResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
5935 {
5936 EcmaVM* vm = runtimeCallInfo->GetVM();
5937 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5938 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
5939 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5940 GetArkUINodeModifiers()->getCommonModifier()->resetMouseResponseRegion(nativeNode);
5941 return panda::JSValueRef::Undefined(vm);
5942 }
5943
SetEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)5944 ArkUINativeModuleValue CommonBridge::SetEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
5945 {
5946 EcmaVM* vm = runtimeCallInfo->GetVM();
5947 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5948 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5949 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
5950 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5951 if (secondArg->IsBoolean()) {
5952 bool boolValue = secondArg->ToBoolean(vm)->Value();
5953 GetArkUINodeModifiers()->getCommonModifier()->setEnabled(nativeNode, boolValue);
5954 } else {
5955 GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
5956 }
5957 return panda::JSValueRef::Undefined(vm);
5958 }
5959
ResetEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)5960 ArkUINativeModuleValue CommonBridge::ResetEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
5961 {
5962 EcmaVM* vm = runtimeCallInfo->GetVM();
5963 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5964 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
5965 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
5966 GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
5967 return panda::JSValueRef::Undefined(vm);
5968 }
5969
SetUseShadowBatching(ArkUIRuntimeCallInfo * runtimeCallInfo)5970 ArkUINativeModuleValue CommonBridge::SetUseShadowBatching(ArkUIRuntimeCallInfo* runtimeCallInfo)
5971 {
5972 EcmaVM* vm = runtimeCallInfo->GetVM();
5973 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5974 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5975 Local<JSValueRef> booleanArg = runtimeCallInfo->GetCallArgRef(1);
5976 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5977 if (booleanArg->IsBoolean()) {
5978 bool boolValue = booleanArg->ToBoolean(vm)->Value();
5979 GetArkUINodeModifiers()->getCommonModifier()->setUseShadowBatching(nativeNode, boolValue);
5980 } else {
5981 GetArkUINodeModifiers()->getCommonModifier()->resetUseShadowBatching(nativeNode);
5982 }
5983 return panda::JSValueRef::Undefined(vm);
5984 }
5985
ResetUseShadowBatching(ArkUIRuntimeCallInfo * runtimeCallInfo)5986 ArkUINativeModuleValue CommonBridge::ResetUseShadowBatching(ArkUIRuntimeCallInfo* runtimeCallInfo)
5987 {
5988 EcmaVM* vm = runtimeCallInfo->GetVM();
5989 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
5990 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
5991 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
5992 GetArkUINodeModifiers()->getCommonModifier()->resetUseShadowBatching(nativeNode);
5993 return panda::JSValueRef::Undefined(vm);
5994 }
5995
SetBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)5996 ArkUINativeModuleValue CommonBridge::SetBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
5997 {
5998 EcmaVM* vm = runtimeCallInfo->GetVM();
5999 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6000 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0); // 0: index of parameter frameNode
6001 Local<JSValueRef> blendModeArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of parameter blendMode
6002 Local<JSValueRef> blendApplyTypeArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of parameter blendApplyType
6003 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
6004 int32_t blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::NONE);
6005 int32_t blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::FAST);
6006 if (blendModeArg->IsNumber()) {
6007 int32_t blendModeNum = blendModeArg->Int32Value(vm);
6008 if (blendModeNum >= static_cast<int32_t>(OHOS::Ace::BlendMode::NONE) &&
6009 blendModeNum <= static_cast<int32_t>(OHOS::Ace::BlendMode::LUMINOSITY)) {
6010 blendModeValue = blendModeNum;
6011 } else if (blendModeNum == BACKWARD_COMPAT_MAGIC_NUMBER_OFFSCREEN) {
6012 blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::SRC_OVER);
6013 blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::OFFSCREEN);
6014 }
6015 if (blendApplyTypeArg->IsNumber()) {
6016 int32_t blendApplyTypeNum = blendApplyTypeArg->Int32Value(vm);
6017 if (blendApplyTypeNum >= static_cast<int>(OHOS::Ace::BlendApplyType::FAST) &&
6018 blendApplyTypeNum <= static_cast<int>(OHOS::Ace::BlendApplyType::OFFSCREEN)) {
6019 blendApplyTypeValue = blendApplyTypeNum;
6020 }
6021 }
6022 GetArkUINodeModifiers()->getCommonModifier()->setBlendMode(nativeNode, blendModeValue, blendApplyTypeValue);
6023 } else {
6024 GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
6025 }
6026 return panda::JSValueRef::Undefined(vm);
6027 }
6028
ResetBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)6029 ArkUINativeModuleValue CommonBridge::ResetBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
6030 {
6031 EcmaVM *vm = runtimeCallInfo->GetVM();
6032 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6033 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
6034 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
6035 GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
6036 return panda::JSValueRef::Undefined(vm);
6037 }
6038
SetAdvancedBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)6039 ArkUINativeModuleValue CommonBridge::SetAdvancedBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
6040 {
6041 EcmaVM* vm = runtimeCallInfo->GetVM();
6042 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6043 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0); // 0: index of parameter frameNode
6044 Local<JSValueRef> blendModeArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of parameter blendMode
6045 Local<JSValueRef> blendApplyTypeArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of parameter blendApplyType
6046 CHECK_NULL_RETURN(frameNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
6047 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
6048 int32_t blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::NONE);
6049 int32_t blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::FAST);
6050 if (blendApplyTypeArg->IsNumber()) {
6051 int32_t blendApplyTypeNum = blendApplyTypeArg->Int32Value(vm);
6052 if (blendApplyTypeNum >= static_cast<int>(OHOS::Ace::BlendApplyType::FAST) &&
6053 blendApplyTypeNum <= static_cast<int>(OHOS::Ace::BlendApplyType::OFFSCREEN)) {
6054 blendApplyTypeValue = blendApplyTypeNum;
6055 }
6056 }
6057 if (blendModeArg->IsNumber()) {
6058 int32_t blendModeNum = blendModeArg->Int32Value(vm);
6059 if (blendModeNum >= static_cast<int32_t>(OHOS::Ace::BlendMode::NONE) &&
6060 blendModeNum <= static_cast<int32_t>(OHOS::Ace::BlendMode::LUMINOSITY)) {
6061 blendModeValue = blendModeNum;
6062 } else if (blendModeNum == BACKWARD_COMPAT_MAGIC_NUMBER_OFFSCREEN) {
6063 blendModeValue = static_cast<int32_t>(OHOS::Ace::BlendMode::SRC_OVER);
6064 blendApplyTypeValue = static_cast<int32_t>(OHOS::Ace::BlendApplyType::OFFSCREEN);
6065 }
6066 GetArkUINodeModifiers()->getCommonModifier()->setBlendMode(nativeNode, blendModeValue, blendApplyTypeValue);
6067 } else if (blendModeArg->IsObject(vm)) {
6068 auto arkBlender = ArkTSUtils::CreateRSBrightnessBlenderFromNapiValue(vm, blendModeArg);
6069 auto blender = reinterpret_cast<ArkUINodeHandle>(arkBlender);
6070 GetArkUINodeModifiers()->getCommonModifier()->setBlendModeByBlender(nativeNode, blender, blendApplyTypeValue);
6071 } else {
6072 GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
6073 }
6074 return panda::JSValueRef::Undefined(vm);
6075 }
6076
ResetAdvancedBlendMode(ArkUIRuntimeCallInfo * runtimeCallInfo)6077 ArkUINativeModuleValue CommonBridge::ResetAdvancedBlendMode(ArkUIRuntimeCallInfo *runtimeCallInfo)
6078 {
6079 EcmaVM *vm = runtimeCallInfo->GetVM();
6080 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
6081 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
6082 CHECK_NULL_RETURN(frameNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
6083 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
6084 GetArkUINodeModifiers()->getCommonModifier()->resetBlendMode(nativeNode);
6085 return panda::JSValueRef::Undefined(vm);
6086 }
6087
SetMonopolizeEvents(ArkUIRuntimeCallInfo * runtimeCallInfo)6088 ArkUINativeModuleValue CommonBridge::SetMonopolizeEvents(ArkUIRuntimeCallInfo* runtimeCallInfo)
6089 {
6090 EcmaVM* vm = runtimeCallInfo->GetVM();
6091 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6092 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
6093 Local<JSValueRef> booleanArg = runtimeCallInfo->GetCallArgRef(1);
6094 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
6095 if (booleanArg->IsBoolean()) {
6096 bool boolValue = booleanArg->ToBoolean(vm)->Value();
6097 GetArkUINodeModifiers()->getCommonModifier()->setMonopolizeEvents(nativeNode, boolValue);
6098 } else {
6099 GetArkUINodeModifiers()->getCommonModifier()->resetMonopolizeEvents(nativeNode);
6100 }
6101 return panda::JSValueRef::Undefined(vm);
6102 }
6103
ResetMonopolizeEvents(ArkUIRuntimeCallInfo * runtimeCallInfo)6104 ArkUINativeModuleValue CommonBridge::ResetMonopolizeEvents(ArkUIRuntimeCallInfo* runtimeCallInfo)
6105 {
6106 EcmaVM* vm = runtimeCallInfo->GetVM();
6107 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6108 Local<JSValueRef> frameNodeArg = runtimeCallInfo->GetCallArgRef(0);
6109 auto nativeNode = nodePtr(frameNodeArg->ToNativePointer(vm)->Value());
6110 GetArkUINodeModifiers()->getCommonModifier()->resetMonopolizeEvents(nativeNode);
6111 return panda::JSValueRef::Undefined(vm);
6112 }
6113
SetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)6114 ArkUINativeModuleValue CommonBridge::SetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
6115 {
6116 EcmaVM* vm = runtimeCallInfo->GetVM();
6117 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6118 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6119 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6120 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6121 if (secondArg->IsBoolean()) {
6122 bool boolValue = secondArg->ToBoolean(vm)->Value();
6123 GetArkUINodeModifiers()->getCommonModifier()->setDraggable(nativeNode, boolValue);
6124 } else {
6125 GetArkUINodeModifiers()->getCommonModifier()->resetDraggable(nativeNode);
6126 }
6127 return panda::JSValueRef::Undefined(vm);
6128 }
6129
ResetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)6130 ArkUINativeModuleValue CommonBridge::ResetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
6131 {
6132 EcmaVM* vm = runtimeCallInfo->GetVM();
6133 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6134 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6135 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6136 GetArkUINodeModifiers()->getCommonModifier()->resetDraggable(nativeNode);
6137 return panda::JSValueRef::Undefined(vm);
6138 }
6139
SetAccessibilityGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)6140 ArkUINativeModuleValue CommonBridge::SetAccessibilityGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
6141 {
6142 EcmaVM* vm = runtimeCallInfo->GetVM();
6143 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6144 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6145 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6146 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6147 if (secondArg->IsBoolean()) {
6148 bool boolValue = secondArg->ToBoolean(vm)->Value();
6149 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityGroup(nativeNode, boolValue);
6150 } else {
6151 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityGroup(nativeNode);
6152 }
6153 return panda::JSValueRef::Undefined(vm);
6154 }
6155
ResetAccessibilityGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)6156 ArkUINativeModuleValue CommonBridge::ResetAccessibilityGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
6157 {
6158 EcmaVM* vm = runtimeCallInfo->GetVM();
6159 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6160 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6161 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6162 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityGroup(nativeNode);
6163 return panda::JSValueRef::Undefined(vm);
6164 }
6165
SetAccessibilityNextFocusId(ArkUIRuntimeCallInfo * runtimeCallInfo)6166 ArkUINativeModuleValue CommonBridge::SetAccessibilityNextFocusId(ArkUIRuntimeCallInfo* runtimeCallInfo)
6167 {
6168 EcmaVM* vm = runtimeCallInfo->GetVM();
6169 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6170 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6171 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6172 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6173 if (secondArg->IsString(vm)) {
6174 std::string stringValue = secondArg->ToString(vm)->ToString(vm);
6175 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityNextFocusId(nativeNode, stringValue.c_str());
6176 } else {
6177 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityNextFocusId(nativeNode);
6178 }
6179 return panda::JSValueRef::Undefined(vm);
6180 }
6181
ResetAccessibilityNextFocusId(ArkUIRuntimeCallInfo * runtimeCallInfo)6182 ArkUINativeModuleValue CommonBridge::ResetAccessibilityNextFocusId(ArkUIRuntimeCallInfo* runtimeCallInfo)
6183 {
6184 EcmaVM* vm = runtimeCallInfo->GetVM();
6185 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6186 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6187 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6188 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityNextFocusId(nativeNode);
6189 return panda::JSValueRef::Undefined(vm);
6190 }
6191
SetAccessibilityDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)6192 ArkUINativeModuleValue CommonBridge::SetAccessibilityDefaultFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
6193 {
6194 EcmaVM* vm = runtimeCallInfo->GetVM();
6195 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6196 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6197 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6198 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6199 if (secondArg->IsBoolean()) {
6200 bool boolValue = secondArg->ToBoolean(vm)->Value();
6201 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityDefaultFocus(nativeNode, boolValue);
6202 } else {
6203 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityDefaultFocus(nativeNode);
6204 }
6205 return panda::JSValueRef::Undefined(vm);
6206 }
6207
ResetAccessibilityDefaultFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)6208 ArkUINativeModuleValue CommonBridge::ResetAccessibilityDefaultFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
6209 {
6210 EcmaVM* vm = runtimeCallInfo->GetVM();
6211 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6212 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6213 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6214 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityDefaultFocus(nativeNode);
6215 return panda::JSValueRef::Undefined(vm);
6216 }
6217
SetAccessibilityUseSamePage(ArkUIRuntimeCallInfo * runtimeCallInfo)6218 ArkUINativeModuleValue CommonBridge::SetAccessibilityUseSamePage(ArkUIRuntimeCallInfo* runtimeCallInfo)
6219 {
6220 EcmaVM* vm = runtimeCallInfo->GetVM();
6221 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6222 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6223 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6224 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6225
6226 if (secondArg->IsUndefined() || !secondArg->IsNumber()) {
6227 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityUseSamePage(nativeNode);
6228 return panda::JSValueRef::Undefined(vm);
6229 }
6230 int32_t intValue = secondArg->Int32Value(vm);
6231 if (intValue >= 0 && intValue < static_cast<int32_t>(PAGE_MODE_TYPE.size())) {
6232 bool isFullSilent = static_cast<bool>(PAGE_MODE_TYPE[intValue]);
6233 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityUseSamePage(nativeNode, isFullSilent);
6234 } else {
6235 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityUseSamePage(nativeNode);
6236 }
6237 return panda::JSValueRef::Undefined(vm);
6238 }
6239
ResetAccessibilityUseSamePage(ArkUIRuntimeCallInfo * runtimeCallInfo)6240 ArkUINativeModuleValue CommonBridge::ResetAccessibilityUseSamePage(ArkUIRuntimeCallInfo* runtimeCallInfo)
6241 {
6242 EcmaVM* vm = runtimeCallInfo->GetVM();
6243 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6244 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6245 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6246 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityUseSamePage(nativeNode);
6247 return panda::JSValueRef::Undefined(vm);
6248 }
6249
SetAccessibilityScrollTriggerable(ArkUIRuntimeCallInfo * runtimeCallInfo)6250 ArkUINativeModuleValue CommonBridge::SetAccessibilityScrollTriggerable(ArkUIRuntimeCallInfo* runtimeCallInfo)
6251 {
6252 EcmaVM* vm = runtimeCallInfo->GetVM();
6253 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6254 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6255 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6256 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6257 if (secondArg->IsBoolean()) {
6258 bool boolValue = secondArg->ToBoolean(vm)->Value();
6259 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityScrollTriggerable(nativeNode, boolValue);
6260 } else {
6261 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityScrollTriggerable(nativeNode);
6262 }
6263 return panda::JSValueRef::Undefined(vm);
6264 }
6265
ResetAccessibilityScrollTriggerable(ArkUIRuntimeCallInfo * runtimeCallInfo)6266 ArkUINativeModuleValue CommonBridge::ResetAccessibilityScrollTriggerable(ArkUIRuntimeCallInfo* runtimeCallInfo)
6267 {
6268 EcmaVM* vm = runtimeCallInfo->GetVM();
6269 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6270 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6271 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6272 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityScrollTriggerable(nativeNode);
6273 return panda::JSValueRef::Undefined(vm);
6274 }
6275
SetAccessibilityFocusDrawLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)6276 ArkUINativeModuleValue CommonBridge::SetAccessibilityFocusDrawLevel(ArkUIRuntimeCallInfo* runtimeCallInfo)
6277 {
6278 EcmaVM* vm = runtimeCallInfo->GetVM();
6279 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6280 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6281 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6282 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6283
6284 if (secondArg->IsUndefined() || !secondArg->IsNumber()) {
6285 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityFocusDrawLevel(nativeNode);
6286 return panda::JSValueRef::Undefined(vm);
6287 }
6288 int32_t intValue = secondArg->Int32Value(vm);
6289 if (intValue >= 0 && intValue < static_cast<int32_t>(FOCUS_DRAW_LEVEL.size())) {
6290 GetArkUINodeModifiers()->getCommonModifier()->setAccessibilityFocusDrawLevel(nativeNode, intValue);
6291 } else {
6292 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityFocusDrawLevel(nativeNode);
6293 }
6294 return panda::JSValueRef::Undefined(vm);
6295 }
6296
ResetAccessibilityFocusDrawLevel(ArkUIRuntimeCallInfo * runtimeCallInfo)6297 ArkUINativeModuleValue CommonBridge::ResetAccessibilityFocusDrawLevel(ArkUIRuntimeCallInfo* runtimeCallInfo)
6298 {
6299 EcmaVM* vm = runtimeCallInfo->GetVM();
6300 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6301 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6302 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6303 GetArkUINodeModifiers()->getCommonModifier()->resetAccessibilityFocusDrawLevel(nativeNode);
6304 return panda::JSValueRef::Undefined(vm);
6305 }
6306
SetHoverEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)6307 ArkUINativeModuleValue CommonBridge::SetHoverEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
6308 {
6309 EcmaVM* vm = runtimeCallInfo->GetVM();
6310 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6311 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6312 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6313 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6314
6315 if (secondArg->IsUndefined() || !secondArg->IsNumber()) {
6316 GetArkUINodeModifiers()->getCommonModifier()->resetHoverEffect(nativeNode);
6317 return panda::JSValueRef::Undefined(vm);
6318 }
6319 int32_t intValue = secondArg->Int32Value(vm);
6320 GetArkUINodeModifiers()->getCommonModifier()->setHoverEffect(nativeNode, intValue);
6321 return panda::JSValueRef::Undefined(vm);
6322 }
6323
ResetHoverEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)6324 ArkUINativeModuleValue CommonBridge::ResetHoverEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
6325 {
6326 EcmaVM* vm = runtimeCallInfo->GetVM();
6327 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6328 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6329 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6330 GetArkUINodeModifiers()->getCommonModifier()->resetHoverEffect(nativeNode);
6331 return panda::JSValueRef::Undefined(vm);
6332 }
6333
SetClickEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)6334 ArkUINativeModuleValue CommonBridge::SetClickEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
6335 {
6336 EcmaVM* vm = runtimeCallInfo->GetVM();
6337 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6338 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6339 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6340 Local<JSValueRef> levelArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6341 Local<JSValueRef> scaleArg = runtimeCallInfo->GetCallArgRef(NUM_2);
6342
6343 int32_t clickEffectLevelValue = 0;
6344 if (levelArg->IsNumber()) {
6345 clickEffectLevelValue = levelArg->Int32Value(vm);
6346 if (clickEffectLevelValue < static_cast<int32_t>(OHOS::Ace::ClickEffectLevel::LIGHT) ||
6347 clickEffectLevelValue > static_cast<int32_t>(OHOS::Ace::ClickEffectLevel::HEAVY)) {
6348 clickEffectLevelValue = 0;
6349 }
6350 }
6351 float scaleNumberValue = 0.9f;
6352 if (!scaleArg->IsNumber()) {
6353 if ((OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::MIDDLE ||
6354 (OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::HEAVY) {
6355 scaleNumberValue = 0.95f;
6356 }
6357 } else {
6358 scaleNumberValue = scaleArg->ToNumber(vm)->Value();
6359 if (LessNotEqual(scaleNumberValue, 0.0) || GreatNotEqual(scaleNumberValue, 1.0)) {
6360 if ((OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::MIDDLE ||
6361 (OHOS::Ace::ClickEffectLevel)clickEffectLevelValue == OHOS::Ace::ClickEffectLevel::HEAVY) {
6362 scaleNumberValue = 0.95f;
6363 } else {
6364 scaleNumberValue = 0.9f;
6365 }
6366 }
6367 }
6368 GetArkUINodeModifiers()->getCommonModifier()->setClickEffect(nativeNode, clickEffectLevelValue,
6369 scaleNumberValue);
6370 return panda::JSValueRef::Undefined(vm);
6371 }
6372
ResetClickEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)6373 ArkUINativeModuleValue CommonBridge::ResetClickEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
6374 {
6375 EcmaVM* vm = runtimeCallInfo->GetVM();
6376 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6377 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6378 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6379 GetArkUINodeModifiers()->getCommonModifier()->resetClickEffect(nativeNode);
6380 return panda::JSValueRef::Undefined(vm);
6381 }
6382
SetKeyBoardShortCut(ArkUIRuntimeCallInfo * runtimeCallInfo)6383 ArkUINativeModuleValue CommonBridge::SetKeyBoardShortCut(ArkUIRuntimeCallInfo* runtimeCallInfo)
6384 {
6385 EcmaVM* vm = runtimeCallInfo->GetVM();
6386 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6387 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6388 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6389 Local<JSValueRef> keysArg = runtimeCallInfo->GetCallArgRef(NUM_2);
6390 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6391 if ((!valueArg->IsString(vm) && !valueArg->IsNumber()) || !keysArg->IsArray(vm)) {
6392 GetArkUINodeModifiers()->getCommonModifier()->resetKeyBoardShortCut(nativeNode);
6393 return panda::JSValueRef::Undefined(vm);
6394 }
6395 std::string stringValue;
6396 if (valueArg->IsNumber()) {
6397 OHOS::Ace::FunctionKey functionkey = static_cast<OHOS::Ace::FunctionKey>(valueArg->Int32Value(vm));
6398 stringValue = JSViewAbstract::GetFunctionKeyName(functionkey);
6399 } else {
6400 stringValue = valueArg->ToString(vm)->ToString(vm);
6401 }
6402 Local<panda::ArrayRef> keysArray = static_cast<Local<panda::ArrayRef>>(keysArg);
6403 auto arrLength = keysArray->Length(vm);
6404 if (arrLength > NUM_10) {
6405 arrLength = NUM_10;
6406 }
6407 int32_t* keysIntArray = new int32_t[arrLength];
6408 for (size_t i = 0; i < arrLength; i++) {
6409 Local<JSValueRef> objValue = keysArray->GetValueAt(vm, keysArg, i);
6410 keysIntArray[i] = objValue->Int32Value(vm);
6411 }
6412 GetArkUINodeModifiers()->getCommonModifier()->setKeyBoardShortCut(
6413 nativeNode, stringValue.c_str(), keysIntArray, arrLength);
6414 delete[] keysIntArray;
6415 return panda::JSValueRef::Undefined(vm);
6416 }
6417
ResetKeyBoardShortCut(ArkUIRuntimeCallInfo * runtimeCallInfo)6418 ArkUINativeModuleValue CommonBridge::ResetKeyBoardShortCut(ArkUIRuntimeCallInfo* runtimeCallInfo)
6419 {
6420 EcmaVM* vm = runtimeCallInfo->GetVM();
6421 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6422 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
6423 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6424 GetArkUINodeModifiers()->getCommonModifier()->resetKeyBoardShortCut(nativeNode);
6425 return panda::JSValueRef::Undefined(vm);
6426 }
6427
CreateResourceWrapper()6428 RefPtr<ResourceWrapper> CreateResourceWrapper()
6429 {
6430 RefPtr<ResourceAdapter> resourceAdapter = nullptr;
6431 RefPtr<ThemeConstants> themeConstants = nullptr;
6432 if (SystemProperties::GetResourceDecoupling()) {
6433 resourceAdapter = ResourceManager::GetInstance().GetResourceAdapter(Container::CurrentIdSafely());
6434 if (!resourceAdapter) {
6435 return nullptr;
6436 }
6437 } else {
6438 themeConstants = JSViewAbstract::GetThemeConstants();
6439 if (!themeConstants) {
6440 return nullptr;
6441 }
6442 }
6443 auto resourceWrapper = AceType::MakeRefPtr<ResourceWrapper>(themeConstants, resourceAdapter);
6444 return resourceWrapper;
6445 }
6446
ParseLightPosition(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,ArkUISizeType & dimPosX,ArkUISizeType & dimPosY,ArkUISizeType & dimPosZ)6447 bool ParseLightPosition(ArkUIRuntimeCallInfo *runtimeCallInfo, EcmaVM* vm, ArkUISizeType& dimPosX,
6448 ArkUISizeType& dimPosY, ArkUISizeType& dimPosZ)
6449 {
6450 Local<JSValueRef> positionXArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6451 Local<JSValueRef> positionYArg = runtimeCallInfo->GetCallArgRef(NUM_2);
6452 Local<JSValueRef> positionZArg = runtimeCallInfo->GetCallArgRef(NUM_3);
6453 CalcDimension dimPositionX;
6454 CalcDimension dimPositionY;
6455 CalcDimension dimPositionZ;
6456 bool xSuccess = ArkTSUtils::ParseJsDimensionVp(vm, positionXArg, dimPositionX, false);
6457 bool ySuccess = ArkTSUtils::ParseJsDimensionVp(vm, positionYArg, dimPositionY, false);
6458 bool zSuccess = ArkTSUtils::ParseJsDimensionVp(vm, positionZArg, dimPositionZ, false);
6459 if (!(xSuccess && ySuccess && zSuccess)) {
6460 return false;
6461 }
6462 dimPosX.value = dimPositionX.Value();
6463 dimPosX.unit = static_cast<int8_t>(dimPositionX.Unit());
6464 dimPosY.value = dimPositionY.Value();
6465 dimPosY.unit = static_cast<int8_t>(dimPositionY.Unit());
6466 dimPosZ.value = dimPositionZ.Value();
6467 dimPosZ.unit = static_cast<int8_t>(dimPositionZ.Unit());
6468 return true;
6469 }
6470
ParseLightSource(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,ArkUINodeHandle & nativeNode)6471 void ParseLightSource(ArkUIRuntimeCallInfo *runtimeCallInfo, EcmaVM* vm, ArkUINodeHandle& nativeNode)
6472 {
6473 struct ArkUISizeType dimPosX = { 0.0, 0 };
6474 struct ArkUISizeType dimPosY = { 0.0, 0 };
6475 struct ArkUISizeType dimPosZ = { 0.0, 0 };
6476 bool success = ParseLightPosition(runtimeCallInfo, vm, dimPosX, dimPosY, dimPosZ);
6477 if (success) {
6478 GetArkUINodeModifiers()->getCommonModifier()->setPointLightPosition(nativeNode, &dimPosX, &dimPosY, &dimPosZ);
6479 } else {
6480 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightPosition(nativeNode);
6481 }
6482
6483 Local<JSValueRef> intensityArg = runtimeCallInfo->GetCallArgRef(NUM_4);
6484 if (intensityArg->IsNumber()) {
6485 auto intensityValue = static_cast<ArkUI_Float32>((intensityArg->ToNumber(vm)->Value()));
6486 GetArkUINodeModifiers()->getCommonModifier()->setPointLightIntensity(nativeNode, intensityValue);
6487 } else {
6488 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIntensity(nativeNode);
6489 }
6490
6491 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_5);
6492 Color colorValue;
6493 if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, colorValue)) {
6494 GetArkUINodeModifiers()->getCommonModifier()->setPointLightColor(nativeNode, colorValue.GetValue());
6495 } else {
6496 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightColor(nativeNode);
6497 }
6498 }
6499
SetPointLightStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)6500 ArkUINativeModuleValue CommonBridge::SetPointLightStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
6501 {
6502 EcmaVM* vm = runtimeCallInfo->GetVM();
6503 #ifdef POINT_LIGHT_ENABLE
6504 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6505 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
6506 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6507
6508 ParseLightSource(runtimeCallInfo, vm, nativeNode);
6509
6510 auto resourceWrapper = CreateResourceWrapper();
6511 Local<JSValueRef> illuminatedArg = runtimeCallInfo->GetCallArgRef(NUM_6);
6512 if (illuminatedArg->IsNumber() || !resourceWrapper) {
6513 auto illuminatedValue = static_cast<ArkUI_Uint32>(illuminatedArg->ToNumber(vm)->Value());
6514 Dimension illuminatedBorderWidth = resourceWrapper->GetDimensionByName(ILLUMINATED_BORDER_WIDTH_SYS_RES_NAME);
6515 struct ArkUISizeType illuminatedBorderWidthValue = { 0.0, 0 };
6516 illuminatedBorderWidthValue.value = illuminatedBorderWidth.Value();
6517 illuminatedBorderWidthValue.unit = static_cast<int8_t>(illuminatedBorderWidth.Unit());
6518 GetArkUINodeModifiers()->getCommonModifier()->setPointLightIlluminated(
6519 nativeNode, illuminatedValue, &illuminatedBorderWidthValue);
6520 } else {
6521 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIlluminated(nativeNode);
6522 }
6523
6524 Local<JSValueRef> bloomArg = runtimeCallInfo->GetCallArgRef(NUM_7);
6525 if (bloomArg->IsNumber() || !resourceWrapper) {
6526 auto bloomValue = static_cast<ArkUI_Float32>(bloomArg->ToNumber(vm)->Value());
6527 double bloomRadius = resourceWrapper->GetDoubleByName(BLOOM_RADIUS_SYS_RES_NAME);
6528 Color bloomColor = resourceWrapper->GetColorByName(BLOOM_COLOR_SYS_RES_NAME);
6529 GetArkUINodeModifiers()->getCommonModifier()->setPointLightBloom(nativeNode, bloomValue,
6530 static_cast<ArkUI_Float32>(bloomRadius), static_cast<ArkUI_Uint32>(bloomColor.GetValue()));
6531 } else {
6532 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightBloom(nativeNode);
6533 }
6534 #endif
6535 return panda::JSValueRef::Undefined(vm);
6536 }
6537
ResetPointLightStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)6538 ArkUINativeModuleValue CommonBridge::ResetPointLightStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
6539 {
6540 EcmaVM *vm = runtimeCallInfo->GetVM();
6541 #ifdef POINT_LIGHT_ENABLE
6542 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6543 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
6544 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6545 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightPosition(nativeNode);
6546 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIntensity(nativeNode);
6547 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightColor(nativeNode);
6548 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightIlluminated(nativeNode);
6549 GetArkUINodeModifiers()->getCommonModifier()->resetPointLightBloom(nativeNode);
6550 #endif
6551 return panda::JSValueRef::Undefined(vm);
6552 }
6553
SetClipWithEdge(ArkUIRuntimeCallInfo * runtimeCallInfo)6554 ArkUINativeModuleValue CommonBridge::SetClipWithEdge(ArkUIRuntimeCallInfo *runtimeCallInfo)
6555 {
6556 EcmaVM *vm = runtimeCallInfo->GetVM();
6557 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6558 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
6559 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6560 auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
6561
6562 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
6563 if (info[NUM_1]->IsUndefined()) {
6564 ViewAbstract::SetClipEdge(frameNode, true);
6565 return panda::JSValueRef::Undefined(vm);
6566 }
6567 if (info[NUM_1]->IsObject()) {
6568 Framework::JSShapeAbstract *clipShape =
6569 Framework::JSRef<Framework::JSObject>::Cast(info[NUM_1])->Unwrap<Framework::JSShapeAbstract>();
6570 if (clipShape == nullptr) {
6571 return panda::JSValueRef::Undefined(vm);
6572 }
6573 ViewAbstract::SetClipShape(frameNode, clipShape->GetBasicShape());
6574 } else if (info[NUM_1]->IsBoolean()) {
6575 ViewAbstract::SetClipEdge(frameNode, info[NUM_1]->ToBoolean());
6576 }
6577 return panda::JSValueRef::Undefined(vm);
6578 }
6579
ResetClipWithEdge(ArkUIRuntimeCallInfo * runtimeCallInfo)6580 ArkUINativeModuleValue CommonBridge::ResetClipWithEdge(ArkUIRuntimeCallInfo *runtimeCallInfo)
6581 {
6582 EcmaVM *vm = runtimeCallInfo->GetVM();
6583 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
6584 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
6585 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6586 auto *frameNode = reinterpret_cast<FrameNode *>(nativeNode);
6587 ViewAbstract::SetClipEdge(frameNode, true);
6588 return panda::JSValueRef::Undefined(vm);
6589 }
6590
GetFrameNode(ArkUIRuntimeCallInfo * runtimeCallInfo)6591 FrameNode* CommonBridge::GetFrameNode(ArkUIRuntimeCallInfo* runtimeCallInfo)
6592 {
6593 EcmaVM* vm = runtimeCallInfo->GetVM();
6594 CHECK_NULL_RETURN(vm, nullptr);
6595 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
6596 CHECK_NULL_RETURN(!firstArg.IsNull() && firstArg->IsNativePointer(vm), nullptr);
6597 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
6598 CHECK_NULL_RETURN(nativeNode, nullptr);
6599 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
6600 return frameNode;
6601 }
6602
CreateChangeValueInfoObj(EcmaVM * vm,const ChangeValueInfo & changeValueInfo)6603 Local<panda::ObjectRef> CommonBridge::CreateChangeValueInfoObj(EcmaVM* vm, const ChangeValueInfo& changeValueInfo)
6604 {
6605 const char* previewTextKeys[] = { "value", "offset" };
6606 Local<JSValueRef> previewTextValues[] = {
6607 panda::StringRef::NewFromUtf16(vm, changeValueInfo.previewText.value.c_str()),
6608 panda::NumberRef::New(vm, changeValueInfo.previewText.offset) };
6609 auto previewTextObj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(previewTextKeys),
6610 previewTextKeys, previewTextValues);
6611
6612 const char* rangeKeys[] = { "start", "end" };
6613 Local<JSValueRef> rangeBeforeValues[] = {
6614 panda::NumberRef::New(vm, changeValueInfo.rangeBefore.start),
6615 panda::NumberRef::New(vm, changeValueInfo.rangeBefore.end) };
6616 auto rangeBeforeObj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(rangeKeys),
6617 rangeKeys, rangeBeforeValues);
6618 Local<JSValueRef> rangeAfterValues[] = {
6619 panda::NumberRef::New(vm, changeValueInfo.rangeAfter.start),
6620 panda::NumberRef::New(vm, changeValueInfo.rangeAfter.end) };
6621 auto rangeAfterObj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(rangeKeys),
6622 rangeKeys, rangeAfterValues);
6623 Local<JSValueRef> oldPreviewTextValues[] = {
6624 panda::StringRef::NewFromUtf16(vm, changeValueInfo.oldPreviewText.value.c_str()),
6625 panda::NumberRef::New(vm, changeValueInfo.oldPreviewText.offset) };
6626 auto oldPreviewTextObj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(previewTextKeys),
6627 previewTextKeys, oldPreviewTextValues);
6628
6629 const char* optionsKeys[] = { "rangeBefore", "rangeAfter", "oldContent", "oldPreviewText" };
6630 Local<JSValueRef> optionsValues[] = { rangeBeforeObj, rangeAfterObj,
6631 panda::StringRef::NewFromUtf16(vm, changeValueInfo.oldContent.c_str()), oldPreviewTextObj };
6632 auto optionsObj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(optionsKeys),
6633 optionsKeys, optionsValues);
6634
6635 const char* changeValueInfoKeys[] = { "content", "previewText", "options" };
6636 Local<JSValueRef> changeValueInfoValues[] = { panda::StringRef::NewFromUtf16(vm, changeValueInfo.value.c_str()),
6637 previewTextObj, optionsObj };
6638 auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(changeValueInfoKeys),
6639 changeValueInfoKeys, changeValueInfoValues);
6640 return eventObject;
6641 }
6642
CreateGestureInfo(EcmaVM * vm,const RefPtr<NG::GestureInfo> & gestureInfo)6643 Local<panda::ObjectRef> CommonBridge::CreateGestureInfo(EcmaVM* vm, const RefPtr<NG::GestureInfo>& gestureInfo)
6644 {
6645 if (gestureInfo->GetTag().has_value()) {
6646 const char* keys[] = { "tag", "type", "isSystemGesture" };
6647 Local<JSValueRef> values[] = { panda::StringRef::NewFromUtf8(vm, gestureInfo->GetTag().value().c_str()),
6648 panda::NumberRef::New(vm, static_cast<int32_t>(gestureInfo->GetType())),
6649 panda::BooleanRef::New(vm, gestureInfo->IsSystemGesture()) };
6650 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6651 }
6652 const char* keys[] = { "type", "isSystemGesture" };
6653 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(gestureInfo->GetType())),
6654 panda::BooleanRef::New(vm, gestureInfo->IsSystemGesture()) };
6655 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6656 }
6657
CreateGestureEventInfo(EcmaVM * vm,GestureTypeName typeName,const std::shared_ptr<BaseGestureEvent> & info)6658 Local<panda::ObjectRef> CommonBridge::CreateGestureEventInfo(
6659 EcmaVM* vm, GestureTypeName typeName, const std::shared_ptr<BaseGestureEvent>& info)
6660 {
6661 auto obj = SetUniqueAttributes(vm, typeName, info);
6662 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "timestamp"),
6663 panda::NumberRef::New(vm, static_cast<double>(info->GetTimeStamp().time_since_epoch().count())));
6664 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "source"),
6665 panda::NumberRef::New(vm, static_cast<int32_t>(info->GetSourceDevice())));
6666 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "pressure"), panda::NumberRef::New(vm, info->GetForce()));
6667 if (info->GetTiltX().has_value()) {
6668 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltX"), panda::NumberRef::New(vm, info->GetTiltX().value()));
6669 }
6670 if (info->GetTiltY().has_value()) {
6671 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltY"), panda::NumberRef::New(vm, info->GetTiltY().value()));
6672 }
6673 if (info->GetRollAngle().has_value()) {
6674 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "rollAngle"),
6675 panda::NumberRef::New(vm, info->GetRollAngle().value()));
6676 }
6677 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sourceTool"),
6678 panda::NumberRef::New(vm, static_cast<int32_t>(info->GetSourceTool())));
6679 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "deviceId"),
6680 panda::NumberRef::New(vm, static_cast<int32_t>(info->GetDeviceId())));
6681 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "targetDisplayId"),
6682 panda::NumberRef::New(vm, static_cast<int32_t>(info->GetTargetDisplayId())));
6683
6684 auto fingerArr = panda::ArrayRef::New(vm);
6685 const std::list<FingerInfo>& fingerList = info->GetFingerList();
6686 std::list<FingerInfo> notTouchFingerList;
6687 int32_t maxFingerId = -1;
6688 for (const FingerInfo& fingerInfo : fingerList) {
6689 auto element = CreateFingerInfo(vm, fingerInfo);
6690 if (fingerInfo.sourceType_ == SourceType::TOUCH && fingerInfo.sourceTool_ == SourceTool::FINGER) {
6691 fingerArr->SetValueAt(vm, fingerArr, fingerInfo.fingerId_, element);
6692 if (fingerInfo.fingerId_ > maxFingerId) {
6693 maxFingerId = fingerInfo.fingerId_;
6694 }
6695 } else {
6696 notTouchFingerList.emplace_back(fingerInfo);
6697 }
6698 }
6699 auto idx = maxFingerId + 1;
6700 for (const FingerInfo& fingerInfo : notTouchFingerList) {
6701 auto element = CreateFingerInfo(vm, fingerInfo);
6702 fingerArr->SetValueAt(vm, fingerArr, idx++, element);
6703 }
6704 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "fingerList"), fingerArr);
6705 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "target"), CreateEventTargetObject(vm, info));
6706 return obj;
6707 }
6708
SetUniqueAttributes(EcmaVM * vm,GestureTypeName typeName,const std::shared_ptr<BaseGestureEvent> & info)6709 Local<panda::ObjectRef> CommonBridge::SetUniqueAttributes(
6710 EcmaVM* vm, GestureTypeName typeName, const std::shared_ptr<BaseGestureEvent>& info)
6711 {
6712 double density = PipelineBase::GetCurrentDensity();
6713 switch (typeName) {
6714 case OHOS::Ace::GestureTypeName::LONG_PRESS_GESTURE: {
6715 auto* longPressGestureEvent = TypeInfoHelper::DynamicCast<LongPressGestureEvent>(info.get());
6716 if (longPressGestureEvent) {
6717 const char* keys[] = { "repeat" };
6718 Local<JSValueRef> values[] = { panda::BooleanRef::New(vm, longPressGestureEvent->GetRepeat()) };
6719 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6720 }
6721 return panda::ObjectRef::New(vm);
6722 }
6723 case OHOS::Ace::GestureTypeName::PAN_GESTURE: {
6724 auto* panGestureEvent = TypeInfoHelper::DynamicCast<PanGestureEvent>(info.get());
6725 if (panGestureEvent) {
6726 const char* keys[] = { "offsetX", "offsetY", "velocityX", "velocityY", "velocity" };
6727 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, panGestureEvent->GetOffsetX() / density),
6728 panda::NumberRef::New(vm, panGestureEvent->GetOffsetY() / density),
6729 panda::NumberRef::New(vm, panGestureEvent->GetVelocity().GetVelocityX() / density),
6730 panda::NumberRef::New(vm, panGestureEvent->GetVelocity().GetVelocityY() / density),
6731 panda::NumberRef::New(vm, panGestureEvent->GetVelocity().GetVelocityValue() / density) };
6732 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6733 }
6734 return panda::ObjectRef::New(vm);
6735 }
6736 case OHOS::Ace::GestureTypeName::PINCH_GESTURE: {
6737 auto* pinchGestureEvent = TypeInfoHelper::DynamicCast<PinchGestureEvent>(info.get());
6738 if (pinchGestureEvent) {
6739 const char* keys[] = { "scale", "pinchCenterX", "pinchCenterY" };
6740 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, pinchGestureEvent->GetScale()),
6741 panda::NumberRef::New(vm, pinchGestureEvent->GetPinchCenter().GetX() / density),
6742 panda::NumberRef::New(vm, pinchGestureEvent->GetPinchCenter().GetY() / density) };
6743 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6744 }
6745 return panda::ObjectRef::New(vm);
6746 }
6747 case OHOS::Ace::GestureTypeName::ROTATION_GESTURE: {
6748 auto* rotationGestureEvent = TypeInfoHelper::DynamicCast<RotationGestureEvent>(info.get());
6749 if (rotationGestureEvent) {
6750 const char* keys[] = { "angle" };
6751 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, rotationGestureEvent->GetAngle()) };
6752 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6753 }
6754 return panda::ObjectRef::New(vm);
6755 }
6756 case OHOS::Ace::GestureTypeName::SWIPE_GESTURE: {
6757 auto* swipeGestureEvent = TypeInfoHelper::DynamicCast<SwipeGestureEvent>(info.get());
6758 if (swipeGestureEvent) {
6759 const char* keys[] = { "angle", "speed" };
6760 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, swipeGestureEvent->GetAngle()),
6761 panda::NumberRef::New(vm, swipeGestureEvent->GetSpeed()) };
6762 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6763 }
6764 return panda::ObjectRef::New(vm);
6765 }
6766 default:
6767 return panda::ObjectRef::New(vm);
6768 }
6769 }
6770
CreateRecognizerObject(EcmaVM * vm,const RefPtr<NG::NGGestureRecognizer> & target)6771 Local<panda::ObjectRef> CommonBridge::CreateRecognizerObject(EcmaVM* vm, const RefPtr<NG::NGGestureRecognizer>& target)
6772 {
6773 auto panRecognizer = AceType::DynamicCast<NG::PanRecognizer>(target);
6774 if (panRecognizer) {
6775 JSRef<JSObject> recognizerObj = JSClass<JSPanRecognizer>::NewInstance();
6776 auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSPanRecognizer>());
6777 currentRecognizer->Update(panRecognizer);
6778 return recognizerObj->GetLocalHandle();
6779 }
6780 auto pinchRecognizer = AceType::DynamicCast<NG::PinchRecognizer>(target);
6781 if (pinchRecognizer) {
6782 JSRef<JSObject> recognizerObj = JSClass<JSPinchRecognizer>::NewInstance();
6783 auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSPinchRecognizer>());
6784 currentRecognizer->Update(pinchRecognizer);
6785 return recognizerObj->GetLocalHandle();
6786 }
6787 auto tapRecognizer = AceType::DynamicCast<NG::ClickRecognizer>(target);
6788 if (tapRecognizer) {
6789 JSRef<JSObject> recognizerObj = JSClass<JSTapRecognizer>::NewInstance();
6790 auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSTapRecognizer>());
6791 currentRecognizer->Update(tapRecognizer);
6792 return recognizerObj->GetLocalHandle();
6793 }
6794 auto longPressRecognizer = AceType::DynamicCast<NG::LongPressRecognizer>(target);
6795 if (longPressRecognizer) {
6796 JSRef<JSObject> recognizerObj = JSClass<JSLongPressRecognizer>::NewInstance();
6797 auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSLongPressRecognizer>());
6798 currentRecognizer->Update(longPressRecognizer);
6799 return recognizerObj->GetLocalHandle();
6800 }
6801 auto rotationRecognizer = AceType::DynamicCast<NG::RotationRecognizer>(target);
6802 if (rotationRecognizer) {
6803 JSRef<JSObject> recognizerObj = JSClass<JSRotationRecognizer>::NewInstance();
6804 auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSRotationRecognizer>());
6805 currentRecognizer->Update(rotationRecognizer);
6806 return recognizerObj->GetLocalHandle();
6807 }
6808 auto swipeRecognizer = AceType::DynamicCast<NG::SwipeRecognizer>(target);
6809 if (swipeRecognizer) {
6810 JSRef<JSObject> recognizerObj = JSClass<JSSwipeRecognizer>::NewInstance();
6811 auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSSwipeRecognizer>());
6812 currentRecognizer->Update(swipeRecognizer);
6813 return recognizerObj->GetLocalHandle();
6814 }
6815 JSRef<JSObject> recognizerObj = JSClass<JSGestureRecognizer>::NewInstance();
6816 auto currentRecognizer = Referenced::Claim(recognizerObj->Unwrap<JSGestureRecognizer>());
6817 currentRecognizer->Update(target);
6818 return recognizerObj->GetLocalHandle();
6819 }
6820
CreateFingerInfo(EcmaVM * vm,const FingerInfo & fingerInfo)6821 Local<panda::ObjectRef> CommonBridge::CreateFingerInfo(EcmaVM* vm, const FingerInfo& fingerInfo)
6822 {
6823 const OHOS::Ace::Offset& globalLocation = fingerInfo.globalLocation_;
6824 const OHOS::Ace::Offset& localLocation = fingerInfo.localLocation_;
6825 const OHOS::Ace::Offset& screenLocation = fingerInfo.screenLocation_;
6826 double density = PipelineBase::GetCurrentDensity();
6827 const char* keys[] = { "id", "globalX", "globalY", "localX", "localY", "displayX", "displayY", "hand" };
6828 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, fingerInfo.fingerId_),
6829 panda::NumberRef::New(vm, globalLocation.GetX() / density),
6830 panda::NumberRef::New(vm, globalLocation.GetY() / density),
6831 panda::NumberRef::New(vm, localLocation.GetX() / density),
6832 panda::NumberRef::New(vm, localLocation.GetY() / density),
6833 panda::NumberRef::New(vm, screenLocation.GetX() / density),
6834 panda::NumberRef::New(vm, screenLocation.GetY() / density),
6835 panda::NumberRef::New(vm, fingerInfo.operatingHand_) };
6836 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
6837 }
6838
CreateEventTargetObject(EcmaVM * vm,const std::shared_ptr<BaseGestureEvent> & info)6839 Local<panda::ObjectRef> CommonBridge::CreateEventTargetObject(EcmaVM* vm, const std::shared_ptr<BaseGestureEvent>& info)
6840 {
6841 const auto& localOffset = info->GetTarget().area.GetOffset();
6842 const auto& origin = info->GetTarget().origin;
6843 const char* keysOfOffset[] = { "x", "y" };
6844 Local<JSValueRef> valuesOfOffset[] = { panda::NumberRef::New(vm, localOffset.GetX().ConvertToVp()),
6845 panda::NumberRef::New(vm, localOffset.GetY().ConvertToVp()) };
6846 auto offset = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfOffset), keysOfOffset, valuesOfOffset);
6847
6848 const char* keysOfGlobalOffset[] = { "x", "y" };
6849 Local<JSValueRef> valuesOfGlobalOffset[] = { panda::NumberRef::New(
6850 vm, (origin.GetX() + localOffset.GetX()).ConvertToVp()),
6851 panda::NumberRef::New(vm, (origin.GetY() + localOffset.GetY()).ConvertToVp()) };
6852 auto globalOffset = panda::ObjectRef::NewWithNamedProperties(
6853 vm, ArraySize(keysOfGlobalOffset), keysOfGlobalOffset, valuesOfGlobalOffset);
6854 const char* keysOfArea[] = { "position", "globalPosition", "width", "height" };
6855 Local<JSValueRef> valuesOfArea[] = { offset, globalOffset,
6856 panda::NumberRef::New(vm, info->GetTarget().area.GetWidth().ConvertToVp()),
6857 panda::NumberRef::New(vm, info->GetTarget().area.GetHeight().ConvertToVp()) };
6858 auto area = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfArea), keysOfArea, valuesOfArea);
6859 auto target = panda::ObjectRef::New(vm);
6860 target->Set(vm, panda::StringRef::NewFromUtf8(vm, "area"), area);
6861 if (info->GetTarget().id.empty()) {
6862 target->Set(vm, panda::StringRef::NewFromUtf8(vm, "id"), panda::JSValueRef().Undefined(vm));
6863 } else {
6864 target->Set(vm, panda::StringRef::NewFromUtf8(vm, "id"),
6865 panda::StringRef::NewFromUtf8(vm, info->GetTarget().id.c_str()));
6866 }
6867 return target;
6868 }
6869
CreateAreaObject(EcmaVM * vm,const RectF & rect,const OffsetF & origin)6870 Local<panda::ObjectRef> CommonBridge::CreateAreaObject(EcmaVM* vm, const RectF& rect, const OffsetF& origin)
6871 {
6872 double density = PipelineBase::GetCurrentDensity();
6873 auto localOffset = rect.GetOffset();
6874 const char* keysOfOffset[] = { "x", "y" };
6875 Local<JSValueRef> valuesOfOffset[] = { panda::NumberRef::New(vm, localOffset.GetX() / density),
6876 panda::NumberRef::New(vm, localOffset.GetY() / density) };
6877 auto offset = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfOffset), keysOfOffset, valuesOfOffset);
6878 const char* keysOfGlobalOffset[] = { "x", "y" };
6879 Local<JSValueRef> valuesOfGlobalOffset[] = { panda::NumberRef::New(
6880 vm, (localOffset.GetX() + origin.GetX()) / density),
6881 panda::NumberRef::New(vm, (localOffset.GetY() + origin.GetY()) / density) };
6882 auto globalOffset = panda::ObjectRef::NewWithNamedProperties(
6883 vm, ArraySize(keysOfGlobalOffset), keysOfGlobalOffset, valuesOfGlobalOffset);
6884
6885 const char* keysOfArea[] = { "pos", "position", "globalPos", "globalPosition", "width", "height" };
6886 Local<JSValueRef> valuesOfArea[] = { offset, offset, globalOffset, globalOffset,
6887 panda::NumberRef::New(vm, rect.Width() / density), panda::NumberRef::New(vm, rect.Height() / density) };
6888 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keysOfArea), keysOfArea, valuesOfArea);
6889 }
6890
GetGestureCommonValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & priority,int32_t & mask)6891 void CommonBridge::GetGestureCommonValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& priority, int32_t& mask)
6892 {
6893 EcmaVM* vm = runtimeCallInfo->GetVM();
6894 CHECK_NULL_VOID(vm);
6895 Local<JSValueRef> priorityArg = runtimeCallInfo->GetCallArgRef(NUM_1);
6896 if (!priorityArg.IsNull() && !priorityArg->IsUndefined()) {
6897 priority = static_cast<int32_t>(priorityArg->ToNumber(vm)->Value());
6898 }
6899 Local<JSValueRef> maskArg = runtimeCallInfo->GetCallArgRef(NUM_2);
6900 if (!maskArg.IsNull() && !maskArg->IsUndefined()) {
6901 mask = static_cast<int32_t>(maskArg->ToNumber(vm)->Value());
6902 }
6903 }
6904
SetGestureTag(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t argNumber,ArkUIGesture * gesture)6905 void CommonBridge::SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture)
6906 {
6907 EcmaVM* vm = runtimeCallInfo->GetVM();
6908 CHECK_NULL_VOID(vm);
6909 Local<JSValueRef> gestureTagArg = runtimeCallInfo->GetCallArgRef(argNumber);
6910 if (!gestureTagArg.IsNull() && !gestureTagArg->IsUndefined()) {
6911 auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
6912 gesturePtr->SetTag(gestureTagArg->ToString(vm)->ToString(vm));
6913 }
6914 }
6915
SetGestureAllowedTypes(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t argNumber,ArkUIGesture * gesture)6916 void CommonBridge::SetGestureAllowedTypes(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber,
6917 ArkUIGesture* gesture)
6918 {
6919 EcmaVM* vm = runtimeCallInfo->GetVM();
6920 CHECK_NULL_VOID(vm);
6921 Local<JSValueRef> typesArg = runtimeCallInfo->GetCallArgRef(argNumber);
6922 if (typesArg.IsNull() || typesArg->IsUndefined() || !typesArg->IsArray(vm)) {
6923 return;
6924 }
6925 auto typesArr = panda::Local<panda::ArrayRef>(typesArg);
6926 auto typesLength = typesArr->Length(vm);
6927 std::set<SourceTool> allowedTypes{};
6928 for (size_t i = 0; i < typesLength; ++i) {
6929 auto type = panda::ArrayRef::GetValueAt(vm, typesArr, i);
6930 if (type->IsNumber()) {
6931 allowedTypes.insert(static_cast<SourceTool>(type->Int32Value(vm)));
6932 }
6933 }
6934 if (allowedTypes.empty()) {
6935 return;
6936 }
6937 auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
6938 gesturePtr->SetAllowedTypes(allowedTypes);
6939 }
6940
GetTapGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,int32_t & count,double & distanceThreshold,bool & limitFingerCount,uint32_t argNumber)6941 void CommonBridge::GetTapGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers,
6942 int32_t& count, double& distanceThreshold, bool& limitFingerCount, uint32_t argNumber)
6943 {
6944 EcmaVM* vm = runtimeCallInfo->GetVM();
6945 CHECK_NULL_VOID(vm);
6946 Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6947 if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6948 auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6949 fingers = (fingersValue < DEFAULT_TAP_FINGER || fingersValue > DEFAULT_MAX_FINGERS) ? DEFAULT_TAP_FINGER
6950 : fingersValue;
6951 }
6952 Local<JSValueRef> countArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6953 if (!countArg.IsNull() && !countArg->IsUndefined()) {
6954 auto countValue = static_cast<int32_t>(countArg->ToNumber(vm)->Value());
6955 count = countValue < DEFAULT_TAP_COUNT ? DEFAULT_TAP_COUNT : countValue;
6956 }
6957 Local<JSValueRef> limitFingerCountArg = runtimeCallInfo->GetCallArgRef(argNumber + 2); // 2: get the third arg
6958 if (!limitFingerCountArg.IsNull() && !limitFingerCountArg->IsUndefined()) {
6959 limitFingerCount = limitFingerCountArg->ToBoolean(vm)->Value();
6960 }
6961 }
6962
GetLongPressGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,bool & repeat,int32_t & duration,bool & limitFingerCount,uint32_t argNumber)6963 void CommonBridge::GetLongPressGestureValue(
6964 ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, bool& repeat, int32_t& duration,
6965 bool& limitFingerCount, uint32_t argNumber)
6966 {
6967 EcmaVM* vm = runtimeCallInfo->GetVM();
6968 CHECK_NULL_VOID(vm);
6969 Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6970 if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6971 auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
6972 fingers = (fingersValue < DEFAULT_LONG_PRESS_FINGER || fingersValue > DEFAULT_MAX_FINGERS)
6973 ? DEFAULT_LONG_PRESS_FINGER
6974 : fingersValue;
6975 }
6976 Local<JSValueRef> repeatArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
6977 if (!repeatArg.IsNull() && !repeatArg->IsUndefined()) {
6978 repeat = repeatArg->ToBoolean(vm)->Value();
6979 }
6980 Local<JSValueRef> durationArg = runtimeCallInfo->GetCallArgRef(argNumber + NUM_2);
6981 if (!durationArg.IsNull() && !durationArg->IsUndefined()) {
6982 auto durationValue = static_cast<int32_t>(durationArg->ToNumber(vm)->Value());
6983 duration = durationValue <= 0 ? DEFAULT_LONG_PRESS_DURATION : durationValue;
6984 }
6985 Local<JSValueRef> limitFingerCountArg = runtimeCallInfo->GetCallArgRef(argNumber + 3); // 3: get the fourth arg
6986 if (!limitFingerCountArg.IsNull() && !limitFingerCountArg->IsUndefined()) {
6987 limitFingerCount = limitFingerCountArg->ToBoolean(vm)->Value();
6988 }
6989 }
6990
GetPanGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,int32_t & direction,double & distance,bool & limitFingerCount,uint32_t argNumber)6991 void CommonBridge::GetPanGestureValue(
6992 ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, int32_t& direction, double& distance,
6993 bool& limitFingerCount, uint32_t argNumber)
6994 {
6995 EcmaVM* vm = runtimeCallInfo->GetVM();
6996 CHECK_NULL_VOID(vm);
6997 Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
6998 if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
6999 auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
7000 fingers = (fingersValue < DEFAULT_PAN_FINGER || fingersValue > DEFAULT_MAX_FINGERS) ? DEFAULT_PAN_FINGER
7001 : fingersValue;
7002 }
7003 Local<JSValueRef> directionArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
7004 if (!directionArg.IsNull() && !directionArg->IsUndefined()) {
7005 direction = static_cast<int32_t>(directionArg->ToNumber(vm)->Value());
7006 }
7007 Local<JSValueRef> distanceArg = runtimeCallInfo->GetCallArgRef(argNumber + 2);
7008 if (!distanceArg.IsNull() && !distanceArg->IsUndefined()) {
7009 auto distanceValue = static_cast<double>(distanceArg->ToNumber(vm)->Value());
7010 distance = distanceValue < 0.0f ? DEFAULT_PAN_DISTANCE.ConvertToPx() : distanceValue;
7011 }
7012 Local<JSValueRef> limitFingerCountArg = runtimeCallInfo->GetCallArgRef(argNumber + 3); // 3: get the fourth arg
7013 if (!limitFingerCountArg.IsNull() && !limitFingerCountArg->IsUndefined()) {
7014 limitFingerCount = limitFingerCountArg->ToBoolean(vm)->Value();
7015 }
7016 }
7017
GetSwipeGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,int32_t & direction,double & speed,bool & limitFingerCount,uint32_t argNumber)7018 void CommonBridge::GetSwipeGestureValue(
7019 ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, int32_t& direction, double& speed,
7020 bool& limitFingerCount, uint32_t argNumber)
7021 {
7022 EcmaVM* vm = runtimeCallInfo->GetVM();
7023 CHECK_NULL_VOID(vm);
7024 Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
7025 if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
7026 auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
7027 fingers = (fingersValue < DEFAULT_SLIDE_FINGER || fingersValue > DEFAULT_MAX_FINGERS) ? DEFAULT_SLIDE_FINGER
7028 : fingersValue;
7029 }
7030 Local<JSValueRef> directionArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
7031 if (!directionArg.IsNull() && !directionArg->IsUndefined()) {
7032 direction = static_cast<int32_t>(directionArg->ToNumber(vm)->Value());
7033 }
7034 Local<JSValueRef> speedArg = runtimeCallInfo->GetCallArgRef(argNumber + 2);
7035 if (!speedArg.IsNull() && !speedArg->IsUndefined()) {
7036 auto speedValue = static_cast<double>(speedArg->ToNumber(vm)->Value());
7037 speed = LessOrEqual(speedValue, 0.0) ? DEFAULT_SLIDE_SPEED : speedValue;
7038 }
7039 Local<JSValueRef> limitFingerCountArg = runtimeCallInfo->GetCallArgRef(argNumber + 3); // 3: get the fourth arg
7040 if (!limitFingerCountArg.IsNull() && !limitFingerCountArg->IsUndefined()) {
7041 limitFingerCount = limitFingerCountArg->ToBoolean(vm)->Value();
7042 }
7043 }
7044
GetPinchGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,double & distance,bool & limitFingerCount,uint32_t argNumber)7045 void CommonBridge::GetPinchGestureValue(
7046 ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, double& distance,
7047 bool& limitFingerCount, uint32_t argNumber)
7048 {
7049 EcmaVM* vm = runtimeCallInfo->GetVM();
7050 CHECK_NULL_VOID(vm);
7051 Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
7052 if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
7053 auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
7054 fingers = (fingersValue < DEFAULT_PINCH_FINGER || fingersValue > DEFAULT_MAX_PINCH_FINGER)
7055 ? DEFAULT_PINCH_FINGER
7056 : fingersValue;
7057 }
7058 Local<JSValueRef> distanceArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
7059 if (!distanceArg.IsNull() && !distanceArg->IsUndefined()) {
7060 auto distanceValue = static_cast<double>(distanceArg->ToNumber(vm)->Value());
7061 distance = distanceValue <= 0.0 ? DEFAULT_PINCH_DISTANCE : distanceValue;
7062 }
7063 Local<JSValueRef> limitFingerCountArg = runtimeCallInfo->GetCallArgRef(argNumber + 2); // 2: get the third arg
7064 if (!limitFingerCountArg.IsNull() && !limitFingerCountArg->IsUndefined()) {
7065 limitFingerCount = limitFingerCountArg->ToBoolean(vm)->Value();
7066 }
7067 }
7068
GetRotationGestureValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & fingers,double & angle,bool & limitFingerCount,uint32_t argNumber)7069 void CommonBridge::GetRotationGestureValue(
7070 ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, double& angle,
7071 bool& limitFingerCount, uint32_t argNumber)
7072 {
7073 EcmaVM* vm = runtimeCallInfo->GetVM();
7074 CHECK_NULL_VOID(vm);
7075 Local<JSValueRef> fingersArg = runtimeCallInfo->GetCallArgRef(argNumber);
7076 if (!fingersArg.IsNull() && !fingersArg->IsUndefined()) {
7077 auto fingersValue = static_cast<int32_t>(fingersArg->ToNumber(vm)->Value());
7078 fingers = (fingersValue < DEFAULT_ROTATION_FINGER || fingersValue > DEFAULT_MAX_ROTATION_FINGER)
7079 ? DEFAULT_ROTATION_FINGER
7080 : fingersValue;
7081 }
7082 Local<JSValueRef> angleArg = runtimeCallInfo->GetCallArgRef(argNumber + 1);
7083 if (!angleArg.IsNull() && !angleArg->IsUndefined()) {
7084 auto angleValue = static_cast<double>(angleArg->ToNumber(vm)->Value());
7085 angle = (angleValue <= 0 || angleValue > DEFAULT_MAX_ROTATION_ANGLE) ? DEFAULT_ROTATION_ANGLE : angleValue;
7086 }
7087 Local<JSValueRef> limitFingerCountArg = runtimeCallInfo->GetCallArgRef(argNumber + 2); // 2: get the third arg
7088 if (!limitFingerCountArg.IsNull() && !limitFingerCountArg->IsUndefined()) {
7089 limitFingerCount = limitFingerCountArg->ToBoolean(vm)->Value();
7090 }
7091 }
7092
GetGestureModeValue(ArkUIRuntimeCallInfo * runtimeCallInfo,int32_t & mode,uint32_t argNumber)7093 void CommonBridge::GetGestureModeValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& mode, uint32_t argNumber)
7094 {
7095 EcmaVM* vm = runtimeCallInfo->GetVM();
7096 CHECK_NULL_VOID(vm);
7097 Local<JSValueRef> modeArg = runtimeCallInfo->GetCallArgRef(argNumber);
7098 if (!modeArg.IsNull() && !modeArg->IsUndefined()) {
7099 mode = static_cast<int32_t>(modeArg->ToNumber(vm)->Value());
7100 }
7101 }
7102
SetOnGestureEvent(ArkUIRuntimeCallInfo * runtimeCallInfo,const GestureEventAction & action,uint32_t argNumber,ArkUIGesture * gesture)7103 void CommonBridge::SetOnGestureEvent(
7104 ArkUIRuntimeCallInfo* runtimeCallInfo, const GestureEventAction& action, uint32_t argNumber, ArkUIGesture* gesture)
7105 {
7106 EcmaVM* vm = runtimeCallInfo->GetVM();
7107 CHECK_NULL_VOID(vm);
7108 Local<JSValueRef> eventArg = runtimeCallInfo->GetCallArgRef(argNumber);
7109 if (eventArg.IsNull() || eventArg->IsUndefined() || !eventArg->IsFunction(vm)) {
7110 return;
7111 }
7112 auto obj = eventArg->ToObject(vm);
7113 auto containerId = Container::CurrentId();
7114 panda::Local<panda::FunctionRef> func = obj;
7115 auto* frameNode = GetFrameNode(runtimeCallInfo);
7116 bool isWeak = frameNode == nullptr ? false : FrameNodeBridge::IsCustomFrameNode(frameNode);
7117
7118 if (action == Ace::GestureEventAction::CANCEL) {
7119 auto onActionCancelFunc = [vm, func = JSFuncObjRef(panda::CopyableGlobal(vm, func), isWeak),
7120 containerId](GestureEvent& info) {
7121 panda::LocalScope pandaScope(vm);
7122 panda::TryCatch trycatch(vm);
7123 ContainerScope scope(containerId);
7124 auto function = func.Lock();
7125 if (!function.IsEmpty() && function->IsFunction(vm)) {
7126 auto obj = CreateCommonGestureEventInfo(vm, info);
7127 panda::Local<panda::JSValueRef> params[1] = { obj };
7128 function->Call(vm, function.ToLocal(), params, 1);
7129 }
7130 };
7131 auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
7132 gesturePtr->SetOnActionCancelId(onActionCancelFunc);
7133 return;
7134 }
7135 auto event = [vm, func = JSFuncObjRef(panda::CopyableGlobal(vm, func), isWeak), containerId](GestureEvent& info) {
7136 panda::LocalScope pandaScope(vm);
7137 panda::TryCatch trycatch(vm);
7138 ContainerScope scope(containerId);
7139 auto function = func.Lock();
7140 if (!function.IsEmpty() && function->IsFunction(vm)) {
7141 auto obj = CreateCommonGestureEventInfo(vm, info);
7142 panda::Local<panda::JSValueRef> params[1] = { obj };
7143 function->Call(vm, function.ToLocal(), params, 1);
7144 }
7145 };
7146 auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
7147 switch (action) {
7148 case Ace::GestureEventAction::ACTION:
7149 gesturePtr->SetOnActionId(event);
7150 break;
7151 case Ace::GestureEventAction::START:
7152 gesturePtr->SetOnActionStartId(event);
7153 break;
7154 case Ace::GestureEventAction::UPDATE:
7155 gesturePtr->SetOnActionUpdateId(event);
7156 break;
7157 case Ace::GestureEventAction::END:
7158 gesturePtr->SetOnActionEndId(event);
7159 break;
7160 default:
7161 break;
7162 }
7163 }
7164
CreateCommonGestureEventInfo(EcmaVM * vm,GestureEvent & info)7165 Local<panda::ObjectRef> CommonBridge::CreateCommonGestureEventInfo(EcmaVM* vm, GestureEvent& info)
7166 {
7167 double density = PipelineBase::GetCurrentDensity();
7168 const char* keys[] = { "repeat", "offsetX", "offsetY", "scale", "angle", "speed", "timestamp", "pinchCenterX",
7169 "pinchCenterY", "source", "pressure", "sourceTool", "velocityX", "velocityY", "velocity",
7170 "deviceId", "getModifierKeyState" };
7171 Local<JSValueRef> values[] = { panda::BooleanRef::New(vm, info.GetRepeat()),
7172 panda::NumberRef::New(vm, info.GetOffsetX() / density), panda::NumberRef::New(vm, info.GetOffsetY() / density),
7173 panda::NumberRef::New(vm, info.GetScale()), panda::NumberRef::New(vm, info.GetAngle()),
7174 panda::NumberRef::New(vm, info.GetSpeed()),
7175 panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
7176 panda::NumberRef::New(vm, info.GetPinchCenter().GetX() / density),
7177 panda::NumberRef::New(vm, info.GetPinchCenter().GetY() / density),
7178 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetSourceDevice())),
7179 panda::NumberRef::New(vm, info.GetForce()),
7180 panda::NumberRef::New(vm, static_cast<int32_t>(static_cast<int32_t>(info.GetSourceTool()))),
7181 panda::NumberRef::New(vm, info.GetVelocity().GetVelocityX() / density),
7182 panda::NumberRef::New(vm, info.GetVelocity().GetVelocityY() / density),
7183 panda::NumberRef::New(vm, info.GetVelocity().GetVelocityValue() / density),
7184 panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
7185 panda::NumberRef::New(vm, info.GetDeviceId()) };
7186 auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
7187 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltX"),
7188 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltX().value_or(0.0f))));
7189 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltY"),
7190 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltY().value_or(0.0f))));
7191 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "rollAngle"),
7192 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetRollAngle().value_or(0.0f))));
7193 auto fingerArr = CreateFingerListArray(vm, info);
7194 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "fingerList"), fingerArr);
7195 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "target"), FrameNodeBridge::CreateEventTargetObject(vm, info));
7196 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "axisVertical"), panda::NumberRef::New(vm, info.GetVerticalAxis()));
7197 obj->Set(
7198 vm, panda::StringRef::NewFromUtf8(vm, "axisHorizontal"), panda::NumberRef::New(vm, info.GetHorizontalAxis()));
7199 obj->Set(
7200 vm, panda::StringRef::NewFromUtf8(vm, "targetDisplayId"), panda::NumberRef::New(vm, info.GetTargetDisplayId()));
7201 obj->SetNativePointerFieldCount(vm, 1);
7202 obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
7203 return obj;
7204 }
7205
CreateFingerListArray(EcmaVM * vm,GestureEvent & info)7206 Local<panda::ArrayRef> CommonBridge::CreateFingerListArray(EcmaVM* vm, GestureEvent& info)
7207 {
7208 auto fingerArr = panda::ArrayRef::New(vm);
7209 const std::list<FingerInfo>& fingerList = info.GetFingerList();
7210 std::list<FingerInfo> notTouchFingerList;
7211 int32_t maxFingerId = -1;
7212 for (const FingerInfo& fingerInfo : fingerList) {
7213 auto element = CreateFingerInfo(vm, fingerInfo);
7214 if (fingerInfo.sourceType_ == SourceType::TOUCH && fingerInfo.sourceTool_ == SourceTool::FINGER) {
7215 fingerArr->SetValueAt(vm, fingerArr, fingerInfo.fingerId_, element);
7216 if (fingerInfo.fingerId_ > maxFingerId) {
7217 maxFingerId = fingerInfo.fingerId_;
7218 }
7219 } else {
7220 notTouchFingerList.emplace_back(fingerInfo);
7221 }
7222 }
7223 auto idx = maxFingerId + 1;
7224 for (const FingerInfo& fingerInfo : notTouchFingerList) {
7225 auto element = CreateFingerInfo(vm, fingerInfo);
7226 fingerArr->SetValueAt(vm, fingerArr, idx++, element);
7227 }
7228 return fingerArr;
7229 }
7230
GetGestureGroup(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t argNumber)7231 ArkUIGesture* CommonBridge::GetGestureGroup(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber)
7232 {
7233 EcmaVM* vm = runtimeCallInfo->GetVM();
7234 CHECK_NULL_RETURN(vm, nullptr);
7235 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(argNumber);
7236 CHECK_NULL_RETURN(!firstArg.IsNull(), nullptr);
7237 auto* group = reinterpret_cast<ArkUIGesture*>(firstArg->ToNativePointer(vm)->Value());
7238 return group;
7239 }
7240
SetOnClick(ArkUIRuntimeCallInfo * runtimeCallInfo)7241 ArkUINativeModuleValue CommonBridge::SetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo)
7242 {
7243 EcmaVM* vm = runtimeCallInfo->GetVM();
7244 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7245 auto* frameNode = GetFrameNode(runtimeCallInfo);
7246 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7247 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7248 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7249 auto obj = secondeArg->ToObject(vm);
7250 auto containerId = Container::CurrentId();
7251 panda::Local<panda::FunctionRef> func = obj;
7252 auto onClick = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
7253 GestureEvent& info) {
7254 panda::LocalScope pandaScope(vm);
7255 panda::TryCatch trycatch(vm);
7256 ContainerScope scope(containerId);
7257 PipelineContext::SetCallBackNode(node);
7258 auto obj = FrameNodeBridge::CreateGestureEventInfo(vm, info);
7259 panda::Local<panda::JSValueRef> params[1] = { obj };
7260 func->Call(vm, func.ToLocal(), params, 1);
7261 };
7262 NG::ViewAbstract::SetOnClick(frameNode, std::move(onClick));
7263 return panda::JSValueRef::Undefined(vm);
7264 }
7265
ResetOnClick(ArkUIRuntimeCallInfo * runtimeCallInfo)7266 ArkUINativeModuleValue CommonBridge::ResetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo)
7267 {
7268 EcmaVM* vm = runtimeCallInfo->GetVM();
7269 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7270 auto* frameNode = GetFrameNode(runtimeCallInfo);
7271 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7272 ViewAbstract::DisableOnClick(frameNode);
7273 return panda::JSValueRef::Undefined(vm);
7274 }
7275
SetOnDragStart(ArkUIRuntimeCallInfo * runtimeCallInfo)7276 ArkUINativeModuleValue CommonBridge::SetOnDragStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
7277 {
7278 EcmaVM* vm = runtimeCallInfo->GetVM();
7279 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7280 auto* frameNode = GetFrameNode(runtimeCallInfo);
7281 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7282 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
7283 static std::vector<JSCallbackInfoType> checkList { JSCallbackInfoType::FUNCTION };
7284 auto jsVal = info[1];
7285 if (!JSViewAbstract::CheckJSCallbackInfo("OnDragStart", jsVal, checkList)) {
7286 return panda::JSValueRef::Undefined(vm);
7287 }
7288 RefPtr<JsDragFunction> jsOnDragStartFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(jsVal));
7289 auto onDragStart = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragStartFunc),
7290 node = AceType::WeakClaim<NG::FrameNode>(frameNode)](
7291 const RefPtr<OHOS::Ace::DragEvent>& info,
7292 const std::string& extraParams) -> NG::DragDropBaseInfo {
7293 NG::DragDropBaseInfo dragDropInfo;
7294 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, dragDropInfo);
7295 PipelineContext::SetCallBackNode(node);
7296 auto ret = func->Execute(info, extraParams);
7297 if (!ret->IsObject()) {
7298 return dragDropInfo;
7299 }
7300 auto builderObj = JSRef<JSObject>::Cast(ret);
7301 #if defined(PIXEL_MAP_SUPPORTED)
7302 auto pixmap = builderObj->GetProperty("pixelMap");
7303 dragDropInfo.pixelMap = CreatePixelMapFromNapiValue(pixmap);
7304 #endif
7305 auto extraInfo = builderObj->GetProperty("extraInfo");
7306 JSViewAbstract::ParseJsString(extraInfo, dragDropInfo.extraInfo);
7307 return dragDropInfo;
7308 };
7309 ViewAbstractModelNG::SetOnDragStart(frameNode, std::move(onDragStart));
7310 return panda::JSValueRef::Undefined(vm);
7311 }
7312
ResetOnDragStart(ArkUIRuntimeCallInfo * runtimeCallInfo)7313 ArkUINativeModuleValue CommonBridge::ResetOnDragStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
7314 {
7315 EcmaVM* vm = runtimeCallInfo->GetVM();
7316 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7317 auto* frameNode = GetFrameNode(runtimeCallInfo);
7318 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7319 ViewAbstract::DisableOnDragStart(frameNode);
7320 return panda::JSValueRef::Undefined(vm);
7321 }
7322
SetOnDragEnter(ArkUIRuntimeCallInfo * runtimeCallInfo)7323 ArkUINativeModuleValue CommonBridge::SetOnDragEnter(ArkUIRuntimeCallInfo* runtimeCallInfo)
7324 {
7325 EcmaVM* vm = runtimeCallInfo->GetVM();
7326 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7327 auto* frameNode = GetFrameNode(runtimeCallInfo);
7328 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7329 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
7330 static std::vector<JSCallbackInfoType> checkList { JSCallbackInfoType::FUNCTION };
7331 auto jsVal = info[1];
7332 if (!JSViewAbstract::CheckJSCallbackInfo("OnDragEnter", jsVal, checkList)) {
7333 return panda::JSValueRef::Undefined(vm);
7334 }
7335 RefPtr<JsDragFunction> jsOnDragEnterFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(jsVal));
7336 auto onDragEnter = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragEnterFunc),
7337 node = AceType::WeakClaim<NG::FrameNode>(frameNode)](
7338 const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams) {
7339 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
7340 ACE_SCORING_EVENT("onDragEnter");
7341 PipelineContext::SetCallBackNode(node);
7342 func->Execute(info, extraParams);
7343 };
7344 NG::ViewAbstract::SetOnDragEnter(frameNode, std::move(onDragEnter));
7345 return panda::JSValueRef::Undefined(vm);
7346 }
7347
ResetOnDragEnter(ArkUIRuntimeCallInfo * runtimeCallInfo)7348 ArkUINativeModuleValue CommonBridge::ResetOnDragEnter(ArkUIRuntimeCallInfo* runtimeCallInfo)
7349 {
7350 EcmaVM* vm = runtimeCallInfo->GetVM();
7351 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7352 auto* frameNode = GetFrameNode(runtimeCallInfo);
7353 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7354 ViewAbstract::DisableOnDragEnter(frameNode);
7355 return panda::JSValueRef::Undefined(vm);
7356 }
7357
SetOnDragMove(ArkUIRuntimeCallInfo * runtimeCallInfo)7358 ArkUINativeModuleValue CommonBridge::SetOnDragMove(ArkUIRuntimeCallInfo* runtimeCallInfo)
7359 {
7360 EcmaVM* vm = runtimeCallInfo->GetVM();
7361 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7362 auto* frameNode = GetFrameNode(runtimeCallInfo);
7363 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7364 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
7365 static std::vector<JSCallbackInfoType> checkList { JSCallbackInfoType::FUNCTION };
7366 auto jsVal = info[1];
7367 if (!JSViewAbstract::CheckJSCallbackInfo("OnDragMove", jsVal, checkList)) {
7368 return panda::JSValueRef::Undefined(vm);
7369 }
7370 RefPtr<JsDragFunction> jsOnDragMoveFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(jsVal));
7371 auto onDragMove = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragMoveFunc),
7372 node = AceType::WeakClaim<NG::FrameNode>(frameNode)](
7373 const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams) {
7374 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
7375 ACE_SCORING_EVENT("onDragMove");
7376 PipelineContext::SetCallBackNode(node);
7377 func->Execute(info, extraParams);
7378 };
7379 NG::ViewAbstract::SetOnDragMove(frameNode, std::move(onDragMove));
7380 return panda::JSValueRef::Undefined(vm);
7381 }
7382
ResetOnDragMove(ArkUIRuntimeCallInfo * runtimeCallInfo)7383 ArkUINativeModuleValue CommonBridge::ResetOnDragMove(ArkUIRuntimeCallInfo* runtimeCallInfo)
7384 {
7385 EcmaVM* vm = runtimeCallInfo->GetVM();
7386 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7387 auto* frameNode = GetFrameNode(runtimeCallInfo);
7388 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7389 ViewAbstract::DisableOnDragMove(frameNode);
7390 return panda::JSValueRef::Undefined(vm);
7391 }
7392
SetOnDragLeave(ArkUIRuntimeCallInfo * runtimeCallInfo)7393 ArkUINativeModuleValue CommonBridge::SetOnDragLeave(ArkUIRuntimeCallInfo* runtimeCallInfo)
7394 {
7395 EcmaVM* vm = runtimeCallInfo->GetVM();
7396 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7397 auto* frameNode = GetFrameNode(runtimeCallInfo);
7398 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7399 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
7400 static std::vector<JSCallbackInfoType> checkList { JSCallbackInfoType::FUNCTION };
7401 auto jsVal = info[1];
7402 if (!JSViewAbstract::CheckJSCallbackInfo("OnDragLeave", jsVal, checkList)) {
7403 return panda::JSValueRef::Undefined(vm);
7404 }
7405 RefPtr<JsDragFunction> jsOnDragLeaveFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(jsVal));
7406 auto onDragLeave = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragLeaveFunc),
7407 node = AceType::WeakClaim<NG::FrameNode>(frameNode)](
7408 const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams) {
7409 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
7410 ACE_SCORING_EVENT("onDragLeave");
7411 PipelineContext::SetCallBackNode(node);
7412 func->Execute(info, extraParams);
7413 };
7414 NG::ViewAbstract::SetOnDragLeave(frameNode, std::move(onDragLeave));
7415 return panda::JSValueRef::Undefined(vm);
7416 }
7417
ResetOnDragLeave(ArkUIRuntimeCallInfo * runtimeCallInfo)7418 ArkUINativeModuleValue CommonBridge::ResetOnDragLeave(ArkUIRuntimeCallInfo* runtimeCallInfo)
7419 {
7420 EcmaVM* vm = runtimeCallInfo->GetVM();
7421 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7422 auto* frameNode = GetFrameNode(runtimeCallInfo);
7423 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7424 ViewAbstract::DisableOnDragLeave(frameNode);
7425 return panda::JSValueRef::Undefined(vm);
7426 }
7427
SetOnDrop(ArkUIRuntimeCallInfo * runtimeCallInfo)7428 ArkUINativeModuleValue CommonBridge::SetOnDrop(ArkUIRuntimeCallInfo* runtimeCallInfo)
7429 {
7430 EcmaVM* vm = runtimeCallInfo->GetVM();
7431 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7432 auto* frameNode = GetFrameNode(runtimeCallInfo);
7433 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7434 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
7435 static std::vector<JSCallbackInfoType> checkList { JSCallbackInfoType::FUNCTION };
7436 auto jsVal = info[1];
7437 if (!JSViewAbstract::CheckJSCallbackInfo("OnDrop", jsVal, checkList)) {
7438 return panda::JSValueRef::Undefined(vm);
7439 }
7440 RefPtr<JsDragFunction> jsOnDropFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(jsVal));
7441 auto onDrop = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDropFunc),
7442 node = AceType::WeakClaim<NG::FrameNode>(frameNode)](
7443 const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams) {
7444 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
7445 ACE_SCORING_EVENT("onDrop");
7446 PipelineContext::SetCallBackNode(node);
7447 func->Execute(info, extraParams);
7448 };
7449 NG::ViewAbstract::SetOnDrop(frameNode, std::move(onDrop));
7450 return panda::JSValueRef::Undefined(vm);
7451 }
7452
ResetOnDrop(ArkUIRuntimeCallInfo * runtimeCallInfo)7453 ArkUINativeModuleValue CommonBridge::ResetOnDrop(ArkUIRuntimeCallInfo* runtimeCallInfo)
7454 {
7455 EcmaVM* vm = runtimeCallInfo->GetVM();
7456 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7457 auto* frameNode = GetFrameNode(runtimeCallInfo);
7458 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7459 ViewAbstract::DisableOnDrop(frameNode);
7460 return panda::JSValueRef::Undefined(vm);
7461 }
7462
SetOnDragEnd(ArkUIRuntimeCallInfo * runtimeCallInfo)7463 ArkUINativeModuleValue CommonBridge::SetOnDragEnd(ArkUIRuntimeCallInfo* runtimeCallInfo)
7464 {
7465 EcmaVM* vm = runtimeCallInfo->GetVM();
7466 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7467 auto* frameNode = GetFrameNode(runtimeCallInfo);
7468 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7469 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
7470 static std::vector<JSCallbackInfoType> checkList { JSCallbackInfoType::FUNCTION };
7471 auto jsVal = info[1];
7472 if (!JSViewAbstract::CheckJSCallbackInfo("OnDragEnd", jsVal, checkList)) {
7473 return panda::JSValueRef::Undefined(vm);
7474 }
7475 RefPtr<JsDragFunction> jsOnDragEndFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(jsVal));
7476 auto onDragEnd = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragEndFunc),
7477 node = AceType::WeakClaim<NG::FrameNode>(frameNode)](
7478 const RefPtr<OHOS::Ace::DragEvent>& info) {
7479 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
7480 ACE_SCORING_EVENT("onDragEnd");
7481 auto extraParams = JsonUtil::Create(true);
7482 PipelineContext::SetCallBackNode(node);
7483 func->Execute(info, extraParams->ToString());
7484 };
7485 NG::ViewAbstract::SetOnDragEnd(frameNode, std::move(onDragEnd));
7486 return panda::JSValueRef::Undefined(vm);
7487 }
7488
ResetOnDragEnd(ArkUIRuntimeCallInfo * runtimeCallInfo)7489 ArkUINativeModuleValue CommonBridge::ResetOnDragEnd(ArkUIRuntimeCallInfo* runtimeCallInfo)
7490 {
7491 EcmaVM* vm = runtimeCallInfo->GetVM();
7492 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7493 auto* frameNode = GetFrameNode(runtimeCallInfo);
7494 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7495 ViewAbstract::DisableOnDragEnd(frameNode);
7496 return panda::JSValueRef::Undefined(vm);
7497 }
7498
SetOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)7499 ArkUINativeModuleValue CommonBridge::SetOnTouch(ArkUIRuntimeCallInfo* runtimeCallInfo)
7500 {
7501 EcmaVM* vm = runtimeCallInfo->GetVM();
7502 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7503 auto* frameNode = GetFrameNode(runtimeCallInfo);
7504 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7505 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7506 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7507 auto obj = secondeArg->ToObject(vm);
7508 auto containerId = Container::CurrentId();
7509 panda::Local<panda::FunctionRef> func = obj;
7510 auto onTouch = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
7511 TouchEventInfo& info) {
7512 panda::LocalScope pandaScope(vm);
7513 panda::TryCatch trycatch(vm);
7514 ContainerScope scope(containerId);
7515 PipelineContext::SetCallBackNode(node);
7516 auto eventObj = FrameNodeBridge::CreateTouchEventInfo(vm, info);
7517 panda::Local<panda::JSValueRef> params[1] = { eventObj };
7518 func->Call(vm, func.ToLocal(), params, 1);
7519 };
7520 NG::ViewAbstract::SetOnTouch(frameNode, std::move(onTouch));
7521 return panda::JSValueRef::Undefined(vm);
7522 }
7523
ResetOnTouch(ArkUIRuntimeCallInfo * runtimeCallInfo)7524 ArkUINativeModuleValue CommonBridge::ResetOnTouch(ArkUIRuntimeCallInfo* runtimeCallInfo)
7525 {
7526 EcmaVM* vm = runtimeCallInfo->GetVM();
7527 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7528 auto* frameNode = GetFrameNode(runtimeCallInfo);
7529 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7530 ViewAbstract::DisableOnTouch(frameNode);
7531 return panda::JSValueRef::Undefined(vm);
7532 }
7533
SetChainMode(ArkUIRuntimeCallInfo * runtimeCallInfo)7534 ArkUINativeModuleValue CommonBridge::SetChainMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
7535 {
7536 EcmaVM* vm = runtimeCallInfo->GetVM();
7537 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7538 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
7539 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7540 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
7541 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
7542 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
7543 int32_t direction = 0;
7544 int32_t style = 0;
7545 if (!secondArg.IsNull() && !secondArg->IsUndefined()) {
7546 direction = static_cast<int32_t>(secondArg->ToNumber(vm)->Value());
7547 }
7548 if (!thirdArg.IsNull() && !thirdArg->IsUndefined()) {
7549 style = static_cast<int32_t>(thirdArg->ToNumber(vm)->Value());
7550 }
7551 GetArkUINodeModifiers()->getCommonModifier()->setChainStyle(nativeNode, direction, style);
7552 return panda::JSValueRef::Undefined(vm);
7553 }
7554
ResetChainMode(ArkUIRuntimeCallInfo * runtimeCallInfo)7555 ArkUINativeModuleValue CommonBridge::ResetChainMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
7556 {
7557 EcmaVM* vm = runtimeCallInfo->GetVM();
7558 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7559 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
7560 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
7561 GetArkUINodeModifiers()->getCommonModifier()->resetChainStyle(nativeNode);
7562 return panda::JSValueRef::Undefined(vm);
7563 }
SetOnAppear(ArkUIRuntimeCallInfo * runtimeCallInfo)7564 ArkUINativeModuleValue CommonBridge::SetOnAppear(ArkUIRuntimeCallInfo* runtimeCallInfo)
7565 {
7566 EcmaVM* vm = runtimeCallInfo->GetVM();
7567 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7568 auto* frameNode = GetFrameNode(runtimeCallInfo);
7569 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7570 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7571 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7572 auto obj = secondeArg->ToObject(vm);
7573 auto containerId = Container::CurrentId();
7574 panda::Local<panda::FunctionRef> func = obj;
7575 auto onAppear = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
7576 panda::LocalScope pandaScope(vm);
7577 panda::TryCatch trycatch(vm);
7578 ContainerScope scope(containerId);
7579 PipelineContext::SetCallBackNode(node);
7580 func->Call(vm, func.ToLocal(), nullptr, 0);
7581 };
7582 NG::ViewAbstract::SetOnAppear(frameNode, std::move(onAppear));
7583 return panda::JSValueRef::Undefined(vm);
7584 }
7585
ResetOnAppear(ArkUIRuntimeCallInfo * runtimeCallInfo)7586 ArkUINativeModuleValue CommonBridge::ResetOnAppear(ArkUIRuntimeCallInfo* runtimeCallInfo)
7587 {
7588 EcmaVM* vm = runtimeCallInfo->GetVM();
7589 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7590 auto* frameNode = GetFrameNode(runtimeCallInfo);
7591 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7592 ViewAbstract::DisableOnAppear(frameNode);
7593 return panda::JSValueRef::Undefined(vm);
7594 }
7595
SetOnDisappear(ArkUIRuntimeCallInfo * runtimeCallInfo)7596 ArkUINativeModuleValue CommonBridge::SetOnDisappear(ArkUIRuntimeCallInfo* runtimeCallInfo)
7597 {
7598 EcmaVM* vm = runtimeCallInfo->GetVM();
7599 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7600 auto* frameNode = GetFrameNode(runtimeCallInfo);
7601 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7602 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7603 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7604 auto obj = secondeArg->ToObject(vm);
7605 auto containerId = Container::CurrentId();
7606 panda::Local<panda::FunctionRef> func = obj;
7607 auto onDisappear = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
7608 containerId]() {
7609 panda::LocalScope pandaScope(vm);
7610 panda::TryCatch trycatch(vm);
7611 ContainerScope scope(containerId);
7612 PipelineContext::SetCallBackNode(node);
7613 func->Call(vm, func.ToLocal(), nullptr, 0);
7614 };
7615 NG::ViewAbstract::SetOnDisappear(frameNode, std::move(onDisappear));
7616 return panda::JSValueRef::Undefined(vm);
7617 }
7618
ResetOnDisappear(ArkUIRuntimeCallInfo * runtimeCallInfo)7619 ArkUINativeModuleValue CommonBridge::ResetOnDisappear(ArkUIRuntimeCallInfo* runtimeCallInfo)
7620 {
7621 EcmaVM* vm = runtimeCallInfo->GetVM();
7622 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7623 auto* frameNode = GetFrameNode(runtimeCallInfo);
7624 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7625 ViewAbstract::DisableOnDisappear(frameNode);
7626 return panda::JSValueRef::Undefined(vm);
7627 }
7628
SetOnAttach(ArkUIRuntimeCallInfo * runtimeCallInfo)7629 ArkUINativeModuleValue CommonBridge::SetOnAttach(ArkUIRuntimeCallInfo* runtimeCallInfo)
7630 {
7631 EcmaVM* vm = runtimeCallInfo->GetVM();
7632 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7633 auto* frameNode = GetFrameNode(runtimeCallInfo);
7634 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7635 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7636 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7637 auto obj = secondeArg->ToObject(vm);
7638 auto containerId = Container::CurrentId();
7639 panda::Local<panda::FunctionRef> func = obj;
7640 auto onAttach = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
7641 panda::LocalScope pandaScope(vm);
7642 panda::TryCatch trycatch(vm);
7643 ContainerScope scope(containerId);
7644 PipelineContext::SetCallBackNode(node);
7645 func->Call(vm, func.ToLocal(), nullptr, 0);
7646 };
7647 NG::ViewAbstract::SetOnAttach(frameNode, std::move(onAttach));
7648 return panda::JSValueRef::Undefined(vm);
7649 }
7650
ResetOnAttach(ArkUIRuntimeCallInfo * runtimeCallInfo)7651 ArkUINativeModuleValue CommonBridge::ResetOnAttach(ArkUIRuntimeCallInfo* runtimeCallInfo)
7652 {
7653 EcmaVM* vm = runtimeCallInfo->GetVM();
7654 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7655 auto* frameNode = GetFrameNode(runtimeCallInfo);
7656 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7657 ViewAbstract::DisableOnAttach(frameNode);
7658 return panda::JSValueRef::Undefined(vm);
7659 }
7660
SetOnDetach(ArkUIRuntimeCallInfo * runtimeCallInfo)7661 ArkUINativeModuleValue CommonBridge::SetOnDetach(ArkUIRuntimeCallInfo* runtimeCallInfo)
7662 {
7663 EcmaVM* vm = runtimeCallInfo->GetVM();
7664 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7665 auto* frameNode = GetFrameNode(runtimeCallInfo);
7666 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7667 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7668 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7669 auto obj = secondeArg->ToObject(vm);
7670 auto containerId = Container::CurrentId();
7671 panda::Local<panda::FunctionRef> func = obj;
7672 auto onDetach = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
7673 containerId]() {
7674 panda::LocalScope pandaScope(vm);
7675 panda::TryCatch trycatch(vm);
7676 ContainerScope scope(containerId);
7677 PipelineContext::SetCallBackNode(node);
7678 func->Call(vm, func.ToLocal(), nullptr, 0);
7679 };
7680 NG::ViewAbstract::SetOnDetach(frameNode, std::move(onDetach));
7681 return panda::JSValueRef::Undefined(vm);
7682 }
7683
ResetOnDetach(ArkUIRuntimeCallInfo * runtimeCallInfo)7684 ArkUINativeModuleValue CommonBridge::ResetOnDetach(ArkUIRuntimeCallInfo* runtimeCallInfo)
7685 {
7686 EcmaVM* vm = runtimeCallInfo->GetVM();
7687 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7688 auto* frameNode = GetFrameNode(runtimeCallInfo);
7689 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7690 ViewAbstract::DisableOnDetach(frameNode);
7691 return panda::JSValueRef::Undefined(vm);
7692 }
7693
SetOnKeyEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)7694 ArkUINativeModuleValue CommonBridge::SetOnKeyEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
7695 {
7696 EcmaVM* vm = runtimeCallInfo->GetVM();
7697 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7698 auto* frameNode = GetFrameNode(runtimeCallInfo);
7699 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7700 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7701 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7702 auto obj = secondeArg->ToObject(vm);
7703 auto containerId = Container::CurrentId();
7704 panda::Local<panda::FunctionRef> func = obj;
7705 auto onKeyEvent = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
7706 KeyEventInfo& info) -> bool {
7707 panda::LocalScope pandaScope(vm);
7708 panda::TryCatch trycatch(vm);
7709 ContainerScope scope(containerId);
7710 PipelineContext::SetCallBackNode(node);
7711 const char* keys[] = { "type", "keyCode", "keyText", "keySource", "deviceId", "metaKey", "unicode",
7712 "timestamp", "stopPropagation", "getModifierKeyState", "intentionCode" };
7713 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyType())),
7714 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyCode())),
7715 panda::StringRef::NewFromUtf8(vm, info.GetKeyText()),
7716 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeySource())),
7717 panda::NumberRef::New(vm, info.GetDeviceId()), panda::NumberRef::New(vm, info.GetMetaKey()),
7718 panda::NumberRef::New(vm, info.GetUnicode()),
7719 panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
7720 panda::FunctionRef::New(vm, Framework::JsStopPropagation),
7721 panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
7722 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyIntention())) };
7723 auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
7724 obj->SetNativePointerFieldCount(vm, 1);
7725 obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
7726 panda::Local<panda::JSValueRef> params[] = { obj };
7727 auto ret = func->Call(vm, func.ToLocal(), params, 1);
7728 if (ret->IsBoolean()) {
7729 return ret->ToBoolean(vm)->Value();
7730 }
7731 return false;
7732 };
7733 NG::ViewAbstract::SetOnKeyEvent(frameNode, std::move(onKeyEvent));
7734 return panda::JSValueRef::Undefined(vm);
7735 }
7736
ResetOnKeyEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)7737 ArkUINativeModuleValue CommonBridge::ResetOnKeyEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
7738 {
7739 EcmaVM* vm = runtimeCallInfo->GetVM();
7740 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7741 auto* frameNode = GetFrameNode(runtimeCallInfo);
7742 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7743 ViewAbstract::DisableOnKeyEvent(frameNode);
7744 return panda::JSValueRef::Undefined(vm);
7745 }
7746
SetOnKeyPreIme(ArkUIRuntimeCallInfo * runtimeCallInfo)7747 ArkUINativeModuleValue CommonBridge::SetOnKeyPreIme(ArkUIRuntimeCallInfo* runtimeCallInfo)
7748 {
7749 EcmaVM* vm = runtimeCallInfo->GetVM();
7750 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7751 auto* frameNode = GetFrameNode(runtimeCallInfo);
7752 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7753 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7754 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7755 auto obj = secondeArg->ToObject(vm);
7756 auto containerId = Container::CurrentId();
7757 panda::Local<panda::FunctionRef> func = obj;
7758 auto onPreImeEvent = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
7759 containerId](KeyEventInfo& info) -> bool {
7760 panda::LocalScope pandaScope(vm);
7761 panda::TryCatch trycatch(vm);
7762 ContainerScope scope(containerId);
7763 PipelineContext::SetCallBackNode(node);
7764 const char* keys[] = { "type", "keyCode", "keyText", "keySource", "deviceId", "metaKey", "timestamp",
7765 "stopPropagation", "getModifierKeyState", "intentionCode" };
7766 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyType())),
7767 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyCode())),
7768 panda::StringRef::NewFromUtf8(vm, info.GetKeyText()),
7769 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeySource())),
7770 panda::NumberRef::New(vm, info.GetDeviceId()), panda::NumberRef::New(vm, info.GetMetaKey()),
7771 panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
7772 panda::FunctionRef::New(vm, Framework::JsStopPropagation),
7773 panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
7774 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyIntention())) };
7775 auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
7776 obj->SetNativePointerFieldCount(vm, 1);
7777 obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
7778 panda::Local<panda::JSValueRef> params[] = { obj };
7779 auto ret = func->Call(vm, func.ToLocal(), params, 1);
7780 if (ret->IsBoolean()) {
7781 return ret->ToBoolean(vm)->Value();
7782 }
7783 return false;
7784 };
7785 NG::ViewAbstractModelNG::SetOnKeyPreIme(frameNode, std::move(onPreImeEvent));
7786 return panda::JSValueRef::Undefined(vm);
7787 }
7788
ResetOnKeyPreIme(ArkUIRuntimeCallInfo * runtimeCallInfo)7789 ArkUINativeModuleValue CommonBridge::ResetOnKeyPreIme(ArkUIRuntimeCallInfo* runtimeCallInfo)
7790 {
7791 EcmaVM* vm = runtimeCallInfo->GetVM();
7792 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7793 auto* frameNode = GetFrameNode(runtimeCallInfo);
7794 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7795 NG::ViewAbstractModelNG::DisableOnKeyPreIme(frameNode);
7796 return panda::JSValueRef::Undefined(vm);
7797 }
7798
SetOnKeyEventDispatch(ArkUIRuntimeCallInfo * runtimeCallInfo)7799 ArkUINativeModuleValue CommonBridge::SetOnKeyEventDispatch(ArkUIRuntimeCallInfo* runtimeCallInfo)
7800 {
7801 EcmaVM* vm = runtimeCallInfo->GetVM();
7802 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7803 auto* frameNode = GetFrameNode(runtimeCallInfo);
7804 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7805 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7806 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7807 auto obj = secondeArg->ToObject(vm);
7808 auto containerId = Container::CurrentId();
7809 panda::Local<panda::FunctionRef> func = obj;
7810 auto onKeyEventDispatch = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
7811 containerId](KeyEventInfo& info) -> bool {
7812 panda::LocalScope pandaScope(vm);
7813 panda::TryCatch trycatch(vm);
7814 ContainerScope scope(containerId);
7815 PipelineContext::SetCallBackNode(node);
7816 const char* keys[] = { "type", "keyCode", "keyText", "keySource", "deviceId", "metaKey", "unicode",
7817 "timestamp", "stopPropagation", "getModifierKeyState", "intentionCode" };
7818 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyType())),
7819 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyCode())),
7820 panda::StringRef::NewFromUtf8(vm, info.GetKeyText()),
7821 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeySource())),
7822 panda::NumberRef::New(vm, info.GetDeviceId()), panda::NumberRef::New(vm, info.GetMetaKey()),
7823 panda::NumberRef::New(vm, info.GetUnicode()),
7824 panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
7825 panda::FunctionRef::New(vm, Framework::JsStopPropagation),
7826 panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
7827 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetKeyIntention())) };
7828 auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
7829 obj->SetNativePointerFieldCount(vm, 1);
7830 obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
7831 panda::Local<panda::JSValueRef> params[] = { obj };
7832 auto ret = func->Call(vm, func.ToLocal(), params, 1);
7833 if (ret->IsBoolean()) {
7834 return ret->ToBoolean(vm)->Value();
7835 }
7836 return false;
7837 };
7838 NG::ViewAbstract::SetOnKeyEventDispatch(frameNode, std::move(onKeyEventDispatch));
7839 return panda::JSValueRef::Undefined(vm);
7840 }
7841
ResetOnKeyEventDispatch(ArkUIRuntimeCallInfo * runtimeCallInfo)7842 ArkUINativeModuleValue CommonBridge::ResetOnKeyEventDispatch(ArkUIRuntimeCallInfo* runtimeCallInfo)
7843 {
7844 EcmaVM* vm = runtimeCallInfo->GetVM();
7845 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7846 auto* frameNode = GetFrameNode(runtimeCallInfo);
7847 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7848 NG::ViewAbstract::DisableOnKeyEventDispatch(frameNode);
7849 return panda::JSValueRef::Undefined(vm);
7850 }
7851
SetOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)7852 ArkUINativeModuleValue CommonBridge::SetOnFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
7853 {
7854 EcmaVM* vm = runtimeCallInfo->GetVM();
7855 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7856 auto* frameNode = GetFrameNode(runtimeCallInfo);
7857 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7858 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7859 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7860 auto obj = secondeArg->ToObject(vm);
7861 auto containerId = Container::CurrentId();
7862 panda::Local<panda::FunctionRef> func = obj;
7863 auto onFocus = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
7864 panda::LocalScope pandaScope(vm);
7865 panda::TryCatch trycatch(vm);
7866 ContainerScope scope(containerId);
7867 PipelineContext::SetCallBackNode(node);
7868 func->Call(vm, func.ToLocal(), nullptr, 0);
7869 };
7870 NG::ViewAbstract::SetOnFocus(frameNode, std::move(onFocus));
7871 return panda::JSValueRef::Undefined(vm);
7872 }
7873
ResetOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)7874 ArkUINativeModuleValue CommonBridge::ResetOnFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
7875 {
7876 EcmaVM* vm = runtimeCallInfo->GetVM();
7877 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7878 auto* frameNode = GetFrameNode(runtimeCallInfo);
7879 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7880 ViewAbstract::DisableOnFocus(frameNode);
7881 return panda::JSValueRef::Undefined(vm);
7882 }
7883
SetOnBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)7884 ArkUINativeModuleValue CommonBridge::SetOnBlur(ArkUIRuntimeCallInfo* runtimeCallInfo)
7885 {
7886 EcmaVM* vm = runtimeCallInfo->GetVM();
7887 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7888 auto* frameNode = GetFrameNode(runtimeCallInfo);
7889 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7890 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7891 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7892 auto obj = secondeArg->ToObject(vm);
7893 auto containerId = Container::CurrentId();
7894 panda::Local<panda::FunctionRef> func = obj;
7895 auto onBlur = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId]() {
7896 panda::LocalScope pandaScope(vm);
7897 panda::TryCatch trycatch(vm);
7898 ContainerScope scope(containerId);
7899 PipelineContext::SetCallBackNode(node);
7900 func->Call(vm, func.ToLocal(), nullptr, 0);
7901 };
7902 NG::ViewAbstract::SetOnBlur(frameNode, std::move(onBlur));
7903 return panda::JSValueRef::Undefined(vm);
7904 }
7905
ResetOnBlur(ArkUIRuntimeCallInfo * runtimeCallInfo)7906 ArkUINativeModuleValue CommonBridge::ResetOnBlur(ArkUIRuntimeCallInfo* runtimeCallInfo)
7907 {
7908 EcmaVM* vm = runtimeCallInfo->GetVM();
7909 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7910 auto* frameNode = GetFrameNode(runtimeCallInfo);
7911 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7912 ViewAbstract::DisableOnBlur(frameNode);
7913 return panda::JSValueRef::Undefined(vm);
7914 }
7915
CreateHoverInfo(EcmaVM * vm,const HoverInfo & hoverInfo)7916 Local<panda::ObjectRef> CommonBridge::CreateHoverInfo(EcmaVM* vm, const HoverInfo& hoverInfo)
7917 {
7918 const char* keys[] = {
7919 "stopPropagation",
7920 "getModifierKeyState",
7921 "timestamp",
7922 "source",
7923 "target",
7924 "deviceId",
7925 "targetDisplayId",
7926 "displayX",
7927 "displayY",
7928 "windowX",
7929 "windowY",
7930 "x",
7931 "y"
7932 };
7933 double density = PipelineBase::GetCurrentDensity();
7934 const Offset& globalOffset = hoverInfo.GetGlobalLocation();
7935 const Offset& localOffset = hoverInfo.GetLocalLocation();
7936 const Offset& screenOffset = hoverInfo.GetScreenLocation();
7937 Local<JSValueRef> values[] = { panda::FunctionRef::New(vm, Framework::JsStopPropagation),
7938 panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
7939 panda::NumberRef::New(vm, static_cast<double>(hoverInfo.GetTimeStamp().time_since_epoch().count())),
7940 panda::NumberRef::New(vm, static_cast<int32_t>(hoverInfo.GetSourceDevice())),
7941 FrameNodeBridge::CreateEventTargetObject(vm, hoverInfo),
7942 panda::NumberRef::New(vm, hoverInfo.GetDeviceId()),
7943 panda::NumberRef::New(vm, hoverInfo.GetTargetDisplayId()),
7944 panda::NumberRef::New(vm, density != 0 ? screenOffset.GetX() / density : 0),
7945 panda::NumberRef::New(vm, density != 0 ? screenOffset.GetY() / density : 0),
7946 panda::NumberRef::New(vm, density != 0 ? globalOffset.GetX() / density : 0),
7947 panda::NumberRef::New(vm, density != 0 ? globalOffset.GetY() / density : 0),
7948 panda::NumberRef::New(vm, density != 0 ? localOffset.GetX() / density : 0),
7949 panda::NumberRef::New(vm, density != 0 ? localOffset.GetY() / density : 0) };
7950 return panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
7951 }
7952
SetOnHover(ArkUIRuntimeCallInfo * runtimeCallInfo)7953 ArkUINativeModuleValue CommonBridge::SetOnHover(ArkUIRuntimeCallInfo* runtimeCallInfo)
7954 {
7955 EcmaVM* vm = runtimeCallInfo->GetVM();
7956 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
7957 auto* frameNode = GetFrameNode(runtimeCallInfo);
7958 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7959 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
7960 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
7961 auto obj = secondeArg->ToObject(vm);
7962 auto containerId = Container::CurrentId();
7963 panda::Local<panda::FunctionRef> func = obj;
7964 auto onHover = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
7965 bool isHover, HoverInfo& hoverInfo) {
7966 panda::LocalScope pandaScope(vm);
7967 panda::TryCatch trycatch(vm);
7968 ContainerScope scope(containerId);
7969 PipelineContext::SetCallBackNode(node);
7970 auto isHoverParam = panda::BooleanRef::New(vm, isHover);
7971 auto obj = CreateHoverInfo(vm, hoverInfo);
7972 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltX"),
7973 panda::NumberRef::New(vm, static_cast<int32_t>(hoverInfo.GetTiltX().value_or(0.0f))));
7974 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "tiltY"),
7975 panda::NumberRef::New(vm, static_cast<int32_t>(hoverInfo.GetTiltY().value_or(0.0f))));
7976 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "rollAngle"),
7977 panda::NumberRef::New(vm, static_cast<int32_t>(hoverInfo.GetRollAngle().value_or(0.0f))));
7978 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "axisVertical"), panda::NumberRef::New(vm, 0.0f));
7979 obj->Set(
7980 vm, panda::StringRef::NewFromUtf8(vm, "axisHorizontal"), panda::NumberRef::New(vm, 0.0f));
7981 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "pressure"), panda::NumberRef::New(vm, 0.0f));
7982 obj->SetNativePointerFieldCount(vm, 1);
7983 obj->SetNativePointerField(vm, 0, static_cast<void*>(&hoverInfo));
7984 panda::Local<panda::JSValueRef> params[] = { isHoverParam, obj };
7985 func->Call(vm, func.ToLocal(), params, ArraySize(params));
7986 };
7987 NG::ViewAbstract::SetOnHover(frameNode, std::move(onHover));
7988 return panda::JSValueRef::Undefined(vm);
7989 }
7990
ResetOnHover(ArkUIRuntimeCallInfo * runtimeCallInfo)7991 ArkUINativeModuleValue CommonBridge::ResetOnHover(ArkUIRuntimeCallInfo* runtimeCallInfo)
7992 {
7993 EcmaVM* vm = runtimeCallInfo->GetVM();
7994 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
7995 auto* frameNode = GetFrameNode(runtimeCallInfo);
7996 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
7997 ViewAbstract::DisableOnHover(frameNode);
7998 return panda::JSValueRef::Undefined(vm);
7999 }
8000
SetOnHoverMove(ArkUIRuntimeCallInfo * runtimeCallInfo)8001 ArkUINativeModuleValue CommonBridge::SetOnHoverMove(ArkUIRuntimeCallInfo* runtimeCallInfo)
8002 {
8003 EcmaVM* vm = runtimeCallInfo->GetVM();
8004 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8005 auto* frameNode = GetFrameNode(runtimeCallInfo);
8006 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8007 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
8008 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
8009 auto obj = secondeArg->ToObject(vm);
8010 auto containerId = Container::CurrentId();
8011 panda::Local<panda::FunctionRef> func = obj;
8012 auto onHoverMove = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
8013 HoverInfo& hoverInfo) {
8014 panda::LocalScope pandaScope(vm);
8015 panda::TryCatch trycatch(vm);
8016 ContainerScope scope(containerId);
8017 PipelineContext::SetCallBackNode(node);
8018 auto obj = CreateHoverInfo(vm, hoverInfo);
8019 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "rollAngle"),
8020 panda::NumberRef::New(vm, static_cast<int32_t>(hoverInfo.GetRollAngle().value_or(0.0f))));
8021 obj->SetNativePointerFieldCount(vm, 1);
8022 obj->SetNativePointerField(vm, 0, static_cast<void*>(&hoverInfo));
8023 panda::Local<panda::JSValueRef> params[] = { obj };
8024 func->Call(vm, func.ToLocal(), params, ArraySize(params));
8025 };
8026 NG::ViewAbstract::SetOnHoverMove(frameNode, std::move(onHoverMove));
8027 return panda::JSValueRef::Undefined(vm);
8028 }
8029
ResetOnHoverMove(ArkUIRuntimeCallInfo * runtimeCallInfo)8030 ArkUINativeModuleValue CommonBridge::ResetOnHoverMove(ArkUIRuntimeCallInfo* runtimeCallInfo)
8031 {
8032 EcmaVM* vm = runtimeCallInfo->GetVM();
8033 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8034 auto* frameNode = GetFrameNode(runtimeCallInfo);
8035 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8036 ViewAbstract::DisableOnHoverMove(frameNode);
8037 return panda::JSValueRef::Undefined(vm);
8038 }
8039
SetOnMouse(ArkUIRuntimeCallInfo * runtimeCallInfo)8040 ArkUINativeModuleValue CommonBridge::SetOnMouse(ArkUIRuntimeCallInfo* runtimeCallInfo)
8041 {
8042 EcmaVM* vm = runtimeCallInfo->GetVM();
8043 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8044 auto* frameNode = GetFrameNode(runtimeCallInfo);
8045 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8046 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
8047 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
8048 auto obj = secondeArg->ToObject(vm);
8049 auto containerId = Container::CurrentId();
8050 panda::Local<panda::FunctionRef> func = obj;
8051 auto onMouse = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
8052 MouseInfo& info) {
8053 panda::LocalScope pandaScope(vm);
8054 panda::TryCatch trycatch(vm);
8055 ContainerScope scope(containerId);
8056 PipelineContext::SetCallBackNode(node);
8057 auto obj = FrameNodeBridge::CreateMouseInfo(vm, info);
8058 panda::Local<panda::JSValueRef> params[1] = { obj };
8059 func->Call(vm, func.ToLocal(), params, 1);
8060 };
8061 NG::ViewAbstract::SetOnMouse(frameNode, std::move(onMouse));
8062 return panda::JSValueRef::Undefined(vm);
8063 }
8064
ResetOnMouse(ArkUIRuntimeCallInfo * runtimeCallInfo)8065 ArkUINativeModuleValue CommonBridge::ResetOnMouse(ArkUIRuntimeCallInfo* runtimeCallInfo)
8066 {
8067 EcmaVM* vm = runtimeCallInfo->GetVM();
8068 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8069 auto* frameNode = GetFrameNode(runtimeCallInfo);
8070 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8071 ViewAbstract::DisableOnMouse(frameNode);
8072 return panda::JSValueRef::Undefined(vm);
8073 }
8074
SetOnSizeChange(ArkUIRuntimeCallInfo * runtimeCallInfo)8075 ArkUINativeModuleValue CommonBridge::SetOnSizeChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
8076 {
8077 EcmaVM* vm = runtimeCallInfo->GetVM();
8078 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8079 auto* frameNode = GetFrameNode(runtimeCallInfo);
8080 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8081 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
8082 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
8083 auto obj = secondeArg->ToObject(vm);
8084 auto containerId = Container::CurrentId();
8085 panda::Local<panda::FunctionRef> func = obj;
8086 auto onSizeChange = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
8087 const NG::RectF& oldRect, const NG::RectF& rect) {
8088 panda::LocalScope pandaScope(vm);
8089 panda::TryCatch trycatch(vm);
8090 ContainerScope scope(containerId);
8091 PipelineContext::SetCallBackNode(node);
8092 double density = PipelineBase::GetCurrentDensity();
8093 const char* keys[] = { "width", "height" };
8094 Local<JSValueRef> oldValues[] = { panda::NumberRef::New(vm, oldRect.Width() / density),
8095 panda::NumberRef::New(vm, oldRect.Height() / density) };
8096 auto oldSize = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, oldValues);
8097 Local<JSValueRef> newValues[] = { panda::NumberRef::New(vm, rect.Width() / density),
8098 panda::NumberRef::New(vm, rect.Height() / density) };
8099 auto newSize = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, newValues);
8100 panda::Local<panda::JSValueRef> params[2] = { oldSize, newSize };
8101 func->Call(vm, func.ToLocal(), params, 2);
8102 };
8103 NG::ViewAbstract::SetOnSizeChanged(frameNode, std::move(onSizeChange));
8104 return panda::JSValueRef::Undefined(vm);
8105 }
8106
ResetOnSizeChange(ArkUIRuntimeCallInfo * runtimeCallInfo)8107 ArkUINativeModuleValue CommonBridge::ResetOnSizeChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
8108 {
8109 EcmaVM* vm = runtimeCallInfo->GetVM();
8110 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8111 auto* frameNode = GetFrameNode(runtimeCallInfo);
8112 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8113 ViewAbstract::SetOnSizeChanged(frameNode, nullptr);
8114 return panda::JSValueRef::Undefined(vm);
8115 }
8116
SetOnAreaChange(ArkUIRuntimeCallInfo * runtimeCallInfo)8117 ArkUINativeModuleValue CommonBridge::SetOnAreaChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
8118 {
8119 EcmaVM* vm = runtimeCallInfo->GetVM();
8120 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8121 auto* frameNode = GetFrameNode(runtimeCallInfo);
8122 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8123 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
8124 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
8125 auto obj = secondeArg->ToObject(vm);
8126 auto containerId = Container::CurrentId();
8127 panda::Local<panda::FunctionRef> func = obj;
8128 auto onAreaChange = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
8129 const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) {
8130 panda::LocalScope pandaScope(vm);
8131 panda::TryCatch trycatch(vm);
8132 ContainerScope scope(containerId);
8133 PipelineContext::SetCallBackNode(node);
8134 auto oldArea = CreateAreaObject(vm, oldRect, oldOrigin);
8135 auto area = CreateAreaObject(vm, rect, origin);
8136 panda::Local<panda::JSValueRef> params[2] = { oldArea, area };
8137 func->Call(vm, func.ToLocal(), params, 2);
8138 };
8139 NG::ViewAbstract::SetOnAreaChanged(frameNode, std::move(onAreaChange));
8140 return panda::JSValueRef::Undefined(vm);
8141 }
8142
ResetOnAreaChange(ArkUIRuntimeCallInfo * runtimeCallInfo)8143 ArkUINativeModuleValue CommonBridge::ResetOnAreaChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
8144 {
8145 EcmaVM* vm = runtimeCallInfo->GetVM();
8146 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8147 auto* frameNode = GetFrameNode(runtimeCallInfo);
8148 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8149 ViewAbstract::DisableOnAreaChange(frameNode);
8150 return panda::JSValueRef::Undefined(vm);
8151 }
8152
SetOnGestureJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)8153 ArkUINativeModuleValue CommonBridge::SetOnGestureJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
8154 {
8155 EcmaVM* vm = runtimeCallInfo->GetVM();
8156 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8157 auto* frameNode = GetFrameNode(runtimeCallInfo);
8158 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8159 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
8160 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
8161 auto obj = secondeArg->ToObject(vm);
8162 auto containerId = Container::CurrentId();
8163 panda::Local<panda::FunctionRef> func = obj;
8164 auto onGestureJudgeBegin = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
8165 containerId](const RefPtr<GestureInfo>& gestureInfo,
8166 const std::shared_ptr<BaseGestureEvent>& info) -> GestureJudgeResult {
8167 panda::LocalScope pandaScope(vm);
8168 panda::TryCatch trycatch(vm);
8169 ContainerScope scope(containerId);
8170 PipelineContext::SetCallBackNode(node);
8171 auto gestureInfoObj = CreateGestureInfo(vm, gestureInfo);
8172 auto gestureEventObj = CreateGestureEventInfo(vm, gestureInfo->GetType(), info);
8173 panda::Local<panda::JSValueRef> params[2] = { gestureInfoObj, gestureEventObj };
8174 auto returnValue = GestureJudgeResult::CONTINUE;
8175 auto value = func->Call(vm, func.ToLocal(), params, 2);
8176 if (value->IsNumber()) {
8177 returnValue = static_cast<GestureJudgeResult>(value->ToNumber(vm)->Value());
8178 }
8179 return returnValue;
8180 };
8181 NG::ViewAbstract::SetOnGestureJudgeBegin(frameNode, std::move(onGestureJudgeBegin));
8182 return panda::JSValueRef::Undefined(vm);
8183 }
8184
ResetOnGestureJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)8185 ArkUINativeModuleValue CommonBridge::ResetOnGestureJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
8186 {
8187 EcmaVM* vm = runtimeCallInfo->GetVM();
8188 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8189 auto* frameNode = GetFrameNode(runtimeCallInfo);
8190 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8191 ViewAbstract::SetOnGestureJudgeBegin(frameNode, nullptr);
8192 return panda::JSValueRef::Undefined(vm);
8193 }
8194
SetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)8195 ArkUINativeModuleValue CommonBridge::SetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
8196 {
8197 EcmaVM* vm = runtimeCallInfo->GetVM();
8198 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8199 auto* frameNode = GetFrameNode(runtimeCallInfo);
8200 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8201 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
8202 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
8203 auto obj = secondeArg->ToObject(vm);
8204 auto containerId = Container::CurrentId();
8205 panda::Local<panda::FunctionRef> func = obj;
8206 auto onGestureRecognizerJudgeBegin =
8207 [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
8208 const std::shared_ptr<BaseGestureEvent>& info, const RefPtr<NGGestureRecognizer>& current,
8209 const std::list<RefPtr<NGGestureRecognizer>>& others) -> GestureJudgeResult {
8210 panda::LocalScope pandaScope(vm);
8211 panda::TryCatch trycatch(vm);
8212 ContainerScope scope(containerId);
8213 PipelineContext::SetCallBackNode(node);
8214 auto gestureInfo = current->GetGestureInfo();
8215 CHECK_NULL_RETURN(gestureInfo, GestureJudgeResult::CONTINUE);
8216 auto gestureEventObj = CreateGestureEventInfo(vm, gestureInfo->GetType(), info);
8217 auto currentObj = CreateRecognizerObject(vm, current);
8218 auto othersArr = panda::ArrayRef::New(vm);
8219 uint32_t othersIdx = 0;
8220 for (const auto& item : others) {
8221 auto othersObj = CreateRecognizerObject(vm, item);
8222 othersArr->SetValueAt(vm, othersArr, othersIdx++, othersObj);
8223 }
8224 panda::Local<panda::JSValueRef> params[3] = { gestureEventObj, currentObj, othersArr };
8225 auto returnValue = GestureJudgeResult::CONTINUE;
8226 auto value = func->Call(vm, func.ToLocal(), params, 3);
8227 if (value->IsNumber()) {
8228 returnValue = static_cast<GestureJudgeResult>(value->ToNumber(vm)->Value());
8229 }
8230 return returnValue;
8231 };
8232 NG::ViewAbstract::SetOnGestureRecognizerJudgeBegin(frameNode, std::move(onGestureRecognizerJudgeBegin));
8233 return panda::JSValueRef::Undefined(vm);
8234 }
8235
ResetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo * runtimeCallInfo)8236 ArkUINativeModuleValue CommonBridge::ResetOnGestureRecognizerJudgeBegin(ArkUIRuntimeCallInfo* runtimeCallInfo)
8237 {
8238 EcmaVM* vm = runtimeCallInfo->GetVM();
8239 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8240 auto* frameNode = GetFrameNode(runtimeCallInfo);
8241 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8242 ViewAbstract::SetOnGestureRecognizerJudgeBegin(frameNode, nullptr);
8243 return panda::JSValueRef::Undefined(vm);
8244 }
8245
SetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo * runtimeCallInfo)8246 ArkUINativeModuleValue CommonBridge::SetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo* runtimeCallInfo)
8247 {
8248 EcmaVM* vm = runtimeCallInfo->GetVM();
8249 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8250 auto* frameNode = GetFrameNode(runtimeCallInfo);
8251 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8252 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
8253 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
8254 auto obj = secondeArg->ToObject(vm);
8255 auto containerId = Container::CurrentId();
8256 panda::Local<panda::FunctionRef> func = obj;
8257 auto shouldBuiltInRecognizerParallelWithFunc =
8258 [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
8259 const RefPtr<NG::NGGestureRecognizer>& current,
8260 const std::vector<RefPtr<NG::NGGestureRecognizer>>& others) -> RefPtr<NG::NGGestureRecognizer> {
8261 panda::LocalScope pandaScope(vm);
8262 panda::TryCatch trycatch(vm);
8263 ContainerScope scope(containerId);
8264 PipelineContext::SetCallBackNode(node);
8265 auto currentObj = CreateRecognizerObject(vm, current);
8266 auto othersArr = panda::ArrayRef::New(vm);
8267 uint32_t othersIdx = 0;
8268 for (const auto& item : others) {
8269 auto othersObj = CreateRecognizerObject(vm, item);
8270 othersArr->SetValueAt(vm, othersArr, othersIdx++, othersObj);
8271 }
8272 panda::Local<panda::JSValueRef> params[2] = { currentObj, othersArr };
8273 auto value = func->Call(vm, func.ToLocal(), params, 2);
8274 if (!value->IsObject(vm)) {
8275 return nullptr;
8276 }
8277 RefPtr<NG::NGGestureRecognizer> returnValue = nullptr;
8278 auto valueObj = value->ToObject(vm);
8279 valueObj->Freeze(vm);
8280 auto jsObj = JSRef<JSObject>(JSObject(valueObj));
8281 returnValue = Referenced::Claim(jsObj->Unwrap<JSGestureRecognizer>())->GetRecognizer().Upgrade();
8282 return returnValue;
8283 };
8284 NG::ViewAbstract::SetShouldBuiltInRecognizerParallelWith(
8285 frameNode, std::move(shouldBuiltInRecognizerParallelWithFunc));
8286 return panda::JSValueRef::Undefined(vm);
8287 }
8288
ResetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo * runtimeCallInfo)8289 ArkUINativeModuleValue CommonBridge::ResetShouldBuiltInRecognizerParallelWith(ArkUIRuntimeCallInfo* runtimeCallInfo)
8290 {
8291 EcmaVM* vm = runtimeCallInfo->GetVM();
8292 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8293 auto* frameNode = GetFrameNode(runtimeCallInfo);
8294 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
8295 ViewAbstract::SetShouldBuiltInRecognizerParallelWith(frameNode, nullptr);
8296 return panda::JSValueRef::Undefined(vm);
8297 }
8298
AddTapGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)8299 ArkUINativeModuleValue CommonBridge::AddTapGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
8300 {
8301 EcmaVM* vm = runtimeCallInfo->GetVM();
8302 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8303 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8304 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8305 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8306 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8307 int32_t priority = 0;
8308 int32_t mask = 0;
8309 GetGestureCommonValue(runtimeCallInfo, priority, mask);
8310 int32_t fingers = DEFAULT_TAP_FINGER;
8311 int32_t count = DEFAULT_TAP_COUNT;
8312 double distanceThreshold = DEFAULT_TAP_DISTANCE;
8313 bool limitFingerCount = false;
8314 GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, limitFingerCount, NUM_5);
8315 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
8316 createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, limitFingerCount, nullptr);
8317 SetGestureTag(runtimeCallInfo, NUM_3, gesture);
8318 SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
8319 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_8, gesture);
8320 GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
8321 nativeNode, gesture, priority, mask);
8322 return panda::JSValueRef::Undefined(vm);
8323 }
8324
AddLongPressGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)8325 ArkUINativeModuleValue CommonBridge::AddLongPressGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
8326 {
8327 EcmaVM* vm = runtimeCallInfo->GetVM();
8328 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8329 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8330 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8331 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8332 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8333 int32_t priority = 0;
8334 int32_t mask = 0;
8335 GetGestureCommonValue(runtimeCallInfo, priority, mask);
8336 int32_t fingers = DEFAULT_LONG_PRESS_FINGER;
8337 bool repeat = false;
8338 int32_t duration = DEFAULT_LONG_PRESS_DURATION;
8339 bool limitFingerCount = false;
8340 GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, limitFingerCount, NUM_5);
8341 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(
8342 fingers, repeat, duration, limitFingerCount, nullptr);
8343 SetGestureTag(runtimeCallInfo, NUM_3, gesture);
8344 SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
8345 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_9, gesture);
8346 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_10, gesture);
8347 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_11, gesture);
8348 GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
8349 nativeNode, gesture, priority, mask);
8350 return panda::JSValueRef::Undefined(vm);
8351 }
8352
AddPanGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)8353 ArkUINativeModuleValue CommonBridge::AddPanGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
8354 {
8355 EcmaVM* vm = runtimeCallInfo->GetVM();
8356 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8357 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8358 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8359 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8360 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8361 int32_t priority = 0;
8362 int32_t mask = 0;
8363 GetGestureCommonValue(runtimeCallInfo, priority, mask);
8364 int32_t fingers = DEFAULT_PAN_FINGER;
8365 int32_t direction = PanDirection::ALL;
8366 double distance = DEFAULT_PAN_DISTANCE.ConvertToPx();
8367 bool limitFingerCount = false;
8368 GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, limitFingerCount, NUM_5);
8369 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(
8370 fingers, direction, distance, limitFingerCount, nullptr);
8371 SetGestureTag(runtimeCallInfo, NUM_3, gesture);
8372 SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
8373 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_9, gesture);
8374 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_10, gesture);
8375 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_11, gesture);
8376 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_12, gesture);
8377 GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
8378 nativeNode, gesture, priority, mask);
8379 return panda::JSValueRef::Undefined(vm);
8380 }
8381
AddSwipeGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)8382 ArkUINativeModuleValue CommonBridge::AddSwipeGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
8383 {
8384 EcmaVM* vm = runtimeCallInfo->GetVM();
8385 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8386 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8387 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8388 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8389 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8390 int32_t priority = 0;
8391 int32_t mask = 0;
8392 GetGestureCommonValue(runtimeCallInfo, priority, mask);
8393 int32_t fingers = DEFAULT_SLIDE_FINGER;
8394 int32_t direction = SwipeDirection::ALL;
8395 double speed = DEFAULT_SLIDE_SPEED;
8396 bool limitFingerCount = false;
8397 GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, limitFingerCount, NUM_5);
8398 auto* gesture =
8399 GetArkUINodeModifiers()->getGestureModifier()-> createSwipeGestureByModifier(
8400 fingers, direction, speed, limitFingerCount);
8401 SetGestureTag(runtimeCallInfo, NUM_3, gesture);
8402 SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
8403 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_9, gesture);
8404 GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
8405 nativeNode, gesture, priority, mask);
8406 return panda::JSValueRef::Undefined(vm);
8407 }
8408
AddPinchGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)8409 ArkUINativeModuleValue CommonBridge::AddPinchGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
8410 {
8411 EcmaVM* vm = runtimeCallInfo->GetVM();
8412 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8413 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8414 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8415 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8416 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8417 int32_t priority = 0;
8418 int32_t mask = 0;
8419 GetGestureCommonValue(runtimeCallInfo, priority, mask);
8420 int32_t fingers = DEFAULT_PINCH_FINGER;
8421 double distance = DEFAULT_PINCH_DISTANCE;
8422 bool limitFingerCount = false;
8423 GetPinchGestureValue(runtimeCallInfo, fingers, distance, limitFingerCount, NUM_5);
8424 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(
8425 fingers, distance, limitFingerCount, nullptr);
8426 SetGestureTag(runtimeCallInfo, NUM_3, gesture);
8427 SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
8428 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_8, gesture);
8429 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_9, gesture);
8430 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_10, gesture);
8431 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_11, gesture);
8432 GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
8433 nativeNode, gesture, priority, mask);
8434 return panda::JSValueRef::Undefined(vm);
8435 }
8436
AddRotationGesture(ArkUIRuntimeCallInfo * runtimeCallInfo)8437 ArkUINativeModuleValue CommonBridge::AddRotationGesture(ArkUIRuntimeCallInfo* runtimeCallInfo)
8438 {
8439 EcmaVM* vm = runtimeCallInfo->GetVM();
8440 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8441 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8442 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8443 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8444 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8445 int32_t priority = 0;
8446 int32_t mask = 0;
8447 GetGestureCommonValue(runtimeCallInfo, priority, mask);
8448 int32_t fingers = DEFAULT_ROTATION_FINGER;
8449 double angle = DEFAULT_ROTATION_ANGLE;
8450 bool limitFingerCount = false;
8451 GetRotationGestureValue(runtimeCallInfo, fingers, angle, limitFingerCount, NUM_5);
8452 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(
8453 fingers, angle, limitFingerCount, nullptr);
8454 SetGestureTag(runtimeCallInfo, NUM_3, gesture);
8455 SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
8456 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_8, gesture);
8457 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_9, gesture);
8458 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_10, gesture);
8459 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_11, gesture);
8460 GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
8461 nativeNode, gesture, priority, mask);
8462 return panda::JSValueRef::Undefined(vm);
8463 }
8464
AddGestureGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8465 ArkUINativeModuleValue CommonBridge::AddGestureGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8466 {
8467 EcmaVM* vm = runtimeCallInfo->GetVM();
8468 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8469 int32_t mode = 2;
8470 // when version >= 20, default mode is 0
8471 if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWENTY)) {
8472 mode = 0;
8473 }
8474 GetGestureModeValue(runtimeCallInfo, mode, NUM_3);
8475 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createGestureGroup(mode);
8476 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8477 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_2, gesture);
8478 return panda::NativePointerRef::New(vm, gesture);
8479 }
8480
AddTapGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8481 ArkUINativeModuleValue CommonBridge::AddTapGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8482 {
8483 EcmaVM* vm = runtimeCallInfo->GetVM();
8484 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8485 int32_t fingers = DEFAULT_TAP_FINGER;
8486 int32_t count = DEFAULT_TAP_COUNT;
8487 double distanceThreshold = DEFAULT_TAP_DISTANCE;
8488 bool limitFingerCount = false;
8489 GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, limitFingerCount, NUM_3);
8490 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
8491 createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, limitFingerCount, nullptr);
8492 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8493 SetGestureAllowedTypes(runtimeCallInfo, NUM_2, gesture);
8494 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_6, gesture);
8495 auto* group = GetGestureGroup(runtimeCallInfo, NUM_7);
8496 GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
8497 return panda::JSValueRef::Undefined(vm);
8498 }
8499
AddLongPressGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8500 ArkUINativeModuleValue CommonBridge::AddLongPressGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8501 {
8502 EcmaVM* vm = runtimeCallInfo->GetVM();
8503 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8504 int32_t fingers = DEFAULT_LONG_PRESS_FINGER;
8505 bool repeat = false;
8506 int32_t duration = DEFAULT_LONG_PRESS_DURATION;
8507 bool limitFingerCount = false;
8508 GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, limitFingerCount, NUM_3);
8509 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(
8510 fingers, repeat, duration, limitFingerCount, nullptr);
8511 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8512 SetGestureAllowedTypes(runtimeCallInfo, NUM_2, gesture);
8513 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture);
8514 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
8515 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
8516 auto* group = GetGestureGroup(runtimeCallInfo, NUM_10);
8517 GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
8518 return panda::JSValueRef::Undefined(vm);
8519 }
8520
AddPanGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8521 ArkUINativeModuleValue CommonBridge::AddPanGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8522 {
8523 EcmaVM* vm = runtimeCallInfo->GetVM();
8524 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8525 int32_t fingers = DEFAULT_PAN_FINGER;
8526 int32_t direction = PanDirection::ALL;
8527 double distance = DEFAULT_PAN_DISTANCE.ConvertToPx();
8528 bool limitFingerCount = false;
8529 GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, limitFingerCount, NUM_3);
8530 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(
8531 fingers, direction, distance, limitFingerCount, nullptr);
8532 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8533 SetGestureAllowedTypes(runtimeCallInfo, NUM_2, gesture);
8534 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_7, gesture);
8535 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_8, gesture);
8536 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_9, gesture);
8537 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_10, gesture);
8538 auto* group = GetGestureGroup(runtimeCallInfo, NUM_11);
8539 GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
8540 return panda::JSValueRef::Undefined(vm);
8541 }
8542
AddSwipeGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8543 ArkUINativeModuleValue CommonBridge::AddSwipeGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8544 {
8545 EcmaVM* vm = runtimeCallInfo->GetVM();
8546 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8547 int32_t fingers = DEFAULT_SLIDE_FINGER;
8548 int32_t direction = SwipeDirection::ALL;
8549 double speed = DEFAULT_SLIDE_SPEED;
8550 bool limitFingerCount = false;
8551 GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, limitFingerCount, NUM_3);
8552 auto* gesture =
8553 GetArkUINodeModifiers()->getGestureModifier()->createSwipeGestureByModifier(
8554 fingers, direction, speed, limitFingerCount);
8555 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8556 SetGestureAllowedTypes(runtimeCallInfo, NUM_2, gesture);
8557 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture);
8558 auto* group = GetGestureGroup(runtimeCallInfo, NUM_8);
8559 GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
8560 return panda::JSValueRef::Undefined(vm);
8561 }
8562
AddPinchGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8563 ArkUINativeModuleValue CommonBridge::AddPinchGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8564 {
8565 EcmaVM* vm = runtimeCallInfo->GetVM();
8566 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8567 int32_t fingers = DEFAULT_PINCH_FINGER;
8568 double distance = DEFAULT_PINCH_DISTANCE;
8569 bool limitFingerCount = false;
8570 GetPinchGestureValue(runtimeCallInfo, fingers, distance, limitFingerCount, NUM_3);
8571 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(
8572 fingers, distance, limitFingerCount, nullptr);
8573 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8574 SetGestureAllowedTypes(runtimeCallInfo, NUM_2, gesture);
8575 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture);
8576 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture);
8577 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
8578 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
8579 auto* group = GetGestureGroup(runtimeCallInfo, NUM_10);
8580 GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
8581 return panda::JSValueRef::Undefined(vm);
8582 }
8583
AddRotationGestureToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8584 ArkUINativeModuleValue CommonBridge::AddRotationGestureToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8585 {
8586 EcmaVM* vm = runtimeCallInfo->GetVM();
8587 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8588 int32_t fingers = DEFAULT_ROTATION_FINGER;
8589 double angle = DEFAULT_ROTATION_ANGLE;
8590 bool limitFingerCount = false;
8591 GetRotationGestureValue(runtimeCallInfo, fingers, angle, limitFingerCount, NUM_3);
8592 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(
8593 fingers, angle, limitFingerCount, nullptr);
8594 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8595 SetGestureAllowedTypes(runtimeCallInfo, NUM_2, gesture);
8596 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture);
8597 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture);
8598 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
8599 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
8600 auto* group = GetGestureGroup(runtimeCallInfo, NUM_10);
8601 GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
8602 return panda::JSValueRef::Undefined(vm);
8603 }
8604
AddGestureGroupToGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8605 ArkUINativeModuleValue CommonBridge::AddGestureGroupToGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8606 {
8607 EcmaVM* vm = runtimeCallInfo->GetVM();
8608 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8609 int32_t mode = 2;
8610 GetGestureModeValue(runtimeCallInfo, mode, NUM_3);
8611 auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createGestureGroup(mode);
8612 SetGestureTag(runtimeCallInfo, NUM_1, gesture);
8613 SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_2, gesture);
8614 auto* group = GetGestureGroup(runtimeCallInfo, NUM_4);
8615 GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
8616 return panda::NativePointerRef::New(vm, gesture);
8617 }
8618
AttachGestureGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)8619 ArkUINativeModuleValue CommonBridge::AttachGestureGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
8620 {
8621 EcmaVM* vm = runtimeCallInfo->GetVM();
8622 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8623 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8624 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8625 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8626 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8627 int32_t priority = 0;
8628 int32_t mask = 0;
8629 GetGestureCommonValue(runtimeCallInfo, priority, mask);
8630 auto* group = GetGestureGroup(runtimeCallInfo, NUM_3);
8631 GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
8632 nativeNode, group, priority, mask);
8633 return panda::JSValueRef::Undefined(vm);
8634 }
8635
RemoveGestureByTag(ArkUIRuntimeCallInfo * runtimeCallInfo)8636 ArkUINativeModuleValue CommonBridge::RemoveGestureByTag(ArkUIRuntimeCallInfo* runtimeCallInfo)
8637 {
8638 EcmaVM* vm = runtimeCallInfo->GetVM();
8639 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8640 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8641 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8642 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8643 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8644 Local<JSValueRef> gestureTagArg = runtimeCallInfo->GetCallArgRef(NUM_1);
8645 if (!gestureTagArg.IsNull() && !gestureTagArg->IsUndefined()) {
8646 auto tag = gestureTagArg->ToString(vm)->ToString(vm);
8647 GetArkUINodeModifiers()->getGestureModifier()->removeGestureFromNodeByTag(nativeNode, tag.c_str());
8648 }
8649 return panda::JSValueRef::Undefined(vm);
8650 }
8651
ClearGestures(ArkUIRuntimeCallInfo * runtimeCallInfo)8652 ArkUINativeModuleValue CommonBridge::ClearGestures(ArkUIRuntimeCallInfo* runtimeCallInfo)
8653 {
8654 EcmaVM* vm = runtimeCallInfo->GetVM();
8655 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8656 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8657 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8658 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8659 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8660 GetArkUINodeModifiers()->getGestureModifier()->clearGestures(nativeNode);
8661 return panda::JSValueRef::Undefined(vm);
8662 }
8663
GetWindowName(ArkUIRuntimeCallInfo * runtimeCallInfo)8664 ArkUINativeModuleValue CommonBridge::GetWindowName(ArkUIRuntimeCallInfo* runtimeCallInfo)
8665 {
8666 EcmaVM* vm = runtimeCallInfo->GetVM();
8667 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8668 auto context = PipelineBase::GetCurrentContext();
8669 CHECK_NULL_RETURN(context, panda::JSValueRef::Undefined(vm));
8670 auto window = context->GetWindow();
8671 CHECK_NULL_RETURN(window, panda::JSValueRef::Undefined(vm));
8672 std::string windowName = window->GetWindowName();
8673 return panda::StringRef::NewFromUtf8(vm, windowName.c_str());
8674 }
8675
GetWindowWidthBreakpoint(ArkUIRuntimeCallInfo * runtimeCallInfo)8676 ArkUINativeModuleValue CommonBridge::GetWindowWidthBreakpoint(ArkUIRuntimeCallInfo* runtimeCallInfo)
8677 {
8678 EcmaVM* vm = runtimeCallInfo->GetVM();
8679 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8680 auto container = Container::Current();
8681 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
8682 auto window = container->GetWindow();
8683 CHECK_NULL_RETURN(window, panda::JSValueRef::Undefined(vm));
8684 double density = PipelineBase::GetCurrentDensity();
8685 double width = 0.0;
8686 if (NearZero(density)) {
8687 width = window->GetCurrentWindowRect().Width();
8688 } else {
8689 width = window->GetCurrentWindowRect().Width() / density;
8690 }
8691
8692 WidthBreakpoint breakpoint;
8693 if (width < WIDTH_BREAKPOINT_320VP) {
8694 breakpoint = WidthBreakpoint::WIDTH_XS;
8695 } else if (width < WIDTH_BREAKPOINT_600VP) {
8696 breakpoint = WidthBreakpoint::WIDTH_SM;
8697 } else if (width < WIDTH_BREAKPOINT_840VP) {
8698 breakpoint = WidthBreakpoint::WIDTH_MD;
8699 } else if (width < WIDTH_BREAKPOINT_1440VP) {
8700 breakpoint = WidthBreakpoint::WIDTH_LG;
8701 } else {
8702 breakpoint = WidthBreakpoint::WIDTH_XL;
8703 }
8704 return panda::IntegerRef::NewFromUnsigned(vm, static_cast<uint32_t>(breakpoint));
8705 }
8706
GetWindowHeightBreakpoint(ArkUIRuntimeCallInfo * runtimeCallInfo)8707 ArkUINativeModuleValue CommonBridge::GetWindowHeightBreakpoint(ArkUIRuntimeCallInfo* runtimeCallInfo)
8708 {
8709 EcmaVM* vm = runtimeCallInfo->GetVM();
8710 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8711 auto container = Container::Current();
8712 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
8713 auto window = container->GetWindow();
8714 CHECK_NULL_RETURN(window, panda::JSValueRef::Undefined(vm));
8715 auto width = window->GetCurrentWindowRect().Width();
8716 auto height = window->GetCurrentWindowRect().Height();
8717 auto aspectRatio = 0.0;
8718 if (NearZero(width)) {
8719 aspectRatio = 0.0;
8720 } else {
8721 aspectRatio = height / width;
8722 }
8723 HeightBreakpoint breakpoint;
8724 if (aspectRatio < HEIGHT_ASPECTRATIO_THRESHOLD1) {
8725 breakpoint = HeightBreakpoint::HEIGHT_SM;
8726 } else if (aspectRatio < HEIGHT_ASPECTRATIO_THRESHOLD2) {
8727 breakpoint = HeightBreakpoint::HEIGHT_MD;
8728 } else {
8729 breakpoint = HeightBreakpoint::HEIGHT_LG;
8730 }
8731 return panda::IntegerRef::NewFromUnsigned(vm, static_cast<uint32_t>(breakpoint));
8732 }
8733
FreezeUINodeById(ArkUIRuntimeCallInfo * runtimeCallInfo)8734 ArkUINativeModuleValue CommonBridge::FreezeUINodeById(ArkUIRuntimeCallInfo* runtimeCallInfo)
8735 {
8736 EcmaVM* vm = runtimeCallInfo->GetVM();
8737 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8738 Local<JSValueRef> idArg = runtimeCallInfo->GetCallArgRef(0);
8739 Local<JSValueRef> isFreezeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
8740 if (!idArg->IsString(vm)) {
8741 return panda::JSValueRef::Undefined(vm);
8742 }
8743 std::string id = idArg->ToString(vm)->ToString(vm);
8744 bool isFreeze = false;
8745 if (isFreezeArg->IsBoolean()) {
8746 isFreeze = isFreezeArg->ToBoolean(vm)->Value();
8747 GetArkUINodeModifiers()->getCommonModifier()->freezeUINodeById(id.c_str(), isFreeze);
8748 } else {
8749 GetArkUINodeModifiers()->getCommonModifier()->freezeUINodeById(id.c_str(), false);
8750 }
8751 return panda::JSValueRef::Undefined(vm);
8752 }
8753
FreezeUINodeByUniqueId(ArkUIRuntimeCallInfo * runtimeCallInfo)8754 ArkUINativeModuleValue CommonBridge::FreezeUINodeByUniqueId(ArkUIRuntimeCallInfo* runtimeCallInfo)
8755 {
8756 EcmaVM* vm = runtimeCallInfo->GetVM();
8757 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8758 Local<JSValueRef> uniqueIdArg = runtimeCallInfo->GetCallArgRef(0);
8759 Local<JSValueRef> isFreezeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
8760 if (!uniqueIdArg->IsNumber()) {
8761 return panda::JSValueRef::Undefined(vm);
8762 }
8763 int32_t uniqueId = uniqueIdArg->IntegerValue(vm);
8764 bool isFreeze = false;
8765 if (isFreezeArg->IsBoolean()) {
8766 isFreeze = isFreezeArg->ToBoolean(vm)->Value();
8767 GetArkUINodeModifiers()->getCommonModifier()->freezeUINodeByUniqueId(uniqueId, isFreeze);
8768 } else {
8769 GetArkUINodeModifiers()->getCommonModifier()->freezeUINodeByUniqueId(uniqueId, false);
8770 }
8771 return panda::JSValueRef::Undefined(vm);
8772 }
8773
SetSystemBarEffect(ArkUIRuntimeCallInfo * runtimeCallInfo)8774 ArkUINativeModuleValue CommonBridge::SetSystemBarEffect(ArkUIRuntimeCallInfo* runtimeCallInfo)
8775 {
8776 EcmaVM* vm = runtimeCallInfo->GetVM();
8777 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8778 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8779 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8780 auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8781 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8782 Local<JSValueRef> enableArg = runtimeCallInfo->GetCallArgRef(NUM_1);
8783 if (enableArg->IsBoolean()) {
8784 auto enable = enableArg->ToBoolean(vm);
8785 GetArkUINodeModifiers()->getCommonModifier()->setSystemBarEffect(nativeNode, enable->Value());
8786 }
8787 return panda::JSValueRef::Undefined(vm);
8788 }
8789
PostFrameCallback(ArkUIRuntimeCallInfo * runtimeCallInfo)8790 ArkUINativeModuleValue CommonBridge::PostFrameCallback(ArkUIRuntimeCallInfo* runtimeCallInfo)
8791 {
8792 EcmaVM* vm = runtimeCallInfo->GetVM();
8793 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8794
8795 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0); // frameCallback
8796 if (firstArg->IsNull() || firstArg->IsUndefined() || !firstArg->IsObject(vm)) {
8797 return panda::JSValueRef::Undefined(vm);
8798 }
8799 auto frameCallback = firstArg->ToObject(vm);
8800
8801 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
8802 int64_t delayMillis = 0;
8803 if (secondArg->IsNumber()) {
8804 delayMillis = secondArg->IntegerValue(vm);
8805 }
8806
8807 if (frameCallback->IsNull() || frameCallback->IsUndefined() || !frameCallback->IsObject(vm)) {
8808 return panda::JSValueRef::Undefined(vm);
8809 }
8810
8811 FrameCallbackFunc onFrameCallbackFunc = nullptr;
8812 FrameCallbackFunc onIdleCallbackFunc = nullptr;
8813
8814 if (frameCallback->Get(vm, "onFrame")->IsFunction(vm)) {
8815 onFrameCallbackFunc = [vm, frameCallbackObj =
8816 panda::CopyableGlobal(vm, frameCallback)](int64_t nanoTimestamp) -> void {
8817 LocalScope scope(vm);
8818 Local<FunctionRef> onFrameFunc = frameCallbackObj->Get(vm, "onFrame");
8819
8820 auto nanoTimestampRef = NumberRef::New(vm, nanoTimestamp);
8821 Local<JSValueRef> params[] = { nanoTimestampRef };
8822 onFrameFunc->Call(vm, frameCallbackObj.ToLocal(), params, 1);
8823 };
8824 }
8825
8826 if (frameCallback->Get(vm, "onIdle")->IsFunction(vm)) {
8827 onIdleCallbackFunc = [vm, frameCallbackObj =
8828 panda::CopyableGlobal(vm, frameCallback)](int64_t nanoTimestamp) -> void {
8829 LocalScope scope(vm);
8830 Local<FunctionRef> onIdleFunc = frameCallbackObj->Get(vm, "onIdle");
8831
8832 auto nanoTimestampRef = NumberRef::New(vm, nanoTimestamp);
8833 Local<JSValueRef> params[] = { nanoTimestampRef };
8834 onIdleFunc->Call(vm, frameCallbackObj.ToLocal(), params, 1);
8835 };
8836 }
8837
8838 if (onFrameCallbackFunc == nullptr && onIdleCallbackFunc == nullptr) {
8839 return panda::JSValueRef::Undefined(vm);
8840 }
8841
8842 auto context = PipelineContext::GetCurrentContext();
8843 CHECK_NULL_RETURN(context, panda::JSValueRef::Undefined(vm));
8844 context->AddFrameCallback(std::move(onFrameCallbackFunc), std::move(onIdleCallbackFunc), delayMillis);
8845 return panda::JSValueRef::Undefined(vm);
8846 }
8847
ResetFocusScopeId(ArkUIRuntimeCallInfo * runtimeCallInfo)8848 ArkUINativeModuleValue CommonBridge::ResetFocusScopeId(ArkUIRuntimeCallInfo* runtimeCallInfo)
8849 {
8850 EcmaVM* vm = runtimeCallInfo->GetVM();
8851 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8852 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8853 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8854 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8855 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8856 GetArkUINodeModifiers()->getCommonModifier()->resetFocusScopeId(nativeNode);
8857 return panda::JSValueRef::Undefined(vm);
8858 }
8859
SetFocusScopeId(ArkUIRuntimeCallInfo * runtimeCallInfo)8860 ArkUINativeModuleValue CommonBridge::SetFocusScopeId(ArkUIRuntimeCallInfo* runtimeCallInfo)
8861 {
8862 EcmaVM* vm = runtimeCallInfo->GetVM();
8863 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8864 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8865 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8866 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8867 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8868 Local<JSValueRef> idArg = runtimeCallInfo->GetCallArgRef(NUM_1);
8869 Local<JSValueRef> isGroupArg = runtimeCallInfo->GetCallArgRef(NUM_2);
8870 Local<JSValueRef> arrowKeyStepOutArg = runtimeCallInfo->GetCallArgRef(NUM_3);
8871 if (!idArg->IsString(vm)) {
8872 return panda::JSValueRef::Undefined(vm);
8873 }
8874 auto id = idArg->ToString(vm)->ToString(vm);
8875 bool isGroup = false;
8876 if (isGroupArg->IsBoolean()) {
8877 isGroup = isGroupArg->ToBoolean(vm)->Value();
8878 }
8879 bool arrowKeyStepOut = true;
8880 if (arrowKeyStepOutArg->IsBoolean()) {
8881 arrowKeyStepOut = arrowKeyStepOutArg->ToBoolean(vm)->Value();
8882 }
8883 GetArkUINodeModifiers()->getCommonModifier()->setFocusScopeId(nativeNode, id.c_str(), isGroup, arrowKeyStepOut);
8884 return panda::JSValueRef::Undefined(vm);
8885 }
8886
ResetFocusScopePriority(ArkUIRuntimeCallInfo * runtimeCallInfo)8887 ArkUINativeModuleValue CommonBridge::ResetFocusScopePriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
8888 {
8889 EcmaVM* vm = runtimeCallInfo->GetVM();
8890 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8891 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8892 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8893 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8894 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8895 GetArkUINodeModifiers()->getCommonModifier()->resetFocusScopePriority(nativeNode);
8896 return panda::JSValueRef::Undefined(vm);
8897 }
8898
SetFocusScopePriority(ArkUIRuntimeCallInfo * runtimeCallInfo)8899 ArkUINativeModuleValue CommonBridge::SetFocusScopePriority(ArkUIRuntimeCallInfo* runtimeCallInfo)
8900 {
8901 EcmaVM* vm = runtimeCallInfo->GetVM();
8902 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8903 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8904 CHECK_NULL_RETURN(!firstArg.IsNull(), panda::JSValueRef::Undefined(vm));
8905 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8906 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8907 Local<JSValueRef> scopeIdArg = runtimeCallInfo->GetCallArgRef(NUM_1);
8908 Local<JSValueRef> priorityArg = runtimeCallInfo->GetCallArgRef(NUM_2);
8909 if (!scopeIdArg->IsString(vm)) {
8910 return panda::JSValueRef::Undefined(vm);
8911 }
8912 auto scopeId = scopeIdArg->ToString(vm)->ToString(vm);
8913 int32_t priority = 0;
8914 if (priorityArg->IsNumber()) {
8915 priority = priorityArg->Int32Value(vm);
8916 }
8917 GetArkUINodeModifiers()->getCommonModifier()->setFocusScopePriority(nativeNode, scopeId.c_str(), priority);
8918 return panda::JSValueRef::Undefined(vm);
8919 }
SetPixelRound(ArkUIRuntimeCallInfo * runtimeCallInfo)8920 ArkUINativeModuleValue CommonBridge::SetPixelRound(ArkUIRuntimeCallInfo* runtimeCallInfo)
8921 {
8922 EcmaVM* vm = runtimeCallInfo->GetVM();
8923 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8924 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
8925 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8926 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
8927 auto startArg = runtimeCallInfo->GetCallArgRef(NUM_1);
8928 auto topArg = runtimeCallInfo->GetCallArgRef(NUM_2);
8929 auto endArg = runtimeCallInfo->GetCallArgRef(NUM_3);
8930 auto bottomArg = runtimeCallInfo->GetCallArgRef(NUM_4);
8931 if (startArg->IsUndefined() && topArg->IsUndefined() && endArg->IsUndefined() && bottomArg->IsUndefined()) {
8932 GetArkUINodeModifiers()->getCommonModifier()->resetPixelRound(nativeNode);
8933 return panda::JSValueRef::Undefined(vm);
8934 }
8935 int32_t values[] = { -1, -1, -1, -1 };
8936 if (startArg->IsInt()) {
8937 values[NUM_0] = startArg->Int32Value(vm);
8938 }
8939 if (topArg->IsInt()) {
8940 values[NUM_1] = topArg->Int32Value(vm);
8941 }
8942 if (endArg->IsInt()) {
8943 values[NUM_2] = endArg->Int32Value(vm);
8944 }
8945 if (bottomArg->IsInt()) {
8946 values[NUM_3] = bottomArg->Int32Value(vm);
8947 }
8948 GetArkUINodeModifiers()->getCommonModifier()->setPixelRound(
8949 nativeNode, values, (sizeof(values) / sizeof(values[NUM_0])));
8950 return panda::JSValueRef::Undefined(vm);
8951 }
8952
ResetPixelRound(ArkUIRuntimeCallInfo * runtimeCallInfo)8953 ArkUINativeModuleValue CommonBridge::ResetPixelRound(ArkUIRuntimeCallInfo* runtimeCallInfo)
8954 {
8955 EcmaVM* vm = runtimeCallInfo->GetVM();
8956 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
8957 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8958 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
8959 GetArkUINodeModifiers()->getCommonModifier()->resetPixelRound(nativeNode);
8960 return panda::JSValueRef::Undefined(vm);
8961 }
8962
GreatOrEqualAPITargetVersion(ArkUIRuntimeCallInfo * runtimeCallInfo)8963 ArkUINativeModuleValue CommonBridge::GreatOrEqualAPITargetVersion(ArkUIRuntimeCallInfo* runtimeCallInfo)
8964 {
8965 EcmaVM* vm = runtimeCallInfo->GetVM();
8966 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8967
8968 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8969 if (firstArg->IsNull() || firstArg->IsUndefined() || !firstArg->IsNumber()) {
8970 return panda::BooleanRef::New(vm, false);
8971 }
8972 int32_t apiTargetVersion = firstArg->Int32Value(vm);
8973 auto platformVersion = static_cast<PlatformVersion>(apiTargetVersion);
8974 return panda::BooleanRef::New(vm, Container::GreatOrEqualAPITargetVersion(platformVersion));
8975 }
8976
LessThanAPITargetVersion(ArkUIRuntimeCallInfo * runtimeCallInfo)8977 ArkUINativeModuleValue CommonBridge::LessThanAPITargetVersion(ArkUIRuntimeCallInfo* runtimeCallInfo)
8978 {
8979 EcmaVM* vm = runtimeCallInfo->GetVM();
8980 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8981
8982 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
8983 if (firstArg->IsNull() || firstArg->IsUndefined() || !firstArg->IsNumber()) {
8984 return panda::BooleanRef::New(vm, false);
8985 }
8986 int32_t apiTargetVersion = firstArg->Int32Value(vm);
8987 auto platformVersion = static_cast<PlatformVersion>(apiTargetVersion);
8988 return panda::BooleanRef::New(vm, Container::LessThanAPITargetVersion(platformVersion));
8989 }
8990
GetApiTargetVersion(ArkUIRuntimeCallInfo * runtimeCallInfo)8991 ArkUINativeModuleValue CommonBridge::GetApiTargetVersion(ArkUIRuntimeCallInfo* runtimeCallInfo)
8992 {
8993 EcmaVM* vm = runtimeCallInfo->GetVM();
8994 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
8995
8996 auto container = Container::CurrentSafely();
8997 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
8998 int32_t apiTargetVersion = container->GetApiTargetVersion();
8999 return panda::NumberRef::New(vm, apiTargetVersion);
9000 }
9001
SetFocusBox(ArkUIRuntimeCallInfo * runtimeCallInfo)9002 ArkUINativeModuleValue CommonBridge::SetFocusBox(ArkUIRuntimeCallInfo* runtimeCallInfo)
9003 {
9004 EcmaVM* vm = runtimeCallInfo->GetVM();
9005 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
9006 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
9007 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
9008 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
9009 auto marginArg = runtimeCallInfo->GetCallArgRef(NUM_1);
9010 auto widthArg = runtimeCallInfo->GetCallArgRef(NUM_2);
9011 auto colorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
9012 ArkUI_Uint32 hasValue = 0;
9013 CalcDimension margin;
9014 if (!marginArg->IsUndefined() && !marginArg->IsNull()) {
9015 if (ArkTSUtils::ParseJsDimensionFpNG(vm, marginArg, margin, false)) {
9016 hasValue = 1;
9017 } else if (ArkTSUtils::ParseJsLengthMetrics(vm, marginArg, margin)) {
9018 hasValue = 1;
9019 }
9020 }
9021 hasValue = hasValue << 1;
9022 CalcDimension width;
9023 if (!widthArg->IsUndefined() && !widthArg->IsNull()) {
9024 if (ArkTSUtils::ParseJsDimensionFpNG(vm, widthArg, width, false) && GreatOrEqual(width.Value(), 0.0f)) {
9025 hasValue += 1;
9026 } else if (ArkTSUtils::ParseJsLengthMetrics(vm, widthArg, width) && GreatOrEqual(width.Value(), 0.0f)) {
9027 hasValue += 1;
9028 }
9029 }
9030 hasValue = hasValue << 1;
9031 Color strokeColor;
9032 if (!colorArg->IsUndefined() && !colorArg->IsNull() && ParseColorMetricsToColor(vm, colorArg, strokeColor)) {
9033 hasValue += 1;
9034 }
9035 GetArkUINodeModifiers()->getCommonModifier()->setFocusBoxStyle(nativeNode, margin.Value(),
9036 static_cast<int>(margin.Unit()), width.Value(), static_cast<int>(width.Unit()), strokeColor.GetValue(),
9037 hasValue);
9038 return panda::JSValueRef::Undefined(vm);
9039 }
9040
ResetFocusBox(ArkUIRuntimeCallInfo * runtimeCallInfo)9041 ArkUINativeModuleValue CommonBridge::ResetFocusBox(ArkUIRuntimeCallInfo* runtimeCallInfo)
9042 {
9043 EcmaVM* vm = runtimeCallInfo->GetVM();
9044 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
9045 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
9046 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
9047 GetArkUINodeModifiers()->getCommonModifier()->resetFocusBoxStyle(nativeNode);
9048 return panda::JSValueRef::Undefined(vm);
9049 }
9050
SetNextFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)9051 ArkUINativeModuleValue CommonBridge::SetNextFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
9052 {
9053 EcmaVM* vm = runtimeCallInfo->GetVM();
9054 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
9055 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
9056 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
9057 CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
9058 ArkUI_Uint32 hasValue = 0;
9059 std::string nextFocusArray[NUM_6];
9060 auto forward = runtimeCallInfo->GetCallArgRef(NUM_1);
9061 auto backward = runtimeCallInfo->GetCallArgRef(NUM_2);
9062 auto up = runtimeCallInfo->GetCallArgRef(NUM_3);
9063 auto down = runtimeCallInfo->GetCallArgRef(NUM_4);
9064 auto left = runtimeCallInfo->GetCallArgRef(NUM_5);
9065 auto right = runtimeCallInfo->GetCallArgRef(NUM_6);
9066 if (forward->IsString(vm)) {
9067 nextFocusArray[NUM_0] = forward->ToString(vm)->ToString(vm);
9068 hasValue = 1;
9069 }
9070 hasValue = hasValue << 1;
9071 if (backward->IsString(vm)) {
9072 nextFocusArray[NUM_1] = backward->ToString(vm)->ToString(vm);
9073 hasValue += 1;
9074 }
9075 hasValue = hasValue << 1;
9076 if (up->IsString(vm)) {
9077 nextFocusArray[NUM_2] = up->ToString(vm)->ToString(vm);
9078 hasValue += 1;
9079 }
9080 hasValue = hasValue << 1;
9081 if (down->IsString(vm)) {
9082 nextFocusArray[NUM_3] = down->ToString(vm)->ToString(vm);
9083 hasValue += 1;
9084 }
9085 hasValue = hasValue << 1;
9086 if (left->IsString(vm)) {
9087 nextFocusArray[NUM_4] = left->ToString(vm)->ToString(vm);
9088 hasValue += 1;
9089 }
9090 hasValue = hasValue << 1;
9091 if (right->IsString(vm)) {
9092 nextFocusArray[NUM_5] = right->ToString(vm)->ToString(vm);
9093 hasValue += 1;
9094 }
9095 GetArkUINodeModifiers()->getCommonModifier()->setNextFocus(nativeNode,
9096 nextFocusArray[NUM_0].c_str(), nextFocusArray[NUM_1].c_str(),
9097 nextFocusArray[NUM_2].c_str(), nextFocusArray[NUM_3].c_str(),
9098 nextFocusArray[NUM_4].c_str(), nextFocusArray[NUM_5].c_str(), hasValue);
9099 return panda::JSValueRef::Undefined(vm);
9100 }
9101
ResetNextFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)9102 ArkUINativeModuleValue CommonBridge::ResetNextFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
9103 {
9104 EcmaVM* vm = runtimeCallInfo->GetVM();
9105 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
9106 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
9107 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
9108 GetArkUINodeModifiers()->getCommonModifier()->resetNextFocus(nativeNode);
9109 return panda::JSValueRef::Undefined(vm);
9110 }
9111
CreateFocusAxisEventInfo(EcmaVM * vm,NG::FocusAxisEventInfo & info)9112 Local<panda::ObjectRef> CommonBridge::CreateFocusAxisEventInfo(EcmaVM* vm, NG::FocusAxisEventInfo& info)
9113 {
9114 auto axisMap = panda::MapRef::New(vm);
9115 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_X)),
9116 panda::NumberRef::New(vm, info.GetAbsXValue()));
9117 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_Y)),
9118 panda::NumberRef::New(vm, info.GetAbsYValue()));
9119 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_Z)),
9120 panda::NumberRef::New(vm, info.GetAbsZValue()));
9121 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_RZ)),
9122 panda::NumberRef::New(vm, info.GetAbsRzValue()));
9123 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_GAS)),
9124 panda::NumberRef::New(vm, info.GetAbsGasValue()));
9125 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_BRAKE)),
9126 panda::NumberRef::New(vm, info.GetAbsBrakeValue()));
9127 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_HAT0X)),
9128 panda::NumberRef::New(vm, info.GetAbsHat0XValue()));
9129 axisMap->Set(vm, panda::NumberRef::New(vm, static_cast<int>(NG::AxisModel::ABS_HAT0Y)),
9130 panda::NumberRef::New(vm, info.GetAbsHat0YValue()));
9131 const char* keys[] = { "axisMap", "target", "timestamp", "source", "pressure", "tiltX", "tiltY", "sourceTool",
9132 "deviceId", "getModifierKeyState", "stopPropagation", "targetDisplayId" };
9133 Local<JSValueRef> values[] = { axisMap, FrameNodeBridge::CreateEventTargetObject(vm, info),
9134 panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
9135 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetSourceDevice())),
9136 panda::NumberRef::New(vm, info.GetForce()),
9137 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltX().value_or(0.0f))),
9138 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltY().value_or(0.0f))),
9139 panda::NumberRef::New(vm, static_cast<int32_t>(static_cast<int32_t>(info.GetSourceTool()))),
9140 panda::NumberRef::New(vm, info.GetDeviceId()), panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState),
9141 panda::FunctionRef::New(vm, Framework::JsStopPropagation),
9142 panda::NumberRef::New(vm, (info.GetTargetDisplayId()))};
9143 auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
9144 obj->SetNativePointerFieldCount(vm, 1);
9145 obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
9146 return obj;
9147 }
9148
SetOnFocusAxisEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)9149 ArkUINativeModuleValue CommonBridge::SetOnFocusAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
9150 {
9151 EcmaVM* vm = runtimeCallInfo->GetVM();
9152 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
9153 auto* frameNode = GetFrameNode(runtimeCallInfo);
9154 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
9155 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
9156 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
9157 auto obj = secondeArg->ToObject(vm);
9158 auto containerId = Container::CurrentId();
9159 panda::Local<panda::FunctionRef> func = obj;
9160 auto onFocusAxisEvent = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode),
9161 containerId](FocusAxisEventInfo& info) {
9162 panda::LocalScope pandaScope(vm);
9163 panda::TryCatch trycatch(vm);
9164 ContainerScope scope(containerId);
9165 PipelineContext::SetCallBackNode(node);
9166 auto obj = CreateFocusAxisEventInfo(vm, info);
9167 panda::Local<panda::JSValueRef> params[] = { obj };
9168 func->Call(vm, func.ToLocal(), params, 1);
9169 };
9170 NG::ViewAbstract::SetOnFocusAxisEvent(frameNode, std::move(onFocusAxisEvent));
9171 return panda::JSValueRef::Undefined(vm);
9172 }
9173
ResetOnFocusAxisEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)9174 ArkUINativeModuleValue CommonBridge::ResetOnFocusAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
9175 {
9176 EcmaVM* vm = runtimeCallInfo->GetVM();
9177 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
9178 auto* frameNode = GetFrameNode(runtimeCallInfo);
9179 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
9180 ViewAbstract::DisableOnFocusAxisEvent(frameNode);
9181 return panda::JSValueRef::Undefined(vm);
9182 }
9183
RegisterFrameNodeDestructorCallback(ArkUIRuntimeCallInfo * runtimeCallInfo)9184 ArkUINativeModuleValue CommonBridge::RegisterFrameNodeDestructorCallback(ArkUIRuntimeCallInfo* runtimeCallInfo)
9185 {
9186 EcmaVM* vm = runtimeCallInfo->GetVM();
9187 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
9188 auto* frameNode = GetFrameNode(runtimeCallInfo);
9189 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
9190 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
9191 if (secondeArg->IsNull() || secondeArg->IsUndefined()) {
9192 frameNode->SetFrameNodeDestructorCallback(nullptr);
9193 return panda::JSValueRef::Undefined(vm);
9194 }
9195 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
9196 auto obj = secondeArg->ToObject(vm);
9197 auto containerId = Container::CurrentId();
9198 CHECK_NULL_RETURN(containerId != -1, panda::JSValueRef::Undefined(vm));
9199 panda::Local<panda::FunctionRef> func = obj;
9200 auto frameNodeDestructorCallback = [vm, func = JsWeak(panda::CopyableGlobal(vm, func)),
9201 node = AceType::WeakClaim(frameNode), containerId](int32_t frameNodeId) {
9202 panda::LocalScope pandaScope(vm);
9203 panda::TryCatch trycatch(vm);
9204 ContainerScope scope(containerId);
9205 auto function = func.Lock();
9206 CHECK_NULL_VOID(!function.IsEmpty());
9207 CHECK_NULL_VOID(function->IsFunction(vm));
9208 PipelineContext::SetCallBackNode(node);
9209 auto frameNodeIdParam = panda::NumberRef::New(vm, frameNodeId);
9210 panda::Local<panda::JSValueRef> params[] = { frameNodeIdParam };
9211 function->Call(vm, function.ToLocal(), params, 1);
9212 };
9213 frameNode->SetFrameNodeDestructorCallback(std::move(frameNodeDestructorCallback));
9214 return panda::JSValueRef::Undefined(vm);
9215 }
9216
CreateAxisEventInfo(EcmaVM * vm,AxisInfo & info)9217 Local<panda::ObjectRef> CommonBridge::CreateAxisEventInfo(EcmaVM* vm, AxisInfo& info)
9218 {
9219 const Offset& globalOffset = info.GetGlobalLocation();
9220 const Offset& localOffset = info.GetLocalLocation();
9221 const Offset& screenOffset = info.GetScreenLocation();
9222 double density = PipelineBase::GetCurrentDensity();
9223 const char* keys[] = { "action", "displayX", "displayY", "windowX", "windowY", "x", "y", "scrollStep",
9224 "propagation", "getHorizontalAxisValue", "getVerticalAxisValue", "target", "timestamp", "source", "pressure",
9225 "tiltX", "tiltY", "sourceTool", "deviceId", "getModifierKeyState" };
9226 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, static_cast<int32_t>(info.GetAction())),
9227 panda::NumberRef::New(vm, screenOffset.GetX() / density),
9228 panda::NumberRef::New(vm, screenOffset.GetY() / density),
9229 panda::NumberRef::New(vm, globalOffset.GetX() / density),
9230 panda::NumberRef::New(vm, globalOffset.GetY() / density),
9231 panda::NumberRef::New(vm, localOffset.GetX() / density),
9232 panda::NumberRef::New(vm, localOffset.GetY() / density), panda::NumberRef::New(vm, info.GetScrollStep()),
9233 panda::FunctionRef::New(vm, Framework::JsPropagation),
9234 panda::FunctionRef::New(vm, ArkTSUtils::JsGetHorizontalAxisValue),
9235 panda::FunctionRef::New(vm, ArkTSUtils::JsGetVerticalAxisValue),
9236 FrameNodeBridge::CreateEventTargetObject(vm, info),
9237 panda::NumberRef::New(vm, static_cast<double>(info.GetTimeStamp().time_since_epoch().count())),
9238 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetSourceDevice())),
9239 panda::NumberRef::New(vm, info.GetForce()),
9240 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltX().value_or(0.0f))),
9241 panda::NumberRef::New(vm, static_cast<int32_t>(info.GetTiltY().value_or(0.0f))),
9242 panda::NumberRef::New(vm, static_cast<int32_t>(static_cast<int32_t>(info.GetSourceTool()))),
9243 panda::NumberRef::New(vm, info.GetDeviceId()), panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState) };
9244 auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
9245 obj->Set(vm, panda::StringRef::NewFromUtf8(vm, "axisVertical"), panda::NumberRef::New(vm, info.GetVerticalAxis()));
9246 obj->Set(
9247 vm, panda::StringRef::NewFromUtf8(vm, "axisHorizontal"), panda::NumberRef::New(vm, info.GetHorizontalAxis()));
9248 obj->SetNativePointerFieldCount(vm, 1);
9249 obj->SetNativePointerField(vm, 0, static_cast<void*>(&info));
9250 return obj;
9251 }
9252
SetOnAxisEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)9253 ArkUINativeModuleValue CommonBridge::SetOnAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
9254 {
9255 EcmaVM* vm = runtimeCallInfo->GetVM();
9256 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
9257 auto* frameNode = GetFrameNode(runtimeCallInfo);
9258 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
9259 Local<JSValueRef> secondeArg = runtimeCallInfo->GetCallArgRef(1);
9260 CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm));
9261 auto obj = secondeArg->ToObject(vm);
9262 auto containerId = Container::CurrentId();
9263 panda::Local<panda::FunctionRef> func = obj;
9264 auto onAxisEvent = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), containerId](
9265 AxisInfo& info) {
9266 panda::LocalScope pandaScope(vm);
9267 panda::TryCatch trycatch(vm);
9268 ContainerScope scope(containerId);
9269 PipelineContext::SetCallBackNode(node);
9270 auto obj = CreateAxisEventInfo(vm, info);
9271 panda::Local<panda::JSValueRef> params[] = { obj };
9272 func->Call(vm, func.ToLocal(), params, 1);
9273 };
9274 NG::ViewAbstract::SetOnAxisEvent(frameNode, std::move(onAxisEvent));
9275 return panda::JSValueRef::Undefined(vm);
9276 }
9277
ResetOnAxisEvent(ArkUIRuntimeCallInfo * runtimeCallInfo)9278 ArkUINativeModuleValue CommonBridge::ResetOnAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo)
9279 {
9280 EcmaVM* vm = runtimeCallInfo->GetVM();
9281 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
9282 auto* frameNode = GetFrameNode(runtimeCallInfo);
9283 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
9284 ViewAbstract::DisableOnAxisEvent(frameNode);
9285 return panda::JSValueRef::Undefined(vm);
9286 }
9287 } // namespace OHOS::Ace::NG
9288