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