1 /*
2 * Copyright (c) 2023 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 "core/interfaces/native/node/node_common_modifier.h"
16
17 #include <cstdint>
18
19 #include "base/geometry/ng/vector.h"
20 #include "base/geometry/shape.h"
21 #include "base/memory/ace_type.h"
22 #include "base/utils/system_properties.h"
23 #include "bridge/common/utils/utils.h"
24 #include "core/animation/animation_pub.h"
25 #include "core/components/common/layout/constants.h"
26 #include "core/components/common/properties/animation_option.h"
27 #include "core/components/common/properties/decoration.h"
28 #include "core/components/theme/shadow_theme.h"
29 #include "core/components_ng/base/frame_node.h"
30 #include "core/components_ng/base/view_abstract.h"
31 #include "core/components_ng/base/view_abstract_model_ng.h"
32 #include "core/components_ng/property/transition_property.h"
33 #include "core/image/image_source_info.h"
34 #include "core/interfaces/native/node/node_api.h"
35
36 namespace OHOS::Ace::NG {
37 namespace {
38 constexpr VisibleType DEFAULT_VISIBILITY = static_cast<VisibleType>(0);
39 constexpr float MAX_ANGLE = 360.0f;
40 constexpr double PERCENT_100 = 100.0;
41 constexpr int NUM_0 = 0;
42 constexpr int NUM_1 = 1;
43 constexpr int NUM_2 = 2;
44 constexpr int NUM_3 = 3;
45 constexpr int NUM_4 = 4;
46 constexpr int NUM_5 = 5;
47 constexpr int NUM_6 = 6;
48 constexpr int NUM_7 = 7;
49 constexpr int NUM_8 = 8;
50 constexpr int NUM_9 = 9;
51 constexpr int NUM_10 = 10;
52 constexpr int NUM_11 = 11;
53 constexpr int NUM_12 = 12;
54 constexpr int NUM_13 = 13;
55 constexpr int NUM_14 = 14;
56 constexpr int NUM_15 = 15;
57 constexpr int NUM_16 = 16;
58 constexpr int NUM_24 = 24;
59 constexpr int DEFAULT_LENGTH = 4;
60 constexpr double ROUND_UNIT = 360.0;
61 constexpr TextDirection DEFAULT_COMMON_DIRECTION = TextDirection::AUTO;
62 constexpr int32_t DEFAULT_COMMON_LAYOUTWEIGHT = 0;
63 constexpr int32_t MAX_ALIGN_VALUE = 8;
64 constexpr int32_t DEFAULT_GRIDSPAN = 1;
65 constexpr uint32_t DEFAULT_ALIGN_VALUE = 2;
66 constexpr uint32_t DEFAULT_ALIGN_RULES_SIZE = 6;
67 constexpr uint8_t DEFAULT_SAFE_AREA_TYPE = 0b111;
68 constexpr uint8_t DEFAULT_SAFE_AREA_EDGE = 0b1111;
69 constexpr Dimension DEFAULT_FLEX_BASIS { 0.0, DimensionUnit::AUTO };
70 constexpr int32_t DEFAULT_DISPLAY_PRIORITY = 0;
71 constexpr int32_t DEFAULT_ID = 0;
72 constexpr int32_t X_INDEX = 0;
73 constexpr int32_t Y_INDEX = 1;
74 constexpr int32_t Z_INDEX = 2;
75 constexpr int32_t ARRAY_SIZE = 3;
ConvertBorderStyle(int32_t value)76 BorderStyle ConvertBorderStyle(int32_t value)
77 {
78 auto style = static_cast<BorderStyle>(value);
79 if (style < BorderStyle::SOLID || style > BorderStyle::NONE) {
80 style = BorderStyle::SOLID;
81 }
82 return style;
83 }
84
ParseAlignment(int32_t align)85 Alignment ParseAlignment(int32_t align)
86 {
87 Alignment alignment = Alignment::CENTER;
88 switch (align) {
89 case NUM_0:
90 alignment = Alignment::TOP_LEFT;
91 break;
92 case NUM_1:
93 alignment = Alignment::TOP_CENTER;
94 break;
95 case NUM_2:
96 alignment = Alignment::TOP_RIGHT;
97 break;
98 case NUM_3:
99 alignment = Alignment::CENTER_LEFT;
100 break;
101 case NUM_4:
102 alignment = Alignment::CENTER;
103 break;
104 case NUM_5:
105 alignment = Alignment::CENTER_RIGHT;
106 break;
107 case NUM_6:
108 alignment = Alignment::BOTTOM_LEFT;
109 break;
110 case NUM_7:
111 alignment = Alignment::BOTTOM_CENTER;
112 break;
113 case NUM_8:
114 alignment = Alignment::BOTTOM_RIGHT;
115 break;
116 default:
117 break;
118 }
119 return alignment;
120 }
121
122 /**
123 * @param colors color value
124 * colors[0], colors[1], colors[2] : color[0](color, hasDimension, dimension)
125 * colors[3], colors[4], colors[5] : color[1](color, hasDimension, dimension)
126 * ...
127 * @param colorsLength colors length
128 */
SetGradientColors(NG::Gradient & gradient,const ArkUI_Float32 * colors,ArkUI_Int32 colorsLength)129 void SetGradientColors(NG::Gradient& gradient, const ArkUI_Float32* colors, ArkUI_Int32 colorsLength)
130 {
131 if ((colors == nullptr) || (colorsLength % NUM_3) != 0) {
132 return;
133 }
134 for (int32_t index = 0; index < colorsLength; index += NUM_3) {
135 auto colorValue = colors[index];
136 auto colorHasDimension = colors[index + NUM_1];
137 auto colorDimension = colors[index + NUM_2];
138 auto color = static_cast<uint32_t>(colorValue);
139 auto hasDimension = static_cast<bool>(colorHasDimension);
140 auto dimension = colorDimension;
141 NG::GradientColor gradientColor;
142 gradientColor.SetColor(Color(color));
143 gradientColor.SetHasValue(hasDimension);
144 if (hasDimension) {
145 gradientColor.SetDimension(CalcDimension(dimension * PERCENT_100, DimensionUnit::PERCENT));
146 }
147 gradient.AddColor(gradientColor);
148 }
149 }
150
SetLinearGradientDirectionTo(std::shared_ptr<LinearGradient> & linearGradient,const GradientDirection direction)151 void SetLinearGradientDirectionTo(std::shared_ptr<LinearGradient>& linearGradient, const GradientDirection direction)
152 {
153 switch (direction) {
154 case GradientDirection::LEFT:
155 linearGradient->linearX = NG::GradientDirection::LEFT;
156 break;
157 case GradientDirection::RIGHT:
158 linearGradient->linearX = NG::GradientDirection::RIGHT;
159 break;
160 case GradientDirection::TOP:
161 linearGradient->linearY = NG::GradientDirection::TOP;
162 break;
163 case GradientDirection::BOTTOM:
164 linearGradient->linearY = NG::GradientDirection::BOTTOM;
165 break;
166 case GradientDirection::LEFT_TOP:
167 linearGradient->linearX = NG::GradientDirection::LEFT;
168 linearGradient->linearY = NG::GradientDirection::TOP;
169 break;
170 case GradientDirection::LEFT_BOTTOM:
171 linearGradient->linearX = NG::GradientDirection::LEFT;
172 linearGradient->linearY = NG::GradientDirection::BOTTOM;
173 break;
174 case GradientDirection::RIGHT_TOP:
175 linearGradient->linearX = NG::GradientDirection::RIGHT;
176 linearGradient->linearY = NG::GradientDirection::TOP;
177 break;
178 case GradientDirection::RIGHT_BOTTOM:
179 linearGradient->linearX = NG::GradientDirection::RIGHT;
180 linearGradient->linearY = NG::GradientDirection::BOTTOM;
181 break;
182 case GradientDirection::NONE:
183 case GradientDirection::START_TO_END:
184 case GradientDirection::END_TO_START:
185 default:
186 break;
187 }
188 }
189
190 /**
191 * @param values value value
192 * values[0], values[1] : angle: hasValue, angle value
193 * values[2] : direction
194 * values[3] : repeating
195 * @param valuesLength values length
196 */
SetLinearGradientValues(NG::Gradient & gradient,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength)197 void SetLinearGradientValues(NG::Gradient& gradient, const ArkUI_Float32* values, ArkUI_Int32 valuesLength)
198 {
199 if ((values == nullptr) || (valuesLength != NUM_4)) {
200 return;
201 }
202 auto angleHasValue = values[NUM_0];
203 auto angleValue = values[NUM_1];
204 auto directionValue = values[NUM_2];
205 auto repeating = values[NUM_3];
206 auto linearGradient = gradient.GetLinearGradient();
207 if (linearGradient == nullptr) {
208 return;
209 }
210 if (static_cast<bool>(angleHasValue)) {
211 linearGradient->angle = CalcDimension(angleValue, DimensionUnit::PX);
212 }
213 SetLinearGradientDirectionTo(linearGradient, static_cast<GradientDirection>(directionValue));
214 gradient.SetRepeat(static_cast<bool>(repeating));
215 }
216
CheckAngle(const float angle)217 float CheckAngle(const float angle)
218 {
219 if (LessNotEqual(angle, 0.0f)) {
220 return 0.0f;
221 }
222 if (GreatNotEqual(angle, MAX_ANGLE)) {
223 return MAX_ANGLE;
224 }
225 return angle;
226 }
227
228 /**
229 * @param values value value
230 * values[0], values[1], values[2] : centerX Dimension: hasValue, value, unit
231 * values[3], values[4], values[5] : centerY Dimension: hasValue, value, unit
232 * values[6], values[7] : start: hasValue, start degree value
233 * values[8], values[9] : end: hasValue, end degree value
234 * values[10], values[11] : rotation: hasValue, rotation degree value
235 * values[12] : repeating
236 * @param valuesLength values length
237 */
SetSweepGradientValues(NG::Gradient & gradient,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength)238 void SetSweepGradientValues(NG::Gradient& gradient, const ArkUI_Float32* values, ArkUI_Int32 valuesLength)
239 {
240 if ((values == nullptr) || (valuesLength != NUM_13)) {
241 return;
242 }
243 auto centerXHasValue = values[NUM_0];
244 auto centerXValue = values[NUM_1];
245 auto centerXUnit = values[NUM_2];
246 auto centerYHasValue = values[NUM_3];
247 auto centerYValue = values[NUM_4];
248 auto centerYUnit = values[NUM_5];
249 auto startHasValue = values[NUM_6];
250 auto startValue = values[NUM_7];
251 auto endHasValue = values[NUM_8];
252 auto endValue = values[NUM_9];
253 auto rotationHasValue = values[NUM_10];
254 auto rotationValue = values[NUM_11];
255 auto repeating = values[NUM_12];
256 if (static_cast<bool>(centerXHasValue)) {
257 auto unit = static_cast<DimensionUnit>(centerXUnit);
258 auto value = (unit == DimensionUnit::PERCENT) ? (centerXValue * PERCENT_100) : centerXValue;
259 gradient.GetSweepGradient()->centerX = CalcDimension(value, unit);
260 }
261 if (static_cast<bool>(centerYHasValue)) {
262 auto unit = static_cast<DimensionUnit>(centerYUnit);
263 auto value = (unit == DimensionUnit::PERCENT) ? (centerYValue * PERCENT_100) : centerYValue;
264 gradient.GetSweepGradient()->centerY = CalcDimension(value, unit);
265 }
266 if (static_cast<bool>(startHasValue)) {
267 gradient.GetSweepGradient()->startAngle = CalcDimension(CheckAngle(startValue), DimensionUnit::PX);
268 }
269 if (static_cast<bool>(endHasValue)) {
270 gradient.GetSweepGradient()->endAngle = CalcDimension(CheckAngle(endValue), DimensionUnit::PX);
271 }
272 if (static_cast<bool>(rotationHasValue)) {
273 gradient.GetSweepGradient()->rotation = CalcDimension(CheckAngle(rotationValue), DimensionUnit::PX);
274 }
275 gradient.SetRepeat(static_cast<bool>(repeating));
276 }
277
278 /**
279 * @param values value value
280 * values[0], values[1], values[2] : centerX Dimension: hasValue, value, unit
281 * values[3], values[4], values[5] : centerY Dimension: hasValue, value, unit
282 * values[6], values[7], values[8] : radius: Dimension: hasValue, value, unit
283 * values[9] : repeating
284 * @param valuesLength values length
285 */
SetRadialGradientValues(NG::Gradient & gradient,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength)286 void SetRadialGradientValues(NG::Gradient& gradient, const ArkUI_Float32* values, ArkUI_Int32 valuesLength)
287 {
288 if ((values == nullptr) || (valuesLength != NUM_10)) {
289 return;
290 }
291 auto centerXHasValue = values[NUM_0];
292 auto centerXValue = values[NUM_1];
293 auto centerXUnit = values[NUM_2];
294 auto centerYHasValue = values[NUM_3];
295 auto centerYValue = values[NUM_4];
296 auto centerYUnit = values[NUM_5];
297 auto radiusHasValue = values[NUM_6];
298 auto radiusValue = values[NUM_7];
299 auto radiusUnit = values[NUM_8];
300 auto repeating = values[NUM_9];
301 if (static_cast<bool>(centerXHasValue)) {
302 auto unit = static_cast<DimensionUnit>(centerXUnit);
303 auto value = (unit == DimensionUnit::PERCENT) ? (centerXValue * PERCENT_100) : centerXValue;
304 gradient.GetRadialGradient()->radialCenterX = CalcDimension(value, unit);
305 }
306 if (static_cast<bool>(centerYHasValue)) {
307 auto unit = static_cast<DimensionUnit>(centerYUnit);
308 auto value = (unit == DimensionUnit::PERCENT) ? (centerYValue * PERCENT_100) : centerYValue;
309 gradient.GetRadialGradient()->radialCenterY = CalcDimension(value, unit);
310 }
311 if (static_cast<bool>(radiusHasValue)) {
312 auto unit = static_cast<DimensionUnit>(radiusUnit);
313 auto value = CheckAngle(radiusValue);
314 gradient.GetRadialGradient()->radialVerticalSize = CalcDimension(value, unit);
315 gradient.GetRadialGradient()->radialHorizontalSize = CalcDimension(value, unit);
316 }
317 gradient.SetRepeat(static_cast<bool>(repeating));
318 }
319
SetCalcDimension(std::optional<CalcDimension> & optDimension,const ArkUIStringAndFloat * options,ArkUI_Int32 optionsLength,ArkUI_Int32 offset)320 bool SetCalcDimension(std::optional<CalcDimension>& optDimension, const ArkUIStringAndFloat* options,
321 ArkUI_Int32 optionsLength, ArkUI_Int32 offset)
322 {
323 if ((options == nullptr) || (offset < 0) || ((offset + NUM_3) >= optionsLength)) {
324 return false;
325 }
326 auto hasValue = options[offset];
327 auto value = options[offset + NUM_1];
328 auto unit = options[offset + NUM_2];
329 if (static_cast<bool>(hasValue.value)) {
330 auto unitValue = static_cast<DimensionUnit>(unit.value);
331 if (unitValue == DimensionUnit::CALC) {
332 std::string str;
333 if (value.valueStr != nullptr) {
334 str = value.valueStr;
335 }
336 CalcDimension calcDimension(str, unitValue);
337 optDimension = calcDimension;
338 } else {
339 CalcDimension calcDimension(value.value, unitValue);
340 optDimension = calcDimension;
341 }
342 }
343 return true;
344 }
345
SetOptionalBorder(std::optional<Dimension> & optionalDimension,const ArkUI_Float32 * values,ArkUI_Int32 valuesSize,ArkUI_Int32 & offset)346 void SetOptionalBorder(std::optional<Dimension>& optionalDimension, const ArkUI_Float32* values,
347 ArkUI_Int32 valuesSize, ArkUI_Int32& offset)
348 {
349 bool hasValue = static_cast<bool>(values[offset]);
350 if (hasValue) {
351 optionalDimension =
352 Dimension(values[offset + NUM_1], static_cast<OHOS::Ace::DimensionUnit>(values[offset + NUM_2]));
353 }
354 offset = offset + NUM_3;
355 }
356
SetOptionalBorderColor(std::optional<Color> & optioalColor,const uint32_t * values,ArkUI_Int32 valuesSize,ArkUI_Int32 & offset)357 void SetOptionalBorderColor(
358 std::optional<Color>& optioalColor, const uint32_t* values, ArkUI_Int32 valuesSize, ArkUI_Int32& offset)
359 {
360 auto hasValue = values[offset];
361 if (static_cast<bool>(hasValue)) {
362 optioalColor = Color(values[offset + NUM_1]);
363 }
364 offset = offset + NUM_2;
365 }
366
SetOptionalBorderStyle(std::optional<BorderStyle> & optioaStyle,const uint32_t * values,ArkUI_Int32 valuesSize,ArkUI_Int32 & offset)367 void SetOptionalBorderStyle(
368 std::optional<BorderStyle>& optioaStyle, const uint32_t* values, ArkUI_Int32 valuesSize, ArkUI_Int32& offset)
369 {
370 auto hasValue = values[offset];
371 if (static_cast<bool>(hasValue)) {
372 optioaStyle = ConvertBorderStyle(values[offset + NUM_1]);
373 }
374 offset = offset + NUM_2;
375 }
376
SetBorderImageSlice(RefPtr<BorderImage> & borderImage,const std::vector<BorderImageDirection> & directions,const ArkUIStringAndFloat * options,ArkUI_Int32 optionsLength,ArkUI_Int32 & offset)377 void SetBorderImageSlice(RefPtr<BorderImage>& borderImage, const std::vector<BorderImageDirection>& directions,
378 const ArkUIStringAndFloat* options, ArkUI_Int32 optionsLength, ArkUI_Int32& offset)
379 {
380 for (unsigned int index = 0; index < NUM_12; index += NUM_3) {
381 std::optional<CalcDimension> optDimension;
382 SetCalcDimension(optDimension, options, optionsLength, offset + index);
383 if (optDimension.has_value()) {
384 auto direction = directions[index / NUM_3];
385 borderImage->SetEdgeSlice(direction, optDimension.value());
386 }
387 }
388 offset += NUM_12;
389 }
390
SetBorderImageRepeat(RefPtr<BorderImage> & borderImage,const ArkUIStringAndFloat * options,ArkUI_Int32 optionsLength,ArkUI_Int32 & offset)391 void SetBorderImageRepeat(RefPtr<BorderImage>& borderImage, const ArkUIStringAndFloat* options,
392 ArkUI_Int32 optionsLength, ArkUI_Int32& offset)
393 {
394 if ((options == nullptr) || (offset < 0) || ((offset + NUM_2) >= optionsLength)) {
395 return;
396 }
397 auto hasValue = options[offset];
398 auto value = options[offset + NUM_1];
399 if (static_cast<bool>(hasValue.value)) {
400 auto repeatMode = static_cast<BorderImageRepeat>(value.value);
401 borderImage->SetRepeatMode(repeatMode);
402 }
403 offset += NUM_2;
404 }
405
SetBorderImageWidth(RefPtr<BorderImage> & borderImage,const std::vector<BorderImageDirection> & directions,const ArkUIStringAndFloat * options,ArkUI_Int32 optionsLength,ArkUI_Int32 & offset)406 void SetBorderImageWidth(RefPtr<BorderImage>& borderImage, const std::vector<BorderImageDirection>& directions,
407 const ArkUIStringAndFloat* options, ArkUI_Int32 optionsLength, ArkUI_Int32& offset)
408 {
409 for (int32_t index = 0; index < NUM_12; index += NUM_3) {
410 std::optional<CalcDimension> optDimension;
411 SetCalcDimension(optDimension, options, optionsLength, offset + index);
412 if (optDimension.has_value()) {
413 auto direction = directions[index / NUM_3];
414 borderImage->SetEdgeWidth(direction, optDimension.value());
415 }
416 }
417 offset += NUM_12;
418 }
419
SetBorderImageOutset(RefPtr<BorderImage> & borderImage,const std::vector<BorderImageDirection> & directions,const ArkUIStringAndFloat * options,ArkUI_Int32 optionsLength,ArkUI_Int32 & offset)420 void SetBorderImageOutset(RefPtr<BorderImage>& borderImage, const std::vector<BorderImageDirection>& directions,
421 const ArkUIStringAndFloat* options, ArkUI_Int32 optionsLength, ArkUI_Int32& offset)
422 {
423 for (unsigned int index = 0; index < NUM_12; index += NUM_3) {
424 std::optional<CalcDimension> optDimension;
425 SetCalcDimension(optDimension, options, optionsLength, offset + index);
426 if (optDimension.has_value()) {
427 auto direction = directions[index / NUM_3];
428 borderImage->SetEdgeOutset(direction, optDimension.value());
429 }
430 }
431 offset += NUM_12;
432 }
433
SetBorderImageFill(RefPtr<BorderImage> & borderImage,const ArkUIStringAndFloat * options,ArkUI_Int32 optionsLength,ArkUI_Int32 & offset)434 void SetBorderImageFill(RefPtr<BorderImage>& borderImage, const ArkUIStringAndFloat* options,
435 ArkUI_Int32 optionsLength, ArkUI_Int32& offset)
436 {
437 if ((options == nullptr) || (offset < 0) || ((offset + NUM_2) >= optionsLength)) {
438 return;
439 }
440 auto hasValue = options[offset];
441 auto value = options[offset + NUM_1];
442 if (static_cast<bool>(hasValue.value)) {
443 borderImage->SetNeedFillCenter(static_cast<bool>(value.value));
444 }
445 offset += NUM_2;
446 }
447
SetBorderImage(FrameNode * frameNode,const RefPtr<BorderImage> & borderImage,ArkUI_Uint32 bitset)448 void SetBorderImage(FrameNode* frameNode, const RefPtr<BorderImage>& borderImage, ArkUI_Uint32 bitset)
449 {
450 CHECK_NULL_VOID(frameNode);
451 CHECK_NULL_VOID(borderImage);
452 if (bitset | BorderImage::SOURCE_BIT) {
453 ViewAbstract::SetBorderImageSource(frameNode, borderImage->GetSrc());
454 }
455 if (bitset | BorderImage::OUTSET_BIT) {
456 ViewAbstract::SetHasBorderImageOutset(frameNode, true);
457 }
458 if (bitset | BorderImage::SLICE_BIT) {
459 ViewAbstract::SetHasBorderImageSlice(frameNode, true);
460 }
461 if (bitset | BorderImage::REPEAT_BIT) {
462 ViewAbstract::SetHasBorderImageRepeat(frameNode, true);
463 }
464 if (bitset | BorderImage::WIDTH_BIT) {
465 ViewAbstract::SetHasBorderImageWidth(frameNode, true);
466 }
467 ViewAbstract::SetBorderImage(frameNode, borderImage);
468 }
469
470 /**
471 * @param values value value
472 * values[0], values[1] : angle: hasValue, angle value
473 * values[2] : direction
474 * values[3] : repeating
475 * @param valuesLength values length
476 */
SetBorderImageGradientValues(NG::Gradient & gradient,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength)477 void SetBorderImageGradientValues(NG::Gradient& gradient, const ArkUI_Float32* values, ArkUI_Int32 valuesLength)
478 {
479 if ((values == nullptr) || (valuesLength != NUM_4)) {
480 return;
481 }
482 auto angleHasValue = values[NUM_0];
483 auto angleValue = values[NUM_1];
484 auto directionValue = values[NUM_2];
485 auto repeating = values[NUM_3];
486 auto linearGradient = gradient.GetLinearGradient();
487 if (linearGradient == nullptr) {
488 return;
489 }
490 if (static_cast<bool>(angleHasValue)) {
491 linearGradient->angle = CalcDimension(angleValue, DimensionUnit::PX);
492 }
493 SetLinearGradientDirectionTo(linearGradient, static_cast<GradientDirection>(directionValue));
494 gradient.SetRepeat(static_cast<bool>(repeating));
495 }
496
SetBgImgPosition(const DimensionUnit & typeX,const DimensionUnit & typeY,ArkUI_Float32 valueX,ArkUI_Float32 valueY,BackgroundImagePosition & bgImgPosition)497 void SetBgImgPosition(const DimensionUnit& typeX, const DimensionUnit& typeY,
498 ArkUI_Float32 valueX, ArkUI_Float32 valueY, BackgroundImagePosition& bgImgPosition)
499 {
500 OHOS::Ace::AnimationOption option;
501 bgImgPosition.SetSizeX(AnimatableDimension(valueX, typeX, option));
502 bgImgPosition.SetSizeY(AnimatableDimension(valueY, typeY, option));
503 }
504
SetBackgroundColor(ArkUINodeHandle node,uint32_t color)505 void SetBackgroundColor(ArkUINodeHandle node, uint32_t color)
506 {
507 auto* frameNode = reinterpret_cast<FrameNode*>(node);
508 CHECK_NULL_VOID(frameNode);
509 ViewAbstract::SetBackgroundColor(frameNode, Color(color));
510 }
511
ResetBackgroundColor(ArkUINodeHandle node)512 void ResetBackgroundColor(ArkUINodeHandle node)
513 {
514 auto* frameNode = reinterpret_cast<FrameNode*>(node);
515 CHECK_NULL_VOID(frameNode);
516 ViewAbstract::SetBackgroundColor(frameNode, Color(Color::TRANSPARENT));
517 }
518
SetWidth(ArkUINodeHandle node,ArkUI_Float32 value,int unit,const char * calcVlaue)519 void SetWidth(ArkUINodeHandle node, ArkUI_Float32 value, int unit, const char* calcVlaue)
520 {
521 auto* frameNode = reinterpret_cast<FrameNode*>(node);
522 CHECK_NULL_VOID(frameNode);
523 auto unitEnum = static_cast<OHOS::Ace::DimensionUnit>(unit);
524 if (unitEnum == DimensionUnit::CALC) {
525 ViewAbstract::SetWidth(frameNode, CalcLength(CalcLength(std::string(calcVlaue))));
526 } else {
527 ViewAbstract::SetWidth(frameNode, CalcLength(value, unitEnum));
528 }
529 }
530
ResetWidth(ArkUINodeHandle node)531 void ResetWidth(ArkUINodeHandle node)
532 {
533 auto* frameNode = reinterpret_cast<FrameNode*>(node);
534 CHECK_NULL_VOID(frameNode);
535 ViewAbstract::ClearWidthOrHeight(frameNode, true);
536 }
SetHeight(ArkUINodeHandle node,ArkUI_Float32 value,int unit,const char * calcVlaue)537 void SetHeight(ArkUINodeHandle node, ArkUI_Float32 value, int unit, const char* calcVlaue)
538 {
539 auto* frameNode = reinterpret_cast<FrameNode*>(node);
540 CHECK_NULL_VOID(frameNode);
541 auto unitEnum = static_cast<OHOS::Ace::DimensionUnit>(unit);
542 if (unitEnum == DimensionUnit::CALC) {
543 ViewAbstract::SetHeight(frameNode, CalcLength(CalcLength(std::string(calcVlaue))));
544 } else {
545 ViewAbstract::SetHeight(frameNode, CalcLength(value, unitEnum));
546 }
547 }
ResetHeight(ArkUINodeHandle node)548 void ResetHeight(ArkUINodeHandle node)
549 {
550 auto* frameNode = reinterpret_cast<FrameNode*>(node);
551 CHECK_NULL_VOID(frameNode);
552 ViewAbstract::ClearWidthOrHeight(frameNode, false);
553 }
554 /**
555 * @param values radius values
556 * value[0] : radius value for TopLeft,value[1] : radius value for TopRight
557 * value[2] : radius value for BottomLeft,value[3] : radius value for BottomRight
558 * @param units adius units
559 * units[0]: radius unit for TopLeft ,units[1] : radius unit for TopRight
560 * units[2]: radius unit for BottomLeft, units[3] : radius unit for TopRight
561 */
SetBorderRadius(ArkUINodeHandle node,const ArkUI_Float32 * values,const int * units,ArkUI_Int32 length)562 void SetBorderRadius(ArkUINodeHandle node, const ArkUI_Float32* values, const int* units, ArkUI_Int32 length)
563 {
564 auto* frameNode = reinterpret_cast<FrameNode*>(node);
565 CHECK_NULL_VOID(frameNode);
566 if (length != DEFAULT_LENGTH) {
567 return;
568 }
569 NG::BorderRadiusProperty borderRadius;
570 borderRadius.radiusTopLeft = Dimension(values[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_0]));
571 borderRadius.radiusTopRight = Dimension(values[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_1]));
572 borderRadius.radiusBottomLeft = Dimension(values[NUM_2], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_2]));
573 borderRadius.radiusBottomRight = Dimension(values[NUM_3], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_3]));
574 borderRadius.multiValued = true;
575 ViewAbstract::SetBorderRadius(frameNode, borderRadius);
576 }
577
ResetBorderRadius(ArkUINodeHandle node)578 void ResetBorderRadius(ArkUINodeHandle node)
579 {
580 auto* frameNode = reinterpret_cast<FrameNode*>(node);
581 CHECK_NULL_VOID(frameNode);
582 OHOS::Ace::CalcDimension reset;
583 ViewAbstract::SetBorderRadius(frameNode, reset);
584 }
585
586 /**
587 * @param values radius values, -1 means no this border width
588 * value[0] : BorderWidth value for left,value[1] : BorderWidth value for right
589 * value[2] : BorderWidth value for top,value[3] : BorderWidth value for bottom
590 * @param units adius units
591 * units[0]: BorderWidth unit for left ,units[1] : BorderWidth unit for right
592 * units[2]: BorderWidth unit for top, units[3] : BorderWidth unit for bottom
593 */
SetBorderWidth(ArkUINodeHandle node,const ArkUI_Float32 * values,const int * units,ArkUI_Int32 length)594 void SetBorderWidth(ArkUINodeHandle node, const ArkUI_Float32* values, const int* units, ArkUI_Int32 length)
595 {
596 auto* frameNode = reinterpret_cast<FrameNode*>(node);
597 CHECK_NULL_VOID(frameNode);
598 if (length != DEFAULT_LENGTH) {
599 return;
600 }
601 std::optional<CalcDimension> topDimen;
602 std::optional<CalcDimension> rightDimen;
603 std::optional<CalcDimension> bottomDimen;
604 std::optional<CalcDimension> leftDimen;
605
606 if (values[NUM_0] != -1 &&
607 static_cast<OHOS::Ace::DimensionUnit>(units[NUM_0]) != OHOS::Ace::DimensionUnit::INVALID) {
608 topDimen = Dimension(values[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_0]));
609 }
610 if (values[NUM_1] != -1 &&
611 static_cast<OHOS::Ace::DimensionUnit>(units[NUM_1]) != OHOS::Ace::DimensionUnit::INVALID) {
612 rightDimen = Dimension(values[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_1]));
613 }
614 if (values[NUM_2] != -1 &&
615 static_cast<OHOS::Ace::DimensionUnit>(units[NUM_2]) != OHOS::Ace::DimensionUnit::INVALID) {
616 bottomDimen = Dimension(values[NUM_2], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_2]));
617 }
618 if (values[NUM_3] != -1 &&
619 static_cast<OHOS::Ace::DimensionUnit>(units[NUM_3]) != OHOS::Ace::DimensionUnit::INVALID) {
620 leftDimen = Dimension(values[NUM_3], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_3]));
621 }
622
623 NG::BorderWidthProperty borderWidth;
624 borderWidth.leftDimen = leftDimen;
625 borderWidth.rightDimen = rightDimen;
626 borderWidth.topDimen = topDimen;
627 borderWidth.bottomDimen = bottomDimen;
628 borderWidth.multiValued = true;
629 ViewAbstract::SetBorderWidth(frameNode, borderWidth);
630 }
631
ResetBorderWidth(ArkUINodeHandle node)632 void ResetBorderWidth(ArkUINodeHandle node)
633 {
634 auto* frameNode = reinterpret_cast<FrameNode*>(node);
635 CHECK_NULL_VOID(frameNode);
636 OHOS::Ace::Dimension borderWidth;
637 ViewAbstract::SetBorderWidth(frameNode, borderWidth);
638 }
639
SetTransform(ArkUINodeHandle node,const float * matrix,ArkUI_Int32 length)640 void SetTransform(ArkUINodeHandle node, const float* matrix, ArkUI_Int32 length)
641 {
642 auto* frameNode = reinterpret_cast<FrameNode*>(node);
643 CHECK_NULL_VOID(frameNode);
644 const auto matrix4Len = Matrix4::DIMENSION * Matrix4::DIMENSION;
645 if (length != matrix4Len) {
646 return;
647 }
648 NG::ViewAbstract::SetTransformMatrix(
649 frameNode, Matrix4(matrix[NUM_0], matrix[NUM_4], matrix[NUM_8], matrix[NUM_12], matrix[NUM_1], matrix[NUM_5],
650 matrix[NUM_9], matrix[NUM_13], matrix[NUM_2], matrix[NUM_6], matrix[NUM_10], matrix[NUM_14],
651 matrix[NUM_3], matrix[NUM_7], matrix[NUM_11], matrix[NUM_15]));
652 }
653
ResetTransform(ArkUINodeHandle node)654 void ResetTransform(ArkUINodeHandle node)
655 {
656 auto* frameNode = reinterpret_cast<FrameNode*>(node);
657 CHECK_NULL_VOID(frameNode);
658 const auto matrix4Len = Matrix4::DIMENSION * Matrix4::DIMENSION;
659 std::vector<float> matrix(matrix4Len);
660 const int32_t initPosition = 5;
661 for (int32_t i = 0; i < matrix4Len; i = i + initPosition) {
662 double value = 1.0;
663 matrix[i] = static_cast<float>(value);
664 }
665 NG::ViewAbstract::SetTransformMatrix(
666 frameNode, Matrix4(matrix[NUM_0], matrix[NUM_4], matrix[NUM_8], matrix[NUM_12], matrix[NUM_1], matrix[NUM_5],
667 matrix[NUM_9], matrix[NUM_13], matrix[NUM_2], matrix[NUM_6], matrix[NUM_10], matrix[NUM_14],
668 matrix[NUM_3], matrix[NUM_7], matrix[NUM_11], matrix[NUM_15]));
669 }
670
SetBorderColor(ArkUINodeHandle node,uint32_t leftColorInt,uint32_t rightColorInt,uint32_t topColorInt,uint32_t bottomColorInt)671 void SetBorderColor(ArkUINodeHandle node, uint32_t leftColorInt, uint32_t rightColorInt,
672 uint32_t topColorInt, uint32_t bottomColorInt)
673 {
674 auto* frameNode = reinterpret_cast<FrameNode*>(node);
675 CHECK_NULL_VOID(frameNode);
676 NG::BorderColorProperty borderColors;
677 borderColors.leftColor = Color(leftColorInt);
678 borderColors.rightColor = Color(rightColorInt);
679 borderColors.topColor = Color(topColorInt);
680 borderColors.bottomColor = Color(bottomColorInt);
681 borderColors.multiValued = true;
682
683 ViewAbstract::SetBorderColor(frameNode, borderColors);
684 }
685
ResetBorderColor(ArkUINodeHandle node)686 void ResetBorderColor(ArkUINodeHandle node)
687 {
688 auto* frameNode = reinterpret_cast<FrameNode*>(node);
689 CHECK_NULL_VOID(frameNode);
690 ViewAbstract::SetBorderColor(frameNode, Color::BLACK);
691 }
692
693 /**
694 * @param xValue position x value
695 * @param xUnit position x unit
696 * @param yValue position y unit
697 * @param yUnit position y unit
698 */
SetPosition(ArkUINodeHandle node,ArkUI_Float32 xValue,int xUnit,ArkUI_Float32 yValue,int yUnit)699 void SetPosition(ArkUINodeHandle node, ArkUI_Float32 xValue, int xUnit, ArkUI_Float32 yValue, int yUnit)
700 {
701 auto* frameNode = reinterpret_cast<FrameNode*>(node);
702 CHECK_NULL_VOID(frameNode);
703
704 ViewAbstract::SetPosition(frameNode, { Dimension(xValue, static_cast<OHOS::Ace::DimensionUnit>(xUnit)),
705 Dimension(yValue, static_cast<OHOS::Ace::DimensionUnit>(yUnit)) });
706 }
707
ResetPosition(ArkUINodeHandle node)708 void ResetPosition(ArkUINodeHandle node)
709 {
710 auto* frameNode = reinterpret_cast<FrameNode*>(node);
711 CHECK_NULL_VOID(frameNode);
712 ViewAbstract::SetPosition(frameNode, { 0.0_vp, 0.0_vp });
713 }
714
715 /**
716 * @param styles styles value
717 * styles[0] : styleLeft, styles[1] : styleRight, styles[2] : styleTop, styles[3] : styleBottom
718 * @param length styles length
719 */
SetBorderStyle(ArkUINodeHandle node,const ArkUI_Int32 * styles,ArkUI_Int32 length)720 void SetBorderStyle(ArkUINodeHandle node, const ArkUI_Int32* styles, ArkUI_Int32 length)
721 {
722 auto* frameNode = reinterpret_cast<FrameNode*>(node);
723 CHECK_NULL_VOID(frameNode);
724 if (length == NUM_1) {
725 ViewAbstract::SetBorderStyle(frameNode, ConvertBorderStyle(styles[NUM_0]));
726 return;
727 }
728 if (length == NUM_4) {
729 NG::BorderStyleProperty borderStyles;
730 borderStyles.styleLeft = ConvertBorderStyle(styles[NUM_3]);
731 borderStyles.styleRight = ConvertBorderStyle(styles[NUM_1]);
732 borderStyles.styleTop = ConvertBorderStyle(styles[NUM_0]);
733 borderStyles.styleBottom = ConvertBorderStyle(styles[NUM_2]);
734 borderStyles.multiValued = true;
735 ViewAbstract::SetBorderStyle(frameNode, borderStyles);
736 }
737 }
738
ResetBorderStyle(ArkUINodeHandle node)739 void ResetBorderStyle(ArkUINodeHandle node)
740 {
741 auto* frameNode = reinterpret_cast<FrameNode*>(node);
742 CHECK_NULL_VOID(frameNode);
743 ViewAbstract::SetBorderStyle(frameNode, BorderStyle::SOLID);
744 }
745
GetShadowFromTheme(ShadowStyle shadowStyle,Shadow & shadow)746 bool GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow)
747 {
748 if (shadowStyle == ShadowStyle::None) {
749 return true;
750 }
751
752 auto container = Container::Current();
753 CHECK_NULL_RETURN(container, false);
754 auto pipelineContext = container->GetPipelineContext();
755 CHECK_NULL_RETURN(pipelineContext, false);
756
757 auto shadowTheme = pipelineContext->GetTheme<ShadowTheme>();
758 CHECK_NULL_RETURN(shadowTheme, false);
759 auto colorMode = SystemProperties::GetColorMode();
760 shadow = shadowTheme->GetShadow(shadowStyle, colorMode);
761 return true;
762 }
763
764 /**
765 * @param shadows shadow value
766 * shadows[0] : BlurRadius, shadows[1] : 1: has ColorStrategy; 2: has Color
767 * shadows[2] : OffsetX, offset[3] : OffsetY
768 * shadows[4] : ShadowType, shadows[5] : Color, shadows[6] : IsFilled
769 * @param length shadows length
770 */
SetBackShadow(ArkUINodeHandle node,const ArkUI_Float32 * shadows,ArkUI_Int32 length)771 void SetBackShadow(ArkUINodeHandle node, const ArkUI_Float32* shadows, ArkUI_Int32 length)
772 {
773 auto* frameNode = reinterpret_cast<FrameNode*>(node);
774 CHECK_NULL_VOID(frameNode);
775 if (length == NUM_1) {
776 Shadow shadow;
777 auto shadowStyle = static_cast<ShadowStyle>(shadows[NUM_0]);
778 auto style = static_cast<ShadowStyle>(shadowStyle);
779 if (GetShadowFromTheme(style, shadow)) {
780 ViewAbstract::SetBackShadow(frameNode, shadow);
781 }
782 }
783 if (length != NUM_7) {
784 return;
785 }
786 auto blurRadius = shadows[NUM_0]; // BlurRadius
787 auto hasColorValue = static_cast<int32_t>(shadows[NUM_1]); // 1: has ColorStrategy; 2: has Color
788 auto offsetX = shadows[NUM_2]; // OffsetX
789 auto offsetY = shadows[NUM_3]; // OffsetY
790 auto shadowType = static_cast<uint32_t>(shadows[NUM_4]); // ShadowType
791 auto color = static_cast<uint32_t>(shadows[NUM_5]); // Color
792 auto isFilled = static_cast<uint32_t>(shadows[NUM_6]); // IsFilled
793 Shadow shadow;
794 shadow.SetBlurRadius(blurRadius);
795 shadow.SetOffsetX(offsetX);
796 shadow.SetOffsetY(offsetY);
797 if (hasColorValue == 1) { // 1: has ColorStrategy
798 shadow.SetShadowColorStrategy(static_cast<ShadowColorStrategy>(color));
799 } else if (hasColorValue == 2) { // 2: has Color
800 shadow.SetColor(Color(color));
801 }
802 shadow.SetShadowType(static_cast<ShadowType>(shadowType));
803 shadow.SetIsFilled(static_cast<bool>(isFilled));
804 ViewAbstract::SetBackShadow(frameNode, shadow);
805 }
806
ResetBackShadow(ArkUINodeHandle node)807 void ResetBackShadow(ArkUINodeHandle node)
808 {
809 auto* frameNode = reinterpret_cast<FrameNode*>(node);
810 CHECK_NULL_VOID(frameNode);
811 Shadow shadow;
812 ViewAbstract::SetBackShadow(frameNode, shadow);
813 }
814
SetHitTestBehavior(ArkUINodeHandle node,uint32_t value)815 void SetHitTestBehavior(ArkUINodeHandle node, uint32_t value)
816 {
817 auto* frameNode = reinterpret_cast<FrameNode*>(node);
818 CHECK_NULL_VOID(frameNode);
819 NG::HitTestMode hitTestModeNG = static_cast<NG::HitTestMode>(value);
820 ViewAbstract::SetHitTestMode(frameNode, hitTestModeNG);
821 }
822
ResetHitTestBehavior(ArkUINodeHandle node)823 void ResetHitTestBehavior(ArkUINodeHandle node)
824 {
825 auto* frameNode = reinterpret_cast<FrameNode*>(node);
826 CHECK_NULL_VOID(frameNode);
827 ViewAbstract::SetHitTestMode(frameNode, NG::HitTestMode::HTMDEFAULT);
828 }
829
SetZIndex(ArkUINodeHandle node,ArkUI_Int32 value)830 void SetZIndex(ArkUINodeHandle node, ArkUI_Int32 value)
831 {
832 auto* frameNode = reinterpret_cast<FrameNode*>(node);
833 CHECK_NULL_VOID(frameNode);
834 ViewAbstract::SetZIndex(frameNode, value);
835 }
836
ResetZIndex(ArkUINodeHandle node)837 void ResetZIndex(ArkUINodeHandle node)
838 {
839 auto* frameNode = reinterpret_cast<FrameNode*>(node);
840 CHECK_NULL_VOID(frameNode);
841 ViewAbstract::SetZIndex(frameNode, 0);
842 }
843
SetOpacity(ArkUINodeHandle node,ArkUI_Float32 opacity)844 void SetOpacity(ArkUINodeHandle node, ArkUI_Float32 opacity)
845 {
846 auto* frameNode = reinterpret_cast<FrameNode*>(node);
847 CHECK_NULL_VOID(frameNode);
848 if ((LessNotEqual(opacity, 0.0)) || opacity > 1) {
849 opacity = 1.0f;
850 }
851 ViewAbstract::SetOpacity(frameNode, opacity);
852 }
853
ResetOpacity(ArkUINodeHandle node)854 void ResetOpacity(ArkUINodeHandle node)
855 {
856 auto* frameNode = reinterpret_cast<FrameNode*>(node);
857 CHECK_NULL_VOID(frameNode);
858 ViewAbstract::SetOpacity(frameNode, 1.0f);
859 }
860
SetAlign(ArkUINodeHandle node,ArkUI_Int32 align)861 void SetAlign(ArkUINodeHandle node, ArkUI_Int32 align)
862 {
863 auto* frameNode = reinterpret_cast<FrameNode*>(node);
864 CHECK_NULL_VOID(frameNode);
865 Alignment alignment = ParseAlignment(align);
866 ViewAbstract::SetAlign(frameNode, alignment);
867 }
868
ResetAlign(ArkUINodeHandle node)869 void ResetAlign(ArkUINodeHandle node)
870 {
871 auto* frameNode = reinterpret_cast<FrameNode*>(node);
872 CHECK_NULL_VOID(frameNode);
873 ViewAbstract::SetAlign(frameNode, Alignment::CENTER);
874 }
875
SetBackdropBlur(ArkUINodeHandle node,ArkUI_Float32 value)876 void SetBackdropBlur(ArkUINodeHandle node, ArkUI_Float32 value)
877 {
878 float blur = 0.0f;
879 auto* frameNode = reinterpret_cast<FrameNode*>(node);
880 CHECK_NULL_VOID(frameNode);
881 if (value > 0) {
882 blur = value;
883 }
884 CalcDimension dimensionRadius(blur, DimensionUnit::PX);
885 ViewAbstract::SetBackdropBlur(frameNode, dimensionRadius);
886 }
887
ResetBackdropBlur(ArkUINodeHandle node)888 void ResetBackdropBlur(ArkUINodeHandle node)
889 {
890 auto* frameNode = reinterpret_cast<FrameNode*>(node);
891 CHECK_NULL_VOID(frameNode);
892 double blur = 0.0;
893 CalcDimension dimensionRadius(blur, DimensionUnit::PX);
894 ViewAbstract::SetBackdropBlur(frameNode, dimensionRadius);
895 }
896
SetHueRotate(ArkUINodeHandle node,float deg)897 void SetHueRotate(ArkUINodeHandle node, float deg)
898 {
899 auto* frameNode = reinterpret_cast<FrameNode*>(node);
900 CHECK_NULL_VOID(frameNode);
901 deg = std::fmod(deg, ROUND_UNIT);
902 if (deg < 0.0f) {
903 deg += ROUND_UNIT;
904 }
905 ViewAbstract::SetHueRotate(frameNode, deg);
906 }
907
ResetHueRotate(ArkUINodeHandle node)908 void ResetHueRotate(ArkUINodeHandle node)
909 {
910 auto* frameNode = reinterpret_cast<FrameNode*>(node);
911 CHECK_NULL_VOID(frameNode);
912 float deg = 0.0f;
913 ViewAbstract::SetHueRotate(frameNode, deg);
914 }
915
SetInvert(ArkUINodeHandle node,ArkUI_Float32 invert)916 void SetInvert(ArkUINodeHandle node, ArkUI_Float32 invert)
917 {
918 auto* frameNode = reinterpret_cast<FrameNode*>(node);
919 CHECK_NULL_VOID(frameNode);
920 InvertVariant invertVariant = static_cast<float>(invert);
921 ViewAbstract::SetInvert(frameNode, invertVariant);
922 }
923
ResetInvert(ArkUINodeHandle node)924 void ResetInvert(ArkUINodeHandle node)
925 {
926 auto* frameNode = reinterpret_cast<FrameNode*>(node);
927 CHECK_NULL_VOID(frameNode);
928 InvertVariant invert = 0.0f;
929 ViewAbstract::SetInvert(frameNode, invert);
930 }
931
SetSepia(ArkUINodeHandle node,ArkUI_Float32 sepia)932 void SetSepia(ArkUINodeHandle node, ArkUI_Float32 sepia)
933 {
934 auto* frameNode = reinterpret_cast<FrameNode*>(node);
935 CHECK_NULL_VOID(frameNode);
936 CalcDimension value = CalcDimension(sepia, DimensionUnit::VP);
937 if (LessNotEqual(value.Value(), 0.0)) {
938 value.SetValue(0.0);
939 }
940 ViewAbstract::SetSepia(frameNode, value);
941 }
942
ResetSepia(ArkUINodeHandle node)943 void ResetSepia(ArkUINodeHandle node)
944 {
945 auto* frameNode = reinterpret_cast<FrameNode*>(node);
946 CHECK_NULL_VOID(frameNode);
947 CalcDimension value(0.0, DimensionUnit::VP);
948 ViewAbstract::SetSepia(frameNode, value);
949 }
950
SetSaturate(ArkUINodeHandle node,ArkUI_Float32 saturate)951 void SetSaturate(ArkUINodeHandle node, ArkUI_Float32 saturate)
952 {
953 auto* frameNode = reinterpret_cast<FrameNode*>(node);
954 CHECK_NULL_VOID(frameNode);
955 CalcDimension value = CalcDimension(saturate, DimensionUnit::VP);
956 if (LessNotEqual(value.Value(), 0.0)) {
957 value.SetValue(0.0);
958 }
959 ViewAbstract::SetSaturate(frameNode, value);
960 }
961
ResetSaturate(ArkUINodeHandle node)962 void ResetSaturate(ArkUINodeHandle node)
963 {
964 auto* frameNode = reinterpret_cast<FrameNode*>(node);
965 CHECK_NULL_VOID(frameNode);
966 CalcDimension value(1.0, DimensionUnit::VP);
967 ViewAbstract::SetSaturate(frameNode, value);
968 }
969
SetColorBlend(ArkUINodeHandle node,uint32_t color)970 void SetColorBlend(ArkUINodeHandle node, uint32_t color)
971 {
972 auto* frameNode = reinterpret_cast<FrameNode*>(node);
973 CHECK_NULL_VOID(frameNode);
974 ViewAbstract::SetColorBlend(frameNode, Color(color));
975 }
976
ResetColorBlend(ArkUINodeHandle node)977 void ResetColorBlend(ArkUINodeHandle node)
978 {
979 auto* frameNode = reinterpret_cast<FrameNode*>(node);
980 CHECK_NULL_VOID(frameNode);
981 Color colorBlend = Color::TRANSPARENT;
982 ViewAbstract::SetColorBlend(frameNode, colorBlend);
983 }
984
SetGrayscale(ArkUINodeHandle node,ArkUI_Float32 grayScale)985 void SetGrayscale(ArkUINodeHandle node, ArkUI_Float32 grayScale)
986 {
987 auto* frameNode = reinterpret_cast<FrameNode*>(node);
988 CHECK_NULL_VOID(frameNode);
989 CalcDimension value = CalcDimension(grayScale, DimensionUnit::VP);
990 if (LessNotEqual(value.Value(), 0.0)) {
991 value.SetValue(0.0);
992 }
993 if (GreatNotEqual(value.Value(), 1.0)) {
994 value.SetValue(1.0);
995 }
996 ViewAbstract::SetGrayScale(frameNode, value);
997 }
998
ResetGrayscale(ArkUINodeHandle node)999 void ResetGrayscale(ArkUINodeHandle node)
1000 {
1001 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1002 CHECK_NULL_VOID(frameNode);
1003 CalcDimension value(0.0, DimensionUnit::VP);
1004 ViewAbstract::SetGrayScale(frameNode, value);
1005 }
1006
SetContrast(ArkUINodeHandle node,ArkUI_Float32 contrast)1007 void SetContrast(ArkUINodeHandle node, ArkUI_Float32 contrast)
1008 {
1009 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1010 CHECK_NULL_VOID(frameNode);
1011 CalcDimension value = CalcDimension(contrast, DimensionUnit::VP);
1012 if (LessNotEqual(value.Value(), 0.0)) {
1013 value.SetValue(0.0);
1014 }
1015 ViewAbstract::SetContrast(frameNode, value);
1016 }
1017
ResetContrast(ArkUINodeHandle node)1018 void ResetContrast(ArkUINodeHandle node)
1019 {
1020 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1021 CHECK_NULL_VOID(frameNode);
1022 CalcDimension value(1.0, DimensionUnit::VP);
1023 ViewAbstract::SetContrast(frameNode, value);
1024 }
1025
SetBrightness(ArkUINodeHandle node,ArkUI_Float32 brightness)1026 void SetBrightness(ArkUINodeHandle node, ArkUI_Float32 brightness)
1027 {
1028 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1029 CHECK_NULL_VOID(frameNode);
1030 CalcDimension value = CalcDimension(brightness, DimensionUnit::VP);
1031 if (LessNotEqual(value.Value(), 0.0)) {
1032 value.SetValue(0.0);
1033 }
1034 ViewAbstract::SetBrightness(frameNode, value);
1035 }
1036
ResetBrightness(ArkUINodeHandle node)1037 void ResetBrightness(ArkUINodeHandle node)
1038 {
1039 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1040 CHECK_NULL_VOID(frameNode);
1041 CalcDimension value(1.0, DimensionUnit::VP);
1042 ViewAbstract::SetBrightness(frameNode, value);
1043 }
1044
SetBlur(ArkUINodeHandle node,ArkUI_Float32 value)1045 void SetBlur(ArkUINodeHandle node, ArkUI_Float32 value)
1046 {
1047 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1048 CHECK_NULL_VOID(frameNode);
1049 float blur = 0.0f;
1050 if (value > 0) {
1051 blur = value;
1052 }
1053 CalcDimension dimensionBlur(blur, DimensionUnit::PX);
1054 ViewAbstract::SetFrontBlur(frameNode, dimensionBlur);
1055 }
1056
ResetBlur(ArkUINodeHandle node)1057 void ResetBlur(ArkUINodeHandle node)
1058 {
1059 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1060 CHECK_NULL_VOID(frameNode);
1061 double blur = 0.0;
1062 CalcDimension dimensionBlur(blur, DimensionUnit::PX);
1063 ViewAbstract::SetFrontBlur(frameNode, dimensionBlur);
1064 }
1065
1066 /**
1067 * @param values value value
1068 * values[0], values[1] : angle: hasValue, angle value
1069 * values[2] : direction
1070 * values[3] : repeating
1071 * @param valuesLength values length
1072 * @param colors color value
1073 * colors[0], colors[1], colors[2] : color[0](color, hasDimension, dimension)
1074 * colors[3], colors[4], colors[5] : color[1](color, hasDimension, dimension)
1075 * ...
1076 * @param colorsLength colors length
1077 */
SetLinearGradient(ArkUINodeHandle node,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength,const ArkUI_Float32 * colors,ArkUI_Int32 colorsLength)1078 void SetLinearGradient(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valuesLength,
1079 const ArkUI_Float32* colors, ArkUI_Int32 colorsLength)
1080 {
1081 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1082 CHECK_NULL_VOID(frameNode);
1083 if ((values == nullptr) || (valuesLength != NUM_4) || ((colorsLength % NUM_3) != 0)) {
1084 return;
1085 }
1086 NG::Gradient gradient;
1087 gradient.CreateGradientWithType(NG::GradientType::LINEAR);
1088 SetLinearGradientValues(gradient, values, valuesLength);
1089 SetGradientColors(gradient, colors, colorsLength);
1090 ViewAbstract::SetLinearGradient(frameNode, gradient);
1091 }
1092
ResetLinearGradient(ArkUINodeHandle node)1093 void ResetLinearGradient(ArkUINodeHandle node)
1094 {
1095 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1096 CHECK_NULL_VOID(frameNode);
1097 NG::Gradient gradient;
1098 gradient.CreateGradientWithType(NG::GradientType::LINEAR);
1099 ViewAbstract::SetLinearGradient(frameNode, gradient);
1100 }
1101
1102 /**
1103 * @param values value value
1104 * values[0], values[1], values[2] : centerX Dimension: hasValue, value, unit
1105 * values[3], values[4], values[5] : centerY Dimension: hasValue, value, unit
1106 * values[6], values[7] : start: hasValue, start degree value
1107 * values[8], values[9] : end: hasValue, end degree value
1108 * values[10], values[11] : rotation: hasValue, rotation degree value
1109 * values[12] : repeating
1110 * @param valuesLength values length
1111 * @param colors color value
1112 * colors[0], colors[1], colors[2] : color[0](color, hasDimension, dimension)
1113 * colors[3], colors[4], colors[5] : color[1](color, hasDimension, dimension)
1114 * ...
1115 * @param colorsLength colors length
1116 */
SetSweepGradient(ArkUINodeHandle node,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength,const ArkUI_Float32 * colors,ArkUI_Int32 colorsLength)1117 void SetSweepGradient(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valuesLength,
1118 const ArkUI_Float32* colors, ArkUI_Int32 colorsLength)
1119 {
1120 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1121 CHECK_NULL_VOID(frameNode);
1122 if ((values == nullptr) || (valuesLength != NUM_13) || ((colorsLength % NUM_3) != 0)) {
1123 return;
1124 }
1125 NG::Gradient gradient;
1126 gradient.CreateGradientWithType(NG::GradientType::SWEEP);
1127 SetSweepGradientValues(gradient, values, valuesLength);
1128 SetGradientColors(gradient, colors, colorsLength);
1129 ViewAbstract::SetSweepGradient(frameNode, gradient);
1130 }
1131
ResetSweepGradient(ArkUINodeHandle node)1132 void ResetSweepGradient(ArkUINodeHandle node)
1133 {
1134 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1135 CHECK_NULL_VOID(frameNode);
1136 NG::Gradient gradient;
1137 gradient.CreateGradientWithType(NG::GradientType::SWEEP);
1138 ViewAbstract::SetSweepGradient(frameNode, gradient);
1139 }
1140
1141 /**
1142 * @param values value value
1143 * values[0], values[1], values[2] : centerX Dimension: hasValue, value, unit
1144 * values[3], values[4], values[5] : centerY Dimension: hasValue, value, unit
1145 * values[6], values[7], values[8] : radius: Dimension: hasValue, value, unit
1146 * values[9] : repeating
1147 * @param valuesLength values length
1148 * @param colors color value
1149 * colors[0], colors[1], colors[2] : color[0](color, hasDimension, dimension)
1150 * colors[3], colors[4], colors[5] : color[1](color, hasDimension, dimension)
1151 * ...
1152 * @param colorsLength colors length
1153 */
SetRadialGradient(ArkUINodeHandle node,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength,const ArkUI_Float32 * colors,ArkUI_Int32 colorsLength)1154 void SetRadialGradient(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valuesLength,
1155 const ArkUI_Float32* colors, ArkUI_Int32 colorsLength)
1156 {
1157 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1158 CHECK_NULL_VOID(frameNode);
1159 if ((values == nullptr) || (valuesLength != NUM_10) || ((colorsLength % NUM_3) != 0)) {
1160 return;
1161 }
1162 NG::Gradient gradient;
1163 gradient.CreateGradientWithType(NG::GradientType::RADIAL);
1164 SetRadialGradientValues(gradient, values, valuesLength);
1165 SetGradientColors(gradient, colors, colorsLength);
1166 ViewAbstract::SetRadialGradient(frameNode, gradient);
1167 }
1168
ResetRadialGradient(ArkUINodeHandle node)1169 void ResetRadialGradient(ArkUINodeHandle node)
1170 {
1171 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1172 CHECK_NULL_VOID(frameNode);
1173 NG::Gradient gradient;
1174 gradient.CreateGradientWithType(NG::GradientType::RADIAL);
1175 ViewAbstract::SetRadialGradient(frameNode, gradient);
1176 }
1177
1178 /**
1179 * @param text text value
1180 * @param options option value
1181 * option[0], option[1]: align(hasValue, value)
1182 * option[2], option[3], option[4]: offsetX(hasValue, value, unit)
1183 * option[5], option[6], option[7]: offsetY(hasValue, value, unit)
1184 * option[8]: hasOptions
1185 * option[9]: hasOffset
1186 * @param optionsLength options length
1187 */
SetOverlay(ArkUINodeHandle node,const char * text,const ArkUI_Float32 * options,ArkUI_Int32 optionsLength)1188 void SetOverlay(ArkUINodeHandle node, const char* text, const ArkUI_Float32* options, ArkUI_Int32 optionsLength)
1189 {
1190 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1191 CHECK_NULL_VOID(frameNode);
1192 if ((options == nullptr) || (optionsLength != NUM_10)) {
1193 return;
1194 }
1195 auto alignHasValue = options[NUM_0];
1196 auto alignValue = options[NUM_1];
1197 auto offsetXHasValue = options[NUM_2];
1198 auto offsetXValue = options[NUM_3];
1199 auto offsetXUnit = options[NUM_4];
1200 auto offsetYHasValue = options[NUM_5];
1201 auto offsetYValue = options[NUM_6];
1202 auto offsetYUnit = options[NUM_7];
1203 auto hasOptions = options[NUM_8];
1204 auto hasOffset = options[NUM_9];
1205 NG::OverlayOptions overlay;
1206 if (text != nullptr) {
1207 overlay.content = text;
1208 }
1209 if (static_cast<bool>(hasOptions)) {
1210 if (static_cast<bool>(alignHasValue)) {
1211 overlay.align = ParseAlignment(static_cast<int32_t>(alignValue));
1212 } else {
1213 overlay.align = Alignment::TOP_LEFT;
1214 }
1215 if (static_cast<bool>(hasOffset)) {
1216 if (static_cast<bool>(offsetXHasValue)) {
1217 overlay.x = CalcDimension(offsetXValue, static_cast<DimensionUnit>(offsetXUnit));
1218 }
1219 if (static_cast<bool>(offsetYHasValue)) {
1220 overlay.y = CalcDimension(offsetYValue, static_cast<DimensionUnit>(offsetYUnit));
1221 }
1222 }
1223 } else {
1224 overlay.align = Alignment::CENTER;
1225 overlay.x = CalcDimension(0);
1226 overlay.y = CalcDimension(0);
1227 }
1228 ViewAbstract::SetOverlay(frameNode, overlay);
1229 }
1230
ResetOverlay(ArkUINodeHandle node)1231 void ResetOverlay(ArkUINodeHandle node)
1232 {
1233 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1234 CHECK_NULL_VOID(frameNode);
1235 NG::OverlayOptions overlay;
1236 overlay.align = Alignment::TOP_LEFT;
1237 overlay.x = CalcDimension(0);
1238 overlay.y = CalcDimension(0);
1239 ViewAbstract::SetOverlay(frameNode, overlay);
1240 }
1241
1242 /**
1243 * @param src source value
1244 * @param options option value
1245 * option[offset + 0], option[offset + 1], option[offset + 2]: sliceTop(hasValue, value, unit)
1246 * option[offset + 3], option[offset + 4], option[offset + 5]: sliceRight(hasValue, value, unit)
1247 * option[offset + 6], option[offset + 7], option[offset + 8]: sliceBottom(hasValue, value, unit)
1248 * option[offset + 9], option[offset + 10], option[offset + 11]: sliceLeft(hasValue, value, unit)
1249 * option[offset + 12], option[offset + 13]: repeat(hasValue, value)
1250 * option[offset + 14], option[offset + 15], option[offset + 16]: widthTop(hasValue, value, unit)
1251 * option[offset + 17], option[offset + 18], option[offset + 19]: widthRight(hasValue, value, unit)
1252 * option[offset + 20], option[offset + 21], option[offset + 22]: widthBottom(hasValue, value, unit)
1253 * option[offset + 23], option[offset + 24], option[offset + 25]: widthLeft(hasValue, value, unit)
1254 * option[offset + 26], option[offset + 27], option[offset + 28]: outsetTop(hasValue, value, unit)
1255 * option[offset + 29], option[offset + 30], option[offset + 31]: outsetRight(hasValue, value, unit)
1256 * option[offset + 32], option[offset + 33], option[offset + 34]: outsetBottom(hasValue, value, unit)
1257 * option[offset + 35], option[offset + 36], option[offset + 37]: outsetLeft(hasValue, value, unit)
1258 * option[offset + 38], option[offset + 39]: fill(hasValue, value)
1259 * option[offset + 40]: bitset
1260 * @param optionsLength options length
1261 */
SetBorderImage(ArkUINodeHandle node,const char * src,const ArkUIStringAndFloat * options,ArkUI_Int32 optionsLength)1262 void SetBorderImage(ArkUINodeHandle node, const char* src,
1263 const ArkUIStringAndFloat* options, ArkUI_Int32 optionsLength)
1264 {
1265 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1266 CHECK_NULL_VOID(frameNode);
1267 // slice:12 double, repeat:2 double, width:12 double, outset:12 double, fill:2 double, bitset:1 double
1268 auto desireLength = NUM_12 + NUM_2 + NUM_12 + NUM_12 + NUM_2 + NUM_1;
1269 if ((options == nullptr) || (optionsLength != desireLength)) {
1270 return;
1271 }
1272 RefPtr<BorderImage> borderImage = AceType::MakeRefPtr<BorderImage>();
1273 if (src != nullptr) {
1274 borderImage->SetSrc(std::string(src));
1275 }
1276 int32_t loc = 0;
1277 std::vector<BorderImageDirection> directions = { BorderImageDirection::TOP, BorderImageDirection::RIGHT,
1278 BorderImageDirection::BOTTOM, BorderImageDirection::LEFT };
1279 SetBorderImageSlice(borderImage, directions, options, optionsLength, loc); // read 12 double
1280 SetBorderImageRepeat(borderImage, options, optionsLength, loc); // read 2 double
1281 SetBorderImageWidth(borderImage, directions, options, optionsLength, loc); // read 12 double
1282 SetBorderImageOutset(borderImage, directions, options, optionsLength, loc); // read 12 double
1283 SetBorderImageFill(borderImage, options, optionsLength, loc); // read 2 double
1284 auto bitsetValue = options[loc].value;
1285 SetBorderImage(frameNode, borderImage, static_cast<uint8_t>(bitsetValue));
1286 }
1287
ResetBorderImage(ArkUINodeHandle node)1288 void ResetBorderImage(ArkUINodeHandle node)
1289 {
1290 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1291 CHECK_NULL_VOID(frameNode);
1292 RefPtr<BorderImage> borderImage = AceType::MakeRefPtr<BorderImage>();
1293 uint8_t imageBorderBitsets = 0;
1294 SetBorderImage(frameNode, borderImage, imageBorderBitsets);
1295 }
1296
SetBorderImageGradient(ArkUINodeHandle node,const ArkUI_Float32 * values,ArkUI_Int32 valuesLength,const ArkUI_Float32 * colors,ArkUI_Int32 colorsLength)1297 void SetBorderImageGradient(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valuesLength,
1298 const ArkUI_Float32* colors, ArkUI_Int32 colorsLength)
1299 {
1300 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1301 CHECK_NULL_VOID(frameNode);
1302 if ((values == nullptr) || (valuesLength != NUM_4) || ((colorsLength % NUM_3) != 0)) {
1303 return;
1304 }
1305 NG::Gradient gradient;
1306 gradient.CreateGradientWithType(NG::GradientType::LINEAR);
1307 SetBorderImageGradientValues(gradient, values, valuesLength);
1308 SetGradientColors(gradient, colors, colorsLength);
1309 ViewAbstract::SetBorderImageGradient(frameNode, gradient);
1310 }
1311
SetForegroundBlurStyle(ArkUINodeHandle node,ArkUI_Int32 blurStyle,ArkUI_Int32 colorMode,ArkUI_Int32 adaptiveColor,ArkUI_Float32 scale)1312 void SetForegroundBlurStyle(
1313 ArkUINodeHandle node, ArkUI_Int32 blurStyle, ArkUI_Int32 colorMode, ArkUI_Int32 adaptiveColor, ArkUI_Float32 scale)
1314 {
1315 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1316 CHECK_NULL_VOID(frameNode);
1317 BlurStyleOption fgBlurStyle;
1318 if (blurStyle >= 0) {
1319 if (blurStyle >= static_cast<int>(BlurStyle::NO_MATERIAL) &&
1320 blurStyle <= static_cast<int>(BlurStyle::BACKGROUND_ULTRA_THICK)) {
1321 fgBlurStyle.blurStyle = static_cast<BlurStyle>(blurStyle);
1322 }
1323 }
1324 bool isHasOptions = !((colorMode < 0) && (adaptiveColor < 0) && (scale < 0));
1325 if (isHasOptions) {
1326 if (colorMode >= static_cast<int32_t>(ThemeColorMode::SYSTEM) &&
1327 colorMode <= static_cast<int32_t>(ThemeColorMode::DARK)) {
1328 fgBlurStyle.colorMode = static_cast<ThemeColorMode>(colorMode);
1329 }
1330 if (adaptiveColor >= static_cast<int32_t>(AdaptiveColor::DEFAULT) &&
1331 adaptiveColor <= static_cast<int32_t>(AdaptiveColor::AVERAGE)) {
1332 fgBlurStyle.adaptiveColor = static_cast<AdaptiveColor>(adaptiveColor);
1333 }
1334 if (scale >= 0) {
1335 fgBlurStyle.scale = std::clamp(scale, 0.0f, 1.0f);
1336 }
1337 }
1338 ViewAbstract::SetForegroundBlurStyle(frameNode, fgBlurStyle);
1339 }
1340
ResetForegroundBlurStyle(ArkUINodeHandle node)1341 void ResetForegroundBlurStyle(ArkUINodeHandle node)
1342 {
1343 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1344 CHECK_NULL_VOID(frameNode);
1345 BlurStyleOption styleOption;
1346 ViewAbstract::SetForegroundBlurStyle(frameNode, styleOption);
1347 }
1348
1349 /**
1350 * @param blurRadius blurRadius value
1351 * @param stops stop value
1352 * stops[0], stops[1] : fractionStops pair[0]
1353 * stops[2], stops[3] : fractionStops pair[1] ...
1354 * @param stopsLength stops length
1355 * @param directionValue direction value
1356 */
SetLinearGradientBlur(ArkUINodeHandle node,ArkUI_Float32 blurRadius,const ArkUI_Float32 * stops,ArkUI_Uint32 stopsLength,ArkUI_Int32 directionValue)1357 void SetLinearGradientBlur(ArkUINodeHandle node, ArkUI_Float32 blurRadius, const ArkUI_Float32* stops,
1358 ArkUI_Uint32 stopsLength, ArkUI_Int32 directionValue)
1359 {
1360 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1361 CHECK_NULL_VOID(frameNode);
1362 blurRadius = std::clamp(blurRadius, 0.0f, 60.0f); // 60.0 represents largest blur radius;
1363 std::vector<std::pair<float, float>> fractionStops;
1364 if ((stopsLength & 0x1) == 0) {
1365 float tmpPos = -1.0f;
1366 for (size_t index = 0; index < stopsLength; index += NUM_2) {
1367 auto first = stops[index];
1368 auto second = stops[index + NUM_1];
1369 std::pair<float, float> fractionStop;
1370 fractionStop.first = static_cast<float>(std::clamp(first, 0.0f, 1.0f));
1371 fractionStop.second = static_cast<float>(std::clamp(second, 0.0f, 1.0f));
1372 if (fractionStop.second <= tmpPos) {
1373 fractionStops.clear();
1374 break;
1375 }
1376 tmpPos = fractionStop.second;
1377 fractionStops.push_back(fractionStop);
1378 }
1379 }
1380 if (static_cast<int32_t>(fractionStops.size()) <= 1) {
1381 fractionStops.clear();
1382 fractionStops.push_back(std::pair<float, float>(0.0f, 0.0f));
1383 fractionStops.push_back(std::pair<float, float>(0.0f, 1.0f));
1384 }
1385 if (directionValue < static_cast<int8_t>(GradientDirection::LEFT) ||
1386 directionValue >= static_cast<int8_t>(GradientDirection::NONE)) {
1387 directionValue = static_cast<int8_t>(GradientDirection::BOTTOM);
1388 }
1389 auto direction = static_cast<GradientDirection>(directionValue);
1390 Dimension dimensionRadius(blurRadius, DimensionUnit::PX);
1391 NG::LinearGradientBlurPara blurPara(dimensionRadius, fractionStops, direction);
1392 ViewAbstract::SetLinearGradientBlur(frameNode, blurPara);
1393 }
1394
ResetLinearGradientBlur(ArkUINodeHandle node)1395 void ResetLinearGradientBlur(ArkUINodeHandle node)
1396 {
1397 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1398 CHECK_NULL_VOID(frameNode);
1399 std::vector<std::pair<float, float>> fractionStops;
1400 fractionStops.push_back(std::pair<float, float>(0.0f, 0.0f));
1401 fractionStops.push_back(std::pair<float, float>(0.0f, 1.0f));
1402 Dimension dimensionRadius(0.0f, DimensionUnit::PX);
1403 NG::LinearGradientBlurPara blurPara(dimensionRadius, fractionStops, GradientDirection::BOTTOM);
1404 ViewAbstract::SetLinearGradientBlur(frameNode, blurPara);
1405 }
1406
SetBackgroundBlurStyle(ArkUINodeHandle node,ArkUI_Int32 blurStyle,ArkUI_Int32 colorMode,ArkUI_Int32 adaptiveColor,ArkUI_Float32 scale)1407 void SetBackgroundBlurStyle(
1408 ArkUINodeHandle node, ArkUI_Int32 blurStyle, ArkUI_Int32 colorMode, ArkUI_Int32 adaptiveColor, ArkUI_Float32 scale)
1409 {
1410 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1411 CHECK_NULL_VOID(frameNode);
1412 BlurStyleOption bgBlurStyle;
1413 if (blurStyle >= 0) {
1414 if (blurStyle >= static_cast<int>(BlurStyle::NO_MATERIAL) &&
1415 blurStyle <= static_cast<int>(BlurStyle::BACKGROUND_ULTRA_THICK)) {
1416 bgBlurStyle.blurStyle = static_cast<BlurStyle>(blurStyle);
1417 }
1418 }
1419 bool isHasOptions = !((colorMode < 0) && (adaptiveColor < 0) && (scale < 0));
1420 if (isHasOptions) {
1421 if (colorMode >= static_cast<int32_t>(ThemeColorMode::SYSTEM) &&
1422 colorMode <= static_cast<int32_t>(ThemeColorMode::DARK)) {
1423 bgBlurStyle.colorMode = static_cast<ThemeColorMode>(colorMode);
1424 }
1425 if (adaptiveColor >= static_cast<int32_t>(AdaptiveColor::DEFAULT) &&
1426 adaptiveColor <= static_cast<int32_t>(AdaptiveColor::AVERAGE)) {
1427 bgBlurStyle.adaptiveColor = static_cast<AdaptiveColor>(adaptiveColor);
1428 }
1429 bgBlurStyle.scale = std::clamp(scale, 0.0f, 1.0f);
1430 }
1431 ViewAbstract::SetBackgroundBlurStyle(frameNode, bgBlurStyle);
1432 }
1433
ResetBackgroundBlurStyle(ArkUINodeHandle node)1434 void ResetBackgroundBlurStyle(ArkUINodeHandle node)
1435 {
1436 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1437 CHECK_NULL_VOID(frameNode);
1438 BlurStyleOption bgBlurStyle;
1439 ViewAbstract::SetBackgroundBlurStyle(frameNode, bgBlurStyle);
1440 }
1441
1442 /**
1443 * @param src source borderWidthand and BorderRadius value
1444 * @param options option value
1445 * values[offset + 0], option[offset + 1], option[offset + 2]: borderWidth left(hasValue, value, unit)
1446 * values[offset + 3], option[offset + 4], option[offset + 5]: borderWidth right(hasValue, value, unit)
1447 * values[offset + 6], option[offset + 7], option[offset + 8]: borderWidth top(hasValue, value, unit)
1448 * values[offset + 9], option[offset + 10], option[offset + 11]: borderWidth bottom(hasValue, value, unit)
1449 * values[offset + 12], option[offset + 13], option[offset + 14] : BorderRadius TopLeft(hasValue, value, unit)
1450 * values[offset + 15], option[offset + 16], option[offset + 17] : BorderRadius TopRight(hasValue, value, unit)
1451 * values[offset + 18], option[offset + 19], option[offset + 20] : BorderRadius BottomLeft(hasValue, value, unit)
1452 * values[offset + 21], option[offset + 22], option[offset + 23] : BorderRadius BottomRight(hasValue, value, unit)
1453 * @param optionsLength options valuesSize
1454 * @param src source color and Style value
1455 * colorAndStyle[offset + 0], option[offset + 1]: borderColors leftColor(hasValue, value)
1456 * colorAndStyle[offset + 2], option[offset + 3]: borderColors rightColor(hasValue, value)
1457 * colorAndStyle[offset + 4], option[offset + 5]: borderColors topColor(hasValue, value)
1458 * colorAndStyle[offset + 6], option[offset + 7]: borderColors bottomColor(hasValue, value)
1459 * colorAndStyle[offset + 8], option[offset + 9]: borderStyles styleLeft(hasValue, value)
1460 * colorAndStyle[offset + 10], option[offset + 11]: borderStyles styleRight(hasValue, value)
1461 * colorAndStyle[offset + 12], option[offset + 12]: borderStyles styleTop(hasValue, value)
1462 * colorAndStyle[offset + 14], option[offset + 15]: borderStyles styleBottom(hasValue, value)
1463 * @param optionsLength options colorAndStyleSize
1464 */
SetBorder(ArkUINodeHandle node,const ArkUI_Float32 * values,ArkUI_Int32 valuesSize,const uint32_t * colorAndStyle,int32_t colorAndStyleSize)1465 void SetBorder(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valuesSize, const uint32_t* colorAndStyle,
1466 int32_t colorAndStyleSize)
1467 {
1468 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1469 CHECK_NULL_VOID(frameNode);
1470 if ((values == nullptr) || (valuesSize != NUM_24) || (colorAndStyle == nullptr) || colorAndStyleSize != NUM_16) {
1471 return;
1472 }
1473
1474 int32_t offset = NUM_0;
1475 NG::BorderWidthProperty borderWidth;
1476
1477 SetOptionalBorder(borderWidth.leftDimen, values, valuesSize, offset);
1478 SetOptionalBorder(borderWidth.rightDimen, values, valuesSize, offset);
1479 SetOptionalBorder(borderWidth.topDimen, values, valuesSize, offset);
1480 SetOptionalBorder(borderWidth.bottomDimen, values, valuesSize, offset);
1481 borderWidth.multiValued = true;
1482 if (borderWidth.leftDimen.has_value() || borderWidth.rightDimen.has_value() || borderWidth.topDimen.has_value() ||
1483 borderWidth.bottomDimen.has_value()) {
1484 ViewAbstract::SetBorderWidth(frameNode, borderWidth);
1485 }
1486
1487 NG::BorderRadiusProperty borderRadius;
1488 SetOptionalBorder(borderRadius.radiusTopLeft, values, valuesSize, offset);
1489 SetOptionalBorder(borderRadius.radiusTopRight, values, valuesSize, offset);
1490 SetOptionalBorder(borderRadius.radiusBottomLeft, values, valuesSize, offset);
1491 SetOptionalBorder(borderRadius.radiusBottomRight, values, valuesSize, offset);
1492
1493 borderRadius.multiValued = true;
1494 if (borderRadius.radiusTopLeft.has_value() || borderRadius.radiusTopRight.has_value() ||
1495 borderRadius.radiusBottomLeft.has_value() || borderRadius.radiusBottomRight.has_value()) {
1496 ViewAbstract::SetBorderRadius(frameNode, borderRadius);
1497 }
1498
1499 int32_t colorAndStyleOffset = NUM_0;
1500 NG::BorderColorProperty borderColors;
1501 SetOptionalBorderColor(borderColors.leftColor, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1502 SetOptionalBorderColor(borderColors.rightColor, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1503 SetOptionalBorderColor(borderColors.topColor, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1504 SetOptionalBorderColor(borderColors.bottomColor, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1505 borderColors.multiValued = true;
1506 ViewAbstract::SetBorderColor(frameNode, borderColors);
1507
1508 NG::BorderStyleProperty borderStyles;
1509 SetOptionalBorderStyle(borderStyles.styleLeft, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1510 SetOptionalBorderStyle(borderStyles.styleRight, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1511 SetOptionalBorderStyle(borderStyles.styleTop, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1512 SetOptionalBorderStyle(borderStyles.styleBottom, colorAndStyle, colorAndStyleSize, colorAndStyleOffset);
1513 borderStyles.multiValued = true;
1514 ViewAbstract::SetBorderStyle(frameNode, borderStyles);
1515 }
1516
ResetBorder(ArkUINodeHandle node)1517 void ResetBorder(ArkUINodeHandle node)
1518 {
1519 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1520 CHECK_NULL_VOID(frameNode);
1521 CalcDimension borderWidth;
1522 ViewAbstract::SetBorderWidth(frameNode, borderWidth);
1523 ViewAbstract::SetBorderColor(frameNode, Color::BLACK);
1524 ViewAbstract::SetBorderRadius(frameNode, borderWidth);
1525 ViewAbstract::SetBorderStyle(frameNode, BorderStyle::SOLID);
1526 }
1527
SetBackgroundImagePosition(ArkUINodeHandle node,const ArkUI_Float32 * values,const ArkUI_Int32 * types,ArkUI_Bool isAlign,int size)1528 void SetBackgroundImagePosition(
1529 ArkUINodeHandle node, const ArkUI_Float32* values, const ArkUI_Int32* types, ArkUI_Bool isAlign, int size)
1530 {
1531 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1532 CHECK_NULL_VOID(frameNode);
1533 if (size != NUM_2) {
1534 return;
1535 }
1536 BackgroundImagePosition bgImgPosition;
1537 double valueX = values[NUM_0];
1538 double valueY = values[NUM_1];
1539 DimensionUnit typeX = static_cast<OHOS::Ace::DimensionUnit>(types[NUM_0]);
1540 DimensionUnit typeY = static_cast<OHOS::Ace::DimensionUnit>(types[NUM_1]);
1541 SetBgImgPosition(typeX, typeY, valueX, valueY, bgImgPosition);
1542 bgImgPosition.SetIsAlign(isAlign);
1543 ViewAbstract::SetBackgroundImagePosition(frameNode, bgImgPosition);
1544 }
1545
ResetBackgroundImagePosition(ArkUINodeHandle node)1546 void ResetBackgroundImagePosition(ArkUINodeHandle node)
1547 {
1548 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1549 CHECK_NULL_VOID(frameNode);
1550 BackgroundImagePosition bgImgPosition;
1551 SetBgImgPosition(DimensionUnit::PX, DimensionUnit::PX, 0.0, 0.0, bgImgPosition);
1552 ViewAbstract::SetBackgroundImagePosition(frameNode, bgImgPosition);
1553 }
1554
SetBackgroundImageSize(ArkUINodeHandle node,ArkUI_Float32 valueWidth,ArkUI_Float32 valueHeight,ArkUI_Int32 typeWidth,ArkUI_Int32 typeHeight)1555 void SetBackgroundImageSize(ArkUINodeHandle node, ArkUI_Float32 valueWidth, ArkUI_Float32 valueHeight,
1556 ArkUI_Int32 typeWidth, ArkUI_Int32 typeHeight)
1557 {
1558 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1559 CHECK_NULL_VOID(frameNode);
1560 BackgroundImageSize bgImgSize;
1561 bgImgSize.SetSizeTypeX(static_cast<OHOS::Ace::BackgroundImageSizeType>(typeWidth));
1562 bgImgSize.SetSizeValueX(valueWidth);
1563 bgImgSize.SetSizeTypeY(static_cast<OHOS::Ace::BackgroundImageSizeType>(typeHeight));
1564 bgImgSize.SetSizeValueY(valueHeight);
1565 ViewAbstract::SetBackgroundImageSize(frameNode, bgImgSize);
1566 }
1567
ResetBackgroundImageSize(ArkUINodeHandle node)1568 void ResetBackgroundImageSize(ArkUINodeHandle node)
1569 {
1570 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1571 CHECK_NULL_VOID(frameNode);
1572 BackgroundImageSize bgImgSize;
1573 bgImgSize.SetSizeTypeX(BackgroundImageSizeType::AUTO);
1574 bgImgSize.SetSizeTypeY(BackgroundImageSizeType::AUTO);
1575 ViewAbstract::SetBackgroundImageSize(frameNode, bgImgSize);
1576 }
1577
SetBackgroundImage(ArkUINodeHandle node,const char * src,const char * bundle,const char * module,ArkUI_Int32 repeatIndex)1578 void SetBackgroundImage(
1579 ArkUINodeHandle node, const char* src, const char* bundle, const char* module, ArkUI_Int32 repeatIndex)
1580 {
1581 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1582 CHECK_NULL_VOID(frameNode);
1583 std::string srcStr(src);
1584 std::string bundleStr(bundle);
1585 std::string moduleStr(module);
1586 ViewAbstract::SetBackgroundImage(frameNode, OHOS::Ace::ImageSourceInfo { srcStr, bundleStr, moduleStr });
1587 auto repeat = static_cast<ImageRepeat>(repeatIndex);
1588 if (repeat >= OHOS::Ace::ImageRepeat::NO_REPEAT && repeat <= OHOS::Ace::ImageRepeat::REPEAT) {
1589 ViewAbstract::SetBackgroundImageRepeat(frameNode, repeat);
1590 } else {
1591 ViewAbstract::SetBackgroundImageRepeat(frameNode, OHOS::Ace::ImageRepeat::NO_REPEAT);
1592 }
1593 }
1594
ResetBackgroundImage(ArkUINodeHandle node)1595 void ResetBackgroundImage(ArkUINodeHandle node)
1596 {
1597 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1598 CHECK_NULL_VOID(frameNode);
1599 std::string srcStr;
1600 std::string bundle;
1601 std::string module;
1602 ViewAbstract::SetBackgroundImage(frameNode, OHOS::Ace::ImageSourceInfo { srcStr, bundle, module });
1603 ViewAbstract::SetBackgroundImageRepeat(frameNode, OHOS::Ace::ImageRepeat::NO_REPEAT);
1604 }
1605
SetTranslate(ArkUINodeHandle node,const ArkUI_Float32 * values,const int * units,ArkUI_Int32 length)1606 void SetTranslate(ArkUINodeHandle node, const ArkUI_Float32* values, const int* units, ArkUI_Int32 length)
1607 {
1608 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1609 CHECK_NULL_VOID(frameNode);
1610 if (length != NUM_3) {
1611 return;
1612 }
1613 auto translateX = CalcDimension(0.0);
1614 auto translateY = CalcDimension(0.0);
1615 auto translateZ = CalcDimension(0.0);
1616 translateX = Dimension(values[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_0]));
1617 translateY = Dimension(values[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_1]));
1618 translateZ = Dimension(values[NUM_2], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_2]));
1619
1620 ViewAbstract::SetTranslate(frameNode, TranslateOptions(translateX, translateY, translateZ));
1621 }
1622
ResetTranslate(ArkUINodeHandle node)1623 void ResetTranslate(ArkUINodeHandle node)
1624 {
1625 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1626 CHECK_NULL_VOID(frameNode);
1627 auto x = CalcDimension(0.0);
1628 auto y = CalcDimension(0.0);
1629 auto z = CalcDimension(0.0);
1630 ViewAbstract::SetTranslate(frameNode, TranslateOptions(x, y, z));
1631 }
1632 /**
1633 * @param values
1634 * values[0] : centerX value; values[1] : centerY value;
1635 * units[0] : centerY unit; units[1] : centerY unit
1636 * values[2]: scaleX;values[3]: scaleY;values[4]: scaleZ
1637 * @param length shadows length
1638 */
SetScale(ArkUINodeHandle node,const ArkUI_Float32 * values,int valLength,const int * units,int unitLength)1639 void SetScale(ArkUINodeHandle node, const ArkUI_Float32* values, int valLength, const int* units, int unitLength)
1640 {
1641 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1642 CHECK_NULL_VOID(frameNode);
1643 if (valLength != NUM_5 || unitLength != NUM_2) {
1644 return;
1645 }
1646 auto x = values[NUM_2];
1647 auto y = values[NUM_3];
1648 // NOT support Z in source code
1649 if (x < 0) {
1650 x = 1;
1651 }
1652 if (y < 0) {
1653 y = 1;
1654 }
1655 VectorF scale(x, y);
1656 ViewAbstract::SetScale(frameNode, scale);
1657
1658 auto centerX = Dimension(values[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_0]));
1659 auto centerY = Dimension(values[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_1]));
1660 auto centerZ = Dimension(0.0, OHOS::Ace::DimensionUnit::VP);
1661
1662 DimensionOffset center(centerX, centerY);
1663 if (!NearZero(centerZ.Value())) {
1664 center.SetZ(centerZ);
1665 }
1666 ViewAbstract::SetPivot(frameNode, center);
1667 }
1668
ResetScale(ArkUINodeHandle node)1669 void ResetScale(ArkUINodeHandle node)
1670 {
1671 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1672 CHECK_NULL_VOID(frameNode);
1673
1674 VectorF scale(1.0f, 1.0f);
1675 ViewAbstract::SetScale(frameNode, scale);
1676
1677 DimensionOffset center(0.5_pct, 0.5_pct);
1678 auto centerZ = Dimension(0.0, OHOS::Ace::DimensionUnit::VP);
1679 if (!NearZero(centerZ.Value())) {
1680 center.SetZ(centerZ);
1681 }
1682 ViewAbstract::SetPivot(frameNode, center);
1683 }
1684
1685 /**
1686 * @param values
1687 * values[0] : centerX value; values[1] : centerY value; values[3] : centerZ value
1688 * units[0] : centerY unit; units[1] : centerY unit; units[3] : centerZ unit
1689 * values[4]: xDirection;values[5]: yDirection;values[6]: zDirection
1690 * values[7]: angle;values[8]:perspective
1691 * @param length shadows length
1692 */
SetRotate(ArkUINodeHandle node,const ArkUI_Float32 * values,ArkUI_Int32 valLength,const int * units,ArkUI_Int32 unitLength)1693 void SetRotate(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valLength,
1694 const int* units, ArkUI_Int32 unitLength)
1695 {
1696 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1697 CHECK_NULL_VOID(frameNode);
1698 if (valLength != NUM_8 || unitLength != NUM_3) {
1699 return;
1700 }
1701 auto centerX = Dimension(values[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_0]));
1702 auto centerY = Dimension(values[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_1]));
1703 auto centerZ = Dimension(values[NUM_2], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_2]));
1704 auto xDirection = values[NUM_3];
1705 auto yDirection = values[NUM_4];
1706 auto zDirection = values[NUM_5];
1707 auto angle = values[NUM_6];
1708 auto perspective = values[NUM_7];
1709 ViewAbstract::SetRotate(frameNode, NG::Vector5F(xDirection, yDirection, zDirection, angle, perspective));
1710
1711 DimensionOffset center(centerX, centerY);
1712 if (!NearZero(centerZ.Value())) {
1713 center.SetZ(centerZ);
1714 }
1715 ViewAbstract::SetPivot(frameNode, center);
1716 }
1717
ResetRotate(ArkUINodeHandle node)1718 void ResetRotate(ArkUINodeHandle node)
1719 {
1720 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1721 CHECK_NULL_VOID(frameNode);
1722 NG::RotateOptions rotate(0.0f, 0.0f, 0.0f, 0.0f, 0.5_pct, 0.5_pct, 0.0f, 0.0f);
1723 ViewAbstract::SetRotate(
1724 frameNode, NG::Vector5F(rotate.xDirection, rotate.yDirection, rotate.zDirection, 0.0, rotate.perspective));
1725
1726 DimensionOffset center(rotate.centerX, rotate.centerY);
1727 if (!NearZero(rotate.centerZ.Value())) {
1728 center.SetZ(rotate.centerZ);
1729 }
1730 ViewAbstract::SetPivot(frameNode, center);
1731 }
1732
SetGeometryTransition(ArkUINodeHandle node,const char * id)1733 void SetGeometryTransition(ArkUINodeHandle node, const char* id)
1734 {
1735 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1736 CHECK_NULL_VOID(frameNode);
1737 std::string idStr(id);
1738 ViewAbstract::SetGeometryTransition(frameNode, idStr, false);
1739 }
1740
ResetGeometryTransition(ArkUINodeHandle node)1741 void ResetGeometryTransition(ArkUINodeHandle node)
1742 {
1743 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1744 CHECK_NULL_VOID(frameNode);
1745 }
1746
SetOffset(ArkUINodeHandle node,const ArkUI_Float32 * number,const ArkUI_Int32 * unit)1747 void SetOffset(ArkUINodeHandle node, const ArkUI_Float32* number, const ArkUI_Int32* unit)
1748 {
1749 CHECK_NULL_VOID(number);
1750 CHECK_NULL_VOID(unit);
1751 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1752 CHECK_NULL_VOID(frameNode);
1753 Dimension xVal(*(number + 0), static_cast<DimensionUnit>(*(unit + 0)));
1754 Dimension yVal(*(number + 1), static_cast<DimensionUnit>(*(unit + 1)));
1755 ViewAbstract::SetOffset(frameNode, { xVal, yVal });
1756 }
1757
ResetOffset(ArkUINodeHandle node)1758 void ResetOffset(ArkUINodeHandle node)
1759 {
1760 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1761 CHECK_NULL_VOID(frameNode);
1762 Dimension xVal(0.0, DimensionUnit::VP);
1763 Dimension yVal(0.0, DimensionUnit::VP);
1764 ViewAbstract::SetOffset(frameNode, { xVal, yVal });
1765 }
SetPadding(ArkUINodeHandle node,const struct ArkUISizeType * top,const struct ArkUISizeType * right,const struct ArkUISizeType * bottom,const struct ArkUISizeType * left)1766 void SetPadding(ArkUINodeHandle node, const struct ArkUISizeType* top, const struct ArkUISizeType* right,
1767 const struct ArkUISizeType* bottom, const struct ArkUISizeType* left)
1768 {
1769 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1770 CHECK_NULL_VOID(frameNode);
1771 CalcLength topDimen;
1772 CalcLength rightDimen;
1773 CalcLength bottomDimen;
1774 CalcLength leftDimen;
1775 if (top->string != nullptr) {
1776 topDimen = CalcLength(top->string);
1777 } else {
1778 topDimen = CalcLength(top->value, static_cast<DimensionUnit>(top->unit));
1779 }
1780 if (right->string != nullptr) {
1781 rightDimen = CalcLength(right->string);
1782 } else {
1783 rightDimen = CalcLength(right->value, static_cast<DimensionUnit>(right->unit));
1784 }
1785 if (bottom->string != nullptr) {
1786 bottomDimen = CalcLength(bottom->string);
1787 } else {
1788 bottomDimen = CalcLength(bottom->value, static_cast<DimensionUnit>(bottom->unit));
1789 }
1790 if (left->string != nullptr) {
1791 leftDimen = CalcLength(left->string);
1792 } else {
1793 leftDimen = CalcLength(left->value, static_cast<DimensionUnit>(left->unit));
1794 }
1795 NG::PaddingProperty paddings;
1796 paddings.top = std::optional<CalcLength>(topDimen);
1797 paddings.bottom = std::optional<CalcLength>(bottomDimen);
1798 paddings.left = std::optional<CalcLength>(leftDimen);
1799 paddings.right = std::optional<CalcLength>(rightDimen);
1800 ViewAbstract::SetPadding(frameNode, paddings);
1801 }
1802
ResetPadding(ArkUINodeHandle node)1803 void ResetPadding(ArkUINodeHandle node)
1804 {
1805 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1806 CHECK_NULL_VOID(frameNode);
1807 NG::PaddingProperty paddings;
1808 paddings.top = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
1809 paddings.bottom = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
1810 paddings.left = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
1811 paddings.right = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
1812 ViewAbstract::SetPadding(frameNode, paddings);
1813 }
1814
1815 /**
1816 * @param values value value
1817 * values[0] : left, values[1] : top, values[2] : right, values[3] : bottom
1818 * @param units unit value
1819 * units[0] : left, units[1] : top, units[2] : right, units[3] : bottom
1820 * @param length values length
1821 */
SetPixelStretchEffect(ArkUINodeHandle node,const ArkUI_Float32 * values,const int * units,ArkUI_Int32 length)1822 void SetPixelStretchEffect(ArkUINodeHandle node, const ArkUI_Float32* values, const int* units, ArkUI_Int32 length)
1823 {
1824 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1825 CHECK_NULL_VOID(frameNode);
1826 if (length != NUM_4) {
1827 return;
1828 }
1829 auto leftValue = values[NUM_0];
1830 auto leftUnit = units[NUM_0];
1831 auto topValue = values[NUM_1];
1832 auto topUnit = units[NUM_1];
1833 auto rightValue = values[NUM_2];
1834 auto rightUnit = units[NUM_2];
1835 auto bottomValue = values[NUM_3];
1836 auto bottomUnit = units[NUM_3];
1837 Dimension left(leftValue, static_cast<DimensionUnit>(leftUnit));
1838 Dimension top(topValue, static_cast<DimensionUnit>(topUnit));
1839 Dimension right(rightValue, static_cast<DimensionUnit>(rightUnit));
1840 Dimension bottom(bottomValue, static_cast<DimensionUnit>(bottomUnit));
1841 bool illegalInput = false;
1842 if (left.Unit() == DimensionUnit::PERCENT || right.Unit() == DimensionUnit::PERCENT ||
1843 top.Unit() == DimensionUnit::PERCENT || bottom.Unit() == DimensionUnit::PERCENT) {
1844 if ((NearEqual(left.Value(), 0.0) || left.Unit() == DimensionUnit::PERCENT) &&
1845 (NearEqual(top.Value(), 0.0) || top.Unit() == DimensionUnit::PERCENT) &&
1846 (NearEqual(right.Value(), 0.0) || right.Unit() == DimensionUnit::PERCENT) &&
1847 (NearEqual(bottom.Value(), 0.0) || bottom.Unit() == DimensionUnit::PERCENT)) {
1848 left.SetUnit(DimensionUnit::PERCENT);
1849 top.SetUnit(DimensionUnit::PERCENT);
1850 right.SetUnit(DimensionUnit::PERCENT);
1851 bottom.SetUnit(DimensionUnit::PERCENT);
1852 } else {
1853 illegalInput = true;
1854 }
1855 }
1856 PixStretchEffectOption option;
1857 if ((left.IsNonNegative() && top.IsNonNegative() && right.IsNonNegative() && bottom.IsNonNegative()) ||
1858 (left.IsNonPositive() && top.IsNonPositive() && right.IsNonPositive() && bottom.IsNonPositive())) {
1859 option.left = left;
1860 option.top = top;
1861 option.right = right;
1862 option.bottom = bottom;
1863 } else {
1864 illegalInput = true;
1865 }
1866 if (illegalInput) {
1867 option.ResetValue();
1868 }
1869 ViewAbstract::SetPixelStretchEffect(frameNode, option);
1870 }
1871
ResetPixelStretchEffect(ArkUINodeHandle node)1872 void ResetPixelStretchEffect(ArkUINodeHandle node)
1873 {
1874 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1875 CHECK_NULL_VOID(frameNode);
1876 PixStretchEffectOption option;
1877 option.ResetValue();
1878 ViewAbstract::SetPixelStretchEffect(frameNode, option);
1879 }
1880
SetLightUpEffect(ArkUINodeHandle node,ArkUI_Float32 radio)1881 void SetLightUpEffect(ArkUINodeHandle node, ArkUI_Float32 radio)
1882 {
1883 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1884 CHECK_NULL_VOID(frameNode);
1885 radio = std::clamp(radio, 0.0f, 1.0f);
1886 ViewAbstract::SetLightUpEffect(frameNode, radio);
1887 }
1888
ResetLightUpEffect(ArkUINodeHandle node)1889 void ResetLightUpEffect(ArkUINodeHandle node)
1890 {
1891 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1892 CHECK_NULL_VOID(frameNode);
1893 ViewAbstract::SetLightUpEffect(frameNode, 1.0);
1894 }
1895
SetSphericalEffect(ArkUINodeHandle node,ArkUI_Float32 radio)1896 void SetSphericalEffect(ArkUINodeHandle node, ArkUI_Float32 radio)
1897 {
1898 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1899 CHECK_NULL_VOID(frameNode);
1900 radio = std::clamp(radio, 0.0f, 1.0f);
1901 ViewAbstract::SetSphericalEffect(frameNode, radio);
1902 }
1903
ResetSphericalEffect(ArkUINodeHandle node)1904 void ResetSphericalEffect(ArkUINodeHandle node)
1905 {
1906 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1907 CHECK_NULL_VOID(frameNode);
1908 ViewAbstract::SetSphericalEffect(frameNode, 0.0);
1909 }
1910
SetRenderGroup(ArkUINodeHandle node,ArkUI_Bool isRenderGroup)1911 void SetRenderGroup(ArkUINodeHandle node, ArkUI_Bool isRenderGroup)
1912 {
1913 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1914 CHECK_NULL_VOID(frameNode);
1915 ViewAbstract::SetRenderGroup(frameNode, isRenderGroup);
1916 }
1917
ResetRenderGroup(ArkUINodeHandle node)1918 void ResetRenderGroup(ArkUINodeHandle node)
1919 {
1920 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1921 CHECK_NULL_VOID(frameNode);
1922 ViewAbstract::SetRenderGroup(frameNode, false);
1923 }
1924
SetRenderFit(ArkUINodeHandle node,ArkUI_Int32 renderFitNumber)1925 void SetRenderFit(ArkUINodeHandle node, ArkUI_Int32 renderFitNumber)
1926 {
1927 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1928 CHECK_NULL_VOID(frameNode);
1929 auto renderFit = RenderFit::TOP_LEFT;
1930 if (renderFitNumber >= static_cast<int32_t>(RenderFit::CENTER) &&
1931 renderFitNumber <= static_cast<int32_t>(RenderFit::RESIZE_COVER_BOTTOM_RIGHT)) {
1932 renderFit = static_cast<RenderFit>(renderFitNumber);
1933 }
1934 ViewAbstract::SetRenderFit(frameNode, renderFit);
1935 }
1936
ResetRenderFit(ArkUINodeHandle node)1937 void ResetRenderFit(ArkUINodeHandle node)
1938 {
1939 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1940 CHECK_NULL_VOID(frameNode);
1941 ViewAbstract::SetRenderFit(frameNode, RenderFit::TOP_LEFT);
1942 }
1943
SetUseEffect(ArkUINodeHandle node,ArkUI_Bool useEffect)1944 void SetUseEffect(ArkUINodeHandle node, ArkUI_Bool useEffect)
1945 {
1946 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1947 CHECK_NULL_VOID(frameNode);
1948 ViewAbstract::SetUseEffect(frameNode, useEffect);
1949 }
1950
ResetUseEffect(ArkUINodeHandle node)1951 void ResetUseEffect(ArkUINodeHandle node)
1952 {
1953 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1954 CHECK_NULL_VOID(frameNode);
1955 ViewAbstract::SetUseEffect(frameNode, false);
1956 }
1957
SetForegroundColor(ArkUINodeHandle node,ArkUI_Bool isColor,uint32_t color)1958 void SetForegroundColor(ArkUINodeHandle node, ArkUI_Bool isColor, uint32_t color)
1959 {
1960 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1961 CHECK_NULL_VOID(frameNode);
1962 if (isColor) {
1963 ViewAbstract::SetForegroundColor(frameNode, Color(color));
1964 } else {
1965 auto strategy = static_cast<ForegroundColorStrategy>(color);
1966 ViewAbstract::SetForegroundColorStrategy(frameNode, strategy);
1967 }
1968 }
1969
ResetForegroundColor(ArkUINodeHandle node)1970 void ResetForegroundColor(ArkUINodeHandle node)
1971 {
1972 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1973 CHECK_NULL_VOID(frameNode);
1974 }
1975
SetMotionPath(ArkUINodeHandle node,const char * path,float from,float to,ArkUI_Bool rotatable)1976 void SetMotionPath(ArkUINodeHandle node, const char* path, float from, float to, ArkUI_Bool rotatable)
1977 {
1978 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1979 CHECK_NULL_VOID(frameNode);
1980 OHOS::Ace::MotionPathOption motionPathOption;
1981 std::string pathString = path;
1982 motionPathOption.SetPath(pathString);
1983 motionPathOption.SetBegin(from);
1984 motionPathOption.SetEnd(to);
1985 motionPathOption.SetRotate(rotatable);
1986 ViewAbstract::SetMotionPath(frameNode, motionPathOption);
1987 }
1988
ResetMotionPath(ArkUINodeHandle node)1989 void ResetMotionPath(ArkUINodeHandle node)
1990 {
1991 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1992 CHECK_NULL_VOID(frameNode);
1993 OHOS::Ace::MotionPathOption motionPathOption = MotionPathOption();
1994 ViewAbstract::SetMotionPath(frameNode, motionPathOption);
1995 }
1996
SetGroupDefaultFocus(ArkUINodeHandle node,ArkUI_Bool groupDefaultFocus)1997 void SetGroupDefaultFocus(ArkUINodeHandle node, ArkUI_Bool groupDefaultFocus)
1998 {
1999 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2000 CHECK_NULL_VOID(frameNode);
2001 ViewAbstract::SetGroupDefaultFocus(frameNode, groupDefaultFocus);
2002 }
2003
ResetGroupDefaultFocus(ArkUINodeHandle node)2004 void ResetGroupDefaultFocus(ArkUINodeHandle node)
2005 {
2006 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2007 CHECK_NULL_VOID(frameNode);
2008 bool groupDefaultFocus = false;
2009 ViewAbstract::SetGroupDefaultFocus(frameNode, groupDefaultFocus);
2010 }
2011
SetFocusOnTouch(ArkUINodeHandle node,ArkUI_Bool focusOnTouch)2012 void SetFocusOnTouch(ArkUINodeHandle node, ArkUI_Bool focusOnTouch)
2013 {
2014 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2015 CHECK_NULL_VOID(frameNode);
2016 ViewAbstract::SetFocusOnTouch(frameNode, focusOnTouch);
2017 }
2018
ResetFocusOnTouch(ArkUINodeHandle node)2019 void ResetFocusOnTouch(ArkUINodeHandle node)
2020 {
2021 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2022 CHECK_NULL_VOID(frameNode);
2023 bool focusOnTouch = false;
2024 ViewAbstract::SetFocusOnTouch(frameNode, focusOnTouch);
2025 }
SetFocusable(ArkUINodeHandle node,ArkUI_Bool focusable)2026 void SetFocusable(ArkUINodeHandle node, ArkUI_Bool focusable)
2027 {
2028 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2029 CHECK_NULL_VOID(frameNode);
2030 ViewAbstract::SetFocusable(frameNode, focusable);
2031 }
2032
ResetFocusable(ArkUINodeHandle node)2033 void ResetFocusable(ArkUINodeHandle node)
2034 {
2035 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2036 CHECK_NULL_VOID(frameNode);
2037 bool focusable = false;
2038 ViewAbstract::SetFocusable(frameNode, focusable);
2039 }
2040
SetTouchable(ArkUINodeHandle node,ArkUI_Bool touchable)2041 void SetTouchable(ArkUINodeHandle node, ArkUI_Bool touchable)
2042 {
2043 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2044 CHECK_NULL_VOID(frameNode);
2045 ViewAbstract::SetTouchable(frameNode, touchable);
2046 }
2047
ResetTouchable(ArkUINodeHandle node)2048 void ResetTouchable(ArkUINodeHandle node)
2049 {
2050 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2051 CHECK_NULL_VOID(frameNode);
2052 bool touchable = true;
2053 ViewAbstract::SetTouchable(frameNode, touchable);
2054 }
2055
SetDefaultFocus(ArkUINodeHandle node,ArkUI_Bool defaultFocus)2056 void SetDefaultFocus(ArkUINodeHandle node, ArkUI_Bool defaultFocus)
2057 {
2058 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2059 CHECK_NULL_VOID(frameNode);
2060 ViewAbstract::SetDefaultFocus(frameNode, defaultFocus);
2061 }
2062
ResetDefaultFocus(ArkUINodeHandle node)2063 void ResetDefaultFocus(ArkUINodeHandle node)
2064 {
2065 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2066 CHECK_NULL_VOID(frameNode);
2067 bool defaultFocus = false;
2068 ViewAbstract::SetDefaultFocus(frameNode, defaultFocus);
2069 }
2070
SetDisplayPriority(ArkUINodeHandle node,ArkUI_Float32 value)2071 void SetDisplayPriority(ArkUINodeHandle node, ArkUI_Float32 value)
2072 {
2073 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2074 CHECK_NULL_VOID(frameNode);
2075 ViewAbstract::SetDisplayIndex(frameNode, static_cast<int32_t>(value));
2076 }
2077
ResetDisplayPriority(ArkUINodeHandle node)2078 void ResetDisplayPriority(ArkUINodeHandle node)
2079 {
2080 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2081 CHECK_NULL_VOID(frameNode);
2082 ViewAbstract::SetDisplayIndex(frameNode, DEFAULT_DISPLAY_PRIORITY);
2083 }
2084
SetMargin(ArkUINodeHandle node,const struct ArkUISizeType * top,const struct ArkUISizeType * right,const struct ArkUISizeType * bottom,const struct ArkUISizeType * left)2085 void SetMargin(ArkUINodeHandle node, const struct ArkUISizeType* top, const struct ArkUISizeType* right,
2086 const struct ArkUISizeType* bottom, const struct ArkUISizeType* left)
2087 {
2088 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2089 CHECK_NULL_VOID(frameNode);
2090 CalcLength topDimen;
2091 CalcLength rightDimen;
2092 CalcLength bottomDimen;
2093 CalcLength leftDimen;
2094 if (top->string != nullptr) {
2095 topDimen = CalcLength(top->string);
2096 } else {
2097 topDimen = CalcLength(top->value, static_cast<DimensionUnit>(top->unit));
2098 }
2099 if (right->string != nullptr) {
2100 rightDimen = CalcLength(right->string);
2101 } else {
2102 rightDimen = CalcLength(right->value, static_cast<DimensionUnit>(right->unit));
2103 }
2104 if (bottom->string != nullptr) {
2105 bottomDimen = CalcLength(bottom->string);
2106 } else {
2107 bottomDimen = CalcLength(bottom->value, static_cast<DimensionUnit>(bottom->unit));
2108 }
2109 if (left->string != nullptr) {
2110 leftDimen = CalcLength(left->string);
2111 } else {
2112 leftDimen = CalcLength(left->value, static_cast<DimensionUnit>(left->unit));
2113 }
2114 NG::PaddingProperty paddings;
2115 paddings.top = std::optional<CalcLength>(topDimen);
2116 paddings.bottom = std::optional<CalcLength>(bottomDimen);
2117 paddings.left = std::optional<CalcLength>(leftDimen);
2118 paddings.right = std::optional<CalcLength>(rightDimen);
2119 ViewAbstract::SetMargin(frameNode, paddings);
2120 }
2121
ResetMargin(ArkUINodeHandle node)2122 void ResetMargin(ArkUINodeHandle node)
2123 {
2124 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2125 CHECK_NULL_VOID(frameNode);
2126 ViewAbstract::SetMargin(frameNode, NG::CalcLength(0.0));
2127 }
2128
SetMarkAnchor(ArkUINodeHandle node,ArkUI_Float32 xValue,ArkUI_Int32 xUnit,ArkUI_Float32 yValue,ArkUI_Int32 yUnit)2129 void SetMarkAnchor(ArkUINodeHandle node, ArkUI_Float32 xValue, ArkUI_Int32 xUnit,
2130 ArkUI_Float32 yValue, ArkUI_Int32 yUnit)
2131 {
2132 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2133 CHECK_NULL_VOID(frameNode);
2134 Dimension xDimension { xValue, static_cast<DimensionUnit>(xUnit) };
2135 Dimension yDimension { yValue, static_cast<DimensionUnit>(yUnit) };
2136 OffsetT<Dimension> value = { xDimension, yDimension };
2137 ViewAbstract::MarkAnchor(frameNode, value);
2138 }
2139
ResetMarkAnchor(ArkUINodeHandle node)2140 void ResetMarkAnchor(ArkUINodeHandle node)
2141 {
2142 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2143 CHECK_NULL_VOID(frameNode);
2144 ViewAbstract::MarkAnchor(frameNode, { Dimension(0.0_vp), Dimension(0.0_vp) });
2145 }
2146
SetVisibility(ArkUINodeHandle node,ArkUI_Int32 value)2147 void SetVisibility(ArkUINodeHandle node, ArkUI_Int32 value)
2148 {
2149 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2150 CHECK_NULL_VOID(frameNode);
2151 VisibleType value_visibleType = static_cast<VisibleType>(value);
2152 ViewAbstract::SetVisibility(frameNode, value_visibleType);
2153 }
2154
ResetVisibility(ArkUINodeHandle node)2155 void ResetVisibility(ArkUINodeHandle node)
2156 {
2157 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2158 CHECK_NULL_VOID(frameNode);
2159 ViewAbstract::SetVisibility(frameNode, DEFAULT_VISIBILITY);
2160 }
2161
SetAccessibilityText(ArkUINodeHandle node,const char * value)2162 void SetAccessibilityText(ArkUINodeHandle node, const char* value)
2163 {
2164 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2165 CHECK_NULL_VOID(frameNode);
2166 std::string valueStr = value;
2167 ViewAbstractModelNG::SetAccessibilityText(frameNode, valueStr);
2168 }
2169
ResetAccessibilityText(ArkUINodeHandle node)2170 void ResetAccessibilityText(ArkUINodeHandle node)
2171 {
2172 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2173 CHECK_NULL_VOID(frameNode);
2174 ViewAbstractModelNG::SetAccessibilityText(frameNode, "");
2175 }
2176
SetAllowDrop(ArkUINodeHandle node,const char ** allowDropCharArray,ArkUI_Int32 length)2177 void SetAllowDrop(ArkUINodeHandle node, const char** allowDropCharArray, ArkUI_Int32 length)
2178 {
2179 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2180 CHECK_NULL_VOID(frameNode);
2181 std::set<std::string> allowDropSet;
2182 allowDropSet.clear();
2183 std::string allowDropStr;
2184 for (int32_t i = 0; i < length; i++) {
2185 allowDropStr = allowDropCharArray[i];
2186 allowDropSet.insert(allowDropStr);
2187 }
2188 ViewAbstract::SetAllowDrop(frameNode, allowDropSet);
2189 }
2190
ResetAllowDrop(ArkUINodeHandle node)2191 void ResetAllowDrop(ArkUINodeHandle node)
2192 {
2193 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2194 CHECK_NULL_VOID(frameNode);
2195 std::set<std::string> allowDrop;
2196 ViewAbstract::SetAllowDrop(frameNode, allowDrop);
2197 }
2198
SetAccessibilityLevel(ArkUINodeHandle node,const char * value)2199 void SetAccessibilityLevel(ArkUINodeHandle node, const char* value)
2200 {
2201 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2202 CHECK_NULL_VOID(frameNode);
2203 CHECK_NULL_VOID(value);
2204 std::string valueStr = value;
2205 ViewAbstractModelNG::SetAccessibilityImportance(frameNode, valueStr);
2206 }
2207
ResetAccessibilityLevel(ArkUINodeHandle node)2208 void ResetAccessibilityLevel(ArkUINodeHandle node)
2209 {
2210 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2211 CHECK_NULL_VOID(frameNode);
2212 ViewAbstractModelNG::SetAccessibilityImportance(frameNode, "");
2213 }
2214
SetDirection(ArkUINodeHandle node,ArkUI_Int32 direction)2215 void SetDirection(ArkUINodeHandle node, ArkUI_Int32 direction)
2216 {
2217 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2218 CHECK_NULL_VOID(frameNode);
2219 ViewAbstract::SetLayoutDirection(frameNode, static_cast<TextDirection>(direction));
2220 }
2221
ResetDirection(ArkUINodeHandle node)2222 void ResetDirection(ArkUINodeHandle node)
2223 {
2224 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2225 CHECK_NULL_VOID(frameNode);
2226 ViewAbstract::SetLayoutDirection(frameNode, DEFAULT_COMMON_DIRECTION);
2227 }
2228
SetLayoutWeight(ArkUINodeHandle node,ArkUI_Int32 layoutWeight)2229 void SetLayoutWeight(ArkUINodeHandle node, ArkUI_Int32 layoutWeight)
2230 {
2231 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2232 CHECK_NULL_VOID(frameNode);
2233 ViewAbstract::SetLayoutWeight(frameNode, layoutWeight);
2234 }
2235
ResetLayoutWeight(ArkUINodeHandle node)2236 void ResetLayoutWeight(ArkUINodeHandle node)
2237 {
2238 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2239 CHECK_NULL_VOID(frameNode);
2240 ViewAbstract::SetLayoutWeight(frameNode, DEFAULT_COMMON_LAYOUTWEIGHT);
2241 }
2242
SetMinWidth(ArkUINodeHandle node,const struct ArkUISizeType * minWidth)2243 void SetMinWidth(ArkUINodeHandle node, const struct ArkUISizeType* minWidth)
2244 {
2245 CHECK_NULL_VOID(minWidth);
2246 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2247 CHECK_NULL_VOID(frameNode);
2248 CalcDimension result(minWidth->value, static_cast<DimensionUnit>(minWidth->unit));
2249 ViewAbstract::SetMinWidth(frameNode, CalcLength(result));
2250 }
2251
ResetMinWidth(ArkUINodeHandle node)2252 void ResetMinWidth(ArkUINodeHandle node)
2253 {
2254 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2255 CHECK_NULL_VOID(frameNode);
2256 ViewAbstract::ResetMinSize(frameNode, true);
2257 }
2258
SetMaxWidth(ArkUINodeHandle node,const struct ArkUISizeType * maxWidth)2259 void SetMaxWidth(ArkUINodeHandle node, const struct ArkUISizeType* maxWidth)
2260 {
2261 CHECK_NULL_VOID(maxWidth);
2262 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2263 CHECK_NULL_VOID(frameNode);
2264 CalcDimension result(maxWidth->value, static_cast<DimensionUnit>(maxWidth->unit));
2265 ViewAbstract::SetMaxWidth(frameNode, CalcLength(result));
2266 }
2267
ResetMaxWidth(ArkUINodeHandle node)2268 void ResetMaxWidth(ArkUINodeHandle node)
2269 {
2270 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2271 CHECK_NULL_VOID(frameNode);
2272 ViewAbstract::ResetMaxSize(frameNode, true);
2273 }
2274
SetMinHeight(ArkUINodeHandle node,const struct ArkUISizeType * minHeight)2275 void SetMinHeight(ArkUINodeHandle node, const struct ArkUISizeType* minHeight)
2276 {
2277 CHECK_NULL_VOID(minHeight);
2278 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2279 CHECK_NULL_VOID(frameNode);
2280 CalcDimension result(minHeight->value, static_cast<DimensionUnit>(minHeight->unit));
2281 ViewAbstract::SetMinHeight(frameNode, CalcLength(result));
2282 }
2283
ResetMinHeight(ArkUINodeHandle node)2284 void ResetMinHeight(ArkUINodeHandle node)
2285 {
2286 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2287 CHECK_NULL_VOID(frameNode);
2288 ViewAbstract::ResetMinSize(frameNode, false);
2289 }
2290
SetMaxHeight(ArkUINodeHandle node,const struct ArkUISizeType * maxHeight)2291 void SetMaxHeight(ArkUINodeHandle node, const struct ArkUISizeType* maxHeight)
2292 {
2293 CHECK_NULL_VOID(maxHeight);
2294 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2295 CHECK_NULL_VOID(frameNode);
2296 CalcDimension result(maxHeight->value, static_cast<DimensionUnit>(maxHeight->unit));
2297 ViewAbstract::SetMaxHeight(frameNode, CalcLength(result));
2298 }
2299
ResetMaxHeight(ArkUINodeHandle node)2300 void ResetMaxHeight(ArkUINodeHandle node)
2301 {
2302 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2303 CHECK_NULL_VOID(frameNode);
2304 ViewAbstract::ResetMaxSize(frameNode, false);
2305 }
2306
SetSize(ArkUINodeHandle node,const ArkUI_Float32 * number,const ArkUI_Int32 * unit,ArkUI_CharPtr * calc)2307 void SetSize(ArkUINodeHandle node, const ArkUI_Float32* number, const ArkUI_Int32* unit, ArkUI_CharPtr* calc)
2308 {
2309 CHECK_NULL_VOID(number);
2310 CHECK_NULL_VOID(unit);
2311 int widthIndex = 0;
2312 int heightIndex = 1;
2313 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2314 CHECK_NULL_VOID(frameNode);
2315 if (*(unit + widthIndex) == static_cast<int8_t>(DimensionUnit::CALC) && *(calc + widthIndex) != nullptr) {
2316 ViewAbstract::SetWidth(frameNode, CalcLength(std::string(*(calc + widthIndex))));
2317 } else {
2318 ViewAbstract::SetWidth(
2319 frameNode, CalcLength(*(number + widthIndex), static_cast<DimensionUnit>(*(unit + widthIndex))));
2320 }
2321 if (*(unit + heightIndex) == static_cast<int8_t>(DimensionUnit::CALC) && *(calc + heightIndex) != nullptr) {
2322 ViewAbstract::SetHeight(frameNode, CalcLength(std::string(*(calc + heightIndex))));
2323 } else {
2324 ViewAbstract::SetHeight(
2325 frameNode, CalcLength(*(number + heightIndex), static_cast<DimensionUnit>(*(unit + heightIndex))));
2326 }
2327 }
2328
ResetSize(ArkUINodeHandle node)2329 void ResetSize(ArkUINodeHandle node)
2330 {
2331 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2332 CHECK_NULL_VOID(frameNode);
2333 ViewAbstract::SetWidth(frameNode, CalcLength(0.0, DimensionUnit::VP));
2334 ViewAbstract::SetHeight(frameNode, CalcLength(0.0, DimensionUnit::VP));
2335 }
2336
ClearWidthOrHeight(ArkUINodeHandle node,ArkUI_Bool isWidth)2337 void ClearWidthOrHeight(ArkUINodeHandle node, ArkUI_Bool isWidth)
2338 {
2339 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2340 CHECK_NULL_VOID(frameNode);
2341 ViewAbstract::ClearWidthOrHeight(frameNode, isWidth);
2342 }
2343
SetAlignSelf(ArkUINodeHandle node,ArkUI_Int32 value)2344 void SetAlignSelf(ArkUINodeHandle node, ArkUI_Int32 value)
2345 {
2346 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2347 CHECK_NULL_VOID(frameNode);
2348 if (value >= 0 && value <= MAX_ALIGN_VALUE) {
2349 ViewAbstract::SetAlignSelf(frameNode, static_cast<FlexAlign>(value));
2350 } else {
2351 ViewAbstract::SetAlignSelf(frameNode, FlexAlign::AUTO);
2352 }
2353 }
2354
ResetAlignSelf(ArkUINodeHandle node)2355 void ResetAlignSelf(ArkUINodeHandle node)
2356 {
2357 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2358 CHECK_NULL_VOID(frameNode);
2359 ViewAbstract::SetAlignSelf(frameNode, FlexAlign::AUTO);
2360 }
2361
SetAspectRatio(ArkUINodeHandle node,ArkUI_Float32 value)2362 void SetAspectRatio(ArkUINodeHandle node, ArkUI_Float32 value)
2363 {
2364 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2365 CHECK_NULL_VOID(frameNode);
2366
2367 double result = value;
2368 if (LessOrEqual(result, 0.0)) {
2369 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
2370 ViewAbstract::ResetAspectRatio(frameNode);
2371 return;
2372 } else {
2373 result = 1.0;
2374 }
2375 }
2376
2377 ViewAbstract::SetAspectRatio(frameNode, static_cast<float>(result));
2378 }
2379
ResetAspectRatio(ArkUINodeHandle node)2380 void ResetAspectRatio(ArkUINodeHandle node)
2381 {
2382 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2383 CHECK_NULL_VOID(frameNode);
2384
2385 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
2386 ViewAbstract::ResetAspectRatio(frameNode);
2387 } else {
2388 ViewAbstract::SetAspectRatio(frameNode, static_cast<float>(1.0));
2389 }
2390 }
2391
SetFlexGrow(ArkUINodeHandle node,ArkUI_Float32 value)2392 void SetFlexGrow(ArkUINodeHandle node, ArkUI_Float32 value)
2393 {
2394 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2395 CHECK_NULL_VOID(frameNode);
2396
2397 double result = value;
2398 if (result < 0.0) {
2399 result = 0.0;
2400 }
2401 ViewAbstract::SetFlexGrow(frameNode, static_cast<float>(result));
2402 }
2403
ResetFlexGrow(ArkUINodeHandle node)2404 void ResetFlexGrow(ArkUINodeHandle node)
2405 {
2406 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2407 CHECK_NULL_VOID(frameNode);
2408 ViewAbstract::SetFlexGrow(static_cast<float>(0.0));
2409 }
2410
SetFlexShrink(ArkUINodeHandle node,ArkUI_Float32 value)2411 void SetFlexShrink(ArkUINodeHandle node, ArkUI_Float32 value)
2412 {
2413 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2414 CHECK_NULL_VOID(frameNode);
2415
2416 if (value < 0.0) {
2417 ViewAbstract::ResetFlexShrink(frameNode);
2418 return;
2419 }
2420 ViewAbstract::SetFlexShrink(frameNode, static_cast<float>(value));
2421 }
2422
ResetFlexShrink(ArkUINodeHandle node)2423 void ResetFlexShrink(ArkUINodeHandle node)
2424 {
2425 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2426 CHECK_NULL_VOID(frameNode);
2427 ViewAbstract::ResetFlexShrink(frameNode);
2428 }
2429
SetGridOffset(ArkUINodeHandle node,ArkUI_Int32 offset)2430 void SetGridOffset(ArkUINodeHandle node, ArkUI_Int32 offset)
2431 {
2432 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2433 CHECK_NULL_VOID(frameNode);
2434 ViewAbstract::SetGrid(frameNode, std::nullopt, offset, GridSizeType::UNDEFINED);
2435 }
2436
ResetGridOffset(ArkUINodeHandle node)2437 void ResetGridOffset(ArkUINodeHandle node)
2438 {
2439 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2440 CHECK_NULL_VOID(frameNode);
2441 ViewAbstract::SetGrid(frameNode, std::nullopt, DEFAULT_GRID_OFFSET, GridSizeType::UNDEFINED);
2442 }
2443
SetGridSpan(ArkUINodeHandle node,ArkUI_Int32 value)2444 void SetGridSpan(ArkUINodeHandle node, ArkUI_Int32 value)
2445 {
2446 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2447 CHECK_NULL_VOID(frameNode);
2448 ViewAbstract::SetGrid(frameNode, value, std::nullopt);
2449 }
2450
ResetGridSpan(ArkUINodeHandle node)2451 void ResetGridSpan(ArkUINodeHandle node)
2452 {
2453 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2454 CHECK_NULL_VOID(frameNode);
2455 ViewAbstract::SetGrid(frameNode, DEFAULT_GRIDSPAN, std::nullopt);
2456 }
2457
SetExpandSafeArea(ArkUINodeHandle node,const char * typeStr,const char * edgesStr)2458 void SetExpandSafeArea(ArkUINodeHandle node, const char* typeStr, const char* edgesStr)
2459 {
2460 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2461 CHECK_NULL_VOID(frameNode);
2462 NG::SafeAreaExpandOpts opts { .type = NG::SAFE_AREA_TYPE_ALL, .edges = NG::SAFE_AREA_EDGE_ALL };
2463 uint32_t safeAreaType = NG::SAFE_AREA_TYPE_NONE;
2464 uint32_t safeAreaEdge = NG::SAFE_AREA_EDGE_NONE;
2465 std::string safeAreaTypeStr = std::string(typeStr);
2466 std::string safeAreaEdgeStr = std::string(edgesStr);
2467 std::string delimiter = "|";
2468 size_t pos = 0;
2469 std::string type;
2470 std::string edges;
2471 while ((pos = safeAreaTypeStr.find(delimiter)) != std::string::npos) {
2472 type = safeAreaTypeStr.substr(0, pos);
2473 safeAreaType |= StringUtils::StringToUint(type);
2474 safeAreaTypeStr.erase(0, pos + delimiter.length());
2475 }
2476 safeAreaType |= StringUtils::StringToUint(safeAreaTypeStr);
2477 while ((pos = safeAreaEdgeStr.find(delimiter)) != std::string::npos) {
2478 edges = safeAreaEdgeStr.substr(0, pos);
2479 safeAreaEdge |= StringUtils::StringToUint(edges);
2480 safeAreaEdgeStr.erase(0, pos + delimiter.length());
2481 }
2482 safeAreaEdge |= StringUtils::StringToUint(safeAreaEdgeStr);
2483 opts.type = safeAreaType;
2484 opts.edges = safeAreaEdge;
2485 ViewAbstract::UpdateSafeAreaExpandOpts(frameNode, opts);
2486 }
2487
ResetExpandSafeArea(ArkUINodeHandle node)2488 void ResetExpandSafeArea(ArkUINodeHandle node)
2489 {
2490 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2491 CHECK_NULL_VOID(frameNode);
2492 NG::SafeAreaExpandOpts opts;
2493 opts.type = DEFAULT_SAFE_AREA_TYPE;
2494 opts.edges = DEFAULT_SAFE_AREA_EDGE;
2495 ViewAbstract::UpdateSafeAreaExpandOpts(frameNode, opts);
2496 }
2497
SetFlexBasis(ArkUINodeHandle node,const struct ArkUIStringAndFloat * flexBasisValue)2498 void SetFlexBasis(ArkUINodeHandle node, const struct ArkUIStringAndFloat* flexBasisValue)
2499 {
2500 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2501 CHECK_NULL_VOID(frameNode);
2502 Dimension result;
2503 if (flexBasisValue->valueStr != nullptr) {
2504 result = StringUtils::StringToDimensionWithUnit(std::string(flexBasisValue->valueStr), DimensionUnit::VP);
2505 if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TEN)) {
2506 // flexbasis don't support percent case.
2507 if (result.Unit() == DimensionUnit::PERCENT) {
2508 result.SetUnit(DimensionUnit::AUTO);
2509 }
2510 }
2511 } else {
2512 result = Dimension(flexBasisValue->value, DimensionUnit::VP);
2513 }
2514 ViewAbstract::SetFlexBasis(frameNode, result);
2515 }
2516
ResetFlexBasis(ArkUINodeHandle node)2517 void ResetFlexBasis(ArkUINodeHandle node)
2518 {
2519 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2520 CHECK_NULL_VOID(frameNode);
2521 ViewAbstract::SetFlexBasis(frameNode, DEFAULT_FLEX_BASIS);
2522 }
2523
SetAlignRules(ArkUINodeHandle node,char ** anchors,const ArkUI_Int32 * direction,ArkUI_Int32 length)2524 void SetAlignRules(ArkUINodeHandle node, char** anchors, const ArkUI_Int32* direction, ArkUI_Int32 length)
2525 {
2526 CHECK_NULL_VOID(anchors);
2527 CHECK_NULL_VOID(direction);
2528 if (length != DEFAULT_ALIGN_RULES_SIZE) {
2529 return;
2530 }
2531 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2532 CHECK_NULL_VOID(frameNode);
2533 std::map<AlignDirection, AlignRule> rulesMap;
2534 for (int index = 0; index < length; index++) {
2535 AlignRule alignRule;
2536 alignRule.anchor = std::string(*(anchors + index) == nullptr ? "" : *(anchors + index));
2537 if (index < HORIZONTAL_DIRECTION_RANGE) {
2538 alignRule.horizontal = static_cast<HorizontalAlign>(*(direction + index));
2539 } else {
2540 alignRule.vertical = static_cast<VerticalAlign>(*(direction + index));
2541 }
2542 rulesMap[static_cast<AlignDirection>(index)] = alignRule;
2543 }
2544 ViewAbstract::SetAlignRules(frameNode, rulesMap);
2545 }
2546
ResetAlignRules(ArkUINodeHandle node)2547 void ResetAlignRules(ArkUINodeHandle node)
2548 {
2549 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2550 CHECK_NULL_VOID(frameNode);
2551 const char* keys[] = { "left", "middle", "right", "top", "center", "bottom" };
2552 std::map<AlignDirection, AlignRule> alignRules;
2553 for (uint32_t i = 0; i < sizeof(keys) / sizeof(const char*); i++) {
2554 AlignRule alignRule;
2555 alignRule.anchor = "__container__";
2556 alignRule.horizontal = static_cast<HorizontalAlign>(DEFAULT_ALIGN_VALUE);
2557 alignRule.vertical = static_cast<VerticalAlign>(DEFAULT_ALIGN_VALUE);
2558 alignRules[static_cast<AlignDirection>(i)] = alignRule;
2559 }
2560 ViewAbstract::SetAlignRules(frameNode, alignRules);
2561 }
2562
SetAccessibilityDescription(ArkUINodeHandle node,const char * value)2563 void SetAccessibilityDescription(ArkUINodeHandle node, const char* value)
2564 {
2565 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2566 CHECK_NULL_VOID(frameNode);
2567 CHECK_NULL_VOID(value);
2568 std::string valueStr = value;
2569 ViewAbstractModelNG::SetAccessibilityDescription(frameNode, valueStr);
2570 }
2571
ResetAccessibilityDescription(ArkUINodeHandle node)2572 void ResetAccessibilityDescription(ArkUINodeHandle node)
2573 {
2574 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2575 CHECK_NULL_VOID(frameNode);
2576 ViewAbstractModelNG::SetAccessibilityDescription(frameNode, "");
2577 }
2578
SetId(ArkUINodeHandle node,const char * id)2579 void SetId(ArkUINodeHandle node, const char* id)
2580 {
2581 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2582 CHECK_NULL_VOID(frameNode);
2583 std::string valueStr = id;
2584 ViewAbstract::SetInspectorId(frameNode, valueStr);
2585 }
2586
ResetId(ArkUINodeHandle node)2587 void ResetId(ArkUINodeHandle node)
2588 {
2589 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2590 CHECK_NULL_VOID(frameNode);
2591 std::string id = "";
2592 ViewAbstract::SetInspectorId(frameNode, id);
2593 }
2594
SetKey(ArkUINodeHandle node,const char * key)2595 void SetKey(ArkUINodeHandle node, const char* key)
2596 {
2597 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2598 CHECK_NULL_VOID(frameNode);
2599 std::string valueStr = key;
2600 ViewAbstract::SetInspectorId(frameNode, valueStr);
2601 }
2602
ResetKey(ArkUINodeHandle node)2603 void ResetKey(ArkUINodeHandle node)
2604 {
2605 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2606 CHECK_NULL_VOID(frameNode);
2607 std::string defaultStr = "";
2608 ViewAbstract::SetInspectorId(frameNode, defaultStr);
2609 }
2610
SetRestoreId(ArkUINodeHandle node,uint32_t id)2611 void SetRestoreId(ArkUINodeHandle node, uint32_t id)
2612 {
2613 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2614 CHECK_NULL_VOID(frameNode);
2615 ViewAbstract::SetRestoreId(frameNode, id);
2616 }
2617
ResetRestoreId(ArkUINodeHandle node)2618 void ResetRestoreId(ArkUINodeHandle node)
2619 {
2620 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2621 CHECK_NULL_VOID(frameNode);
2622 ViewAbstract::SetRestoreId(frameNode, DEFAULT_ID);
2623 }
2624
SetTabIndex(ArkUINodeHandle node,ArkUI_Int32 index)2625 void SetTabIndex(ArkUINodeHandle node, ArkUI_Int32 index)
2626 {
2627 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2628 CHECK_NULL_VOID(frameNode);
2629 ViewAbstract::SetTabIndex(frameNode, index);
2630 }
2631
ResetTabIndex(ArkUINodeHandle node)2632 void ResetTabIndex(ArkUINodeHandle node)
2633 {
2634 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2635 CHECK_NULL_VOID(frameNode);
2636 int32_t index = 0;
2637 ViewAbstract::SetTabIndex(frameNode, index);
2638 }
2639
SetObscured(ArkUINodeHandle node,const ArkUI_Int32 * reason,ArkUI_Int32 length)2640 void SetObscured(ArkUINodeHandle node, const ArkUI_Int32* reason, ArkUI_Int32 length)
2641 {
2642 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2643 CHECK_NULL_VOID(frameNode);
2644 std::vector<ObscuredReasons> reasons(length);
2645 reasons.clear();
2646 for (int32_t i = 0; i < length; i++) {
2647 reasons.emplace_back(static_cast<ObscuredReasons>(reason[i]));
2648 }
2649
2650 ViewAbstract::SetObscured(frameNode, reasons);
2651 }
2652
ResetObscured(ArkUINodeHandle node)2653 void ResetObscured(ArkUINodeHandle node)
2654 {
2655 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2656 CHECK_NULL_VOID(frameNode);
2657 std::vector<ObscuredReasons> reasons(0);
2658 ViewAbstract::SetObscured(frameNode, reasons);
2659 }
2660
SetResponseRegion(ArkUINodeHandle node,const ArkUI_Float32 * values,const ArkUI_Int32 * units,ArkUI_Int32 length)2661 void SetResponseRegion(ArkUINodeHandle node, const ArkUI_Float32* values, const ArkUI_Int32* units, ArkUI_Int32 length)
2662 {
2663 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2664 CHECK_NULL_VOID(frameNode);
2665 std::vector<DimensionRect> region;
2666 for (int32_t i = 0; i < length / NUM_4; i++) {
2667 CalcDimension xDimen =
2668 CalcDimension(values[i * NUM_4 + NUM_0], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_0]));
2669 CalcDimension yDimen =
2670 CalcDimension(values[i * NUM_4 + NUM_1], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_1]));
2671 CalcDimension widthDimen =
2672 CalcDimension(values[i * NUM_4 + NUM_2], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_2]));
2673 CalcDimension heightDimen =
2674 CalcDimension(values[i * NUM_4 + NUM_3], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_3]));
2675 DimensionOffset offsetDimen(xDimen, yDimen);
2676 DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
2677 region.emplace_back(dimenRect);
2678 }
2679 ViewAbstract::SetResponseRegion(frameNode, region);
2680 }
2681
ResetResponseRegion(ArkUINodeHandle node)2682 void ResetResponseRegion(ArkUINodeHandle node)
2683 {
2684 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2685 CHECK_NULL_VOID(frameNode);
2686 std::vector<DimensionRect> region;
2687 CalcDimension xDimen = CalcDimension(0.0, DimensionUnit::VP);
2688 CalcDimension yDimen = CalcDimension(0.0, DimensionUnit::VP);
2689 CalcDimension widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
2690 CalcDimension heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
2691 DimensionOffset offsetDimen(xDimen, yDimen);
2692 DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
2693 region.emplace_back(dimenRect);
2694 ViewAbstract::SetResponseRegion(frameNode, region);
2695 }
2696
SetMouseResponseRegion(ArkUINodeHandle node,const ArkUI_Float32 * values,const ArkUI_Int32 * units,ArkUI_Int32 length)2697 void SetMouseResponseRegion(ArkUINodeHandle node, const ArkUI_Float32* values,
2698 const ArkUI_Int32* units, ArkUI_Int32 length)
2699 {
2700 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2701 CHECK_NULL_VOID(frameNode);
2702 std::vector<DimensionRect> region;
2703 for (int32_t i = 0; i < length / NUM_4; i++) {
2704 CalcDimension xDimen =
2705 CalcDimension(values[i * NUM_4 + NUM_0], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_0]));
2706 CalcDimension yDimen =
2707 CalcDimension(values[i * NUM_4 + NUM_1], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_1]));
2708 CalcDimension widthDimen =
2709 CalcDimension(values[i * NUM_4 + NUM_2], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_2]));
2710 CalcDimension heightDimen =
2711 CalcDimension(values[i * NUM_4 + NUM_3], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_3]));
2712 DimensionOffset offsetDimen(xDimen, yDimen);
2713 DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
2714 region.emplace_back(dimenRect);
2715 }
2716 ViewAbstract::SetMouseResponseRegion(frameNode, region);
2717 }
2718
ResetMouseResponseRegion(ArkUINodeHandle node)2719 void ResetMouseResponseRegion(ArkUINodeHandle node)
2720 {
2721 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2722 CHECK_NULL_VOID(frameNode);
2723 std::vector<DimensionRect> region;
2724 CalcDimension xDimen = CalcDimension(0.0, DimensionUnit::VP);
2725 CalcDimension yDimen = CalcDimension(0.0, DimensionUnit::VP);
2726 CalcDimension widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
2727 CalcDimension heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
2728 DimensionOffset offsetDimen(xDimen, yDimen);
2729 DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
2730 region.emplace_back(dimenRect);
2731 ViewAbstract::SetMouseResponseRegion(frameNode, region);
2732 }
2733
SetEnabled(ArkUINodeHandle node,ArkUI_Bool value)2734 void SetEnabled(ArkUINodeHandle node, ArkUI_Bool value)
2735 {
2736 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2737 CHECK_NULL_VOID(frameNode);
2738 ViewAbstract::SetEnabled(frameNode, value);
2739 }
2740
ResetEnabled(ArkUINodeHandle node)2741 void ResetEnabled(ArkUINodeHandle node)
2742 {
2743 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2744 CHECK_NULL_VOID(frameNode);
2745 ViewAbstract::SetEnabled(frameNode, true);
2746 }
2747
SetDraggable(ArkUINodeHandle node,ArkUI_Bool value)2748 void SetDraggable(ArkUINodeHandle node, ArkUI_Bool value)
2749 {
2750 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2751 CHECK_NULL_VOID(frameNode);
2752 ViewAbstract::SetDraggable(frameNode, value);
2753 }
2754
ResetDraggable(ArkUINodeHandle node)2755 void ResetDraggable(ArkUINodeHandle node)
2756 {
2757 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2758 CHECK_NULL_VOID(frameNode);
2759 ViewAbstract::SetDraggable(frameNode, false);
2760 }
2761
SetAccessibilityGroup(ArkUINodeHandle node,ArkUI_Bool value)2762 void SetAccessibilityGroup(ArkUINodeHandle node, ArkUI_Bool value)
2763 {
2764 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2765 CHECK_NULL_VOID(frameNode);
2766 ViewAbstractModelNG::SetAccessibilityGroup(frameNode, value);
2767 }
2768
ResetAccessibilityGroup(ArkUINodeHandle node)2769 void ResetAccessibilityGroup(ArkUINodeHandle node)
2770 {
2771 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2772 CHECK_NULL_VOID(frameNode);
2773 ViewAbstractModelNG::SetAccessibilityGroup(frameNode, false);
2774 }
2775
SetHoverEffect(ArkUINodeHandle node,ArkUI_Int32 hoverEffectValue)2776 void SetHoverEffect(ArkUINodeHandle node, ArkUI_Int32 hoverEffectValue)
2777 {
2778 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2779 CHECK_NULL_VOID(frameNode);
2780 OHOS::Ace::HoverEffectType hoverEffect = OHOS::Ace::HoverEffectType::AUTO;
2781 hoverEffect = static_cast<OHOS::Ace::HoverEffectType>(hoverEffectValue);
2782 ViewAbstract::SetHoverEffect(frameNode, hoverEffect);
2783 }
2784
ResetHoverEffect(ArkUINodeHandle node)2785 void ResetHoverEffect(ArkUINodeHandle node)
2786 {
2787 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2788 CHECK_NULL_VOID(frameNode);
2789 ViewAbstract::SetHoverEffect(frameNode, OHOS::Ace::HoverEffectType::AUTO);
2790 }
2791
SetClickEffect(ArkUINodeHandle node,const int32_t levelValue,float scaleValue)2792 void SetClickEffect(ArkUINodeHandle node, const int32_t levelValue, float scaleValue)
2793 {
2794 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2795 CHECK_NULL_VOID(frameNode);
2796 OHOS::Ace::ClickEffectLevel level = OHOS::Ace::ClickEffectLevel::UNDEFINED;
2797 level = static_cast<OHOS::Ace::ClickEffectLevel>(levelValue);
2798 ViewAbstract::SetClickEffectLevel(frameNode, level, scaleValue);
2799 }
2800
ResetClickEffect(ArkUINodeHandle node)2801 void ResetClickEffect(ArkUINodeHandle node)
2802 {
2803 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2804 CHECK_NULL_VOID(frameNode);
2805 ViewAbstract::SetClickEffectLevel(frameNode, OHOS::Ace::ClickEffectLevel::UNDEFINED, 0.9f);
2806 }
2807
SetKeyBoardShortCut(ArkUINodeHandle node,const char * value,const ArkUI_Int32 * keysIntArray,ArkUI_Int32 length)2808 void SetKeyBoardShortCut(ArkUINodeHandle node, const char* value, const ArkUI_Int32* keysIntArray, ArkUI_Int32 length)
2809 {
2810 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2811 CHECK_NULL_VOID(frameNode);
2812 std::string valueStr = value;
2813 std::vector<OHOS::Ace::ModifierKey> keysVector(length);
2814 keysVector.clear();
2815 for (int32_t i = 0; i < length; i++) {
2816 keysVector.emplace_back(static_cast<OHOS::Ace::ModifierKey>(keysIntArray[i]));
2817 }
2818 ViewAbstractModelNG::SetKeyboardShortcut(frameNode, valueStr, keysVector, nullptr);
2819 }
2820
ResetKeyBoardShortCut(ArkUINodeHandle node)2821 void ResetKeyBoardShortCut(ArkUINodeHandle node)
2822 {
2823 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2824 CHECK_NULL_VOID(frameNode);
2825 ViewAbstractModelNG::SetKeyboardShortcut(frameNode, "", std::vector<OHOS::Ace::ModifierKey>(), nullptr);
2826 }
2827
SetClip(ArkUINodeHandle node,ArkUI_Int32 isClip)2828 void SetClip(ArkUINodeHandle node, ArkUI_Int32 isClip)
2829 {
2830 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2831 CHECK_NULL_VOID(frameNode);
2832 ViewAbstract::SetClipEdge(frameNode, static_cast<bool>(isClip));
2833 }
2834
SetClipShape(ArkUINodeHandle node,const char * type,const ArkUI_Float32 * attribute,int length)2835 void SetClipShape(ArkUINodeHandle node, const char* type, const ArkUI_Float32* attribute, int length)
2836 {
2837 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2838 CHECK_NULL_VOID(frameNode);
2839 if (std::strcmp(type, "rect") == 0) {
2840 auto shape = AceType::MakeRefPtr<ShapeRect>();
2841 auto width = Dimension(attribute[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(1));
2842 auto height = Dimension(attribute[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(1));
2843 auto radiusWidth = Dimension(attribute[NUM_2], static_cast<OHOS::Ace::DimensionUnit>(1));
2844 auto radiusHeight = Dimension(attribute[NUM_3], static_cast<OHOS::Ace::DimensionUnit>(1));
2845 shape->SetWidth(width);
2846 shape->SetHeight(height);
2847 shape->SetRadiusWidth(radiusWidth);
2848 shape->SetRadiusHeight(radiusHeight);
2849 ViewAbstract::SetClipShape(frameNode, shape);
2850 }
2851 if (std::strcmp(type, "circle") == 0) {
2852 auto shape = AceType::MakeRefPtr<Circle>();
2853 auto width = Dimension(attribute[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(1));
2854 auto height = Dimension(attribute[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(1));
2855 shape->SetWidth(width);
2856 shape->SetHeight(height);
2857 ViewAbstract::SetClipShape(frameNode, shape);
2858 }
2859 if (std::strcmp(type, "ellipse") == 0) {
2860 auto shape = AceType::MakeRefPtr<Ellipse>();
2861 auto width = Dimension(attribute[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(1));
2862 auto height = Dimension(attribute[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(1));
2863 shape->SetWidth(width);
2864 shape->SetHeight(height);
2865 ViewAbstract::SetClipShape(frameNode, shape);
2866 }
2867 }
2868
SetClipPath(ArkUINodeHandle node,const char * type,const ArkUI_Float32 * attribute,const char * commands)2869 void SetClipPath(ArkUINodeHandle node, const char* type, const ArkUI_Float32* attribute, const char* commands)
2870 {
2871 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2872 CHECK_NULL_VOID(frameNode);
2873 auto path = AceType::MakeRefPtr<Path>();
2874 auto width = Dimension(attribute[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(1));
2875 auto height = Dimension(attribute[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(1));
2876 std::string pathCommands(commands);
2877 path->SetWidth(width);
2878 path->SetHeight(height);
2879 path->SetValue(StringUtils::TrimStr(pathCommands));
2880 ViewAbstract::SetClipShape(frameNode, path);
2881 }
2882
SetAnimationOption(std::shared_ptr<AnimationOption> & option,const ArkUIAnimationOptionType * animationOption)2883 void SetAnimationOption(std::shared_ptr<AnimationOption>& option, const ArkUIAnimationOptionType* animationOption)
2884 {
2885 option->SetDuration(animationOption->duration);
2886 option->SetCurve(Framework::CreateCurve(std::string(animationOption->curve)));
2887 option->SetDelay(animationOption->delay);
2888 option->SetIteration(animationOption->iteration);
2889 auto direction = static_cast<AnimationDirection>(animationOption->palyMode);
2890 option->SetAnimationDirection(direction);
2891 option->SetTempo(animationOption->tempo);
2892 }
2893
SetTransitionCenter(ArkUINodeHandle node,float centerXValue,ArkUI_Int32 centerXUnit,float centerYValue,int32_t centerYUnit,float centerZValue,ArkUI_Int32 centerZUnit)2894 void SetTransitionCenter(ArkUINodeHandle node, float centerXValue, ArkUI_Int32 centerXUnit, float centerYValue,
2895 int32_t centerYUnit, float centerZValue, ArkUI_Int32 centerZUnit)
2896 {
2897 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2898 CHECK_NULL_VOID(frameNode);
2899 Dimension centerXDimension(centerXValue, static_cast<DimensionUnit>(centerXUnit));
2900 Dimension centerYDimension(centerYValue, static_cast<DimensionUnit>(centerYUnit));
2901 Dimension centerZDimension(centerZValue, static_cast<DimensionUnit>(centerZUnit));
2902 RefPtr<OneCenterTransitionOptionType> oneCenterTransition;
2903 auto renderContext = frameNode->GetRenderContext();
2904 if (renderContext) {
2905 oneCenterTransition = renderContext->GetOneCenterTransitionOption();
2906 }
2907 if (!oneCenterTransition) {
2908 oneCenterTransition = AceType::MakeRefPtr<OneCenterTransitionOptionType>();
2909 }
2910 oneCenterTransition->SetCenterX(centerXDimension);
2911 oneCenterTransition->SetCenterY(centerYDimension);
2912 oneCenterTransition->SetCenterZ(centerZDimension);
2913 RefPtr<NG::ChainedTransitionEffect> chainEffect = oneCenterTransition->GetTransitionEffect();
2914 CHECK_NULL_VOID(chainEffect);
2915 while (chainEffect) {
2916 if (chainEffect->GetType() == ChainedTransitionEffectType::ROTATE) {
2917 auto rotateEffect = AceType::DynamicCast<NG::ChainedRotateEffect>(chainEffect);
2918 NG::RotateOptions rotate(rotateEffect->GetEffect().xDirection, rotateEffect->GetEffect().yDirection,
2919 rotateEffect->GetEffect().zDirection, rotateEffect->GetEffect().angle,
2920 oneCenterTransition->GetCenterX(), oneCenterTransition->GetCenterY(), oneCenterTransition->GetCenterZ(),
2921 rotateEffect->GetEffect().perspective);
2922 rotateEffect->SetRotateEffect(rotate);
2923 } else if (chainEffect->GetType() == ChainedTransitionEffectType::SCALE) {
2924 auto scaleEffect = AceType::DynamicCast<NG::ChainedScaleEffect>(chainEffect);
2925 NG::ScaleOptions scale(scaleEffect->GetEffect().xScale, scaleEffect->GetEffect().yScale,
2926 scaleEffect->GetEffect().zScale, oneCenterTransition->GetCenterX(), oneCenterTransition->GetCenterY());
2927 scaleEffect->SetScaleEffect(scale);
2928 }
2929 chainEffect = chainEffect->GetNext();
2930 }
2931 ACE_UPDATE_NODE_RENDER_CONTEXT(OneCenterTransitionOption, oneCenterTransition, frameNode);
2932 ViewAbstract::SetChainedTransition(frameNode, oneCenterTransition->GetTransitionEffect());
2933 DimensionOffset offset(centerXDimension, centerYDimension);
2934 offset.SetZ(centerZDimension);
2935 ViewAbstract::SetPivot(frameNode, offset);
2936 }
2937
SetOpacityTransition(ArkUINodeHandle node,float value,const ArkUIAnimationOptionType * animationOption)2938 void SetOpacityTransition(ArkUINodeHandle node, float value, const ArkUIAnimationOptionType* animationOption)
2939 {
2940 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2941 CHECK_NULL_VOID(frameNode);
2942 double opacity = value;
2943 if (opacity > 1.0 || LessNotEqual(opacity, 0.0)) {
2944 opacity = 1.0;
2945 }
2946 RefPtr<OneCenterTransitionOptionType> oneCenterTransition;
2947 auto renderContext = frameNode->GetRenderContext();
2948 if (renderContext) {
2949 oneCenterTransition = renderContext->GetOneCenterTransitionOption();
2950 }
2951 if (!oneCenterTransition) {
2952 oneCenterTransition = AceType::MakeRefPtr<OneCenterTransitionOptionType>();
2953 }
2954 RefPtr<NG::ChainedTransitionEffect> chainEffect = oneCenterTransition->GetTransitionEffect();
2955 RefPtr<NG::ChainedOpacityEffect> opacityEffect;
2956 while (chainEffect) {
2957 if (chainEffect->GetType() == ChainedTransitionEffectType::OPACITY) {
2958 opacityEffect = AceType::DynamicCast<NG::ChainedOpacityEffect>(chainEffect);
2959 break;
2960 }
2961 chainEffect = chainEffect->GetNext();
2962 }
2963 auto option = std::make_shared<AnimationOption>();
2964 SetAnimationOption(option, animationOption);
2965 if (!opacityEffect) {
2966 opacityEffect = AceType::MakeRefPtr<NG::ChainedOpacityEffect>(opacity);
2967 opacityEffect->SetAnimationOption(option);
2968 opacityEffect->SetNext(oneCenterTransition->GetTransitionEffect());
2969 oneCenterTransition->SetTransitionEffect(opacityEffect);
2970 } else {
2971 opacityEffect->SetOpacity(opacity);
2972 opacityEffect->SetAnimationOption(option);
2973 }
2974 ACE_UPDATE_NODE_RENDER_CONTEXT(OneCenterTransitionOption, oneCenterTransition, frameNode);
2975 ViewAbstract::SetChainedTransition(frameNode, oneCenterTransition->GetTransitionEffect());
2976 }
2977
SetRotateTransition(ArkUINodeHandle node,float * arrayValue,ArkUI_Int32 length,float perspective,float angle,const ArkUIAnimationOptionType * animationOption)2978 void SetRotateTransition(ArkUINodeHandle node, float* arrayValue, ArkUI_Int32 length, float perspective, float angle,
2979 const ArkUIAnimationOptionType* animationOption)
2980 {
2981 CHECK_NULL_VOID(arrayValue);
2982 auto* frameNode = reinterpret_cast<FrameNode*>(node);
2983 CHECK_NULL_VOID(frameNode);
2984 if (length < ARRAY_SIZE) {
2985 return;
2986 }
2987 RefPtr<OneCenterTransitionOptionType> oneCenterTransition;
2988 auto renderContext = frameNode->GetRenderContext();
2989 if (renderContext) {
2990 oneCenterTransition = renderContext->GetOneCenterTransitionOption();
2991 }
2992 if (!oneCenterTransition) {
2993 oneCenterTransition = AceType::MakeRefPtr<OneCenterTransitionOptionType>();
2994 }
2995 RefPtr<NG::ChainedTransitionEffect> chainEffect = oneCenterTransition->GetTransitionEffect();
2996 RefPtr<NG::ChainedRotateEffect> rotateEffect;
2997 while (chainEffect) {
2998 if (chainEffect->GetType() == ChainedTransitionEffectType::ROTATE) {
2999 rotateEffect = AceType::DynamicCast<NG::ChainedRotateEffect>(chainEffect);
3000 break;
3001 }
3002 chainEffect = chainEffect->GetNext();
3003 }
3004 auto option = std::make_shared<AnimationOption>();
3005 SetAnimationOption(option, animationOption);
3006 NG::RotateOptions rotate(arrayValue[X_INDEX], arrayValue[Y_INDEX], arrayValue[Z_INDEX], angle,
3007 oneCenterTransition->GetCenterX(), oneCenterTransition->GetCenterY(), oneCenterTransition->GetCenterZ(),
3008 perspective);
3009 if (!rotateEffect) {
3010 rotateEffect = AceType::MakeRefPtr<NG::ChainedRotateEffect>(rotate);
3011 rotateEffect->SetAnimationOption(option);
3012 rotateEffect->SetNext(oneCenterTransition->GetTransitionEffect());
3013 oneCenterTransition->SetTransitionEffect(rotateEffect);
3014 } else {
3015 rotateEffect->SetRotateEffect(rotate);
3016 rotateEffect->SetAnimationOption(option);
3017 }
3018 ACE_UPDATE_NODE_RENDER_CONTEXT(OneCenterTransitionOption, oneCenterTransition, frameNode);
3019 ViewAbstract::SetChainedTransition(frameNode, oneCenterTransition->GetTransitionEffect());
3020 }
3021
SetScaleTransition(ArkUINodeHandle node,float * arrayValue,ArkUI_Int32 length,const ArkUIAnimationOptionType * animationOption)3022 void SetScaleTransition(
3023 ArkUINodeHandle node, float* arrayValue, ArkUI_Int32 length, const ArkUIAnimationOptionType* animationOption)
3024 {
3025 CHECK_NULL_VOID(arrayValue);
3026 auto* frameNode = reinterpret_cast<FrameNode*>(node);
3027 CHECK_NULL_VOID(frameNode);
3028 if (length < ARRAY_SIZE) {
3029 return;
3030 }
3031 RefPtr<OneCenterTransitionOptionType> oneCenterTransition;
3032 auto renderContext = frameNode->GetRenderContext();
3033 if (renderContext) {
3034 oneCenterTransition = renderContext->GetOneCenterTransitionOption();
3035 }
3036 if (!oneCenterTransition) {
3037 oneCenterTransition = AceType::MakeRefPtr<OneCenterTransitionOptionType>();
3038 }
3039 RefPtr<NG::ChainedTransitionEffect> chainEffect = oneCenterTransition->GetTransitionEffect();
3040 RefPtr<NG::ChainedScaleEffect> scaleEffect;
3041 while (chainEffect) {
3042 if (chainEffect->GetType() == ChainedTransitionEffectType::SCALE) {
3043 scaleEffect = AceType::DynamicCast<NG::ChainedScaleEffect>(chainEffect);
3044 break;
3045 }
3046 chainEffect = chainEffect->GetNext();
3047 }
3048 auto option = std::make_shared<AnimationOption>();
3049 SetAnimationOption(option, animationOption);
3050 NG::ScaleOptions scale(arrayValue[X_INDEX], arrayValue[Y_INDEX], arrayValue[Z_INDEX],
3051 oneCenterTransition->GetCenterX(), oneCenterTransition->GetCenterY());
3052 if (!scaleEffect) {
3053 scaleEffect = AceType::MakeRefPtr<NG::ChainedScaleEffect>(scale);
3054 scaleEffect->SetAnimationOption(option);
3055 scaleEffect->SetNext(oneCenterTransition->GetTransitionEffect());
3056 oneCenterTransition->SetTransitionEffect(scaleEffect);
3057 } else {
3058 scaleEffect->SetScaleEffect(scale);
3059 scaleEffect->SetAnimationOption(option);
3060 }
3061 ACE_UPDATE_NODE_RENDER_CONTEXT(OneCenterTransitionOption, oneCenterTransition, frameNode);
3062 ViewAbstract::SetChainedTransition(frameNode, oneCenterTransition->GetTransitionEffect());
3063 }
3064
SetTranslateTransition(ArkUINodeHandle node,float xValue,ArkUI_Int32 xUnit,float yValue,ArkUI_Int32 yUnit,float zValue,ArkUI_Int32 zUnit,const ArkUIAnimationOptionType * animationOption)3065 void SetTranslateTransition(ArkUINodeHandle node, float xValue, ArkUI_Int32 xUnit, float yValue, ArkUI_Int32 yUnit,
3066 float zValue, ArkUI_Int32 zUnit, const ArkUIAnimationOptionType* animationOption)
3067 {
3068 auto* frameNode = reinterpret_cast<FrameNode*>(node);
3069 CHECK_NULL_VOID(frameNode);
3070 RefPtr<OneCenterTransitionOptionType> oneCenterTransition;
3071 auto renderContext = frameNode->GetRenderContext();
3072 if (renderContext) {
3073 oneCenterTransition = renderContext->GetOneCenterTransitionOption();
3074 }
3075 if (!oneCenterTransition) {
3076 oneCenterTransition = AceType::MakeRefPtr<OneCenterTransitionOptionType>();
3077 }
3078 RefPtr<NG::ChainedTransitionEffect> chainEffect = oneCenterTransition->GetTransitionEffect();
3079 RefPtr<NG::ChainedTranslateEffect> translateEffect;
3080 while (chainEffect) {
3081 if (chainEffect->GetType() == ChainedTransitionEffectType::TRANSLATE) {
3082 translateEffect = AceType::DynamicCast<NG::ChainedTranslateEffect>(chainEffect);
3083 break;
3084 }
3085 chainEffect = chainEffect->GetNext();
3086 }
3087
3088 auto option = std::make_shared<AnimationOption>();
3089 SetAnimationOption(option, animationOption);
3090 Dimension xDimension(xValue, static_cast<DimensionUnit>(xUnit));
3091 Dimension yDimension(yValue, static_cast<DimensionUnit>(yUnit));
3092 Dimension zDimension(zValue, static_cast<DimensionUnit>(zUnit));
3093 NG::TranslateOptions translate(xDimension, yDimension, zDimension);
3094 if (!translateEffect) {
3095 translateEffect = AceType::MakeRefPtr<NG::ChainedTranslateEffect>(translate);
3096 translateEffect->SetAnimationOption(option);
3097 translateEffect->SetNext(oneCenterTransition->GetTransitionEffect());
3098 oneCenterTransition->SetTransitionEffect(translateEffect);
3099 } else {
3100 translateEffect->SetTranslateEffect(translate);
3101 translateEffect->SetAnimationOption(option);
3102 }
3103 ACE_UPDATE_NODE_RENDER_CONTEXT(OneCenterTransitionOption, oneCenterTransition, frameNode);
3104 ViewAbstract::SetChainedTransition(frameNode, oneCenterTransition->GetTransitionEffect());
3105 }
3106 } // namespace
3107
3108 namespace NodeModifier {
GetCommonModifier()3109 const ArkUICommonModifier* GetCommonModifier()
3110 {
3111 static const ArkUICommonModifier modifier = { SetBackgroundColor, ResetBackgroundColor, SetWidth, ResetWidth,
3112 SetHeight, ResetHeight, SetBorderRadius, ResetBorderRadius, SetBorderWidth, ResetBorderWidth, SetTransform,
3113 ResetTransform, SetBorderColor, ResetBorderColor, SetPosition, ResetPosition, SetBorderStyle, ResetBorderStyle,
3114 SetBackShadow, ResetBackShadow, SetHitTestBehavior, ResetHitTestBehavior, SetZIndex, ResetZIndex, SetOpacity,
3115 ResetOpacity, SetAlign, ResetAlign, SetBackdropBlur, ResetBackdropBlur, SetHueRotate, ResetHueRotate, SetInvert,
3116 ResetInvert, SetSepia, ResetSepia, SetSaturate, ResetSaturate, SetColorBlend, ResetColorBlend, SetGrayscale,
3117 ResetGrayscale, SetContrast, ResetContrast, SetBrightness, ResetBrightness, SetBlur, ResetBlur,
3118 SetLinearGradient, ResetLinearGradient, SetSweepGradient, ResetSweepGradient, SetRadialGradient,
3119 ResetRadialGradient, SetOverlay, ResetOverlay, SetBorderImage, ResetBorderImage, SetBorderImageGradient,
3120 SetForegroundBlurStyle, ResetForegroundBlurStyle, SetLinearGradientBlur, ResetLinearGradientBlur,
3121 SetBackgroundBlurStyle, ResetBackgroundBlurStyle, SetBorder, ResetBorder, SetBackgroundImagePosition,
3122 ResetBackgroundImagePosition, SetBackgroundImageSize, ResetBackgroundImageSize, SetBackgroundImage,
3123 ResetBackgroundImage, SetTranslate, ResetTranslate, SetScale, ResetScale, SetRotate, ResetRotate,
3124 SetGeometryTransition, ResetGeometryTransition, SetPixelStretchEffect, ResetPixelStretchEffect,
3125 SetLightUpEffect, ResetLightUpEffect, SetSphericalEffect, ResetSphericalEffect, SetRenderGroup,
3126 ResetRenderGroup, SetRenderFit, ResetRenderFit, SetUseEffect, ResetUseEffect, SetForegroundColor,
3127 ResetForegroundColor, SetMotionPath, ResetMotionPath, SetGroupDefaultFocus, ResetGroupDefaultFocus,
3128 SetFocusOnTouch, ResetFocusOnTouch, SetFocusable, ResetFocusable, SetTouchable, ResetTouchable, SetDefaultFocus,
3129 ResetDefaultFocus, SetDisplayPriority, ResetDisplayPriority, SetOffset, ResetOffset, SetPadding, ResetPadding,
3130 SetMargin, ResetMargin, SetMarkAnchor, ResetMarkAnchor, SetVisibility, ResetVisibility, SetAccessibilityText,
3131 ResetAccessibilityText, SetAllowDrop, ResetAllowDrop, SetAccessibilityLevel, ResetAccessibilityLevel,
3132 SetDirection, ResetDirection, SetLayoutWeight, ResetLayoutWeight, SetMinWidth, ResetMinWidth, SetMaxWidth,
3133 ResetMaxWidth, SetMinHeight, ResetMinHeight, SetMaxHeight, ResetMaxHeight, SetSize, ResetSize,
3134 ClearWidthOrHeight, SetAlignSelf, ResetAlignSelf, SetAspectRatio, ResetAspectRatio, SetFlexGrow, ResetFlexGrow,
3135 SetFlexShrink, ResetFlexShrink, SetGridOffset, ResetGridOffset, SetGridSpan, ResetGridSpan, SetExpandSafeArea,
3136 ResetExpandSafeArea, SetFlexBasis, ResetFlexBasis, SetAlignRules, ResetAlignRules, SetAccessibilityDescription,
3137 ResetAccessibilityDescription, SetId, ResetId, SetKey, ResetKey, SetRestoreId, ResetRestoreId, SetTabIndex,
3138 ResetTabIndex, SetObscured, ResetObscured, SetResponseRegion, ResetResponseRegion, SetMouseResponseRegion,
3139 ResetMouseResponseRegion, SetEnabled, ResetEnabled, SetDraggable, ResetDraggable, SetAccessibilityGroup,
3140 ResetAccessibilityGroup, SetHoverEffect, ResetHoverEffect, SetClickEffect, ResetClickEffect,
3141 SetKeyBoardShortCut, ResetKeyBoardShortCut, SetClip, SetClipShape, SetClipPath, SetTransitionCenter,
3142 SetOpacityTransition, SetRotateTransition, SetScaleTransition, SetTranslateTransition };
3143
3144 return &modifier;
3145 }
3146
SetOnFocus(ArkUINodeHandle node,ArkUI_Int32 eventId,void * extraParam)3147 void SetOnFocus(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam)
3148 {
3149 auto* frameNode = reinterpret_cast<FrameNode*>(node);
3150 CHECK_NULL_VOID(frameNode);
3151 auto onEvent = [node, eventId, extraParam]() {
3152 ArkUINodeEvent event;
3153 event.kind = ON_FOCUS;
3154 event.eventId = eventId;
3155 event.extraParam = extraParam;
3156 SendArkUIAsyncEvent(&event);
3157 };
3158 ViewAbstract::SetOnFocus(frameNode, std::move(onEvent));
3159 }
3160
SetOnBlur(ArkUINodeHandle node,ArkUI_Int32 eventId,void * extraParam)3161 void SetOnBlur(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam)
3162 {
3163 auto* frameNode = reinterpret_cast<FrameNode*>(node);
3164 CHECK_NULL_VOID(frameNode);
3165 auto onEvent = [node, eventId, extraParam]() {
3166 ArkUINodeEvent event;
3167 event.kind = ON_BLUR;
3168 event.eventId = eventId;
3169 event.extraParam = extraParam;
3170 SendArkUIAsyncEvent(&event);
3171 };
3172 ViewAbstract::SetOnBlur(frameNode, std::move(onEvent));
3173 }
3174
3175 } // namespace NodeModifier
3176 } // namespace OHOS::Ace::NG