• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_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 #include "core/common/resource/resource_parse_utils.h"
27 
28 namespace OHOS::Ace::NG {
29 constexpr int32_t ARG_NUM_NATIVE_NODE = 0;
30 constexpr int32_t ARG_NUM_VALUE = 1;
31 constexpr int32_t ARG_COLOR_INDEX_VALUE = 1;
32 constexpr int32_t ARG_NUM_STYLE_STROKE_WIDTH = 1;
33 constexpr int32_t ARG_NUM_STYLE_BORDER_WIDTH = 6;
34 constexpr int32_t ARG_NUM_STYLE_PROGRESS_STATUS = 16;
35 constexpr int32_t ARG_NUM_STYLE_FONT_STYLE = 11;
36 constexpr int32_t ARG_NUM_STYLE_SCALE_COUNT = 2;
37 constexpr int32_t ARG_NUM_STYLE_SCALE_WIDTH = 3;
38 constexpr int32_t ARG_NUM_STYLE_FONT_SIZE = 8;
39 constexpr int32_t ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT = 4;
40 constexpr int32_t ARG_NUM_STYLE_BORDER_COLOR = 5;
41 constexpr int32_t ARG_NUM_STYLE_CONTENT = 7;
42 constexpr int32_t ARG_NUM_STYLE_FONT_WEIGHT = 9;
43 constexpr int32_t ARG_NUM_STYLE_FONT_COLOR = 12;
44 constexpr int32_t ARG_NUM_STYLE_ENABLE_SCAN_EFFECT = 13;
45 constexpr int32_t ARG_NUM_STYLE_SHADOW = 15;
46 constexpr int32_t ARG_NUM_STYLE_SHOW_DEFAULT_PERCENTAGE = 14;
47 constexpr int32_t ARG_NUM_STYLE_FONT_FAMILY = 10;
48 constexpr int32_t ARG_NUM_STYLE_STROKE_RADIUS = 17;
49 constexpr int32_t ARG_NUM_STYLE_BORDER_RADIUS = 18;
50 constexpr int32_t ARG_SECOND = 2;
51 const char* PROGRESS_NODEPTR_OF_UINODE = "nodePtr_";
52 constexpr double DEFAULT_PROGRESS_VALUE = 0;
53 constexpr double DEFAULT_STROKE_WIDTH = 4;
54 constexpr double DEFAULT_BORDER_WIDTH = 1;
55 constexpr double DEFAULT_SCALE_WIDTH = 2;
56 constexpr double DEFAULT_STROKE_RADIUS = 0;
57 constexpr int32_t DEFAULT_SCALE_COUNT = 120;
58 constexpr Color DEFAULT_BORDER_COLOR = Color(0x33006cde);
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     RefPtr<ResourceObject> colorResObj;
165     auto nodeModifiers = GetArkUINodeModifiers();
166     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
167     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
168     if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color, colorResObj, nodeInfo)) {
169         auto colorRawPtr = AceType::RawPtr(colorResObj);
170         nodeModifiers->getProgressModifier()->setProgressColorPtr(nativeNode, color.GetValue(), colorRawPtr);
171     } else if (ConvertProgressResourceColor(vm, colorArg, gradient)) {
172         ArkUIGradientType gradientObj;
173         auto colorlength = gradient.GetColors().size();
174         std::vector<uint32_t> colorValues;
175         std::vector<ArkUILengthType> offsetValues;
176         if (colorlength <= 0) {
177             nodeModifiers->getProgressModifier()->resetProgressColor(nativeNode);
178             return panda::JSValueRef::Undefined(vm);
179         }
180 
181         for (int32_t i = 0; i < static_cast<int32_t>(colorlength); i++) {
182             colorValues.push_back(gradient.GetColors()[i].GetLinearColor().GetValue());
183             offsetValues.push_back(ArkUILengthType { .number = gradient.GetColors()[i].GetDimension().Value(),
184                 .unit = static_cast<int8_t>(gradient.GetColors()[i].GetDimension().Unit()) });
185         }
186 
187         gradientObj.color = &(*colorValues.begin());
188         gradientObj.offset = &(*offsetValues.begin());
189         nodeModifiers->getProgressModifier()->setProgressGradientColor(
190             nativeNode, &gradientObj, colorlength);
191     } else {
192         nodeModifiers->getProgressModifier()->resetProgressColor(nativeNode);
193     }
194 
195     return panda::JSValueRef::Undefined(vm);
196 }
197 
ResetProgressStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)198 ArkUINativeModuleValue ProgressBridge::ResetProgressStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
199 {
200     EcmaVM* vm = runtimeCallInfo->GetVM();
201     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
202     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
203     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
204     auto nodeModifiers = GetArkUINodeModifiers();
205     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
206     nodeModifiers->getProgressModifier()->resetProgressStyle(nativeNode);
207     return panda::JSValueRef::Undefined(vm);
208 }
209 
ParseStrokeWidth(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)210 void ParseStrokeWidth(
211     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
212 {
213     Local<JSValueRef> strokeWidthArg = runtimeCallInfo->GetCallArgRef(index);
214     CalcDimension strokeWidth = CalcDimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP);
215     auto theme = ArkTSUtils::GetTheme<ProgressTheme>();
216 
217     if (strokeWidthArg->IsString(vm)) {
218         const std::string& value = strokeWidthArg->ToString(vm)->ToString(vm);
219         strokeWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, DEFAULT_STROKE_WIDTH);
220     } else {
221         RefPtr<ResourceObject> resObj;
222         ArkTSUtils::ParseJsDimension(vm, strokeWidthArg, strokeWidth, DimensionUnit::VP, resObj, false);
223         if (resObj) {
224             progressStyle.styleResource.strokeWidthRawPtr = AceType::RawPtr(resObj);
225             resObj->IncRefCount();
226         }
227     }
228 
229     if ((LessOrEqual(strokeWidth.Value(), 0.0f) || strokeWidth.Unit() == DimensionUnit::PERCENT) && theme) {
230         strokeWidth = theme->GetTrackThickness();
231     }
232     if (strokeWidth.IsNegative()) {
233         progressStyle.strokeWidthValue = DEFAULT_STROKE_WIDTH;
234         progressStyle.strokeWidthUnit = static_cast<uint8_t>(DimensionUnit::VP);
235     } else {
236         progressStyle.strokeWidthValue = strokeWidth.Value();
237         progressStyle.strokeWidthUnit = static_cast<uint8_t>(strokeWidth.Unit());
238     }
239 }
240 
ParseBorderWidth(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)241 void ParseBorderWidth(
242     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
243 {
244     Local<JSValueRef> borderWidthArg = runtimeCallInfo->GetCallArgRef(index);
245     CalcDimension borderWidth = CalcDimension(DEFAULT_BORDER_WIDTH, DimensionUnit::VP);
246 
247     if (borderWidthArg->IsString(vm)) {
248         const std::string& value = borderWidthArg->ToString(vm)->ToString(vm);
249         borderWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, DEFAULT_BORDER_WIDTH);
250     } else {
251         RefPtr<ResourceObject> resObj;
252         ArkTSUtils::ParseJsDimension(vm, borderWidthArg, borderWidth, DimensionUnit::VP, resObj, false);
253         if (resObj) {
254             progressStyle.styleResource.borderWidthRawPtr = AceType::RawPtr(resObj);
255             resObj->IncRefCount();
256         }
257     }
258     if (borderWidth.IsNegative()) {
259         progressStyle.borderWidthValue = DEFAULT_BORDER_WIDTH;
260         progressStyle.borderWidthUnit = static_cast<uint8_t>(DimensionUnit::VP);
261     } else {
262         progressStyle.borderWidthValue = borderWidth.Value();
263         progressStyle.borderWidthUnit = static_cast<uint8_t>(borderWidth.Unit());
264     }
265 }
266 
ParseScaleCount(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)267 void ParseScaleCount(
268     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
269 {
270     Local<JSValueRef> scaleCountArg = runtimeCallInfo->GetCallArgRef(index);
271     int32_t scaleCount = DEFAULT_SCALE_COUNT;
272     auto theme = ArkTSUtils::GetTheme<ProgressTheme>();
273     if (theme) {
274         scaleCount = theme->GetScaleNumber();
275     }
276 
277     if (scaleCountArg->IsNull() || !ArkTSUtils::ParseJsInteger(vm, scaleCountArg, scaleCount)) {
278         scaleCount = DEFAULT_SCALE_COUNT;
279     }
280     if (scaleCount > 1) {
281         progressStyle.scaleCount = scaleCount;
282     } else if (theme) {
283         progressStyle.scaleCount = theme->GetScaleNumber();
284     }
285 }
286 
ParseProgressStatus(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)287 void ParseProgressStatus(
288     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
289 {
290     Local<JSValueRef> ProgressStatusArg = runtimeCallInfo->GetCallArgRef(index);
291     NG::ProgressStatus progressStatus = DEFAULT_PROGRESS_STATUS;
292     std::string statusStr;
293     if (ProgressStatusArg->IsUndefined() || ProgressStatusArg->IsNull() ||
294         !ArkTSUtils::ParseJsString(vm, ProgressStatusArg, statusStr)) {
295         progressStatus = DEFAULT_PROGRESS_STATUS;
296     } else {
297         if (statusStr.compare("LOADING") == 0) {
298             progressStatus = NG::ProgressStatus::LOADING;
299         } else {
300             progressStatus = NG::ProgressStatus::PROGRESSING;
301         }
302     }
303     progressStyle.status = static_cast<int8_t>(progressStatus);
304 }
305 
ParseScaleWidth(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)306 void ParseScaleWidth(
307     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
308 {
309     Local<JSValueRef> scaleWidthArg = runtimeCallInfo->GetCallArgRef(index);
310     CalcDimension scaleWidth = CalcDimension(DEFAULT_SCALE_WIDTH, DimensionUnit::VP);
311 
312     if (scaleWidthArg->IsString(vm)) {
313         const std::string& value = scaleWidthArg->ToString(vm)->ToString(vm);
314         scaleWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, DEFAULT_SCALE_WIDTH);
315     } else {
316         RefPtr<ResourceObject> resObj;
317         ArkTSUtils::ParseJsDimension(vm, scaleWidthArg, scaleWidth, DimensionUnit::VP, resObj, false);
318         if (resObj) {
319             progressStyle.styleResource.scaleWidthRawPtr = AceType::RawPtr(resObj);
320             resObj->IncRefCount();
321         }
322     }
323     if (scaleWidth.IsNegative()) {
324         scaleWidth = CalcDimension(DEFAULT_SCALE_WIDTH, DimensionUnit::VP);
325     }
326 
327     progressStyle.scaleWidthValue = scaleWidth.Value();
328     progressStyle.scaleWidthUnit = static_cast<uint8_t>(scaleWidth.Unit());
329 }
330 
ParseStrokeRadius(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)331 void ParseStrokeRadius(
332     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
333 {
334     Local<JSValueRef> strokeRadiusArg = runtimeCallInfo->GetCallArgRef(index);
335     CalcDimension strokeRadius = CalcDimension(DEFAULT_STROKE_RADIUS, DimensionUnit::PERCENT);
336     if (strokeRadiusArg->IsNull() ||
337         !ArkTSUtils::ParseJsDimension(vm, strokeRadiusArg, strokeRadius, DimensionUnit::VP, true)) {
338         strokeRadius.SetUnit(DimensionUnit::PERCENT);
339     }
340 
341     progressStyle.strokeRadiusValue = strokeRadius.Value();
342     progressStyle.strokeRadiusUnit = static_cast<uint8_t>(strokeRadius.Unit());
343 }
344 
ParseBorderColor(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index,const NodeInfo & nodeInfo)345 void ParseBorderColor(
346     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index,
347     const NodeInfo& nodeInfo)
348 {
349     Local<JSValueRef> borderColorArg = runtimeCallInfo->GetCallArgRef(index);
350     Color borderColor = DEFAULT_BORDER_COLOR;
351     RefPtr<ResourceObject> resObj;
352     if (borderColorArg->IsNull() || !ArkTSUtils::ParseJsColorAlpha(vm, borderColorArg, borderColor, resObj, nodeInfo)) {
353         borderColor = DEFAULT_BORDER_COLOR;
354     }
355 
356     if (resObj) {
357         progressStyle.styleResource.borderColorRawPtr = AceType::RawPtr(resObj);
358         resObj->IncRefCount();
359     }
360 
361     progressStyle.borderColor = borderColor.GetValue();
362 }
363 
ParseFontColor(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index,const NodeInfo & nodeInfo)364 void ParseFontColor(
365     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index,
366     const NodeInfo& nodeInfo)
367 {
368     Local<JSValueRef> fontColorArg = runtimeCallInfo->GetCallArgRef(index);
369     auto theme = ArkTSUtils::GetTheme<ProgressTheme>();
370     Color fontColor = theme->GetTextColor();
371 
372     RefPtr<ResourceObject> colorResObj;
373     if (fontColorArg->IsNull() || !ArkTSUtils::ParseJsColorAlpha(vm, fontColorArg, fontColor, colorResObj, nodeInfo)) {
374         fontColor = theme->GetTextColor();
375         progressStyle.fontColorSetByUser = false;
376     } else {
377         progressStyle.fontColorSetByUser = true;
378     }
379     if (colorResObj) {
380         progressStyle.styleResource.fontColorRawPtr = AceType::RawPtr(colorResObj);
381         colorResObj->IncRefCount();
382     }
383 
384     progressStyle.fontColor = fontColor.GetValue();
385 }
386 
ParseEnableSmoothEffect(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)387 void ParseEnableSmoothEffect(
388     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
389 {
390     Local<JSValueRef> enableSmoothEffectArg = runtimeCallInfo->GetCallArgRef(index);
391     progressStyle.enableSmoothEffect =
392         (enableSmoothEffectArg->IsBoolean()) ? enableSmoothEffectArg->ToBoolean(vm)->Value() : true;
393 }
394 
ParseContent(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)395 void ParseContent(
396     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
397 {
398     Local<JSValueRef> contentArg = runtimeCallInfo->GetCallArgRef(index);
399     std::string content = contentArg->ToString(vm)->ToString(vm);
400     progressStyle.content = (contentArg->IsString(vm)) ? content.c_str() : nullptr;
401 }
402 
ParseEnableScanEffect(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)403 void ParseEnableScanEffect(
404     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
405 {
406     Local<JSValueRef> enableScanEffectArg = runtimeCallInfo->GetCallArgRef(index);
407     progressStyle.enableScanEffect =
408         (enableScanEffectArg->IsBoolean()) ? enableScanEffectArg->ToBoolean(vm)->Value() : false;
409 }
410 
ParseShadow(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)411 void ParseShadow(
412     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
413 {
414     Local<JSValueRef> shadowArg = runtimeCallInfo->GetCallArgRef(index);
415     progressStyle.shadow = (shadowArg->IsBoolean()) ? shadowArg->ToBoolean(vm)->Value() : false;
416 }
417 
ParseShowDefaultPercentage(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)418 void ParseShowDefaultPercentage(
419     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
420 {
421     Local<JSValueRef> showDefaultPercentageArg = runtimeCallInfo->GetCallArgRef(index);
422     progressStyle.showDefaultPercentage =
423         (showDefaultPercentageArg->IsBoolean()) ? showDefaultPercentageArg->ToBoolean(vm)->Value() : false;
424 }
425 
ParseCapsuleFontSize(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)426 void ParseCapsuleFontSize(
427     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
428 {
429     Local<JSValueRef> sizeArg = runtimeCallInfo->GetCallArgRef(index);
430 
431     CalcDimension fontSize;
432     RefPtr<ResourceObject> resObj;
433     if (sizeArg->IsNull() || !ArkTSUtils::ParseJsDimensionFp(vm, sizeArg, fontSize, resObj) || fontSize.IsNegative() ||
434         fontSize.Unit() == DimensionUnit::PERCENT) {
435         progressStyle.fontInfo.fontSizeNumber = DEFAULT_CAPSULE_FONT_SIZE;
436         progressStyle.fontInfo.fontSizeUnit = static_cast<int8_t>(DEFAULT_CAPSULE_FONT_UNIT);
437     } else {
438         progressStyle.fontInfo.fontSizeNumber = fontSize.Value();
439         progressStyle.fontInfo.fontSizeUnit = static_cast<int8_t>(fontSize.Unit());
440         if (resObj) {
441             progressStyle.styleResource.fontResource.fontSizeRawPtr = AceType::RawPtr(resObj);
442             resObj->IncRefCount();
443         }
444     }
445 }
446 
ParseCapsuleFontWeight(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)447 void ParseCapsuleFontWeight(
448     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
449 {
450     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(index);
451     auto pipelineContext = PipelineContext::GetCurrentContext();
452     CHECK_NULL_VOID(pipelineContext);
453     auto theme = pipelineContext->GetTheme<TextTheme>();
454 
455     std::string weight;
456     if (!weightArg->IsNull()) {
457         if (weightArg->IsNumber()) {
458             weight = std::to_string(weightArg->Int32Value(vm));
459         } else if (weightArg->IsString(vm)) {
460             weight = weightArg->ToString(vm)->ToString(vm);
461         }
462         progressStyle.fontInfo.fontWeight = static_cast<uint8_t>(Framework::ConvertStrToFontWeight(weight));
463     } else {
464         progressStyle.fontInfo.fontWeight = static_cast<uint8_t>(theme->GetTextStyle().GetFontWeight());
465     }
466 }
467 
ParseCapsuleFontStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)468 void ParseCapsuleFontStyle(
469     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
470 {
471     Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(index);
472     auto pipelineContext = PipelineContext::GetCurrentContext();
473     CHECK_NULL_VOID(pipelineContext);
474     auto theme = pipelineContext->GetTheme<TextTheme>();
475 
476     uint8_t style = static_cast<uint8_t>(theme->GetTextStyle().GetFontStyle());
477     if (!styleArg->IsNull() && styleArg->IsInt()) {
478         style = static_cast<uint8_t>(styleArg->Int32Value(vm));
479         if (style <= 0 || style > static_cast<uint8_t>(FONT_STYLES.size())) {
480             style = static_cast<uint8_t>(theme->GetTextStyle().GetFontStyle());
481         }
482     }
483 
484     progressStyle.fontInfo.fontStyle = style;
485 }
486 
ParseCapsuleFontFamily(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,std::vector<std::string> & fontFamilies,std::unique_ptr<const char * []> & families)487 void ParseCapsuleFontFamily(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle,
488     std::vector<std::string>& fontFamilies, std::unique_ptr<const char*[]>& families)
489 {
490     Local<JSValueRef> familyArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_STYLE_FONT_FAMILY);
491     auto pipelineContext = PipelineContext::GetCurrentContext();
492     CHECK_NULL_VOID(pipelineContext);
493     auto theme = pipelineContext->GetTheme<TextTheme>();
494 
495     if (familyArg->IsNull() || !ArkTSUtils::ParseJsFontFamilies(vm, familyArg, fontFamilies)) {
496         fontFamilies = theme->GetTextStyle().GetFontFamilies();
497     }
498 
499     families.reset();
500     families = std::make_unique<const char* []>(fontFamilies.size());
501     for (uint32_t i = 0; i < fontFamilies.size(); i++) {
502         families[i] = fontFamilies[i].c_str();
503     }
504 
505     progressStyle.fontInfo.fontFamilies = families.get();
506     progressStyle.fontInfo.familyLength = fontFamilies.size();
507 }
508 
ParseBorderRadius(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,int32_t index)509 void ParseBorderRadius(
510     const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle, int32_t index)
511 {
512     Local<JSValueRef> borderRadiusArg = runtimeCallInfo->GetCallArgRef(index);
513     CalcDimension borderRadius = CalcDimension(DEFAULT_BORDER_RADIUS, DimensionUnit::PERCENT);
514     if (borderRadiusArg->IsNull() || !ArkTSUtils::ParseJsLengthMetrics(vm, borderRadiusArg, borderRadius)) {
515         // Set illegal units, and the background will be handled according to the default value.
516         borderRadius.SetUnit(DimensionUnit::PERCENT);
517     }
518     progressStyle.borderRadiusValue = borderRadius.Value();
519     progressStyle.borderRadiusUnit = static_cast<uint8_t>(borderRadius.Unit());
520 }
521 
ParseLinearStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle)522 void ParseLinearStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle)
523 {
524     ParseStrokeWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_WIDTH);
525     ParseStrokeRadius(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_RADIUS);
526     ParseEnableScanEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SCAN_EFFECT);
527     ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
528 }
529 
ParseRingStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle)530 void ParseRingStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle)
531 {
532     ParseStrokeWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_WIDTH);
533     ParseShadow(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SHADOW);
534     ParseProgressStatus(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_PROGRESS_STATUS);
535     ParseEnableScanEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SCAN_EFFECT);
536     ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
537 }
538 
ParseCapsuleStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle,std::vector<std::string> & fontFamilies,std::unique_ptr<const char * []> & families,const NodeInfo & nodeInfo)539 void ParseCapsuleStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle,
540     std::vector<std::string>& fontFamilies, std::unique_ptr<const char*[]>& families, const NodeInfo& nodeInfo)
541 {
542     ParseBorderColor(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_BORDER_COLOR, nodeInfo);
543     ParseBorderWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_BORDER_WIDTH);
544     ParseFontColor(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_COLOR, nodeInfo);
545     ParseCapsuleFontSize(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_SIZE);
546     ParseCapsuleFontWeight(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_WEIGHT);
547     ParseCapsuleFontStyle(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_FONT_STYLE);
548     ParseCapsuleFontFamily(vm, runtimeCallInfo, progressStyle, fontFamilies, families);
549     ParseEnableScanEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SCAN_EFFECT);
550     ParseShowDefaultPercentage(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SHOW_DEFAULT_PERCENTAGE);
551     ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
552     ParseBorderRadius(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_BORDER_RADIUS);
553 }
554 
ParseProgressStyle(const EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUIProgressStyle & progressStyle)555 void ParseProgressStyle(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUIProgressStyle& progressStyle)
556 {
557     auto progressTheme = ArkTSUtils::GetTheme<ProgressTheme>();
558     CHECK_NULL_VOID(progressTheme);
559     ParseStrokeWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_STROKE_WIDTH);
560     ParseScaleCount(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SCALE_COUNT);
561     ParseScaleWidth(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_SCALE_WIDTH);
562     if ((progressStyle.scaleWidthValue <= 0.0) || (progressStyle.scaleWidthValue > progressStyle.strokeWidthValue) ||
563         progressStyle.scaleWidthUnit == static_cast<int8_t>(DimensionUnit::PERCENT)) {
564         progressStyle.scaleWidthValue = progressTheme->GetScaleWidth().Value();
565         progressStyle.scaleWidthUnit = static_cast<int8_t>(progressTheme->GetScaleWidth().Unit());
566     }
567     ParseEnableSmoothEffect(vm, runtimeCallInfo, progressStyle, ARG_NUM_STYLE_ENABLE_SMOOTH_EFFECT);
568 }
569 
SetProgressStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)570 ArkUINativeModuleValue ProgressBridge::SetProgressStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
571 {
572     EcmaVM* vm = runtimeCallInfo->GetVM();
573     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
574     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_NATIVE_NODE);
575     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
576     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
577     auto pipelineContext = PipelineContext::GetCurrentContext();
578     CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
579     auto theme = pipelineContext->GetTheme<TextTheme>();
580 
581     auto fontFamilies = theme->GetTextStyle().GetFontFamilies();
582     auto families = std::make_unique<const char* []>(fontFamilies.size());
583     for (uint32_t i = 0; i < fontFamilies.size(); i++) {
584         families[i] = fontFamilies[i].c_str();
585     }
586     auto progressTheme = ArkTSUtils::GetTheme<ProgressTheme>();
587 
588     ArkUIProgressStyle progressStyle = { DEFAULT_STROKE_WIDTH, static_cast<int8_t>(DimensionUnit::VP),
589         DEFAULT_BORDER_WIDTH, static_cast<int8_t>(DimensionUnit::VP), DEFAULT_SCALE_COUNT,
590         static_cast<uint8_t>(DEFAULT_PROGRESS_STATUS), DEFAULT_SCALE_WIDTH, static_cast<int8_t>(DimensionUnit::VP),
591         DEFAULT_STROKE_RADIUS, static_cast<int8_t>(DimensionUnit::PERCENT), true,
592         static_cast<ArkUI_Uint32>(DEFAULT_BORDER_COLOR.GetValue()), nullptr,
593         static_cast<ArkUI_Uint32>(progressTheme->GetTextColor().GetValue()), false, false, false, false,
594         { DEFAULT_CAPSULE_FONT_SIZE, static_cast<int8_t>(DEFAULT_CAPSULE_FONT_UNIT),
595             static_cast<uint8_t>(theme->GetTextStyle().GetFontWeight()),
596             static_cast<uint8_t>(theme->GetTextStyle().GetFontStyle()), families.get(), fontFamilies.size() } };
597 
598     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
599     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
600     auto progressLayoutProperty = frameNode->GetLayoutProperty<ProgressLayoutProperty>();
601     CHECK_NULL_RETURN(progressLayoutProperty, panda::JSValueRef::Undefined(vm));
602     Local<JSValueRef> contentArg = runtimeCallInfo->GetCallArgRef(ARG_NUM_STYLE_CONTENT);
603     std::string content;
604     RefPtr<ResourceObject> contentResObj;
605     ArkTSUtils::ParseJsString(vm, contentArg, content, contentResObj);
606     if (contentResObj) {
607         progressStyle.styleResource.contentRawPtr = AceType::RawPtr(contentResObj);
608     }
609     auto progresstype = progressLayoutProperty->GetType();
610     if (progresstype == ProgressType::LINEAR) {
611         ParseLinearStyle(vm, runtimeCallInfo, progressStyle);
612     } else if (progresstype == ProgressType::RING) {
613         ParseRingStyle(vm, runtimeCallInfo, progressStyle);
614     } else if (progresstype == ProgressType::CAPSULE) {
615         auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
616         ParseCapsuleStyle(vm, runtimeCallInfo, progressStyle, fontFamilies, families, nodeInfo);
617         progressStyle.content = (contentArg->IsString(vm) || contentArg->IsObject(vm)) ? content.c_str() : nullptr;
618     } else {
619         ParseProgressStyle(vm, runtimeCallInfo, progressStyle);
620     }
621     auto nodeModifiers = GetArkUINodeModifiers();
622     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
623     nodeModifiers->getProgressModifier()->setProgressStyle(nativeNode, &progressStyle);
624     return panda::JSValueRef::Undefined(vm);
625 }
626 
SetProgressBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)627 ArkUINativeModuleValue ProgressBridge::SetProgressBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
628 {
629     EcmaVM *vm = runtimeCallInfo->GetVM();
630     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
631     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
632     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
633     CHECK_NULL_RETURN(nativeNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
634     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
635     Color color;
636     auto nodeModifiers = GetArkUINodeModifiers();
637     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
638     RefPtr<ResourceObject> resObj;
639     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
640     if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color, resObj, nodeInfo)) {
641         nodeModifiers->getProgressModifier()->resetProgressBackgroundColor(nativeNode);
642     } else {
643         auto colorRawPtr = AceType::RawPtr(resObj);
644         nodeModifiers->getProgressModifier()->setProgressBackgroundColorWithColorSpace(
645             nativeNode, color.GetValue(), color.GetColorSpace(), colorRawPtr);
646     }
647 
648     return panda::JSValueRef::Undefined(vm);
649 }
650 
ResetProgressBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)651 ArkUINativeModuleValue ProgressBridge::ResetProgressBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
652 {
653     EcmaVM* vm = runtimeCallInfo->GetVM();
654     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
655     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
656     CHECK_NULL_RETURN(nativeNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
657     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
658     auto nodeModifiers = GetArkUINodeModifiers();
659     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
660     nodeModifiers->getProgressModifier()->resetProgressBackgroundColor(nativeNode);
661     return panda::JSValueRef::Undefined(vm);
662 }
663 
SetContentModifierBuilder(ArkUIRuntimeCallInfo * runtimeCallInfo)664 ArkUINativeModuleValue ProgressBridge::SetContentModifierBuilder(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     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
670     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
671     auto* frameNode = reinterpret_cast<FrameNode*>(firstArg->ToNativePointer(vm)->Value());
672     if (!secondArg->IsObject(vm)) {
673         ProgressModelNG::SetBuilderFunc(frameNode, nullptr);
674         return panda::JSValueRef::Undefined(vm);
675     }
676     panda::CopyableGlobal<panda::ObjectRef> obj(vm, secondArg);
677     ProgressModelNG::SetBuilderFunc(frameNode, [vm, frameNode, obj = std::move(obj),
678         containerId = Container::CurrentId()](ProgressConfiguration config) -> RefPtr<FrameNode> {
679         ContainerScope scope(containerId);
680         auto context = ArkTSUtils::GetContext(vm);
681         CHECK_EQUAL_RETURN(context->IsUndefined(), true, nullptr);
682         const char* keysOfProgress[] = { "value", "total", "enabled"};
683         Local<JSValueRef> valuesOfProgress[] = { panda::NumberRef::New(vm, config.value_),
684             panda::NumberRef::New(vm, config.total_), panda::BooleanRef::New(vm, config.enabled_)};
685         auto progress = panda::ObjectRef::NewWithNamedProperties(vm,
686             ArraySize(keysOfProgress), keysOfProgress, valuesOfProgress);
687         progress->SetNativePointerFieldCount(vm, 1);
688         progress->SetNativePointerField(vm, 0, static_cast<void*>(frameNode));
689         panda::Local<panda::JSValueRef> params[ARG_SECOND] = { context, progress };
690         LocalScope pandaScope(vm);
691         panda::TryCatch trycatch(vm);
692         auto jsObject = obj.ToLocal();
693         auto makeFunc = jsObject->Get(vm, panda::StringRef::NewFromUtf8(vm, "makeContentModifierNode"));
694         CHECK_NULL_RETURN(makeFunc->IsFunction(vm), nullptr);
695         panda::Local<panda::FunctionRef> func = makeFunc;
696         auto result = func->Call(vm, jsObject, params, 2);
697         JSNApi::ExecutePendingJob(vm);
698         if (result.IsEmpty() || trycatch.HasCaught() || !result->IsObject(vm)) {
699             return nullptr;
700         }
701         auto resultObj = result->ToObject(vm);
702         panda::Local<panda::JSValueRef> nodeptr = resultObj->Get(vm, panda::StringRef::NewFromUtf8(vm,
703             PROGRESS_NODEPTR_OF_UINODE));
704         if (nodeptr.IsEmpty() || nodeptr->IsUndefined() || nodeptr->IsNull()) {
705             return nullptr;
706         }
707         auto* frameNode = reinterpret_cast<FrameNode*>(nodeptr->ToNativePointer(vm)->Value());
708         CHECK_NULL_RETURN(frameNode, nullptr);
709         return AceType::Claim(frameNode);
710     });
711     return panda::JSValueRef::Undefined(vm);
712 }
713 
ResetProgressInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)714 ArkUINativeModuleValue ProgressBridge::ResetProgressInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
715 {
716     EcmaVM* vm = runtimeCallInfo->GetVM();
717     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
718     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
719     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
720     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
721     auto nodeModifiers = GetArkUINodeModifiers();
722     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
723     nodeModifiers->getProgressModifier()->resetProgressInitialize(nativeNode);
724     return panda::JSValueRef::Undefined(vm);
725 }
726 
SetProgressInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)727 ArkUINativeModuleValue ProgressBridge::SetProgressInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
728 {
729     EcmaVM* vm = runtimeCallInfo->GetVM();
730     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
731     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
732     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
733     Local<JSValueRef> totalArg = runtimeCallInfo->GetCallArgRef(2);
734     Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(3);
735     Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(4);
736     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
737     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
738     auto value = 0;
739     if (valueArg->IsNumber()) {
740         value = valueArg->ToNumber(vm)->Value();
741     }
742     auto total = 100;
743     if (totalArg->IsNumber() && totalArg->ToNumber(vm)->Value() > 0) {
744         total = totalArg->Int32Value(vm);
745     }
746     if (value > total) {
747         value = total;
748     } else if (value < 0) {
749         value = 0;
750     }
751     auto type = 0;
752     if (styleArg->IsNull() || styleArg->IsUndefined()) {
753         if (typeArg->IsNumber()) {
754             type = typeArg->Int32Value(vm);
755         }
756     } else if (styleArg->IsNumber()) {
757         type = styleArg->Int32Value(vm);
758     }
759     auto progressStyle = static_cast<Framework::ProgressStyle>(type);
760     ProgressType g_progressType = NG::ProgressType::LINEAR;
761     if (progressStyle == Framework::ProgressStyle::Eclipse) {
762         g_progressType = NG::ProgressType::MOON;
763     } else if (progressStyle == Framework::ProgressStyle::Ring) {
764         g_progressType = NG::ProgressType::RING;
765     } else if (progressStyle == Framework::ProgressStyle::ScaleRing) {
766         g_progressType = NG::ProgressType::SCALE;
767     } else if (progressStyle == Framework::ProgressStyle::Capsule) {
768         g_progressType = NG::ProgressType::CAPSULE;
769     }
770     auto nodeModifiers = GetArkUINodeModifiers();
771     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
772     nodeModifiers->getProgressModifier()->setProgressInitialize(
773         nativeNode, value, total, static_cast<int>(g_progressType));
774     return panda::JSValueRef::Undefined(vm);
775 }
776 
SetProgressPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)777 ArkUINativeModuleValue ProgressBridge::SetProgressPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
778 {
779     EcmaVM* vm = runtimeCallInfo->GetVM();
780     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
781     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
782     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
783     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
784     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
785     uint32_t sensitive = false;
786     if (secondArg->IsBoolean()) {
787         sensitive = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
788     }
789     auto nodeModifiers = GetArkUINodeModifiers();
790     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
791     nodeModifiers->getCommonModifier()->setPrivacySensitive(nativeNode, sensitive);
792     return panda::JSValueRef::Undefined(vm);
793 }
794 
ResetProgressPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)795 ArkUINativeModuleValue ProgressBridge::ResetProgressPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
796 {
797     EcmaVM* vm = runtimeCallInfo->GetVM();
798     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
799     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
800     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
801     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
802     auto nodeModifiers = GetArkUINodeModifiers();
803     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
804     nodeModifiers->getCommonModifier()->resetPrivacySensitive(nativeNode);
805     return panda::JSValueRef::Undefined(vm);
806 }
807 } // namespace OHOS::Ace::NG
808