1 /*
2  * Copyright (c) 2021 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 
16 #include "core/animation/animatable_properties.h"
17 
18 #include "core/animation/animatable_data.h"
19 #include "core/components/box/render_box.h"
20 #include "core/components/display/render_display.h"
21 
22 namespace OHOS::Ace {
23 
UpdatePropAnimation(const PropAnimationMap & propAnimations)24 void AnimatableProperties::UpdatePropAnimation(const PropAnimationMap& propAnimations)
25 {
26     if (propAnimations.empty()) {
27         return;
28     }
29     for (const auto& [type, animation] : propAnimations) {
30         auto weakAnimation = AceType::WeakClaim(AceType::RawPtr(animation));
31         switch (type) {
32             case AnimatableType::PROPERTY_WIDTH: {
33                 animation->AddListener(
34                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
35                         auto animation = weakAnimation.Upgrade();
36                         auto animatableProperties = weak.Upgrade();
37                         auto width = AceType::DynamicCast<AnimatableData<Dimension>>(data);
38                         if (animatableProperties && width) {
39                             if (animation && animation->GetInit() == nullptr) {
40                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(
41                                     animatableProperties->GetPropWidth());
42                                 animation->SetInit(init);
43                             }
44                             animatableProperties->SetPropWidth(width->GetValue());
45                         }
46                     });
47                 break;
48             }
49             case AnimatableType::PROPERTY_HEIGHT: {
50                 animation->AddListener(
51                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
52                         auto animation = weakAnimation.Upgrade();
53                         auto animatableProperties = weak.Upgrade();
54                         auto height = AceType::DynamicCast<AnimatableData<Dimension>>(data);
55                         if (animatableProperties && height) {
56                             if (animation && animation->GetInit() == nullptr) {
57                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(
58                                     animatableProperties->GetPropHeight());
59                                 animation->SetInit(init);
60                             }
61                             animatableProperties->SetPropHeight(height->GetValue());
62                         }
63                     });
64                 break;
65             }
66             case AnimatableType::PROPERTY_BG_COLOR: {
67                 animation->AddListener(
68                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
69                         auto animation = weakAnimation.Upgrade();
70                         auto animatableProperties = weak.Upgrade();
71                         auto color = AceType::DynamicCast<AnimatableData<Color>>(data);
72                         if (animatableProperties && color) {
73                             if (animation && animation->GetInit() == nullptr) {
74                                 auto init =
75                                     AceType::MakeRefPtr<AnimatableData<Color>>(animatableProperties->GetPropBgColor());
76                                 animation->SetInit(init);
77                             }
78                             animatableProperties->SetPropBgColor(color->GetValue());
79                         }
80                     });
81                 break;
82             }
83             case AnimatableType::PROPERTY_OPACITY: {
84                 animation->AddListener(
85                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
86                         auto animation = weakAnimation.Upgrade();
87                         auto animatableProperties = weak.Upgrade();
88                         auto opacity = AceType::DynamicCast<AnimatableData<float>>(data);
89                         if (animatableProperties && opacity) {
90                             if (animation && animation->GetInit() == nullptr) {
91                                 auto init =
92                                     AceType::MakeRefPtr<AnimatableData<float>>(animatableProperties->GetPropOpacity());
93                                 animation->SetInit(init);
94                             }
95                             animatableProperties->SetPropOpacity(opacity->GetValue());
96                         }
97                     });
98                 break;
99             }
100             case AnimatableType::PROPERTY_MARGIN_LEFT:
101             case AnimatableType::PROPERTY_MARGIN_TOP:
102             case AnimatableType::PROPERTY_MARGIN_RIGHT:
103             case AnimatableType::PROPERTY_MARGIN_BOTTOM: {
104                 auto setter = DimensionHelper(&Edge::SetLeft, &Edge::Left);
105                 if (type == AnimatableType::PROPERTY_MARGIN_TOP) {
106                     setter = DimensionHelper(&Edge::SetTop, &Edge::Top);
107                 } else if (type == AnimatableType::PROPERTY_MARGIN_RIGHT) {
108                     setter = DimensionHelper(&Edge::SetRight, &Edge::Right);
109                 } else if (type == AnimatableType::PROPERTY_MARGIN_BOTTOM) {
110                     setter = DimensionHelper(&Edge::SetBottom, &Edge::Bottom);
111                 }
112                 animation->AddListener(
113                     [weak = AceType::WeakClaim(this), setter = setter, weakAnimation](const RefPtr<Animatable>& data) {
114                         auto animation = weakAnimation.Upgrade();
115                         auto animatableProperties = weak.Upgrade();
116                         auto margin = AceType::DynamicCast<AnimatableData<Dimension>>(data);
117                         if (animatableProperties && margin) {
118                             if (animation && animation->GetInit() == nullptr) {
119                                 const Dimension& dimension = animatableProperties->GetMargin(setter);
120                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(dimension);
121                                 animation->SetInit(init);
122                             }
123                             animatableProperties->SetMargin(AnimatableDimension(margin->GetValue()), setter);
124                         }
125                     });
126                 break;
127             }
128             case AnimatableType::PROPERTY_PADDING_LEFT:
129             case AnimatableType::PROPERTY_PADDING_TOP:
130             case AnimatableType::PROPERTY_PADDING_RIGHT:
131             case AnimatableType::PROPERTY_PADDING_BOTTOM: {
132                 auto setter = DimensionHelper(&Edge::SetLeft, &Edge::Left);
133                 if (type == AnimatableType::PROPERTY_PADDING_TOP) {
134                     setter = DimensionHelper(&Edge::SetTop, &Edge::Top);
135                 } else if (type == AnimatableType::PROPERTY_PADDING_RIGHT) {
136                     setter = DimensionHelper(&Edge::SetRight, &Edge::Right);
137                 } else if (type == AnimatableType::PROPERTY_PADDING_BOTTOM) {
138                     setter = DimensionHelper(&Edge::SetBottom, &Edge::Bottom);
139                 }
140                 animation->AddListener(
141                     [weak = AceType::WeakClaim(this), setter = setter, weakAnimation](const RefPtr<Animatable>& data) {
142                         auto animation = weakAnimation.Upgrade();
143                         auto animatableProperties = weak.Upgrade();
144                         auto padding = AceType::DynamicCast<AnimatableData<Dimension>>(data);
145                         if (animatableProperties && padding) {
146                             if (animation && animation->GetInit() == nullptr) {
147                                 const Dimension& dimension = animatableProperties->GetPadding(setter);
148                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(dimension);
149                                 animation->SetInit(init);
150                             }
151                             animatableProperties->SetPadding(AnimatableDimension(padding->GetValue()), setter);
152                         }
153                     });
154                 break;
155             }
156             case AnimatableType::PROPERTY_BACKGROUND_POSITION: {
157                 animation->AddListener(
158                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
159                         auto animation = weakAnimation.Upgrade();
160                         auto animatableProperties = weak.Upgrade();
161                         auto position = AceType::DynamicCast<AnimatableData<BackgroundImagePosition>>(data);
162                         if (animatableProperties && position) {
163                             if (animation && animation->GetInit() == nullptr) {
164                                 auto init = AceType::MakeRefPtr<AnimatableData<BackgroundImagePosition>>(
165                                     animatableProperties->GetPropBackgroundImagePosition());
166                                 animation->SetInit(init);
167                             }
168                             animatableProperties->SetPropBackgroundPosition(position->GetValue());
169                         }
170                     });
171                 break;
172             }
173             case AnimatableType::PROPERTY_BACKGROUND_SIZE: {
174                 animation->AddListener(
175                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
176                         auto animation = weakAnimation.Upgrade();
177                         auto animatableProperties = weak.Upgrade();
178                         auto size = AceType::DynamicCast<AnimatableData<BackgroundImageSize>>(data);
179                         if (animatableProperties && size) {
180                             if (animation && animation->GetInit() == nullptr) {
181                                 auto init = AceType::MakeRefPtr<AnimatableData<BackgroundImageSize>>(
182                                     animatableProperties->GetPropBackgroundImageSize());
183                                 animation->SetInit(init);
184                             }
185                             animatableProperties->SetPropBackgroundSize(size->GetValue());
186                         }
187                     });
188                 break;
189             }
190             case AnimatableType::PROPERTY_FILTER_BLUR: {
191                 animation->AddListener(
192                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
193                         auto animation = weakAnimation.Upgrade();
194                         auto animatableProperties = weak.Upgrade();
195                         auto radius = AceType::DynamicCast<AnimatableData<float>>(data);
196                         if (animatableProperties && radius) {
197                             if (animation && animation->GetInit() == nullptr) {
198                                 auto init = AceType::MakeRefPtr<AnimatableData<float>>(
199                                     animatableProperties->GetBlurRadius().Value());
200                                 animation->SetInit(init);
201                             }
202                             animatableProperties->SetBlurRadius(
203                                 AnimatableDimension(radius->GetValue(), DimensionUnit::PX));
204                         }
205                     });
206                 break;
207             }
208             case AnimatableType::PROPERTY_BACKDROP_FILTER_BLUR: {
209                 animation->AddListener(
210                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
211                         auto animation = weakAnimation.Upgrade();
212                         auto animatableProperties = weak.Upgrade();
213                         auto radius = AceType::DynamicCast<AnimatableData<float>>(data);
214                         if (animatableProperties && radius) {
215                             if (animation && animation->GetInit() == nullptr) {
216                                 auto init = AceType::MakeRefPtr<AnimatableData<float>>(
217                                     animatableProperties->GetBackdropRadius().Value());
218                                 animation->SetInit(init);
219                             }
220                             animatableProperties->SetBackdropRadius(
221                                 AnimatableDimension(radius->GetValue(), DimensionUnit::PX));
222                         }
223                     });
224                 break;
225             }
226             case AnimatableType::PROPERTY_WINDOW_FILTER_BLUR: {
227                 animation->AddListener(
228                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
229                         auto animation = weakAnimation.Upgrade();
230                         auto animatableProperties = weak.Upgrade();
231                         auto progress = AceType::DynamicCast<AnimatableData<float>>(data);
232                         if (animatableProperties && progress) {
233                             if (animation && animation->GetInit() == nullptr) {
234                                 auto init = AceType::MakeRefPtr<AnimatableData<float>>(
235                                     animatableProperties->GetWindowBlurProgress());
236                                 animation->SetInit(init);
237                             }
238                             animatableProperties->SetWindowBlurProgress(progress->GetValue());
239                         }
240                     });
241                 break;
242             }
243             case AnimatableType::PROPERTY_BOX_SHADOW: {
244                 animation->AddListener(
245                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
246                         auto animation = weakAnimation.Upgrade();
247                         auto animatableProperties = weak.Upgrade();
248                         auto shadow = AceType::DynamicCast<AnimatableData<Shadow>>(data);
249                         if (animatableProperties && shadow) {
250                             if (animation && animation->GetInit() == nullptr) {
251                                 auto init =
252                                     AceType::MakeRefPtr<AnimatableData<Shadow>>(animatableProperties->GetPropShadow());
253                                 animation->SetInit(init);
254                             }
255                             animatableProperties->SetPropShadow(shadow->GetValue());
256                         }
257                     });
258                 break;
259             }
260             case AnimatableType::PROPERTY_BORDER_LEFT_WIDTH:
261             case AnimatableType::PROPERTY_BORDER_TOP_WIDTH:
262             case AnimatableType::PROPERTY_BORDER_RIGHT_WIDTH:
263             case AnimatableType::PROPERTY_BORDER_BOTTOM_WIDTH: {
264                 auto setter = BorderEdgeHelper(&Border::SetLeftEdge, &Border::Left);
265                 if (type == AnimatableType::PROPERTY_BORDER_TOP_WIDTH) {
266                     setter = BorderEdgeHelper(&Border::SetTopEdge, &Border::Top);
267                 } else if (type == AnimatableType::PROPERTY_BORDER_RIGHT_WIDTH) {
268                     setter = BorderEdgeHelper(&Border::SetRightEdge, &Border::Right);
269                 } else if (type == AnimatableType::PROPERTY_BORDER_BOTTOM_WIDTH) {
270                     setter = BorderEdgeHelper(&Border::SetBottomEdge, &Border::Bottom);
271                 }
272                 animation->AddListener(
273                     [weak = AceType::WeakClaim(this), setter = setter, weakAnimation](const RefPtr<Animatable>& data) {
274                         auto animation = weakAnimation.Upgrade();
275                         auto animatableProperties = weak.Upgrade();
276                         auto width = AceType::DynamicCast<AnimatableData<float>>(data);
277                         if (animatableProperties && width) {
278                             if (animation && animation->GetInit() == nullptr) {
279                                 auto init = AceType::MakeRefPtr<AnimatableData<float>>(
280                                     animatableProperties->GetBorderWidth(setter));
281                                 animation->SetInit(init);
282                             }
283                             animatableProperties->SetBorderWidth(width->GetValue(), setter);
284                         }
285                     });
286                 break;
287             }
288             case AnimatableType::PROPERTY_BORDER_LEFT_COLOR:
289             case AnimatableType::PROPERTY_BORDER_TOP_COLOR:
290             case AnimatableType::PROPERTY_BORDER_RIGHT_COLOR:
291             case AnimatableType::PROPERTY_BORDER_BOTTOM_COLOR: {
292                 auto setter = BorderEdgeHelper(&Border::SetLeftEdge, &Border::Left);
293                 if (type == AnimatableType::PROPERTY_BORDER_TOP_COLOR) {
294                     setter = BorderEdgeHelper(&Border::SetTopEdge, &Border::Top);
295                 } else if (type == AnimatableType::PROPERTY_BORDER_RIGHT_COLOR) {
296                     setter = BorderEdgeHelper(&Border::SetRightEdge, &Border::Right);
297                 } else if (type == AnimatableType::PROPERTY_BORDER_BOTTOM_COLOR) {
298                     setter = BorderEdgeHelper(&Border::SetBottomEdge, &Border::Bottom);
299                 }
300                 animation->AddListener(
301                     [weak = AceType::WeakClaim(this), setter = setter, weakAnimation](const RefPtr<Animatable>& data) {
302                         auto animation = weakAnimation.Upgrade();
303                         auto animatableProperties = weak.Upgrade();
304                         auto color = AceType::DynamicCast<AnimatableData<Color>>(data);
305                         if (animatableProperties && color) {
306                             if (animation && animation->GetInit() == nullptr) {
307                                 auto init = AceType::MakeRefPtr<AnimatableData<Color>>(
308                                     animatableProperties->GetBorderColor(setter));
309                                 animation->SetInit(init);
310                             }
311                             animatableProperties->SetBorderColor(color->GetValue(), setter);
312                         }
313                     });
314                 break;
315             }
316             case AnimatableType::PROPERTY_BORDER_LEFT_STYLE:
317             case AnimatableType::PROPERTY_BORDER_TOP_STYLE:
318             case AnimatableType::PROPERTY_BORDER_RIGHT_STYLE:
319             case AnimatableType::PROPERTY_BORDER_BOTTOM_STYLE: {
320                 auto setter = BorderEdgeHelper(&Border::SetLeftEdge, &Border::Left);
321                 if (type == AnimatableType::PROPERTY_BORDER_TOP_STYLE) {
322                     setter = BorderEdgeHelper(&Border::SetTopEdge, &Border::Top);
323                 } else if (type == AnimatableType::PROPERTY_BORDER_RIGHT_STYLE) {
324                     setter = BorderEdgeHelper(&Border::SetRightEdge, &Border::Right);
325                 } else if (type == AnimatableType::PROPERTY_BORDER_BOTTOM_STYLE) {
326                     setter = BorderEdgeHelper(&Border::SetBottomEdge, &Border::Bottom);
327                 }
328                 animation->AddListener(
329                     [weak = AceType::WeakClaim(this), setter = setter, weakAnimation](const RefPtr<Animatable>& data) {
330                         auto animation = weakAnimation.Upgrade();
331                         auto animatableProperties = weak.Upgrade();
332                         auto borderStyle = AceType::DynamicCast<AnimatableData<BorderStyle>>(data);
333                         if (animatableProperties && borderStyle) {
334                             if (animation && animation->GetInit() == nullptr) {
335                                 auto init = AceType::MakeRefPtr<AnimatableData<BorderStyle>>(
336                                     animatableProperties->GetBorderStyle(setter));
337                                 animation->SetInit(init);
338                             }
339                             animatableProperties->SetBorderStyle(borderStyle->GetValue(), setter);
340                         }
341                     });
342                 break;
343             }
344             case AnimatableType::PROPERTY_BORDER_TOP_LEFT_RADIUS:
345             case AnimatableType::PROPERTY_BORDER_TOP_RIGHT_RADIUS:
346             case AnimatableType::PROPERTY_BORDER_BOTTOM_LEFT_RADIUS:
347             case AnimatableType::PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS: {
348                 auto setter = BorderRadiusHelper(&Border::SetTopLeftRadius, &Border::TopLeftRadius);
349                 if (type == AnimatableType::PROPERTY_BORDER_TOP_RIGHT_RADIUS) {
350                     setter = BorderRadiusHelper(&Border::SetTopRightRadius, &Border::TopRightRadius);
351                 } else if (type == AnimatableType::PROPERTY_BORDER_BOTTOM_LEFT_RADIUS) {
352                     setter = BorderRadiusHelper(&Border::SetBottomLeftRadius, &Border::BottomLeftRadius);
353                 } else if (type == AnimatableType::PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS) {
354                     setter = BorderRadiusHelper(&Border::SetBottomRightRadius, &Border::BottomRightRadius);
355                 }
356                 animation->AddListener(
357                     [weak = AceType::WeakClaim(this), setter = setter, weakAnimation](const RefPtr<Animatable>& data) {
358                         auto animation = weakAnimation.Upgrade();
359                         auto animatableProperties = weak.Upgrade();
360                         auto radius = AceType::DynamicCast<AnimatableData<float>>(data);
361                         if (animatableProperties && radius) {
362                             if (animation && animation->GetInit() == nullptr) {
363                                 auto init = AceType::MakeRefPtr<AnimatableData<float>>(
364                                     animatableProperties->GetBorderRadius(setter));
365                                 animation->SetInit(init);
366                             }
367                             animatableProperties->SetBorderRadius(radius->GetValue(), setter);
368                         }
369                     });
370                 break;
371             }
372             case AnimatableType::PROPERTY_POSITION_LEFT: {
373                 animation->AddListener(
374                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
375                         auto animation = weakAnimation.Upgrade();
376                         auto animatableProperties = weak.Upgrade();
377                         auto left = AceType::DynamicCast<AnimatableData<Dimension>>(data);
378                         if (animatableProperties && left) {
379                             if (animation && animation->GetInit() == nullptr) {
380                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(
381                                     animatableProperties->GetPositionLeft());
382                                 animation->SetInit(init);
383                             }
384                             animatableProperties->SetPositionLeft(left->GetValue());
385                         }
386                     });
387                 break;
388             }
389             case AnimatableType::PROPERTY_POSITION_TOP: {
390                 animation->AddListener(
391                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
392                         auto animation = weakAnimation.Upgrade();
393                         auto animatableProperties = weak.Upgrade();
394                         auto top = AceType::DynamicCast<AnimatableData<Dimension>>(data);
395                         if (animatableProperties && top) {
396                             if (animation && animation->GetInit() == nullptr) {
397                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(
398                                     animatableProperties->GetPositionTop());
399                                 animation->SetInit(init);
400                             }
401                             animatableProperties->SetPositionTop(top->GetValue());
402                         }
403                     });
404                 break;
405             }
406             case AnimatableType::PROPERTY_POSITION_RIGHT: {
407                 animation->AddListener(
408                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
409                         auto animation = weakAnimation.Upgrade();
410                         auto animatableProperties = weak.Upgrade();
411                         auto right = AceType::DynamicCast<AnimatableData<Dimension>>(data);
412                         if (animatableProperties && right) {
413                             if (animation && animation->GetInit() == nullptr) {
414                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(
415                                     animatableProperties->GetPositionRight());
416                                 animation->SetInit(init);
417                             }
418                             animatableProperties->SetPositionRight(right->GetValue());
419                         }
420                     });
421                 break;
422             }
423             case AnimatableType::PROPERTY_POSITION_BOTTOM: {
424                 animation->AddListener(
425                     [weak = AceType::WeakClaim(this), weakAnimation](const RefPtr<Animatable>& data) {
426                         auto animation = weakAnimation.Upgrade();
427                         auto animatableProperties = weak.Upgrade();
428                         auto bottom = AceType::DynamicCast<AnimatableData<Dimension>>(data);
429                         if (animatableProperties && bottom) {
430                             if (animation && animation->GetInit() == nullptr) {
431                                 auto init = AceType::MakeRefPtr<AnimatableData<Dimension>>(
432                                     animatableProperties->GetPositionBottom());
433                                 animation->SetInit(init);
434                             }
435                             animatableProperties->SetPositionBottom(bottom->GetValue());
436                         }
437                     });
438                 break;
439             }
440             default:
441                 break;
442         }
443     }
444 }
445 
SetPropWidth(const Dimension & width)446 void AnimatableProperties::SetPropWidth(const Dimension& width)
447 {
448     auto renderNode = AceType::DynamicCast<RenderBox>(this);
449     if (renderNode == nullptr) {
450         return;
451     }
452     renderNode->SetWidth(width);
453 }
454 
GetPropWidth() const455 Dimension AnimatableProperties::GetPropWidth() const
456 {
457     auto renderNode = AceType::DynamicCast<RenderBox>(this);
458     if (renderNode == nullptr) {
459         return {};
460     }
461     return renderNode->GetWidthDimension();
462 }
463 
SetPropHeight(const Dimension & height)464 void AnimatableProperties::SetPropHeight(const Dimension& height)
465 {
466     auto renderNode = AceType::DynamicCast<RenderBox>(this);
467     if (renderNode == nullptr) {
468         return;
469     }
470     renderNode->SetHeight(height);
471 }
472 
GetPropHeight() const473 Dimension AnimatableProperties::GetPropHeight() const
474 {
475     auto renderNode = AceType::DynamicCast<RenderBox>(this);
476     if (renderNode == nullptr) {
477         return {};
478     }
479     return renderNode->GetHeightDimension();
480 }
481 
SetPropBgColor(const Color & color)482 void AnimatableProperties::SetPropBgColor(const Color& color)
483 {
484     auto renderNode = AceType::DynamicCast<RenderBox>(this);
485     if (renderNode == nullptr) {
486         return;
487     }
488     renderNode->SetColor(color, true);
489 }
490 
GetPropBgColor() const491 Color AnimatableProperties::GetPropBgColor() const
492 {
493     auto renderNode = AceType::DynamicCast<RenderBox>(this);
494     if (renderNode == nullptr) {
495         return {};
496     }
497     return renderNode->GetColor();
498 }
499 
SetPropOpacity(float opacity)500 void AnimatableProperties::SetPropOpacity(float opacity)
501 {
502     auto renderNode = AceType::DynamicCast<RenderDisplay>(this);
503     if (renderNode == nullptr) {
504         return;
505     }
506     renderNode->UpdateOpacity(UINT8_MAX * opacity);
507 }
508 
GetPropOpacity() const509 float AnimatableProperties::GetPropOpacity() const
510 {
511     auto renderNode = AceType::DynamicCast<RenderDisplay>(this);
512     if (renderNode == nullptr) {
513         return 1.0f;
514     }
515     return renderNode->GetOpacity() / (UINT8_MAX * 1.0f);
516 }
517 
SetPropShadow(const Shadow & shadow)518 void AnimatableProperties::SetPropShadow(const Shadow& shadow)
519 {
520     auto renderNode = AceType::DynamicCast<RenderBox>(this);
521     if (renderNode == nullptr) {
522         return;
523     }
524     renderNode->SetShadow(shadow);
525 }
526 
GetPropShadow() const527 Shadow AnimatableProperties::GetPropShadow() const
528 {
529     auto renderNode = AceType::DynamicCast<RenderBox>(this);
530     if (renderNode == nullptr) {
531         return {};
532     }
533     return renderNode->GetShadow();
534 }
535 
SetPropBackgroundPosition(const BackgroundImagePosition & position)536 void AnimatableProperties::SetPropBackgroundPosition(const BackgroundImagePosition& position)
537 {
538     auto renderNode = AceType::DynamicCast<RenderBox>(this);
539     if (renderNode == nullptr) {
540         return;
541     }
542     renderNode->SetBackgroundPosition(position);
543 }
544 
GetPropBackgroundImagePosition() const545 BackgroundImagePosition AnimatableProperties::GetPropBackgroundImagePosition() const
546 {
547     auto renderNode = AceType::DynamicCast<RenderBox>(this);
548     if (renderNode == nullptr) {
549         return {};
550     }
551     return renderNode->GetBackgroundPosition();
552 }
553 
SetPropBackgroundSize(const BackgroundImageSize & size)554 void AnimatableProperties::SetPropBackgroundSize(const BackgroundImageSize& size)
555 {
556     auto renderNode = AceType::DynamicCast<RenderBox>(this);
557     if (renderNode == nullptr) {
558         return;
559     }
560     renderNode->SetBackgroundSize(size);
561 }
562 
GetPropBackgroundImageSize() const563 BackgroundImageSize AnimatableProperties::GetPropBackgroundImageSize() const
564 {
565     auto renderNode = AceType::DynamicCast<RenderBox>(this);
566     if (renderNode == nullptr) {
567         return {};
568     }
569     return renderNode->GetBackgroundSize();
570 }
571 
SetPadding(const AnimatableDimension & value,const DimensionHelper & helper)572 void AnimatableProperties::SetPadding(const AnimatableDimension& value, const DimensionHelper& helper)
573 {
574     auto renderNode = AceType::DynamicCast<RenderBox>(this);
575     if (renderNode == nullptr) {
576         return;
577     }
578     renderNode->SetPadding(value, helper);
579 }
580 
GetPadding(const DimensionHelper & helper)581 AnimatableDimension AnimatableProperties::GetPadding(const DimensionHelper& helper)
582 {
583     auto renderNode = AceType::DynamicCast<RenderBox>(this);
584     if (renderNode == nullptr) {
585         return {};
586     }
587     return renderNode->GetPadding(helper);
588 }
589 
SetMargin(const AnimatableDimension & value,const DimensionHelper & helper)590 void AnimatableProperties::SetMargin(const AnimatableDimension& value, const DimensionHelper& helper)
591 {
592     auto renderNode = AceType::DynamicCast<RenderBox>(this);
593     if (renderNode == nullptr) {
594         return;
595     }
596     renderNode->SetMargin(value, helper);
597 }
598 
GetMargin(const DimensionHelper & helper) const599 AnimatableDimension AnimatableProperties::GetMargin(const DimensionHelper& helper) const
600 {
601     auto renderNode = AceType::DynamicCast<RenderBox>(this);
602     if (renderNode == nullptr) {
603         return {};
604     }
605     return renderNode->GetMargin(helper);
606 }
607 
SetBorderWidth(float value,const BorderEdgeHelper & helper)608 void AnimatableProperties::SetBorderWidth(float value, const BorderEdgeHelper& helper)
609 {
610     auto renderNode = AceType::DynamicCast<RenderBox>(this);
611     if (renderNode == nullptr) {
612         return;
613     }
614     renderNode->SetBorderWidth(value, helper);
615 }
616 
GetBorderWidth(const BorderEdgeHelper & helper) const617 float AnimatableProperties::GetBorderWidth(const BorderEdgeHelper& helper) const
618 {
619     auto renderNode = AceType::DynamicCast<RenderBox>(this);
620     if (renderNode == nullptr) {
621         return 0.0f;
622     }
623     return renderNode->GetBorderWidth(helper);
624 }
625 
SetBorderColor(const Color & color,const BorderEdgeHelper & helper)626 void AnimatableProperties::SetBorderColor(const Color& color, const BorderEdgeHelper& helper)
627 {
628     auto renderNode = AceType::DynamicCast<RenderBox>(this);
629     if (renderNode == nullptr) {
630         return;
631     }
632     renderNode->SetBorderColor(color, helper);
633 }
634 
GetBorderColor(const BorderEdgeHelper & helper) const635 Color AnimatableProperties::GetBorderColor(const BorderEdgeHelper& helper) const
636 {
637     auto renderNode = AceType::DynamicCast<RenderBox>(this);
638     if (renderNode == nullptr) {
639         return {};
640     }
641     return renderNode->GetBorderColor(helper);
642 }
643 
SetBorderStyle(BorderStyle style,const BorderEdgeHelper & helper)644 void AnimatableProperties::SetBorderStyle(BorderStyle style, const BorderEdgeHelper& helper)
645 {
646     auto renderNode = AceType::DynamicCast<RenderBox>(this);
647     if (renderNode == nullptr) {
648         return;
649     }
650     renderNode->SetBorderStyle(style, helper);
651 }
652 
GetBorderStyle(const BorderEdgeHelper & helper) const653 BorderStyle AnimatableProperties::GetBorderStyle(const BorderEdgeHelper& helper) const
654 {
655     auto renderNode = AceType::DynamicCast<RenderBox>(this);
656     if (renderNode == nullptr) {
657         return BorderStyle::NONE;
658     }
659     return renderNode->GetBorderStyle(helper);
660 }
661 
SetBorderRadius(float value,const BorderRadiusHelper & helper)662 void AnimatableProperties::SetBorderRadius(float value, const BorderRadiusHelper& helper)
663 {
664     auto renderNode = AceType::DynamicCast<RenderBox>(this);
665     if (renderNode == nullptr) {
666         return;
667     }
668     renderNode->SetBorderRadius(value, helper);
669 }
670 
GetBorderRadius(const BorderRadiusHelper & helper) const671 float AnimatableProperties::GetBorderRadius(const BorderRadiusHelper& helper) const
672 {
673     auto renderNode = AceType::DynamicCast<RenderBox>(this);
674     if (renderNode == nullptr) {
675         return 0.0f;
676     }
677     return renderNode->GetBorderRadius(helper);
678 }
679 
SetBlurRadius(const AnimatableDimension & radius)680 void AnimatableProperties::SetBlurRadius(const AnimatableDimension& radius)
681 {
682     auto renderNode = AceType::DynamicCast<RenderBox>(this);
683     if (renderNode == nullptr) {
684         return;
685     }
686     renderNode->SetBlurRadius(radius);
687 }
688 
GetBlurRadius() const689 AnimatableDimension AnimatableProperties::GetBlurRadius() const
690 {
691     auto renderNode = AceType::DynamicCast<RenderBox>(this);
692     if (renderNode == nullptr) {
693         return AnimatableDimension(0.0, DimensionUnit::PX);
694     }
695     return renderNode->GetBlurRadius();
696 }
697 
SetBackdropRadius(const AnimatableDimension & radius)698 void AnimatableProperties::SetBackdropRadius(const AnimatableDimension& radius)
699 {
700     auto renderNode = AceType::DynamicCast<RenderBox>(this);
701     if (renderNode == nullptr) {
702         return;
703     }
704     renderNode->SetBackdropRadius(radius);
705 }
706 
GetBackdropRadius() const707 AnimatableDimension AnimatableProperties::GetBackdropRadius() const
708 {
709     auto renderNode = AceType::DynamicCast<RenderBox>(this);
710     if (renderNode == nullptr) {
711         return AnimatableDimension(0.0, DimensionUnit::PX);
712     }
713     return renderNode->GetBackdropRadius();
714 }
715 
SetWindowBlurProgress(double progress)716 void AnimatableProperties::SetWindowBlurProgress(double progress)
717 {
718     auto renderNode = AceType::DynamicCast<RenderBox>(this);
719     if (renderNode == nullptr) {
720         return;
721     }
722     renderNode->SetWindowBlurProgress(progress);
723 }
724 
GetWindowBlurProgress() const725 double AnimatableProperties::GetWindowBlurProgress() const
726 {
727     auto renderNode = AceType::DynamicCast<RenderBox>(this);
728     if (renderNode == nullptr) {
729         return 0.0f;
730     }
731     return renderNode->GetWindowBlurProgress();
732 }
733 
SetPositionLeft(const Dimension & left)734 void AnimatableProperties::SetPositionLeft(const Dimension& left)
735 {
736     auto renderNode = AceType::DynamicCast<RenderNode>(this);
737     if (renderNode == nullptr) {
738         return;
739     }
740     renderNode->SetLeft(left);
741 }
742 
GetPositionLeft() const743 Dimension AnimatableProperties::GetPositionLeft() const
744 {
745     auto renderNode = AceType::DynamicCast<RenderNode>(this);
746     if (renderNode == nullptr) {
747         return {};
748     }
749     return renderNode->GetLeft();
750 }
751 
SetPositionTop(const Dimension & top)752 void AnimatableProperties::SetPositionTop(const Dimension& top)
753 {
754     auto renderNode = AceType::DynamicCast<RenderNode>(this);
755     if (renderNode == nullptr) {
756         return;
757     }
758     renderNode->SetTop(top);
759 }
760 
GetPositionTop() const761 Dimension AnimatableProperties::GetPositionTop() const
762 {
763     auto renderNode = AceType::DynamicCast<RenderNode>(this);
764     if (renderNode == nullptr) {
765         return {};
766     }
767     return renderNode->GetTop();
768 }
769 
SetPositionRight(const Dimension & right)770 void AnimatableProperties::SetPositionRight(const Dimension& right)
771 {
772     auto renderNode = AceType::DynamicCast<RenderNode>(this);
773     if (renderNode == nullptr) {
774         return;
775     }
776     renderNode->SetRight(right);
777 }
778 
GetPositionRight() const779 Dimension AnimatableProperties::GetPositionRight() const
780 {
781     auto renderNode = AceType::DynamicCast<RenderNode>(this);
782     if (renderNode == nullptr) {
783         return {};
784     }
785     return renderNode->GetRight();
786 }
787 
SetPositionBottom(const Dimension & bottom)788 void AnimatableProperties::SetPositionBottom(const Dimension& bottom)
789 {
790     auto renderNode = AceType::DynamicCast<RenderNode>(this);
791     if (renderNode == nullptr) {
792         return;
793     }
794     renderNode->SetBottom(bottom);
795 }
796 
GetPositionBottom() const797 Dimension AnimatableProperties::GetPositionBottom() const
798 {
799     auto renderNode = AceType::DynamicCast<RenderNode>(this);
800     if (renderNode == nullptr) {
801         return {};
802     }
803     return renderNode->GetBottom();
804 }
805 
806 } // namespace OHOS::Ace
807