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