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_progress_bridge.h"
16
17 #include "base/utils/utils.h"
18 #include "bridge/declarative_frontend/jsview/js_progress.h"
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components/progress/progress_theme.h"
21 #include "core/components_ng/pattern/progress/progress_date.h"
22 #include "core/components_ng/pattern/progress/progress_layout_property.h"
23 #include "core/components_ng/pattern/progress/progress_model_ng.h"
24 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
25 #include "bridge/declarative_frontend/jsview/js_linear_gradient.h"
26
27 namespace OHOS::Ace::NG {
28 constexpr int32_t ARG_NUM_NATIVE_NODE = 0;
29 constexpr int32_t ARG_NUM_VALUE = 1;
30 constexpr int32_t ARG_COLOR_INDEX_VALUE = 1;
31 constexpr int32_t ARG_NUM_STYLE_STROKE_WIDTH = 1;
32 constexpr int32_t ARG_NUM_STYLE_BORDER_WIDTH = 6;
33 constexpr int32_t ARG_NUM_STYLE_PROGRESS_STATUS = 16;
34 constexpr int32_t ARG_NUM_STYLE_FONT_STYLE = 11;
35 constexpr int32_t ARG_NUM_STYLE_SCALE_COUNT = 2;
36 constexpr int32_t ARG_NUM_STYLE_SCALE_WIDTH = 3;
37 constexpr int32_t ARG_NUM_STYLE_FONT_SIZE = 8;
38 constexpr int32_t ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT = 4;
39 constexpr int32_t ARG_NUM_STYLE_BORDER_COLOR = 5;
40 constexpr int32_t ARG_NUM_STYLE_CONTENT = 7;
41 constexpr int32_t ARG_NUM_STYLE_FONT_WEIGHT = 9;
42 constexpr int32_t ARG_NUM_STYLE_FONT_COLOR = 12;
43 constexpr int32_t ARG_NUM_STYLE_ENABLE_SCAN_EFFECT = 13;
44 constexpr int32_t ARG_NUM_STYLE_SHADOW = 15;
45 constexpr int32_t ARG_NUM_STYLE_SHOW_DEFAULT_PERCENTAGE = 14;
46 constexpr int32_t ARG_NUM_STYLE_FONT_FAMILY = 10;
47 constexpr int32_t ARG_NUM_STYLE_STROKE_RADIUS = 17;
48 constexpr int32_t ARG_NUM_STYLE_BORDER_RADIUS = 18;
49 constexpr int32_t ARG_SECOND = 2;
50 const char* PROGRESS_NODEPTR_OF_UINODE = "nodePtr_";
51 constexpr double DEFAULT_PROGRESS_VALUE = 0;
52 constexpr double DEFAULT_STROKE_WIDTH = 4;
53 constexpr double DEFAULT_BORDER_WIDTH = 1;
54 constexpr double DEFAULT_SCALE_WIDTH = 2;
55 constexpr double DEFAULT_STROKE_RADIUS = 0;
56 constexpr int32_t DEFAULT_SCALE_COUNT = 120;
57 constexpr Color DEFAULT_BORDER_COLOR = Color(0x33006cde);
58 constexpr Color DEFAULT_FONT_COLOR = Color(0xff182431);
59 constexpr double DEFAULT_CAPSULE_FONT_SIZE = 12;
60 constexpr NG::ProgressStatus DEFAULT_PROGRESS_STATUS = NG::ProgressStatus::PROGRESSING;
61 constexpr DimensionUnit DEFAULT_CAPSULE_FONT_UNIT = DimensionUnit::FP;
62 const std::vector<Ace::FontStyle> FONT_STYLES = { Ace::FontStyle::NORMAL, Ace::FontStyle::ITALIC };
63 const std::vector<NG::ProgressStatus> STATUS_STYLES = { NG::ProgressStatus::PROGRESSING, NG::ProgressStatus::LOADING };
64 constexpr double DEFAULT_BORDER_RADIUS = 0;
65
66 namespace {
ConvertProgressRResourceColor(const EcmaVM * vm,const Local<JSValueRef> & item,OHOS::Ace::NG::Gradient & gradient)67 bool ConvertProgressRResourceColor(const EcmaVM* vm, const Local<JSValueRef>& item, OHOS::Ace::NG::Gradient& gradient)
68 {
69 Color color;
70 if (!ArkTSUtils::ParseJsColor(vm, item, color)) {
71 return false;
72 }
73 OHOS::Ace::NG::GradientColor gradientColorStart;
74 gradientColorStart.SetLinearColor(LinearColor(color));
75 gradientColorStart.SetDimension(Dimension(0.0));
76 gradient.AddColor(gradientColorStart);
77 OHOS::Ace::NG::GradientColor gradientColorEnd;
78 gradientColorEnd.SetLinearColor(LinearColor(color));
79 gradientColorEnd.SetDimension(Dimension(1.0));
80 gradient.AddColor(gradientColorEnd);
81 return true;
82 }
83
ConvertProgressResourceColor(const EcmaVM * vm,const Local<JSValueRef> & itemParam,OHOS::Ace::NG::Gradient & gradient)84 bool ConvertProgressResourceColor(
85 const EcmaVM* vm, const Local<JSValueRef>& itemParam, OHOS::Ace::NG::Gradient& gradient)
86 {
87 if (!itemParam->IsObject(vm)) {
88 return ConvertProgressRResourceColor(vm, itemParam, gradient);
89 }
90 Framework::JSLinearGradient* jsLinearGradient =
91 static_cast<Framework::JSLinearGradient*>(itemParam->ToObject(vm)->GetNativePointerField(vm, 0));
92 if (!jsLinearGradient) {
93 return ConvertProgressRResourceColor(vm, itemParam, gradient);
94 }
95
96 size_t colorLength = jsLinearGradient->GetGradient().size();
97 if (colorLength == 0) {
98 return false;
99 }
100 for (size_t colorIndex = 0; colorIndex < colorLength; ++colorIndex) {
101 OHOS::Ace::NG::GradientColor gradientColor;
102 gradientColor.SetLinearColor(LinearColor(jsLinearGradient->GetGradient().at(colorIndex).first));
103 gradientColor.SetDimension(jsLinearGradient->GetGradient().at(colorIndex).second);
104 gradient.AddColor(gradientColor);
105 }
106 return true;
107 }
108 } // namespace
109
ResetProgressValue(ArkUIRuntimeCallInfo * runtimeCallInfo)110 ArkUINativeModuleValue ProgressBridge::ResetProgressValue(ArkUIRuntimeCallInfo* runtimeCallInfo)
111 {
112 EcmaVM* vm = runtimeCallInfo->GetVM();
113 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
114 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
115 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
116 auto nodeModifiers = GetArkUINodeModifiers();
117 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
118 nodeModifiers->getProgressModifier()->resetProgressValue(nativeNode);
119 return panda::JSValueRef::Undefined(vm);
120 }
121
SetProgressValue(ArkUIRuntimeCallInfo * runtimeCallInfo)122 ArkUINativeModuleValue ProgressBridge::SetProgressValue(ArkUIRuntimeCallInfo* runtimeCallInfo)
123 {
124 EcmaVM* vm = runtimeCallInfo->GetVM();
125 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
126 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
127 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_VALUE);
128 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
129 auto nodeModifiers = GetArkUINodeModifiers();
130 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
131 if (secondArg->IsNumber()) {
132 ArkUI_Float32 value = secondArg->ToNumber(vm)->Value();
133 if (value < DEFAULT_PROGRESS_VALUE) {
134 value = DEFAULT_PROGRESS_VALUE;
135 }
136 nodeModifiers->getProgressModifier()->setProgressValue(nativeNode, value);
137 } else {
138 nodeModifiers->getProgressModifier()->resetProgressValue(nativeNode);
139 }
140 return panda::JSValueRef::Undefined(vm);
141 }
142
ResetProgressColor(ArkUIRuntimeCallInfo * runtimeCallInfo)143 ArkUINativeModuleValue ProgressBridge::ResetProgressColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
144 {
145 EcmaVM* vm = runtimeCallInfo->GetVM();
146 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
147 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
148 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
149 auto nodeModifiers = GetArkUINodeModifiers();
150 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
151 nodeModifiers->getProgressModifier()->resetProgressColor(nativeNode);
152 return panda::JSValueRef::Undefined(vm);
153 }
154
SetProgressColor(ArkUIRuntimeCallInfo * runtimeCallInfo)155 ArkUINativeModuleValue ProgressBridge::SetProgressColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
156 {
157 EcmaVM* vm = runtimeCallInfo->GetVM();
158 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
159 Local<JSValueRef> nativeArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
160 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(ARG_COLOR_INDEX_VALUE);
161 auto nativeNode = nodePtr(nativeArg->ToNativePointer(vm)->Value());
162 Color color;
163 OHOS::Ace::NG::Gradient gradient;
164 auto nodeModifiers = GetArkUINodeModifiers();
165 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
166 if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
167 nodeModifiers->getProgressModifier()->setProgressColor(nativeNode, color.GetValue());
168 } else if (ConvertProgressResourceColor(vm, colorArg, gradient)) {
169 ArkUIGradientType gradientObj;
170 auto colorlength = gradient.GetColors().size();
171 std::vector<uint32_t> colorValues;
172 std::vector<ArkUILengthType> offsetValues;
173 if (colorlength <= 0) {
174 nodeModifiers->getProgressModifier()->resetProgressColor(nativeNode);
175 return panda::JSValueRef::Undefined(vm);
176 }
177
178 for (int32_t i = 0; i < static_cast<int32_t>(colorlength); i++) {
179 colorValues.push_back(gradient.GetColors()[i].GetLinearColor().GetValue());
180 offsetValues.push_back(ArkUILengthType { .number = gradient.GetColors()[i].GetDimension().Value(),
181 .unit = static_cast<int8_t>(gradient.GetColors()[i].GetDimension().Unit()) });
182 }
183
184 gradientObj.color = &(*colorValues.begin());
185 gradientObj.offset = &(*offsetValues.begin());
186 nodeModifiers->getProgressModifier()->setProgressGradientColor(
187 nativeNode, &gradientObj, colorlength);
188 } else {
189 nodeModifiers->getProgressModifier()->resetProgressColor(nativeNode);
190 }
191
192 return panda::JSValueRef::Undefined(vm);
193 }
194
ResetProgressStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)195 ArkUINativeModuleValue ProgressBridge::ResetProgressStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
196 {
197 EcmaVM* vm = runtimeCallInfo->GetVM();
198 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
199 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
200 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
201 auto nodeModifiers = GetArkUINodeModifiers();
202 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
203 nodeModifiers->getProgressModifier()->resetProgressStyle(nativeNode);
204 return panda::JSValueRef::Undefined(vm);
205 }
206
ParseStrokeWidth(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)207 void ParseStrokeWidth(
208 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
209 {
210 Local<JSValueRef> strokeWidthArg = runtimeCallInfo->GetCallArgRef(index);
211 CalcDimension strokeWidth = CalcDimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP);
212 auto theme = ArkTSUtils::GetTheme<ProgressTheme>();
213
214 if (strokeWidthArg->IsString(vm)) {
215 const std::string& value = strokeWidthArg->ToString(vm)->ToString(vm);
216 strokeWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, DEFAULT_STROKE_WIDTH);
217 } else {
218 ArkTSUtils::ParseJsDimension(vm, strokeWidthArg, strokeWidth, DimensionUnit::VP, false);
219 }
220
221 if ((LessOrEqual(strokeWidth.Value(), 0.0f) || strokeWidth.Unit() == DimensionUnit::PERCENT) && theme) {
222 strokeWidth = theme->GetTrackThickness();
223 }
224 if (strokeWidth.IsNegative()) {
225 progressStyle.strokeWidthValue = DEFAULT_STROKE_WIDTH;
226 progressStyle.strokeWidthUnit = static_cast<uint8_t>(DimensionUnit::VP);
227 } else {
228 progressStyle.strokeWidthValue = strokeWidth.Value();
229 progressStyle.strokeWidthUnit = static_cast<uint8_t>(strokeWidth.Unit());
230 }
231 }
232
ParseBorderWidth(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)233 void ParseBorderWidth(
234 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
235 {
236 Local<JSValueRef> borderWidthArg = runtimeCallInfo->GetCallArgRef(index);
237 CalcDimension borderWidth = CalcDimension(DEFAULT_BORDER_WIDTH, DimensionUnit::VP);
238
239 if (borderWidthArg->IsString(vm)) {
240 const std::string& value = borderWidthArg->ToString(vm)->ToString(vm);
241 borderWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, DEFAULT_BORDER_WIDTH);
242 } else {
243 ArkTSUtils::ParseJsDimension(vm, borderWidthArg, borderWidth, DimensionUnit::VP, false);
244 }
245 if (borderWidth.IsNegative()) {
246 progressStyle.borderWidthValue = DEFAULT_BORDER_WIDTH;
247 progressStyle.borderWidthUnit = static_cast<uint8_t>(DimensionUnit::VP);
248 } else {
249 progressStyle.borderWidthValue = borderWidth.Value();
250 progressStyle.borderWidthUnit = static_cast<uint8_t>(borderWidth.Unit());
251 }
252 }
253
ParseScaleCount(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)254 void ParseScaleCount(
255 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
256 {
257 Local<JSValueRef> scaleCountArg = runtimeCallInfo->GetCallArgRef(index);
258 int32_t scaleCount = DEFAULT_SCALE_COUNT;
259 auto theme = ArkTSUtils::GetTheme<ProgressTheme>();
260 if (theme) {
261 scaleCount = theme->GetScaleNumber();
262 }
263
264 if (scaleCountArg->IsNull() || !ArkTSUtils::ParseJsInteger(vm, scaleCountArg, scaleCount)) {
265 scaleCount = DEFAULT_SCALE_COUNT;
266 }
267 if (scaleCount > 1) {
268 progressStyle.scaleCount = scaleCount;
269 } else if (theme) {
270 progressStyle.scaleCount = theme->GetScaleNumber();
271 }
272 }
273
ParseProgressStatus(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)274 void ParseProgressStatus(
275 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
276 {
277 Local<JSValueRef> ProgressStatusArg = runtimeCallInfo->GetCallArgRef(index);
278 NG::ProgressStatus progressStatus = DEFAULT_PROGRESS_STATUS;
279 std::string statusStr;
280 if (ProgressStatusArg->IsUndefined() || ProgressStatusArg->IsNull() ||
281 !ArkTSUtils::ParseJsString(vm, ProgressStatusArg, statusStr)) {
282 progressStatus = DEFAULT_PROGRESS_STATUS;
283 } else {
284 if (statusStr.compare("LOADING") == 0) {
285 progressStatus = NG::ProgressStatus::LOADING;
286 } else {
287 progressStatus = NG::ProgressStatus::PROGRESSING;
288 }
289 }
290 progressStyle.status = static_cast<int8_t>(progressStatus);
291 }
292
ParseScaleWidth(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)293 void ParseScaleWidth(
294 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
295 {
296 Local<JSValueRef> scaleWidthArg = runtimeCallInfo->GetCallArgRef(index);
297 CalcDimension scaleWidth = CalcDimension(DEFAULT_SCALE_WIDTH, DimensionUnit::VP);
298
299 if (scaleWidthArg->IsString(vm)) {
300 const std::string& value = scaleWidthArg->ToString(vm)->ToString(vm);
301 scaleWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, DEFAULT_SCALE_WIDTH);
302 } else {
303 ArkTSUtils::ParseJsDimension(vm, scaleWidthArg, scaleWidth, DimensionUnit::VP, false);
304 }
305 if (scaleWidth.IsNegative()) {
306 scaleWidth = CalcDimension(DEFAULT_SCALE_WIDTH, DimensionUnit::VP);
307 }
308
309 progressStyle.scaleWidthValue = scaleWidth.Value();
310 progressStyle.scaleWidthUnit = static_cast<uint8_t>(scaleWidth.Unit());
311 }
312
ParseStrokeRadius(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)313 void ParseStrokeRadius(
314 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
315 {
316 Local<JSValueRef> strokeRadiusArg = runtimeCallInfo->GetCallArgRef(index);
317 CalcDimension strokeRadius = CalcDimension(DEFAULT_STROKE_RADIUS, DimensionUnit::PERCENT);
318 if (strokeRadiusArg->IsNull() ||
319 !ArkTSUtils::ParseJsDimension(vm, strokeRadiusArg, strokeRadius, DimensionUnit::VP, true)) {
320 strokeRadius.SetUnit(DimensionUnit::PERCENT);
321 }
322
323 progressStyle.strokeRadiusValue = strokeRadius.Value();
324 progressStyle.strokeRadiusUnit = static_cast<uint8_t>(strokeRadius.Unit());
325 }
326
ParseBorderColor(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)327 void ParseBorderColor(
328 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
329 {
330 Local<JSValueRef> borderColorArg = runtimeCallInfo->GetCallArgRef(index);
331 Color borderColor = DEFAULT_BORDER_COLOR;
332
333 if (borderColorArg->IsNull() || !ArkTSUtils::ParseJsColorAlpha(vm, borderColorArg, borderColor)) {
334 borderColor = DEFAULT_BORDER_COLOR;
335 }
336
337 progressStyle.borderColor = borderColor.GetValue();
338 }
339
ParseFontColor(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)340 void ParseFontColor(
341 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
342 {
343 Local<JSValueRef> fontColorArg = runtimeCallInfo->GetCallArgRef(index);
344 Color fontColor = DEFAULT_FONT_COLOR;
345
346 if (fontColorArg->IsNull() || !ArkTSUtils::ParseJsColorAlpha(vm, fontColorArg, fontColor)) {
347 fontColor = DEFAULT_FONT_COLOR;
348 }
349
350 progressStyle.fontColor = fontColor.GetValue();
351 }
352
ParseEnableSmoothEffect(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)353 void ParseEnableSmoothEffect(
354 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
355 {
356 Local<JSValueRef> enableSmoothEffectArg = runtimeCallInfo->GetCallArgRef(index);
357 progressStyle.enableSmoothEffect =
358 (enableSmoothEffectArg->IsBoolean()) ? enableSmoothEffectArg->ToBoolean(vm)->Value() : true;
359 }
360
ParseContent(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)361 void ParseContent(
362 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
363 {
364 Local<JSValueRef> contentArg = runtimeCallInfo->GetCallArgRef(index);
365 std::string content = contentArg->ToString(vm)->ToString(vm);
366 progressStyle.content = (contentArg->IsString(vm)) ? content.c_str() : nullptr;
367 }
368
ParseEnableScanEffect(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)369 void ParseEnableScanEffect(
370 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
371 {
372 Local<JSValueRef> enableScanEffectArg = runtimeCallInfo->GetCallArgRef(index);
373 progressStyle.enableScanEffect =
374 (enableScanEffectArg->IsBoolean()) ? enableScanEffectArg->ToBoolean(vm)->Value() : false;
375 }
376
ParseShadow(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)377 void ParseShadow(
378 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
379 {
380 Local<JSValueRef> shadowArg = runtimeCallInfo->GetCallArgRef(index);
381 progressStyle.shadow = (shadowArg->IsBoolean()) ? shadowArg->ToBoolean(vm)->Value() : false;
382 }
383
ParseShowDefaultPercentage(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)384 void ParseShowDefaultPercentage(
385 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
386 {
387 Local<JSValueRef> showDefaultPercentageArg = runtimeCallInfo->GetCallArgRef(index);
388 progressStyle.showDefaultPercentage =
389 (showDefaultPercentageArg->IsBoolean()) ? showDefaultPercentageArg->ToBoolean(vm)->Value() : false;
390 }
391
ParseCapsuleFontSize(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)392 void ParseCapsuleFontSize(
393 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
394 {
395 Local<JSValueRef> sizeArg = runtimeCallInfo->GetCallArgRef(index);
396
397 CalcDimension fontSize;
398 if (sizeArg->IsNull() || !ArkTSUtils::ParseJsDimensionFp(vm, sizeArg, fontSize) || fontSize.IsNegative() ||
399 fontSize.Unit() == DimensionUnit::PERCENT) {
400 progressStyle.fontInfo.fontSizeNumber = DEFAULT_CAPSULE_FONT_SIZE;
401 progressStyle.fontInfo.fontSizeUnit = static_cast<int8_t>(DEFAULT_CAPSULE_FONT_UNIT);
402 } else {
403 progressStyle.fontInfo.fontSizeNumber = fontSize.Value();
404 progressStyle.fontInfo.fontSizeUnit = static_cast<int8_t>(fontSize.Unit());
405 }
406 }
407
ParseCapsuleFontWeight(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)408 void ParseCapsuleFontWeight(
409 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
410 {
411 Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(index);
412 auto pipelineContext = PipelineContext::GetCurrentContext();
413 CHECK_NULL_VOID(pipelineContext);
414 auto theme = pipelineContext->GetTheme<TextTheme>();
415
416 std::string weight;
417 if (!weightArg->IsNull()) {
418 if (weightArg->IsNumber()) {
419 weight = std::to_string(weightArg->Int32Value(vm));
420 } else if (weightArg->IsString(vm)) {
421 weight = weightArg->ToString(vm)->ToString(vm);
422 }
423 progressStyle.fontInfo.fontWeight = static_cast<uint8_t>(Framework::ConvertStrToFontWeight(weight));
424 } else {
425 progressStyle.fontInfo.fontWeight = static_cast<uint8_t>(theme->GetTextStyle().GetFontWeight());
426 }
427 }
428
ParseCapsuleFontStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)429 void ParseCapsuleFontStyle(
430 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
431 {
432 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(index);
433 auto pipelineContext = PipelineContext::GetCurrentContext();
434 CHECK_NULL_VOID(pipelineContext);
435 auto theme = pipelineContext->GetTheme<TextTheme>();
436
437 uint8_t style = static_cast<uint8_t>(theme->GetTextStyle().GetFontStyle());
438 if (!styleArg->IsNull() && styleArg->IsInt()) {
439 style = static_cast<uint8_t>(styleArg->Int32Value(vm));
440 if (style <= 0 || style > static_cast<uint8_t>(FONT_STYLES.size())) {
441 style = static_cast<uint8_t>(theme->GetTextStyle().GetFontStyle());
442 }
443 }
444
445 progressStyle.fontInfo.fontStyle = style;
446 }
447
ParseCapsuleFontFamily(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,std::vector<std::string> & fontFamilies,std::unique_ptr<const char * []> & families)448 void ParseCapsuleFontFamily(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle,
449 std::vector<std::string>& fontFamilies, std::unique_ptr<const char*[]>& families)
450 {
451 Local<JSValueRef> familyArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_STYLE_FONT_FAMILY);
452 auto pipelineContext = PipelineContext::GetCurrentContext();
453 CHECK_NULL_VOID(pipelineContext);
454 auto theme = pipelineContext->GetTheme<TextTheme>();
455
456 if (familyArg->IsNull() || !ArkTSUtils::ParseJsFontFamilies(vm, familyArg, fontFamilies)) {
457 fontFamilies = theme->GetTextStyle().GetFontFamilies();
458 }
459
460 families.reset();
461 families = std::make_unique<const char* []>(fontFamilies.size());
462 for (uint32_t i = 0; i < fontFamilies.size(); i++) {
463 families[i] = fontFamilies[i].c_str();
464 }
465
466 progressStyle.fontInfo.fontFamilies = families.get();
467 progressStyle.fontInfo.familyLength = fontFamilies.size();
468 }
469
ParseBorderRadius(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)470 void ParseBorderRadius(
471 const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
472 {
473 Local<JSValueRef> borderRadiusArg = runtimeCallInfo->GetCallArgRef(index);
474 CalcDimension borderRadius = CalcDimension(DEFAULT_BORDER_RADIUS, DimensionUnit::PERCENT);
475 if (borderRadiusArg->IsNull() || !ArkTSUtils::ParseJsLengthMetrics(vm, borderRadiusArg, borderRadius)) {
476 // Set illegal units, and the background will be handled according to the default value.
477 borderRadius.SetUnit(DimensionUnit::PERCENT);
478 }
479 progressStyle.borderRadiusValue = borderRadius.Value();
480 progressStyle.borderRadiusUnit = static_cast<uint8_t>(borderRadius.Unit());
481 }
482
ParseLinearStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle)483 void ParseLinearStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle)
484 {
485 ParseStrokeWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_WIDTH);
486 ParseStrokeRadius(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_RADIUS);
487 ParseEnableScanEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SCAN_EFFECT);
488 ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
489 }
490
ParseRingStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle)491 void ParseRingStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle)
492 {
493 ParseStrokeWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_WIDTH);
494 ParseShadow(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SHADOW);
495 ParseProgressStatus(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_PROGRESS_STATUS);
496 ParseEnableScanEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SCAN_EFFECT);
497 ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
498 }
499
ParseCapsuleStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,std::vector<std::string> & fontFamilies,std::unique_ptr<const char * []> & families)500 void ParseCapsuleStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle,
501 std::vector<std::string>& fontFamilies, std::unique_ptr<const char*[]>& families)
502 {
503 ParseBorderColor(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_BORDER_COLOR);
504 ParseBorderWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_BORDER_WIDTH);
505 ParseFontColor(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_COLOR);
506 ParseCapsuleFontSize(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_SIZE);
507 ParseCapsuleFontWeight(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_WEIGHT);
508 ParseCapsuleFontStyle(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_STYLE);
509 ParseCapsuleFontFamily(vm, runtimeCallInfo, progressStyle, fontFamilies, families);
510 ParseEnableScanEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SCAN_EFFECT);
511 ParseShowDefaultPercentage(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SHOW_DEFAULT_PERCENTAGE);
512 ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
513 ParseBorderRadius(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_BORDER_RADIUS);
514 }
515
ParseProgressStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle)516 void ParseProgressStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle)
517 {
518 auto progressTheme = ArkTSUtils::GetTheme<ProgressTheme>();
519 CHECK_NULL_VOID(progressTheme);
520 ParseStrokeWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_WIDTH);
521 ParseScaleCount(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SCALE_COUNT);
522 ParseScaleWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SCALE_WIDTH);
523 if ((progressStyle.scaleWidthValue <= 0.0) || (progressStyle.scaleWidthValue > progressStyle.strokeWidthValue) ||
524 progressStyle.scaleWidthUnit == static_cast<int8_t>(DimensionUnit::PERCENT)) {
525 progressStyle.scaleWidthValue = progressTheme->GetScaleWidth().Value();
526 progressStyle.scaleWidthUnit = static_cast<int8_t>(progressTheme->GetScaleWidth().Unit());
527 }
528 ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
529 }
530
SetProgressStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)531 ArkUINativeModuleValue ProgressBridge::SetProgressStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
532 {
533 EcmaVM* vm = runtimeCallInfo->GetVM();
534 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
535 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
536 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
537 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
538 auto pipelineContext = PipelineContext::GetCurrentContext();
539 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
540 auto theme = pipelineContext->GetTheme<TextTheme>();
541
542 auto fontFamilies = theme->GetTextStyle().GetFontFamilies();
543 auto families = std::make_unique<const char* []>(fontFamilies.size());
544 for (uint32_t i = 0; i < fontFamilies.size(); i++) {
545 families[i] = fontFamilies[i].c_str();
546 }
547
548 ArkUIProgressStyle progressStyle = { DEFAULT_STROKE_WIDTH, static_cast<int8_t>(DimensionUnit::VP),
549 DEFAULT_BORDER_WIDTH, static_cast<int8_t>(DimensionUnit::VP), DEFAULT_SCALE_COUNT,
550 static_cast<uint8_t>(DEFAULT_PROGRESS_STATUS), DEFAULT_SCALE_WIDTH, static_cast<int8_t>(DimensionUnit::VP),
551 DEFAULT_STROKE_RADIUS, static_cast<int8_t>(DimensionUnit::PERCENT), true,
552 static_cast<double>(DEFAULT_BORDER_COLOR.GetValue()), nullptr,
553 static_cast<double>(DEFAULT_FONT_COLOR.GetValue()), false, false, false,
554 { DEFAULT_CAPSULE_FONT_SIZE, static_cast<int8_t>(DEFAULT_CAPSULE_FONT_UNIT),
555 static_cast<uint8_t>(theme->GetTextStyle().GetFontWeight()),
556 static_cast<uint8_t>(theme->GetTextStyle().GetFontStyle()), families.get(), fontFamilies.size() } };
557
558 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
559 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
560 auto progressLayoutProperty = frameNode->GetLayoutProperty<ProgressLayoutProperty>();
561 CHECK_NULL_RETURN(progressLayoutProperty, panda::JSValueRef::Undefined(vm));
562 Local<JSValueRef> contentArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_STYLE_CONTENT);
563 std::string content = contentArg->ToString(vm)->ToString(vm);
564 auto progresstype = progressLayoutProperty->GetType();
565 if (progresstype == ProgressType::LINEAR) {
566 ParseLinearStyle(vm, runtimeCallInfo, progressStyle);
567 } else if (progresstype == ProgressType::RING) {
568 ParseRingStyle(vm, runtimeCallInfo, progressStyle);
569 } else if (progresstype == ProgressType::CAPSULE) {
570 ParseCapsuleStyle(vm, runtimeCallInfo, progressStyle, fontFamilies, families);
571 progressStyle.content = (contentArg->IsString(vm)) ? content.c_str() : nullptr;
572 } else {
573 ParseProgressStyle(vm, runtimeCallInfo, progressStyle);
574 }
575 auto nodeModifiers = GetArkUINodeModifiers();
576 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
577 nodeModifiers->getProgressModifier()->setProgressStyle(nativeNode, &progressStyle);
578 return panda::JSValueRef::Undefined(vm);
579 }
580
SetProgressBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)581 ArkUINativeModuleValue ProgressBridge::SetProgressBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
582 {
583 EcmaVM *vm = runtimeCallInfo->GetVM();
584 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
585 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
586 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
587 CHECK_NULL_RETURN(nativeNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
588 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
589 Color color;
590 auto nodeModifiers = GetArkUINodeModifiers();
591 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
592 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
593 nodeModifiers->getProgressModifier()->resetProgressBackgroundColor(nativeNode);
594 } else {
595 nodeModifiers->getProgressModifier()->setProgressBackgroundColor(nativeNode, color.GetValue());
596 }
597
598 return panda::JSValueRef::Undefined(vm);
599 }
600
ResetProgressBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)601 ArkUINativeModuleValue ProgressBridge::ResetProgressBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
602 {
603 EcmaVM* vm = runtimeCallInfo->GetVM();
604 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
605 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
606 CHECK_NULL_RETURN(nativeNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
607 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
608 auto nodeModifiers = GetArkUINodeModifiers();
609 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
610 nodeModifiers->getProgressModifier()->resetProgressBackgroundColor(nativeNode);
611 return panda::JSValueRef::Undefined(vm);
612 }
613
SetContentModifierBuilder(ArkUIRuntimeCallInfo * runtimeCallInfo)614 ArkUINativeModuleValue ProgressBridge::SetContentModifierBuilder(ArkUIRuntimeCallInfo* runtimeCallInfo)
615 {
616 EcmaVM* vm = runtimeCallInfo->GetVM();
617 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
618 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
619 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
620 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
621 auto* frameNode = reinterpret_cast<FrameNode*>(firstArg->ToNativePointer(vm)->Value());
622 if (!secondArg->IsObject(vm)) {
623 ProgressModelNG::SetBuilderFunc(frameNode, nullptr);
624 return panda::JSValueRef::Undefined(vm);
625 }
626 panda::CopyableGlobal<panda::ObjectRef> obj(vm, secondArg);
627 ProgressModelNG::SetBuilderFunc(frameNode, [vm, frameNode, obj = std::move(obj),
628 containerId = Container::CurrentId()](ProgressConfiguration config) -> RefPtr<FrameNode> {
629 ContainerScope scope(containerId);
630 auto context = ArkTSUtils::GetContext(vm);
631 CHECK_EQUAL_RETURN(context->IsUndefined(), true, nullptr);
632 const char* keysOfProgress[] = { "value", "total", "enabled"};
633 Local<JSValueRef> valuesOfProgress[] = { panda::NumberRef::New(vm, config.value_),
634 panda::NumberRef::New(vm, config.total_), panda::BooleanRef::New(vm, config.enabled_)};
635 auto progress = panda::ObjectRef::NewWithNamedProperties(vm,
636 ArraySize(keysOfProgress), keysOfProgress, valuesOfProgress);
637 progress->SetNativePointerFieldCount(vm, 1);
638 progress->SetNativePointerField(vm, 0, static_cast<void*>(frameNode));
639 panda::Local<panda::JSValueRef> params[ARG_SECOND] = { context, progress };
640 LocalScope pandaScope(vm);
641 panda::TryCatch trycatch(vm);
642 auto jsObject = obj.ToLocal();
643 auto makeFunc = jsObject->Get(vm, panda::StringRef::NewFromUtf8(vm, "makeContentModifierNode"));
644 CHECK_NULL_RETURN(makeFunc->IsFunction(vm), nullptr);
645 panda::Local<panda::FunctionRef> func = makeFunc;
646 auto result = func->Call(vm, jsObject, params, 2);
647 JSNApi::ExecutePendingJob(vm);
648 if (result.IsEmpty() || trycatch.HasCaught() || !result->IsObject(vm)) {
649 return nullptr;
650 }
651 auto resultObj = result->ToObject(vm);
652 panda::Local<panda::JSValueRef> nodeptr = resultObj->Get(vm, panda::StringRef::NewFromUtf8(vm,
653 PROGRESS_NODEPTR_OF_UINODE));
654 if (nodeptr.IsEmpty() || nodeptr->IsUndefined() || nodeptr->IsNull()) {
655 return nullptr;
656 }
657 auto* frameNode = reinterpret_cast<FrameNode*>(nodeptr->ToNativePointer(vm)->Value());
658 CHECK_NULL_RETURN(frameNode, nullptr);
659 return AceType::Claim(frameNode);
660 });
661 return panda::JSValueRef::Undefined(vm);
662 }
663
ResetProgressInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)664 ArkUINativeModuleValue ProgressBridge::ResetProgressInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
665 {
666 EcmaVM* vm = runtimeCallInfo->GetVM();
667 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
668 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
669 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
670 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
671 auto nodeModifiers = GetArkUINodeModifiers();
672 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
673 nodeModifiers->getProgressModifier()->resetProgressInitialize(nativeNode);
674 return panda::JSValueRef::Undefined(vm);
675 }
676
SetProgressInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)677 ArkUINativeModuleValue ProgressBridge::SetProgressInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
678 {
679 EcmaVM* vm = runtimeCallInfo->GetVM();
680 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
681 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
682 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
683 Local<JSValueRef> totalArg = runtimeCallInfo->GetCallArgRef(2);
684 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(3);
685 Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(4);
686 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
687 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
688 auto value = 0;
689 if (valueArg->IsNumber()) {
690 value = valueArg->ToNumber(vm)->Value();
691 }
692 auto total = 100;
693 if (totalArg->IsNumber() && totalArg->ToNumber(vm)->Value() > 0) {
694 total = totalArg->Int32Value(vm);
695 }
696 if (value > total) {
697 value = total;
698 } else if (value < 0) {
699 value = 0;
700 }
701 auto type = 0;
702 if (styleArg->IsNull() || styleArg->IsUndefined()) {
703 if (typeArg->IsNumber()) {
704 type = typeArg->Int32Value(vm);
705 }
706 } else if (styleArg->IsNumber()) {
707 type = styleArg->Int32Value(vm);
708 }
709 auto progressStyle = static_cast<Framework::ProgressStyle>(type);
710 ProgressType g_progressType = NG::ProgressType::LINEAR;
711 if (progressStyle == Framework::ProgressStyle::Eclipse) {
712 g_progressType = NG::ProgressType::MOON;
713 } else if (progressStyle == Framework::ProgressStyle::Ring) {
714 g_progressType = NG::ProgressType::RING;
715 } else if (progressStyle == Framework::ProgressStyle::ScaleRing) {
716 g_progressType = NG::ProgressType::SCALE;
717 } else if (progressStyle == Framework::ProgressStyle::Capsule) {
718 g_progressType = NG::ProgressType::CAPSULE;
719 }
720 auto nodeModifiers = GetArkUINodeModifiers();
721 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
722 nodeModifiers->getProgressModifier()->setProgressInitialize(
723 nativeNode, value, total, static_cast<int>(g_progressType));
724 return panda::JSValueRef::Undefined(vm);
725 }
726
SetProgressPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)727 ArkUINativeModuleValue ProgressBridge::SetProgressPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
728 {
729 EcmaVM* vm = runtimeCallInfo->GetVM();
730 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
731 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
732 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
733 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
734 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
735 uint32_t sensitive = false;
736 if (secondArg->IsBoolean()) {
737 sensitive = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
738 }
739 auto nodeModifiers = GetArkUINodeModifiers();
740 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
741 nodeModifiers->getCommonModifier()->setPrivacySensitive(nativeNode, sensitive);
742 return panda::JSValueRef::Undefined(vm);
743 }
744
ResetProgressPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)745 ArkUINativeModuleValue ProgressBridge::ResetProgressPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
746 {
747 EcmaVM* vm = runtimeCallInfo->GetVM();
748 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
749 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
750 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
751 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
752 auto nodeModifiers = GetArkUINodeModifiers();
753 CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
754 nodeModifiers->getCommonModifier()->resetPrivacySensitive(nativeNode);
755 return panda::JSValueRef::Undefined(vm);
756 }
757 } // namespace OHOS::Ace::NG
758