1
2 /*
3 * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "core/interfaces/native/node/progress_modifier.h"
18
19 #include "core/components_ng/pattern/progress/progress_paint_property.h"
20 #include "core/components_ng/pattern/progress/progress_layout_property.h"
21 #include "core/components_ng/pattern/progress/progress_model_ng.h"
22 #include "core/components/select/select_theme.h"
23 #include "core/pipeline_ng/pipeline_context.h"
24
25 namespace OHOS::Ace::NG {
26 constexpr double DEFAULT_PROGRESS_VALUE = 0;
27 constexpr double DEFAULT_PROGRESS_TOTAL = 100;
28 constexpr int32_t MIN_COLOR_STOPS_VALUE_INDEX = 0;
29 constexpr int32_t MIN_COLOR_STOPS_HAS_DIMENSION_INDEX = 1;
30 constexpr int32_t MIN_COLOR_STOPS_DIMENSION_INDEX = 2;
31 constexpr int32_t MIN_COLOR_STOPS_LENGTH = 3;
32 constexpr double PERCENT_100 = 100;
33 constexpr int32_t DEFAULT_SCALE_COUNT = 120;
34 constexpr double DEFAULT_STROKE_WIDTH = 4;
35 constexpr double DEFAULT_BORDER_WIDTH = 1;
36 constexpr double DEFAULT_SCALE_WIDTHS = 2;
37 constexpr double DEFAULT_FONT_SIZE = 12;
38 const uint32_t ERROR_UINT_CODE = -1;
39 const float ERROR_FLOAT_CODE = -1.0f;
40 const int32_t ERROR_INT_CODE = -1;
41 constexpr float STROKEWIDTH_DEFAULT_VALUE = 4.0f;
42 constexpr ArkUI_Uint32 MAX_FONT_FAMILY_LENGTH = Infinity<ArkUI_Uint32>();
43
44 /**
45 * @param colors color value
46 * colors[0], colors[1], colors[2] : color[0](color, hasDimension, dimension)
47 * colors[3], colors[4], colors[5] : color[1](color, hasDimension, dimension)
48 * ...
49 * @param colorsLength colors length
50 */
SetGradientColors(NG::Gradient & gradient,const ArkUI_Float32 * colors,int32_t colorsLength)51 void SetGradientColors(NG::Gradient& gradient, const ArkUI_Float32* colors, int32_t colorsLength)
52 {
53 if ((colors == nullptr) || (colorsLength % MIN_COLOR_STOPS_LENGTH) != 0) {
54 return;
55 }
56 for (int32_t index = 0; index < colorsLength; index += MIN_COLOR_STOPS_LENGTH) {
57 auto colorValue = colors[index + MIN_COLOR_STOPS_VALUE_INDEX];
58 auto colorHasDimension = colors[index + MIN_COLOR_STOPS_HAS_DIMENSION_INDEX];
59 auto colorDimension = colors[index + MIN_COLOR_STOPS_DIMENSION_INDEX];
60 auto color = static_cast<uint32_t>(colorValue);
61 auto hasDimension = static_cast<bool>(colorHasDimension);
62 auto dimension = colorDimension;
63 NG::GradientColor gradientColor;
64 gradientColor.SetColor(Color(color));
65 gradientColor.SetHasValue(hasDimension);
66 if (hasDimension) {
67 gradientColor.SetDimension(CalcDimension(dimension * PERCENT_100, DimensionUnit::PERCENT));
68 }
69 gradient.AddColor(gradientColor);
70 }
71 }
72
SetProgressValue(ArkUINodeHandle node,ArkUI_Float32 value)73 void SetProgressValue(ArkUINodeHandle node, ArkUI_Float32 value)
74 {
75 auto* frameNode = reinterpret_cast<FrameNode*>(node);
76 CHECK_NULL_VOID(frameNode);
77 ProgressModelNG::SetValue(frameNode, value);
78 }
79
ResetProgressValue(ArkUINodeHandle node)80 void ResetProgressValue(ArkUINodeHandle node)
81 {
82 auto* frameNode = reinterpret_cast<FrameNode*>(node);
83 CHECK_NULL_VOID(frameNode);
84 ProgressModelNG::SetValue(frameNode, DEFAULT_PROGRESS_VALUE);
85 ProgressModelNG::SetTotal(frameNode, DEFAULT_PROGRESS_TOTAL);
86 }
87
88
SetProgressTotal(ArkUINodeHandle node,ArkUI_Float32 value)89 void SetProgressTotal(ArkUINodeHandle node, ArkUI_Float32 value)
90 {
91 auto* frameNode = reinterpret_cast<FrameNode*>(node);
92 CHECK_NULL_VOID(frameNode);
93 ProgressModelNG::SetTotal(frameNode, value);
94 }
95
SetProgressType(ArkUINodeHandle node,int type)96 void SetProgressType(ArkUINodeHandle node, int type)
97 {
98 auto* frameNode = reinterpret_cast<FrameNode*>(node);
99 CHECK_NULL_VOID(frameNode);
100 ProgressModelNG::SetType(frameNode, static_cast<ProgressType>(type));
101 }
102
ResetProgressType(ArkUINodeHandle node)103 void ResetProgressType(ArkUINodeHandle node)
104 {
105 auto* frameNode = reinterpret_cast<FrameNode*>(node);
106 CHECK_NULL_VOID(frameNode);
107 ProgressModelNG::SetType(frameNode, ProgressType::LINEAR);
108 }
109
SetProgressGradientColor(ArkUINodeHandle node,const struct ArkUIGradientType * gradient,int32_t length)110 void SetProgressGradientColor(ArkUINodeHandle node, const struct ArkUIGradientType* gradient, int32_t length)
111 {
112 auto* frameNode = reinterpret_cast<FrameNode*>(node);
113 CHECK_NULL_VOID(frameNode);
114 OHOS::Ace::NG::Gradient tempGradient;
115 for (int32_t j = 0; j < length; j++) {
116 OHOS::Ace::NG::GradientColor gradientColor;
117 gradientColor.SetLinearColor(LinearColor(Color(gradient->color[j])));
118 gradientColor.SetDimension(
119 Dimension(gradient->offset[j].number, static_cast<DimensionUnit>(gradient->offset[j].unit)));
120 tempGradient.AddColor(gradientColor);
121 }
122
123 ProgressModelNG::SetGradientColor(frameNode, tempGradient);
124 ProgressModelNG::SetGradientColorByUser(frameNode, true);
125 }
126
SetProgressColor(ArkUINodeHandle node,uint32_t color)127 void SetProgressColor(ArkUINodeHandle node, uint32_t color)
128 {
129 auto *frameNode = reinterpret_cast<FrameNode *>(node);
130 CHECK_NULL_VOID(frameNode);
131 NG::Gradient gradient;
132 NG::GradientColor endSideColor;
133 NG::GradientColor beginSideColor;
134 endSideColor.SetLinearColor(LinearColor(Color(color)));
135 endSideColor.SetDimension(Dimension(0.0));
136 beginSideColor.SetLinearColor(LinearColor(Color(color)));
137 beginSideColor.SetDimension(Dimension(1.0));
138 gradient.AddColor(endSideColor);
139 gradient.AddColor(beginSideColor);
140 ProgressModelNG::SetGradientColor(frameNode, gradient);
141 ProgressModelNG::SetModifierInitiatedColor(frameNode, true);
142 ProgressModelNG::SetColor(frameNode, Color(color));
143 }
144
CreateWithResourceObjIfNeeded(FrameNode * node,JsProgressResourceType type,void * rawPtr,bool needDecRef=true)145 void CreateWithResourceObjIfNeeded(FrameNode* node, JsProgressResourceType type, void* rawPtr, bool needDecRef = true)
146 {
147 if (!SystemProperties::ConfigChangePerform()) {
148 return;
149 }
150 if (rawPtr) {
151 auto* obj = reinterpret_cast<ResourceObject*>(rawPtr);
152 if (obj != nullptr) {
153 auto resObj = AceType::Claim(obj);
154 if (resObj) {
155 ProgressModelNG::CreateWithResourceObj(node, type, resObj);
156 }
157 if (needDecRef) {
158 obj->DecRefCount();
159 }
160 }
161 } else {
162 ProgressModelNG::CreateWithResourceObj(node, type, nullptr);
163 }
164 }
165
SetProgressColorPtr(ArkUINodeHandle node,uint32_t color,void * colorRawPtr)166 void SetProgressColorPtr(ArkUINodeHandle node, uint32_t color, void* colorRawPtr)
167 {
168 auto *frameNode = reinterpret_cast<FrameNode *>(node);
169 CHECK_NULL_VOID(frameNode);
170 NG::Gradient gradient;
171 NG::GradientColor endSideColor;
172 NG::GradientColor beginSideColor;
173 endSideColor.SetLinearColor(LinearColor(Color(color)));
174 endSideColor.SetDimension(Dimension(0.0));
175 beginSideColor.SetLinearColor(LinearColor(Color(color)));
176 beginSideColor.SetDimension(Dimension(1.0));
177 gradient.AddColor(endSideColor);
178 gradient.AddColor(beginSideColor);
179 ProgressModelNG::SetGradientColor(frameNode, gradient);
180 ProgressModelNG::SetModifierInitiatedColor(frameNode, true);
181 ProgressModelNG::SetColor(frameNode, Color(color));
182 CreateWithResourceObjIfNeeded(frameNode, JsProgressResourceType::COLOR, colorRawPtr, false);
183 ProgressModelNG::SetGradientColorByUser(frameNode, true);
184 }
185
ResetProgressColor(ArkUINodeHandle node)186 void ResetProgressColor(ArkUINodeHandle node)
187 {
188 auto* frameNode = reinterpret_cast<FrameNode*>(node);
189 CHECK_NULL_VOID(frameNode);
190 Color endColor;
191 Color beginColor;
192 Color colorVal;
193 auto progressLayoutProperty = frameNode->GetLayoutProperty<ProgressLayoutProperty>();
194 CHECK_NULL_VOID(progressLayoutProperty);
195 auto progresstype = progressLayoutProperty->GetType();
196 auto pipeline = PipelineBase::GetCurrentContext();
197 CHECK_NULL_VOID(pipeline);
198 auto progressTheme = pipeline->GetTheme<ProgressTheme>();
199 CHECK_NULL_VOID(progressTheme);
200 bool isGradientColor = false;
201 if (progresstype == ProgressType::RING) {
202 endColor = progressTheme->GetRingProgressEndSideColor();
203 beginColor = progressTheme->GetRingProgressBeginSideColor();
204 isGradientColor = true;
205 } else if (progresstype == ProgressType::CAPSULE) {
206 colorVal = progressTheme->GetCapsuleParseFailedSelectColor();
207 } else {
208 colorVal = progressTheme->GetTrackParseFailedSelectedColor();
209 }
210
211 OHOS::Ace::NG::Gradient gradient;
212 OHOS::Ace::NG::GradientColor endSideColor;
213 OHOS::Ace::NG::GradientColor beginSideColor;
214 endSideColor.SetLinearColor(LinearColor(endColor));
215 endSideColor.SetDimension(Dimension(0.0f));
216 beginSideColor.SetLinearColor(LinearColor(beginColor));
217 beginSideColor.SetDimension(Dimension(1.0f));
218 gradient.AddColor(endSideColor);
219 gradient.AddColor(beginSideColor);
220 ProgressModelNG::SetGradientColor(frameNode, gradient);
221 ProgressModelNG::SetModifierInitiatedColor(frameNode, false);
222 ProgressModelNG::SetColor(frameNode, colorVal);
223 RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
224 ProgressModelNG::CreateWithResourceObj(frameNode, JsProgressResourceType::COLOR, resObj);
225 ProgressModelNG::SetGradientColorByUser(frameNode, isGradientColor);
226 }
227
SetLinearStyleOptions(FrameNode * node,ArkUIProgressStyle * value)228 void SetLinearStyleOptions(FrameNode* node, ArkUIProgressStyle* value)
229 {
230 if ((value->strokeWidthValue < 0) ||
231 (static_cast<DimensionUnit>(value->strokeWidthUnit) == DimensionUnit::PERCENT)) {
232 ProgressModelNG::SetStrokeWidth(node, Dimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP));
233 } else {
234 ProgressModelNG::SetStrokeWidth(
235 node, Dimension(value->strokeWidthValue, static_cast<DimensionUnit>(value->strokeWidthUnit)));
236 }
237 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::LSStrokeWidth, value->styleResource.strokeWidthRawPtr);
238 ProgressModelNG::SetLinearSweepingEffect(node, value->enableScanEffect);
239 if ((value->strokeRadiusValue < 0) ||
240 (static_cast<DimensionUnit>(value->strokeRadiusUnit) == DimensionUnit::PERCENT)) {
241 ProgressModelNG::ResetStrokeRadius(node);
242 } else {
243 ProgressModelNG::SetStrokeRadius(
244 node, Dimension(value->strokeRadiusValue, static_cast<DimensionUnit>(value->strokeRadiusUnit)));
245 }
246 }
247
SetRingStyleOptions(FrameNode * node,ArkUIProgressStyle * value)248 void SetRingStyleOptions(FrameNode* node, ArkUIProgressStyle* value)
249 {
250 if ((value->strokeWidthValue < 0) ||
251 (static_cast<DimensionUnit>(value->strokeWidthUnit) == DimensionUnit::PERCENT)) {
252 ProgressModelNG::SetStrokeWidth(node, Dimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP));
253 } else {
254 ProgressModelNG::SetStrokeWidth(
255 node, Dimension(value->strokeWidthValue, static_cast<DimensionUnit>(value->strokeWidthUnit)));
256 }
257 CreateWithResourceObjIfNeeded(
258 node, JsProgressResourceType::RingStrokeWidth, value->styleResource.strokeWidthRawPtr);
259 ProgressModelNG::SetPaintShadow(node, value->shadow);
260 ProgressModelNG::SetProgressStatus(node, static_cast<ProgressStatus>(value->status));
261 ProgressModelNG::SetRingSweepingEffect(node, value->enableScanEffect);
262 }
263
SetProgressStyleOptions(FrameNode * node,ArkUIProgressStyle * value)264 void SetProgressStyleOptions(FrameNode* node, ArkUIProgressStyle* value)
265 {
266 if ((value->strokeWidthValue < 0) ||
267 (static_cast<DimensionUnit>(value->strokeWidthUnit) == DimensionUnit::PERCENT)) {
268 ProgressModelNG::SetStrokeWidth(node, Dimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP));
269 } else {
270 ProgressModelNG::SetStrokeWidth(
271 node, Dimension(value->strokeWidthValue, static_cast<DimensionUnit>(value->strokeWidthUnit)));
272 CreateWithResourceObjIfNeeded(
273 node, JsProgressResourceType::PSStrokeWidth, value->styleResource.strokeWidthRawPtr);
274 }
275 ProgressModelNG::SetScaleCount(node, value->scaleCount);
276 if ((static_cast<DimensionUnit>(value->scaleWidthUnit) == DimensionUnit::PERCENT) ||
277 (value->scaleWidthValue > value->strokeWidthValue)) {
278 ProgressModelNG::SetScaleWidth(node, Dimension(DEFAULT_SCALE_WIDTHS, DimensionUnit::VP));
279 } else {
280 ProgressModelNG::SetScaleWidth(
281 node, Dimension(value->scaleWidthValue, static_cast<DimensionUnit>(value->scaleWidthUnit)));
282 CreateWithResourceObjIfNeeded(
283 node, JsProgressResourceType::PSScaleWidth, value->styleResource.scaleWidthRawPtr);
284 }
285 }
286
SetCapsuleStyleOptions(FrameNode * node,ArkUIProgressStyle * value)287 void SetCapsuleStyleOptions(FrameNode* node, ArkUIProgressStyle* value)
288 {
289 double fontSizeNumber = value->fontInfo.fontSizeNumber;
290 int8_t fontSizeUnit = value->fontInfo.fontSizeUnit;
291 uint8_t fontStyle = static_cast<uint8_t>(value->fontInfo.fontStyle);
292 uint8_t fontWeight = static_cast<uint8_t>(value->fontInfo.fontWeight);
293 const char** fontFamilies = value->fontInfo.fontFamilies;
294 uint32_t familyLength = value->fontInfo.familyLength;
295 std::vector<std::string> families;
296 if (fontFamilies && familyLength > 0 && familyLength <= MAX_FONT_FAMILY_LENGTH) {
297 families.resize(familyLength);
298 for (uint32_t i = 0; i < familyLength; i++) {
299 families.at(i) = std::string(*(fontFamilies + i));
300 }
301 }
302 if ((value->borderWidthValue < 0) ||
303 (static_cast<DimensionUnit>(value->borderWidthUnit) == DimensionUnit::PERCENT)) {
304 ProgressModelNG::SetBorderWidth(node, Dimension(DEFAULT_BORDER_WIDTH, DimensionUnit::VP));
305 } else {
306 ProgressModelNG::SetBorderWidth(
307 node, Dimension(value->borderWidthValue, static_cast<DimensionUnit>(value->borderWidthUnit)));
308 }
309 auto styleRes = value->styleResource;
310 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::CapsuleBorderWidth, styleRes.borderWidthRawPtr);
311 ProgressModelNG::SetBorderColor(node, Color(value->borderColor));
312 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::CapsuleBorderColor, styleRes.borderColorRawPtr);
313 ProgressModelNG::SetSweepingEffect(node, value->enableScanEffect);
314 ProgressModelNG::SetShowText(node, value->showDefaultPercentage);
315 if (value->content == nullptr) {
316 ProgressModelNG::SetText(node, std::nullopt);
317 } else {
318 ProgressModelNG::SetText(node, std::string(value->content));
319 }
320 ProgressModelNG::SetCapsuleStyle(node, true);
321 ProgressModelNG::SetCapsuleStyleFontColor(node, value->fontColorSetByUser);
322 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::Text, styleRes.contentRawPtr, false);
323 ProgressModelNG::SetFontColor(node, Color(value->fontColor));
324 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::FontColor, styleRes.fontColorRawPtr);
325 ProgressModelNG::SetFontSize(node, Dimension(fontSizeNumber, static_cast<DimensionUnit>(fontSizeUnit)));
326 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::FontSize, styleRes.fontResource.fontSizeRawPtr);
327 ProgressModelNG::SetFontWeight(node, static_cast<FontWeight>(fontWeight));
328 ProgressModelNG::SetFontFamily(node, families);
329 ProgressModelNG::SetItalicFontStyle(node, static_cast<Ace::FontStyle>(fontStyle));
330 if (Negative(value->borderRadiusValue) ||
331 (static_cast<DimensionUnit>(value->borderRadiusUnit) == DimensionUnit::PERCENT)) {
332 ProgressModelNG::ResetBorderRadius(node);
333 } else {
334 ProgressModelNG::SetBorderRadius(node, Dimension(value->borderRadiusValue,
335 static_cast<DimensionUnit>(value->borderRadiusUnit)));
336 }
337 }
338
SetProgressStyle(ArkUINodeHandle node,ArkUIProgressStyle * value)339 void SetProgressStyle(ArkUINodeHandle node, ArkUIProgressStyle* value)
340 {
341 auto* frameNode = reinterpret_cast<FrameNode*>(node);
342 CHECK_NULL_VOID(frameNode);
343 auto progressLayoutProperty = frameNode->GetLayoutProperty<ProgressLayoutProperty>();
344 CHECK_NULL_VOID(progressLayoutProperty);
345 auto progresstype = progressLayoutProperty->GetType();
346
347 ProgressModelNG::SetSmoothEffect(frameNode, value->enableSmoothEffect);
348
349 if (progresstype == ProgressType::LINEAR) {
350 SetLinearStyleOptions(frameNode, value);
351 } else if (progresstype == ProgressType::RING) {
352 SetRingStyleOptions(frameNode, value);
353 } else if (progresstype == ProgressType::CAPSULE) {
354 SetCapsuleStyleOptions(frameNode, value);
355 } else {
356 SetProgressStyleOptions(frameNode, value);
357 }
358 }
359
SetLinearStyleOptions(FrameNode * node)360 void SetLinearStyleOptions(FrameNode* node)
361 {
362 ProgressModelNG::SetStrokeWidth(node, Dimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP));
363 ProgressModelNG::SetLinearSweepingEffect(node, false);
364 ProgressModelNG::ResetStrokeRadius(node);
365 if (SystemProperties::ConfigChangePerform()) {
366 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::LSStrokeWidth, nullptr);
367 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::LSSweepingEffect, nullptr);
368 }
369 }
370
SetRingStyleOptions(FrameNode * node)371 void SetRingStyleOptions(FrameNode* node)
372 {
373 ProgressModelNG::SetStrokeWidth(node, Dimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP));
374 ProgressModelNG::SetPaintShadow(node, false);
375 ProgressModelNG::SetProgressStatus(node, ProgressStatus::PROGRESSING);
376 ProgressModelNG::SetRingSweepingEffect(node, false);
377 if (SystemProperties::ConfigChangePerform()) {
378 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::RingStrokeWidth, nullptr);
379 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::RingShadow, nullptr);
380 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::RingStatus, nullptr);
381 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::RingSweepingEffect, nullptr);
382 }
383 }
384
SetProgressStyleOptions(FrameNode * node)385 void SetProgressStyleOptions(FrameNode* node)
386 {
387 ProgressModelNG::SetStrokeWidth(node, Dimension(DEFAULT_STROKE_WIDTH, DimensionUnit::VP));
388 ProgressModelNG::SetScaleCount(node, DEFAULT_SCALE_COUNT);
389 ProgressModelNG::SetScaleWidth(node, Dimension(DEFAULT_SCALE_WIDTHS, DimensionUnit::VP));
390 if (SystemProperties::ConfigChangePerform()) {
391 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::PSStrokeWidth, nullptr);
392 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::PSScaleWidth, nullptr);
393 }
394 }
395
SetCapsuleStyleOptions(FrameNode * node)396 void SetCapsuleStyleOptions(FrameNode* node)
397 {
398 auto context = node->GetContext();
399 CHECK_NULL_VOID(context);
400 auto themeManager = context->GetThemeManager();
401 CHECK_NULL_VOID(themeManager);
402
403 auto selectTheme = themeManager->GetTheme<SelectTheme>();
404 CHECK_NULL_VOID(selectTheme);
405 auto textTheme = themeManager->GetTheme<TextTheme>();
406 CHECK_NULL_VOID(textTheme);
407 std::optional<std::string> textOpt = std::nullopt;
408 ProgressModelNG::SetCapsuleStyle(node, false);
409 ProgressModelNG::SetCapsuleStyleFontColor(node, false);
410 ProgressModelNG::SetBorderWidth(node, Dimension(DEFAULT_BORDER_WIDTH, DimensionUnit::VP));
411 ProgressModelNG::SetBorderColor(node, Color(0x33006cde));
412 ProgressModelNG::SetSweepingEffect(node, false);
413 ProgressModelNG::SetShowText(node, false);
414 ProgressModelNG::SetText(node, textOpt);
415 ProgressModelNG::SetFontColor(node, Color(0xff182431));
416 ProgressModelNG::SetFontSize(node, Dimension(DEFAULT_FONT_SIZE, DimensionUnit::FP));
417 ProgressModelNG::SetFontWeight(node, textTheme->GetTextStyle().GetFontWeight());
418 ProgressModelNG::SetFontFamily(node, textTheme->GetTextStyle().GetFontFamilies());
419 ProgressModelNG::SetItalicFontStyle(node, textTheme->GetTextStyle().GetFontStyle());
420 ProgressModelNG::ResetBorderRadius(node); // Set default value.
421 if (SystemProperties::ConfigChangePerform()) {
422 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::CapsuleBorderWidth, nullptr);
423 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::CapsuleBorderColor, nullptr);
424 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::Text, nullptr);
425 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::FontColor, nullptr);
426 CreateWithResourceObjIfNeeded(node, JsProgressResourceType::FontSize, nullptr);
427 }
428 }
429
ResetProgressStyle(ArkUINodeHandle node)430 void ResetProgressStyle(ArkUINodeHandle node)
431 {
432 auto* frameNode = reinterpret_cast<FrameNode*>(node);
433 CHECK_NULL_VOID(frameNode);
434 auto progressLayoutProperty = frameNode->GetLayoutProperty<ProgressLayoutProperty>();
435 CHECK_NULL_VOID(progressLayoutProperty);
436 auto progresstype = progressLayoutProperty->GetType();
437 ProgressModelNG::SetSmoothEffect(frameNode, true);
438
439 if (progresstype == ProgressType::LINEAR) {
440 SetLinearStyleOptions(frameNode);
441 } else if (progresstype == ProgressType::RING) {
442 SetRingStyleOptions(frameNode);
443 } else if (progresstype == ProgressType::CAPSULE) {
444 SetCapsuleStyleOptions(frameNode);
445 } else {
446 SetProgressStyleOptions(frameNode);
447 }
448 }
449
SetProgressBackgroundColor(ArkUINodeHandle node,uint32_t color)450 void SetProgressBackgroundColor(ArkUINodeHandle node, uint32_t color)
451 {
452 auto *frameNode = reinterpret_cast<FrameNode *>(node);
453 CHECK_NULL_VOID(frameNode);
454 ProgressModelNG::SetModifierInitiatedBgColor(frameNode, true);
455 ProgressModelNG::SetBackgroundColor(frameNode, Color(color));
456 }
457
SetProgressBackgroundColorWithColorSpace(ArkUINodeHandle node,ArkUI_Uint32 color,ArkUI_Int32 colorSpace,void * colorRawPtr)458 void SetProgressBackgroundColorWithColorSpace(
459 ArkUINodeHandle node, ArkUI_Uint32 color, ArkUI_Int32 colorSpace, void* colorRawPtr)
460 {
461 auto* frameNode = reinterpret_cast<FrameNode*>(node);
462 CHECK_NULL_VOID(frameNode);
463 Color backgroundColor { color };
464 if (ColorSpace::DISPLAY_P3 == colorSpace) {
465 backgroundColor.SetColorSpace(ColorSpace::DISPLAY_P3);
466 } else {
467 backgroundColor.SetColorSpace(ColorSpace::SRGB);
468 }
469
470 if (SystemProperties::ConfigChangePerform()) {
471 CreateWithResourceObjIfNeeded(frameNode, JsProgressResourceType::BackgroundColor, colorRawPtr, false);
472 }
473
474 ProgressModelNG::SetBackgroundColor(frameNode, backgroundColor);
475 }
476
ResetProgressBackgroundColor(ArkUINodeHandle node)477 void ResetProgressBackgroundColor(ArkUINodeHandle node)
478 {
479 auto *frameNode = reinterpret_cast<FrameNode *>(node);
480 CHECK_NULL_VOID(frameNode);
481 auto progressLayoutProperty = frameNode->GetLayoutProperty<ProgressLayoutProperty>();
482 CHECK_NULL_VOID(progressLayoutProperty);
483 auto progresstype = progressLayoutProperty->GetType();
484 auto pipelineContext = PipelineBase::GetCurrentContext();
485 CHECK_NULL_VOID(pipelineContext);
486 auto theme = pipelineContext->GetTheme<ProgressTheme>();
487 CHECK_NULL_VOID(theme);
488
489 Color backgroundColor;
490 if (progresstype == ProgressType::CAPSULE) {
491 backgroundColor = theme->GetCapsuleParseFailedBgColor();
492 } else if (progresstype == ProgressType::RING) {
493 backgroundColor = theme->GetRingProgressParseFailedBgColor();
494 } else {
495 backgroundColor = theme->GetTrackParseFailedBgColor();
496 }
497
498 if (SystemProperties::ConfigChangePerform()) {
499 RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
500 ProgressModelNG::CreateWithResourceObj(frameNode, JsProgressResourceType::BackgroundColor, resObj);
501 }
502
503 ProgressModelNG::SetModifierInitiatedBgColor(frameNode, false);
504 ProgressModelNG::SetBackgroundColor(frameNode, backgroundColor);
505 }
506
GetProgressValue(ArkUINodeHandle node)507 ArkUI_Float32 GetProgressValue(ArkUINodeHandle node)
508 {
509 auto *frameNode = reinterpret_cast<FrameNode *>(node);
510 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
511 return ProgressModelNG::GetValue(frameNode);
512 }
513
GetProgressTotal(ArkUINodeHandle node)514 ArkUI_Float32 GetProgressTotal(ArkUINodeHandle node)
515 {
516 auto *frameNode = reinterpret_cast<FrameNode *>(node);
517 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
518 return ProgressModelNG::GetTotal(frameNode);
519 }
520
GetProgressType(ArkUINodeHandle node)521 ArkUI_Int32 GetProgressType(ArkUINodeHandle node)
522 {
523 auto *frameNode = reinterpret_cast<FrameNode *>(node);
524 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
525 return static_cast<ArkUI_Int32>(ProgressModelNG::GetType(frameNode));
526 }
527
GetProgressColor(ArkUINodeHandle node)528 ArkUI_Uint32 GetProgressColor(ArkUINodeHandle node)
529 {
530 auto *frameNode = reinterpret_cast<FrameNode *>(node);
531 CHECK_NULL_RETURN(frameNode, ERROR_UINT_CODE);
532 return ProgressModelNG::GetColor(frameNode).GetValue();
533 }
534
GetProgressLinearStyle(ArkUINodeHandle node,ArkUIProgressLinearStyleOption & option)535 void GetProgressLinearStyle(ArkUINodeHandle node, ArkUIProgressLinearStyleOption& option)
536 {
537 auto* frameNode = reinterpret_cast<FrameNode *>(node);
538 CHECK_NULL_VOID(frameNode);
539 auto paintProperty = frameNode->GetPaintProperty<ProgressPaintProperty>();
540 CHECK_NULL_VOID(paintProperty);
541 auto layoutProperty = frameNode->GetLayoutProperty<ProgressLayoutProperty>();
542 CHECK_NULL_VOID(layoutProperty);
543
544 option.scanEffectEnable = paintProperty->GetEnableLinearScanEffect().value_or(false);
545 option.smoothEffectEnable = paintProperty->GetEnableSmoothEffect().value_or(true);
546 auto strokeWidth = layoutProperty->GetStrokeWidth().value_or(
547 Dimension(STROKEWIDTH_DEFAULT_VALUE, DimensionUnit::VP)).Value();
548 option.strokeWidth = strokeWidth;
549 auto strokeRadius = paintProperty->GetStrokeRadiusValue(Dimension(strokeWidth / 2.0f, DimensionUnit::VP)).Value();
550 strokeRadius = std::min(strokeWidth / 2.0f, strokeRadius);
551 option.strokeRadius = strokeRadius;
552 }
553
SetProgressInitialize(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Float32 total,ArkUI_Int32 progressStyle)554 void SetProgressInitialize(
555 ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Float32 total, ArkUI_Int32 progressStyle)
556 {
557 auto* frameNode = reinterpret_cast<FrameNode*>(node);
558 CHECK_NULL_VOID(frameNode);
559 ProgressModelNG::ProgressInitialize(
560 frameNode, 0.0, value, 0.0, total, static_cast<NG::ProgressType>(progressStyle));
561 }
562
ResetProgressInitialize(ArkUINodeHandle node)563 void ResetProgressInitialize(ArkUINodeHandle node)
564 {
565 auto* frameNode = reinterpret_cast<FrameNode*>(node);
566 CHECK_NULL_VOID(frameNode);
567 auto value = 0;
568 auto total = 100;
569 ProgressModelNG::ProgressInitialize(
570 frameNode, 0.0, value, 0.0, total, ProgressType::LINEAR);
571 }
572
573 namespace NodeModifier {
GetProgressModifier()574 const ArkUIProgressModifier* GetProgressModifier()
575 {
576 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
577 static const ArkUIProgressModifier modifier = {
578 .setProgressValue = SetProgressValue,
579 .resetProgressValue = ResetProgressValue,
580 .setProgressGradientColor = SetProgressGradientColor,
581 .setProgressColor = SetProgressColor,
582 .setProgressColorPtr = SetProgressColorPtr,
583 .resetProgressColor = ResetProgressColor,
584 .setProgressStyle = SetProgressStyle,
585 .resetProgressStyle = ResetProgressStyle,
586 .setProgressBackgroundColor = SetProgressBackgroundColor,
587 .setProgressBackgroundColorWithColorSpace = SetProgressBackgroundColorWithColorSpace,
588 .resetProgressBackgroundColor = ResetProgressBackgroundColor,
589 .setProgressTotal = SetProgressTotal,
590 .setProgressType = SetProgressType,
591 .resetProgressType = ResetProgressType,
592 .getProgressValue = GetProgressValue,
593 .getProgressTotal = GetProgressTotal,
594 .getProgressType = GetProgressType,
595 .getProgressColor = GetProgressColor,
596 .setProgressInitialize = SetProgressInitialize,
597 .resetProgressInitialize = ResetProgressInitialize,
598 .getProgressLinearStyle = GetProgressLinearStyle,
599 };
600 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
601 return &modifier;
602 }
603
GetCJUIProgressModifier()604 const CJUIProgressModifier* GetCJUIProgressModifier()
605 {
606 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
607 static const CJUIProgressModifier modifier = {
608 .setProgressValue = SetProgressValue,
609 .resetProgressValue = ResetProgressValue,
610 .setProgressGradientColor = SetProgressGradientColor,
611 .setProgressColor = SetProgressColor,
612 .setProgressColorPtr = SetProgressColorPtr,
613 .resetProgressColor = ResetProgressColor,
614 .setProgressStyle = SetProgressStyle,
615 .resetProgressStyle = ResetProgressStyle,
616 .setProgressBackgroundColor = SetProgressBackgroundColor,
617 .setProgressBackgroundColorWithColorSpace = SetProgressBackgroundColorWithColorSpace,
618 .resetProgressBackgroundColor = ResetProgressBackgroundColor,
619 .setProgressTotal = SetProgressTotal,
620 .setProgressType = SetProgressType,
621 .resetProgressType = ResetProgressType,
622 .getProgressValue = GetProgressValue,
623 .getProgressTotal = GetProgressTotal,
624 .getProgressType = GetProgressType,
625 .getProgressColor = GetProgressColor,
626 .setProgressInitialize = SetProgressInitialize,
627 .resetProgressInitialize = ResetProgressInitialize,
628 };
629 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
630 return &modifier;
631 }
632 }
633 } // namespace OHOS::Ace::NG
634