• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H
18 
19 #include <memory>
20 #include <optional>
21 #include <regex>
22 #include <vector>
23 
24 #include "base/geometry/dimension.h"
25 #include "base/geometry/rect.h"
26 #include "base/memory/ace_type.h"
27 #include "base/utils/macros.h"
28 #include "core/components/common/properties/alignment.h"
29 #include "core/components/common/properties/animatable_color.h"
30 #include "core/components/common/properties/border.h"
31 #include "core/components/common/properties/border_image.h"
32 #include "core/components/common/properties/color.h"
33 #include "core/components/common/properties/edge.h"
34 #include "core/components/common/properties/shadow.h"
35 #include "core/pipeline/pipeline_context.h"
36 #include "core/components/theme/theme_utils.h"
37 
38 namespace OHOS::Ace {
39 
40 constexpr double CENTER_OFFSET = 50.0;
41 constexpr double FULL_IMG_SIZE = 100.0;
42 constexpr double BOX_BEGIN_SIZE = 0.0;
43 constexpr double BOX_END_SIZE = 100.0;
44 constexpr double PERCENT_TRANSLATE = 100.0;
45 
46 enum class GradientDirection {
47     LEFT = 0,
48     TOP,
49     RIGHT,
50     BOTTOM,
51     LEFT_TOP,
52     LEFT_BOTTOM,
53     RIGHT_TOP,
54     RIGHT_BOTTOM,
55     NONE,
56     START_TO_END,
57     END_TO_START,
58 };
59 
60 enum class GradientType {
61     LINEAR,
62     RADIAL,
63     SWEEP,
64     CONIC,
65 };
66 
67 enum class RadialSizeType {
68     CLOSEST_SIDE,
69     CLOSEST_CORNER,
70     FARTHEST_SIDE,
71     FARTHEST_CORNER,
72     NONE,
73 };
74 
75 enum class RadialShapeType {
76     CIRCLE,
77     ELLIPSE,
78     NONE,
79 };
80 
81 enum class SpreadMethod {
82     PAD,
83     REFLECT,
84     REPEAT,
85 };
86 
87 enum class BlurStyle {
88     NO_MATERIAL = 0,
89     THIN,
90     REGULAR,
91     THICK,
92     BACKGROUND_THIN,
93     BACKGROUND_REGULAR,
94     BACKGROUND_THICK,
95     BACKGROUND_ULTRA_THICK,
96 };
97 
98 enum class ThemeColorMode {
99     SYSTEM = 0,
100     LIGHT,
101     DARK,
102 };
103 
104 enum class AdaptiveColor {
105     DEFAULT = 0,
106     AVERAGE,
107 };
108 
109 struct BlurStyleOption {
110     BlurStyle blurStyle = BlurStyle::NO_MATERIAL;
111     ThemeColorMode colorMode = ThemeColorMode::SYSTEM;
112     AdaptiveColor adaptiveColor = AdaptiveColor::DEFAULT;
113     bool operator == (const BlurStyleOption& other) const
114     {
115         return blurStyle == other.blurStyle && colorMode == other.colorMode && adaptiveColor == other.adaptiveColor;
116     }
117 };
118 
119 struct LinearGradientInfo {
120     double x1 = 0.0;
121     double x2 = 0.0;
122     double y1 = 0.0;
123     double y2 = 0.0;
124 };
125 
126 struct RadialGradientInfo {
127     double r = 0.0;
128     double cx = 0.0;
129     double cy = 0.0;
130     double fx = 0.0;
131     double fy = 0.0;
132 };
133 
134 class GradientColor final {
135 public:
136     GradientColor() = default;
137     ~GradientColor() = default;
138 
GradientColor(const Color & color)139     explicit GradientColor(const Color& color)
140     {
141         color_ = color;
142     }
143 
144     void SetDimension(double value, DimensionUnit unit = DimensionUnit::PERCENT)
145     {
146         if (value < 0.0) {
147             return;
148         }
149         if (unit == DimensionUnit::PERCENT && value > BOX_END_SIZE) {
150             return;
151         }
152         dimension_ = Dimension(value, unit);
153     }
154 
SetDimension(const Dimension & dimension)155     void SetDimension(const Dimension& dimension)
156     {
157         if (dimension.Value() < 0.0) {
158             return;
159         }
160         if (dimension.Unit() == DimensionUnit::PERCENT && dimension.Value() > BOX_END_SIZE) {
161             return;
162         }
163         dimension_ = dimension;
164     }
165 
SetHasValue(bool hasValue)166     void SetHasValue(bool hasValue)
167     {
168         hasValue_ = hasValue;
169     }
170 
SetColor(const Color & color)171     void SetColor(const Color& color)
172     {
173         color_ = color;
174     }
175 
GetColor()176     const Color& GetColor() const
177     {
178         return color_;
179     }
180 
GetDimension()181     const Dimension& GetDimension() const
182     {
183         return dimension_;
184     }
185 
GetHasValue()186     bool GetHasValue() const
187     {
188         return hasValue_;
189     }
190 
SetOpacity(double opacity)191     void SetOpacity(double opacity)
192     {
193         opacity_ = opacity;
194     }
195 
GetOpacity()196     double GetOpacity() const
197     {
198         return opacity_;
199     }
200 
201 private:
202     bool hasValue_ = true;
203     Color color_ { Color::TRANSPARENT };
204     Dimension dimension_ { BOX_END_SIZE, DimensionUnit::PERCENT };
205     double opacity_ = 1.0;
206 };
207 
208 struct ACE_EXPORT RadialGradient {
209     // size type
210     std::optional<RadialSizeType> radialSizeType;
211     // shape circle or ellipse
212     std::optional<RadialShapeType> radialShape;
213     // size in x-axis
214     std::optional<AnimatableDimension> radialHorizontalSize;
215     // size in y-axis
216     std::optional<AnimatableDimension> radialVerticalSize;
217     // center of shape
218     std::optional<AnimatableDimension> radialCenterX;
219     std::optional<AnimatableDimension> radialCenterY;
220 
221     std::optional<Dimension> fRadialCenterX;
222     std::optional<Dimension> fRadialCenterY;
223 };
224 
225 struct ACE_EXPORT LinearGradient {
226     // direction in x-axis
227     std::optional<GradientDirection> linearX;
228     // direction in y-axis
229     std::optional<GradientDirection> linearY;
230     // angle of gradient line in bearing angle
231     std::optional<AnimatableDimension> angle;
232 
233     std::optional<Dimension> x1;
234     std::optional<Dimension> y1;
235     std::optional<Dimension> x2;
236     std::optional<Dimension> y2;
237 
238     // is direction in x-axis
IsXAxisLinearGradient239     static bool IsXAxis(GradientDirection direction)
240     {
241         return (direction == GradientDirection::LEFT || direction == GradientDirection::RIGHT ||
242                 direction == GradientDirection::START_TO_END || direction == GradientDirection::END_TO_START);
243     }
244 };
245 
246 struct ACE_EXPORT SweepGradient {
247     // center of x-axis
248     std::optional<AnimatableDimension> centerX;
249     // center of y-axis
250     std::optional<AnimatableDimension> centerY;
251     // startAngle in degree
252     std::optional<AnimatableDimension> startAngle;
253     // endAngle in degree
254     std::optional<AnimatableDimension> endAngle;
255     // rotation in degree
256     std::optional<AnimatableDimension> rotation;
257 };
258 
259 class ACE_EXPORT Gradient final {
260 public:
261     void AddColor(const GradientColor& color);
262 
263     void ClearColors();
264 
IsSweepGradientValid()265     bool IsSweepGradientValid() const
266     {
267         if (sweepGradient_.startAngle.has_value() && sweepGradient_.endAngle.has_value()) {
268             return LessOrEqual(sweepGradient_.startAngle.value().Value(),
269                 sweepGradient_.endAngle.value().Value());
270         }
271         if (sweepGradient_.startAngle.has_value() && !sweepGradient_.endAngle.has_value()) {
272             return LessOrEqual(sweepGradient_.startAngle.value().Value(), 0.0);
273         }
274         if (!sweepGradient_.startAngle.has_value() && sweepGradient_.endAngle.has_value()) {
275             return LessOrEqual(0.0, sweepGradient_.endAngle.value().Value());
276         }
277         return true;
278     }
279 
IsValid()280     bool IsValid() const
281     {
282         if (GetType() == GradientType::SWEEP) {
283             return IsSweepGradientValid() && colors_.size() > 1;
284         }
285         return colors_.size() > 1;
286     }
287 
SetRepeat(bool repeat)288     void SetRepeat(bool repeat)
289     {
290         repeat_ = repeat;
291     }
292 
GetRepeat()293     bool GetRepeat() const
294     {
295         return repeat_;
296     }
297 
GetColors()298     const std::vector<GradientColor>& GetColors() const
299     {
300         return colors_;
301     }
302 
GetBeginOffset()303     const Offset& GetBeginOffset() const
304     {
305         return beginOffset_;
306     }
307 
SetBeginOffset(const Offset & beginOffset)308     void SetBeginOffset(const Offset& beginOffset)
309     {
310         beginOffset_ = beginOffset;
311     }
312 
GetEndOffset()313     const Offset& GetEndOffset() const
314     {
315         return endOffset_;
316     }
317 
SetEndOffset(const Offset & endOffset)318     void SetEndOffset(const Offset& endOffset)
319     {
320         endOffset_ = endOffset;
321     }
322 
GetInnerRadius()323     double GetInnerRadius() const
324     {
325         return innerRadius_;
326     }
327 
SetInnerRadius(double innerRadius)328     void SetInnerRadius(double innerRadius)
329     {
330         innerRadius_ = innerRadius;
331     }
332 
GetOuterRadius()333     double GetOuterRadius() const
334     {
335         return outerRadius_;
336     }
337 
SetOuterRadius(double outerRadius)338     void SetOuterRadius(double outerRadius)
339     {
340         outerRadius_ = outerRadius;
341     }
342 
GetType()343     GradientType GetType() const
344     {
345         return type_;
346     }
347 
SetType(GradientType type)348     void SetType(GradientType type)
349     {
350         type_ = type;
351     }
352 
ToString()353     std::string ToString() const
354     {
355         return std::string("Gradient (")
356             .append(beginOffset_.ToString())
357             .append(",")
358             .append(std::to_string(innerRadius_))
359             .append(" --- ")
360             .append(endOffset_.ToString())
361             .append(",")
362             .append(std::to_string(outerRadius_))
363             .append(")");
364     }
365 
GetSweepGradient()366     SweepGradient& GetSweepGradient()
367     {
368         return sweepGradient_;
369     }
370 
GetSweepGradient()371     const SweepGradient& GetSweepGradient() const
372     {
373         return sweepGradient_;
374     }
375 
SetSweepGradient(const SweepGradient & sweepGradient)376     void SetSweepGradient(const SweepGradient& sweepGradient)
377     {
378         sweepGradient_ = sweepGradient;
379     }
380 
GetRadialGradient()381     RadialGradient& GetRadialGradient()
382     {
383         return radialGradient_;
384     }
385 
GetRadialGradient()386     const RadialGradient& GetRadialGradient() const
387     {
388         return radialGradient_;
389     }
390 
SetRadialGradient(const RadialGradient & radialGradient)391     void SetRadialGradient(const RadialGradient& radialGradient)
392     {
393         radialGradient_ = radialGradient;
394     }
395 
GetLinearGradient()396     LinearGradient& GetLinearGradient()
397     {
398         return linearGradient_;
399     }
400 
GetLinearGradient()401     const LinearGradient& GetLinearGradient() const
402     {
403         return linearGradient_;
404     }
405 
SetLinearGradient(const LinearGradient & linearGradient)406     void SetLinearGradient(const LinearGradient& linearGradient)
407     {
408         linearGradient_ = linearGradient;
409     }
410 
SetDirection(const GradientDirection & direction)411     void SetDirection(const GradientDirection& direction)
412     {
413         if (LinearGradient::IsXAxis(direction)) {
414             linearGradient_.linearX = direction;
415         } else {
416             linearGradient_.linearY = direction;
417         }
418     }
419 
SetSpreadMethod(SpreadMethod spreadMethod)420     void SetSpreadMethod(SpreadMethod spreadMethod)
421     {
422         spreadMethod_ = spreadMethod;
423     }
424 
SetGradientTransform(const std::string & gradientTransform)425     void SetGradientTransform(const std::string& gradientTransform)
426     {
427         gradientTransform_ = gradientTransform;
428     }
429 
GetSpreadMethod()430     SpreadMethod GetSpreadMethod() const
431     {
432         return spreadMethod_;
433     }
434 
GetGradientTransform()435     const std::string& GetGradientTransform() const
436     {
437         return gradientTransform_;
438     }
439 
GetRadialGradientInfo()440     const RadialGradientInfo& GetRadialGradientInfo() const
441     {
442         return radialGradientInfo_;
443     }
444 
SetRadialGradientInfo(const RadialGradientInfo & radialGradientInfo)445     void SetRadialGradientInfo(const RadialGradientInfo& radialGradientInfo)
446     {
447         radialGradientInfo_ = radialGradientInfo;
448     }
449 
GetLinearGradientInfo()450     const LinearGradientInfo& GetLinearGradientInfo() const
451     {
452         return linearGradientInfo_;
453     }
454 
SetLinearGradientInfo(const LinearGradientInfo & linearGradientInfo)455     void SetLinearGradientInfo(const LinearGradientInfo& linearGradientInfo)
456     {
457         linearGradientInfo_ = linearGradientInfo;
458     }
459 
460 private:
461     GradientType type_ = GradientType::LINEAR;
462     bool repeat_ = false;
463     std::vector<GradientColor> colors_;
464     // for RadialGradient
465     RadialGradient radialGradient_;
466     // for LinearGradient
467     LinearGradient linearGradient_;
468     // for SweepGradient
469     SweepGradient sweepGradient_;
470     // used for CanvasLinearGradient
471     Offset beginOffset_;
472     Offset endOffset_;
473     // used for CanvasRadialGradient
474     double innerRadius_ = 0.0;
475     double outerRadius_ = 0.0;
476     SpreadMethod spreadMethod_ = SpreadMethod::PAD;
477     std::string gradientTransform_;
478     LinearGradientInfo linearGradientInfo_;
479     RadialGradientInfo radialGradientInfo_;
480 };
481 
482 enum class ACE_EXPORT BackgroundImageSizeType {
483     CONTAIN = 0,
484     COVER,
485     AUTO,
486     LENGTH,
487     PERCENT,
488 };
489 
490 class ACE_EXPORT BackgroundImageSize final {
491 public:
492     BackgroundImageSize() = default;
BackgroundImageSize(BackgroundImageSizeType type,double value)493     BackgroundImageSize(BackgroundImageSizeType type, double value) : typeX_(type), valueX_(value) {}
BackgroundImageSize(BackgroundImageSizeType typeX,double valueX,BackgroundImageSizeType typeY,double valueY)494     BackgroundImageSize(BackgroundImageSizeType typeX, double valueX, BackgroundImageSizeType typeY, double valueY)
495         : typeX_(typeX), valueX_(valueX), typeY_(typeY), valueY_(valueY)
496     {}
497     ~BackgroundImageSize() = default;
498 
499     void SetSizeTypeX(BackgroundImageSizeType type);
500     void SetSizeTypeY(BackgroundImageSizeType type);
501     void SetSizeValueX(double value);
502     void SetSizeValueY(double value);
503     bool IsValid() const;
504     BackgroundImageSizeType GetSizeTypeX() const;
505     BackgroundImageSizeType GetSizeTypeY() const;
506     double GetSizeValueX() const;
507     double GetSizeValueY() const;
508 
509     BackgroundImageSize operator+(const BackgroundImageSize& size) const;
510     BackgroundImageSize operator-(const BackgroundImageSize& size) const;
511     BackgroundImageSize operator*(double value) const;
512 
513     bool operator==(const BackgroundImageSize& size) const;
514     bool operator!=(const BackgroundImageSize& size) const;
515 
516     std::string ToString() const;
517 
518 private:
519     BackgroundImageSizeType typeX_ { BackgroundImageSizeType::AUTO };
520     double valueX_ = 0.0;
521     BackgroundImageSizeType typeY_ { BackgroundImageSizeType::AUTO };
522     double valueY_ = 0.0;
523 };
524 
525 enum class ACE_EXPORT BackgroundImagePositionType {
526     PERCENT = 0,
527     PX,
528 };
529 
530 class ACE_EXPORT BackgroundImagePosition {
531 public:
532     BackgroundImagePosition() = default;
533     ~BackgroundImagePosition() = default;
BackgroundImagePosition(BackgroundImagePositionType typeX,double valueX,BackgroundImagePositionType typeY,double valueY)534     BackgroundImagePosition(
535         BackgroundImagePositionType typeX, double valueX, BackgroundImagePositionType typeY, double valueY)
536         : typeX_(typeX), typeY_(typeY), valueX_(AnimatableDimension(valueX)), valueY_(AnimatableDimension(valueY))
537     {}
538 
SetContextAndCallback(const WeakPtr<PipelineContext> & context,const RenderNodeAnimationCallback & callback)539     void SetContextAndCallback(const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback)
540     {
541         valueX_.SetContextAndCallback(context, callback);
542         valueY_.SetContextAndCallback(context, callback);
543     }
544 
SetSizeTypeX(BackgroundImagePositionType type)545     void SetSizeTypeX(BackgroundImagePositionType type)
546     {
547         typeX_ = type;
548     }
549 
SetSizeX(const AnimatableDimension & sizeX)550     void SetSizeX(const AnimatableDimension& sizeX)
551     {
552         if (sizeX.Unit() == DimensionUnit::PERCENT) {
553             typeX_ = BackgroundImagePositionType::PERCENT;
554         } else {
555             typeX_ = BackgroundImagePositionType::PX;
556         }
557         valueX_ = sizeX;
558     }
559 
SetSizeTypeY(BackgroundImagePositionType type)560     void SetSizeTypeY(BackgroundImagePositionType type)
561     {
562         typeY_ = type;
563     }
564 
SetSizeY(const AnimatableDimension & sizeY)565     void SetSizeY(const AnimatableDimension& sizeY)
566     {
567         if (sizeY.Unit() == DimensionUnit::PERCENT) {
568             typeY_ = BackgroundImagePositionType::PERCENT;
569         } else {
570             typeY_ = BackgroundImagePositionType::PX;
571         }
572         valueY_ = sizeY;
573     }
574 
SetSizeValueX(double value)575     void SetSizeValueX(double value)
576     {
577         valueX_ = AnimatableDimension(value);
578     }
579 
SetSizeValueY(double value)580     void SetSizeValueY(double value)
581     {
582         valueY_ = AnimatableDimension(value);
583     }
584 
GetSizeTypeX()585     BackgroundImagePositionType GetSizeTypeX() const
586     {
587         return typeX_;
588     }
589 
GetSizeTypeY()590     BackgroundImagePositionType GetSizeTypeY() const
591     {
592         return typeY_;
593     }
594 
GetSizeX()595     const AnimatableDimension& GetSizeX() const
596     {
597         return valueX_;
598     }
599 
GetSizeY()600     const AnimatableDimension& GetSizeY() const
601     {
602         return valueY_;
603     }
604 
GetSizeValueX()605     double GetSizeValueX() const
606     {
607         return valueX_.Value();
608     }
609 
GetSizeValueY()610     double GetSizeValueY() const
611     {
612         return valueY_.Value();
613     }
614 
615     BackgroundImagePosition operator+(const BackgroundImagePosition& position) const;
616 
617     BackgroundImagePosition operator-(const BackgroundImagePosition& position) const;
618 
619     BackgroundImagePosition operator*(double value) const;
620 
621     bool operator==(const BackgroundImagePosition& backgroundImagePosition) const;
622 
623     bool operator!=(const BackgroundImagePosition& backgroundImagePosition) const;
624 
625     std::string ToString() const;
626 
627 private:
628     BackgroundImagePositionType typeX_ { BackgroundImagePositionType::PX };
629     BackgroundImagePositionType typeY_ { BackgroundImagePositionType::PX };
630     AnimatableDimension valueX_ = AnimatableDimension(-1.0);
631     AnimatableDimension valueY_ = AnimatableDimension(0.0);
632 };
633 
634 class ImageObjectPosition final : public BackgroundImagePosition {
635 
636 };
637 
638 class BackgroundImage final : public AceType {
639     DECLARE_ACE_TYPE(BackgroundImage, AceType);
640 
641 public:
642     BackgroundImage() = default;
643     ~BackgroundImage() override = default;
644 
GetImageSize()645     const BackgroundImageSize& GetImageSize() const
646     {
647         return imageSize_;
648     }
649 
GetImagePosition()650     const BackgroundImagePosition& GetImagePosition() const
651     {
652         return imagePosition_;
653     }
654 
GetImageRepeat()655     ImageRepeat GetImageRepeat() const
656     {
657         return imageRepeat_;
658     }
659 
GetSrc()660     const std::string& GetSrc() const
661     {
662         return src_;
663     }
664 
SetImageSize(BackgroundImageSize imageSize)665     void SetImageSize(BackgroundImageSize imageSize)
666     {
667         imageSize_ = imageSize;
668     }
669 
670     void SetImageSize(BackgroundImageSizeType type, double value = FULL_IMG_SIZE)
671     {
672         imageSize_ = BackgroundImageSize(type, value);
673     }
674 
SetImageSize(BackgroundImageSizeType typeX,double valueX,BackgroundImageSizeType typeY,double valueY)675     void SetImageSize(BackgroundImageSizeType typeX, double valueX, BackgroundImageSizeType typeY, double valueY)
676     {
677         imageSize_ = BackgroundImageSize(typeX, valueX, typeY, valueY);
678     }
679 
SetImagePosition(const BackgroundImagePosition & imagePosition)680     void SetImagePosition(const BackgroundImagePosition& imagePosition)
681     {
682         imagePosition_ = imagePosition;
683     }
684 
SetImagePosition(BackgroundImagePositionType typeX,double valueX,BackgroundImagePositionType typeY,double valueY)685     void SetImagePosition(
686         BackgroundImagePositionType typeX, double valueX, BackgroundImagePositionType typeY, double valueY)
687     {
688         imagePosition_ = BackgroundImagePosition(typeX, valueX, typeY, valueY);
689     }
690 
SetImageRepeat(const ImageRepeat & imageRepeat)691     void SetImageRepeat(const ImageRepeat& imageRepeat)
692     {
693         imageRepeat_ = imageRepeat;
694     }
695 
SetSrc(const std::string & src,const RefPtr<ThemeConstants> & themeConstants)696     void SetSrc(const std::string& src, const RefPtr<ThemeConstants>& themeConstants)
697     {
698         // If match the regex, src with the outer "url()" removed is returned.
699         // Otherwise return a copy of src directly.
700         auto imgSrc = std::regex_replace(src, std::regex(R"(^url\(\s*['"]?\s*([^()]+?)\s*['"]?\s*\)$)"), "$1");
701         src_ = ThemeUtils::ProcessImageSource(imgSrc, themeConstants);
702     }
703 
704     void SetParsedSrc(const std::string& src)
705     {
706         // src is processed by ParseJsMedia function
707         src_ = src;
708     }
709 
710     bool operator==(const BackgroundImage& image) const
711     {
712         bool fileName = src_ == image.GetSrc();
713         bool size = imageSize_ == image.GetImageSize();
714         bool position = imagePosition_ == image.GetImagePosition();
715         bool repeat = imageRepeat_ == image.GetImageRepeat();
716         return fileName && size && position && repeat;
717     }
718 
719     bool operator!=(const BackgroundImage& image) const
720     {
721         return !operator==(image);
722     }
723 
724 private:
725     std::string src_;
726     BackgroundImageSize imageSize_;
727     BackgroundImagePosition imagePosition_;
728     ImageRepeat imageRepeat_ { ImageRepeat::REPEAT };
729 };
730 
731 class ArcBackground final : public AceType {
732     DECLARE_ACE_TYPE(ArcBackground, AceType);
733 
734 public:
735     ~ArcBackground() override = default;
736     ArcBackground(Point center, double radius)
737     {
738         SetCenter(center);
739         SetRadius(radius);
740     }
741 
742     const Point& GetCenter() const
743     {
744         return center_;
745     }
746 
747     double GetRadius() const
748     {
749         return radius_;
750     }
751 
752     void SetCenter(const Point& center)
753     {
754         center_ = center;
755     }
756 
757     void SetRadius(double radius)
758     {
759         radius_ = radius;
760     }
761 
762     void SetColor(const Color& color)
763     {
764         color_ = color;
765     }
766 
767     const Color& GetColor() const
768     {
769         return color_;
770     }
771 
772 private:
773     Point center_;
774     double radius_ = 0.0;
775     Color color_;
776 };
777 
778 class Decoration final : public AceType {
779     DECLARE_ACE_TYPE(Decoration, AceType);
780 
781 public:
782     Decoration() = default;
783     ~Decoration() override = default;
784 
785     void SetContextAndCallback(
786         const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback);
787 
788     void AddShadow(const Shadow& shadow);
789 
790     void ClearAllShadow();
791 
792     void SetBackgroundColor(const Color& backgroundColor, const AnimationOption& option = AnimationOption())
793     {
794         backgroundColor_ = AnimatableColor(backgroundColor, option);
795     }
796 
797     void SetBackgroundColor(const AnimatableColor& backgroundColor)
798     {
799         backgroundColor_ = backgroundColor;
800     }
801 
802     void SetAnimationColor(const Color& animationColor)
803     {
804         animationColor_ = animationColor;
805     }
806 
807     void SetGradient(
808         const Gradient& gradient, const WeakPtr<PipelineContext>& context = nullptr,
809         const RenderNodeAnimationCallback& callback = nullptr)
810     {
811         gradient_ = gradient;
812         if (callback) {
813             switch (gradient_.GetType()) {
814                 case GradientType::LINEAR:
815                     if (gradient_.GetLinearGradient().angle) {
816                         gradient_.GetLinearGradient().angle->SetContextAndCallbackAfterFirstAssign(context, callback);
817                     }
818                     break;
819                 case GradientType::SWEEP:
820                     if (gradient_.GetSweepGradient().centerX) {
821                         gradient_.GetSweepGradient().centerX->SetContextAndCallbackAfterFirstAssign(
822                             context, callback);
823                     }
824                     if (gradient_.GetSweepGradient().centerY) {
825                         gradient_.GetSweepGradient().centerY->SetContextAndCallbackAfterFirstAssign(context, callback);
826                     }
827                     if (gradient_.GetSweepGradient().startAngle) {
828                         gradient_.GetSweepGradient().startAngle->SetContextAndCallbackAfterFirstAssign(
829                             context, callback);
830                     }
831                     if (gradient_.GetSweepGradient().endAngle) {
832                         gradient_.GetSweepGradient().endAngle->SetContextAndCallbackAfterFirstAssign(context, callback);
833                     }
834                     if (gradient_.GetSweepGradient().rotation) {
835                         gradient_.GetSweepGradient().rotation->SetContextAndCallbackAfterFirstAssign(context, callback);
836                     }
837                     break;
838                 case GradientType::RADIAL:
839                     if (gradient_.GetRadialGradient().radialHorizontalSize) {
840                         gradient_.GetRadialGradient().radialHorizontalSize->SetContextAndCallbackAfterFirstAssign(
841                             context, callback);
842                     }
843                     if (gradient_.GetRadialGradient().radialVerticalSize) {
844                         gradient_.GetRadialGradient().radialVerticalSize->SetContextAndCallbackAfterFirstAssign(
845                             context, callback);
846                     }
847                     if (gradient_.GetRadialGradient().radialCenterX) {
848                         gradient_.GetRadialGradient().radialCenterX->SetContextAndCallbackAfterFirstAssign(
849                             context, callback);
850                     }
851                     if (gradient_.GetRadialGradient().radialCenterY) {
852                         gradient_.GetRadialGradient().radialCenterY->SetContextAndCallbackAfterFirstAssign(
853                             context, callback);
854                     }
855                     break;
856                 default:
857                     break;
858             }
859         }
860     }
861 
862     void SetBorderImageGradient(const Gradient& gradient)
863     {
864         gradientBorderImage_ = gradient;
865     }
866     void SetImage(const RefPtr<BackgroundImage>& image)
867     {
868         image_ = image;
869     }
870 
871     void SetBorderImage(const RefPtr<BorderImage>& borderImage)
872     {
873         borderImage_ = borderImage;
874     }
875 
876     void SetHasBorderImageSource(const bool tag)
877     {
878         hasBorderImageSource_ = tag;
879     }
880 
881     void SetHasBorderImageSlice(const bool tag)
882     {
883         hasBorderImageSlice_ = tag;
884     }
885 
886     void SetHasBorderImageWidth(const bool tag)
887     {
888         hasBorderImageWidth_ = tag;
889     }
890 
891     void SetHasBorderImageOutset(const bool tag)
892     {
893         hasBorderImageOutset_ = tag;
894     }
895 
896     void SetHasBorderImageRepeat(const bool tag)
897     {
898         hasBorderImageRepeat_ = tag;
899     }
900 
901     void SetHasBorderImageGradient(const bool tag)
902     {
903         hasBorderImageGradient_ = tag;
904     }
905 
906     void SetPadding(const Edge& padding)
907     {
908         padding_ = padding;
909     }
910 
911     void SetBorderRadius(const Radius& radius)
912     {
913         border_.SetBorderRadius(radius);
914     }
915 
916     void SetBorder(const Border& border)
917     {
918         border_ = border;
919     }
920 
921     void SetArcBackground(const RefPtr<ArcBackground>& arcBG)
922     {
923         arcBG_ = arcBG;
924     }
925 
926     void SetBlurRadius(const Dimension& radius)
927     {
928         blurRadius_ = radius;
929     }
930 
931     void SetBlurRadius(const AnimatableDimension& radius)
932     {
933         blurRadius_ = radius;
934     }
935 
936     const Color& GetColorBlend(void) const
937     {
938         return colorBlend;
939     }
940 
941     void SetColorBlend(const Color& color)
942     {
943         colorBlend = color;
944     }
945 
946     void SetWindowBlurProgress(float progress)
947     {
948         windowBlurProgress_ = progress;
949     }
950 
951     void SetWindowBlurStyle(WindowBlurStyle style)
952     {
953         windowBlurStyle_ = style;
954     }
955 
956     void SetBlurStyle(const BlurStyleOption& style)
957     {
958         blurStyle_ = style;
959     }
960 
961     const Border& GetBorder() const
962     {
963         return border_;
964     }
965 
966     const Edge& GetPadding() const
967     {
968         return padding_;
969     }
970 
971     const RefPtr<BackgroundImage>& GetImage() const
972     {
973         return image_;
974     }
975 
976     const RefPtr<BorderImage>& GetBorderImage() const
977     {
978         return borderImage_;
979     }
980 
981     const Gradient& GetGradient() const
982     {
983         return gradient_;
984     }
985 
986     const Gradient& GetBorderImageGradient() const
987     {
988         return gradientBorderImage_;
989     }
990 
991     bool GetHasBorderImageSource()
992     {
993         return hasBorderImageSource_;
994     }
995 
996     bool GetHasBorderImageSlice()
997     {
998         return hasBorderImageSlice_;
999     }
1000 
1001     bool GetHasBorderImageWidth()
1002     {
1003         return hasBorderImageWidth_;
1004     }
1005 
1006     bool GetHasBorderImageOutset()
1007     {
1008         return hasBorderImageOutset_;
1009     }
1010 
1011     bool GetHasBorderImageRepeat()
1012     {
1013         return hasBorderImageRepeat_;
1014     }
1015 
1016     bool GetHasBorderImageGradient()
1017     {
1018         return hasBorderImageGradient_;
1019     }
1020 
1021     const AnimatableColor& GetBackgroundColor() const
1022     {
1023         return backgroundColor_;
1024     }
1025 
1026     const Color& GetAnimationColor() const
1027     {
1028         return animationColor_;
1029     }
1030 
1031     const std::vector<Shadow>& GetShadows() const
1032     {
1033         return shadows_;
1034     }
1035 
1036     void SetShadows(const std::vector<Shadow>& shadows)
1037     {
1038         shadows_.assign(shadows.begin(), shadows.end());
1039     }
1040 
1041     const Dimension& GetGrayScale(void) const
1042     {
1043         return grayScale_;
1044     }
1045 
1046     void SetGrayScale(const Dimension& grayScale)
1047     {
1048         grayScale_ = grayScale;
1049     }
1050 
1051     void SetBrightness(const Dimension& brightness)
1052     {
1053         brightness_ = brightness;
1054     }
1055 
1056     const Dimension& GetBrightness() const
1057     {
1058         return brightness_;
1059     }
1060 
1061     const Dimension& GetContrast(void) const
1062     {
1063         return contrast_;
1064     }
1065 
1066     void SetContrast(const Dimension& contrast)
1067     {
1068         contrast_ = contrast;
1069     }
1070 
1071     const Dimension& GetSaturate(void) const
1072     {
1073         return saturate_;
1074     }
1075 
1076     void SetSaturate(const Dimension& saturate)
1077     {
1078         saturate_ = saturate;
1079     }
1080 
1081     const Dimension& GetSepia(void) const
1082     {
1083         return sepia_;
1084     }
1085 
1086     void SetSepia(const Dimension& sepia)
1087     {
1088         sepia_ = sepia;
1089     }
1090 
1091     void SetInvert(const Dimension& invert)
1092     {
1093         invert_ = invert;
1094     }
1095 
1096     const Dimension& GetInvert(void) const
1097     {
1098         return invert_;
1099     }
1100 
1101     float GetHueRotate(void) const
1102     {
1103         return hueRotate_;
1104     }
1105 
1106     void SetHueRotate(const float& hueRotate)
1107     {
1108         hueRotate_ = hueRotate;
1109     }
1110 
1111     const RefPtr<ArcBackground>& GetArcBackground() const
1112     {
1113         return arcBG_;
1114     }
1115 
1116     bool NeedReloadImage(const RefPtr<Decoration>& lastDecoration) const
1117     {
1118         if (!image_) {
1119             return false;
1120         }
1121 
1122         if (!lastDecoration || !(lastDecoration->GetImage())) {
1123             return true;
1124         }
1125 
1126         return (*image_) != (*(lastDecoration->GetImage()));
1127     }
1128 
1129     const AnimatableDimension& GetBlurRadius() const
1130     {
1131         return blurRadius_;
1132     }
1133 
1134     float GetWindowBlurProgress() const
1135     {
1136         return windowBlurProgress_;
1137     }
1138 
1139     WindowBlurStyle GetWindowBlurStyle() const
1140     {
1141         return windowBlurStyle_;
1142     }
1143 
1144     const BlurStyleOption& GetBlurStyle() const
1145     {
1146         return blurStyle_;
1147     }
1148 
1149     // Indicate how much size the decoration taken, excluding the content size.
1150     Size GetOccupiedSize(double dipScale) const;
1151     double HorizontalSpaceOccupied(double dipScale) const;
1152     double VerticalSpaceOccupied(double dipScale) const;
1153 
1154     Offset GetOffset(double dipScale) const;
1155 
1156 private:
1157     bool hasBorderImageSource_ = false;
1158     bool hasBorderImageSlice_ = false;
1159     bool hasBorderImageWidth_ = false;
1160     bool hasBorderImageOutset_ = false;
1161     bool hasBorderImageRepeat_ = false;
1162     bool hasBorderImageGradient_ = false;
1163 
1164     // padding is zero
1165     Edge padding_;
1166     // border contains black color and 1.0f thickness as default
1167     Border border_;
1168     // shadow vector is empty
1169     std::vector<Shadow> shadows_;
1170     Dimension grayScale_;
1171     // Brightness (1.0 as default), range = (0, 2)
1172     Dimension brightness_ = 1.0_px;
1173     // hueRotate
1174     float hueRotate_ = 0.0f;
1175     // Contrast (1.0 as default), complete gray at 0
1176     Dimension contrast_ = 1.0_px;
1177     // Saturate
1178     Dimension saturate_ = 1.0_px;
1179     // Sepia
1180     Dimension sepia_;
1181     // invert
1182     Dimension invert_;
1183     // color is transparent
1184     AnimatableColor backgroundColor_ { Color::TRANSPARENT };
1185     Color animationColor_ = Color::TRANSPARENT;
1186     // Gradient is not implemented
1187     Gradient gradient_ = Gradient();
1188     Gradient gradientBorderImage_ = Gradient();
1189     RefPtr<BackgroundImage> image_;
1190     RefPtr<BorderImage> borderImage_;
1191     RefPtr<ArcBackground> arcBG_;
1192     // Blur radius
1193     AnimatableDimension blurRadius_;
1194     // window blur progress
1195     float windowBlurProgress_ = 0.0f;
1196     // window blur style;
1197     WindowBlurStyle windowBlurStyle_ = WindowBlurStyle::STYLE_BACKGROUND_SMALL_LIGHT;
1198     Color colorBlend;
1199     // blur from rosen
1200     BlurStyleOption blurStyle_;
1201 };
1202 
1203 class Pattern final {
1204 public:
1205     bool IsValid() const
1206     {
1207         return !imgSrc_.empty();
1208     }
1209 
1210     const std::string& GetImgSrc() const
1211     {
1212         return imgSrc_;
1213     }
1214 
1215     void SetImgSrc(const std::string& imgSrc)
1216     {
1217         imgSrc_ = imgSrc;
1218     }
1219 
1220     const std::string& GetRepetition() const
1221     {
1222         return repetition_;
1223     }
1224 
1225     void SetRepetition(const std::string& repetition)
1226     {
1227         repetition_ = repetition;
1228     }
1229 
1230     double GetImageWidth() const
1231     {
1232         return imageWidth_;
1233     }
1234 
1235     void SetImageWidth(double imageWidth)
1236     {
1237         imageWidth_ = imageWidth;
1238     }
1239 
1240     double GetImageHeight() const
1241     {
1242         return imageHeight_;
1243     }
1244 
1245     void SetImageHeight(double imageHeight)
1246     {
1247         imageHeight_ = imageHeight;
1248     }
1249 
1250 private:
1251     double imageWidth_ = 0.0;
1252     double imageHeight_ = 0.0;
1253     std::string imgSrc_;
1254     std::string repetition_;
1255 };
1256 
1257 enum class PathCmd {
1258     CMDS,
1259     TRANSFORM,
1260     MOVE_TO,
1261     LINE_TO,
1262     ARC,
1263     ARC_TO,
1264     QUADRATIC_CURVE_TO,
1265     BEZIER_CURVE_TO,
1266     ELLIPSE,
1267     RECT,
1268     CLOSE_PATH,
1269 };
1270 
1271 struct PathArgs {
1272     std::string cmds;
1273     double para1 = 0.0;
1274     double para2 = 0.0;
1275     double para3 = 0.0;
1276     double para4 = 0.0;
1277     double para5 = 0.0;
1278     double para6 = 0.0;
1279     double para7 = 0.0;
1280     double para8 = 0.0;
1281 };
1282 
1283 class ACE_EXPORT CanvasPath2D : virtual public AceType {
1284     DECLARE_ACE_TYPE(CanvasPath2D, AceType)
1285 public:
1286     CanvasPath2D() = default;
1287     ~CanvasPath2D() = default;
1288     explicit CanvasPath2D(const std::string& cmds);
1289     explicit CanvasPath2D(const RefPtr<CanvasPath2D>& path);
1290     void AddPath(const RefPtr<CanvasPath2D>& path);
1291     void SetTransform(double a, double b, double c, double d, double e, double f);
1292     void MoveTo(double x, double y);
1293     void LineTo(double x, double y);
1294     void Arc(double x, double y, double radius, double startAngle, double endAngle, double ccw);
1295     void ArcTo(double x1, double y1, double x2, double y2, double radius);
1296     void QuadraticCurveTo(double cpx, double cpy, double x, double y);
1297     void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
1298     void Ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle,
1299         double endAngle, double ccw);
1300     void Rect(double x, double y, double width, double height);
1301     void ClosePath();
1302     const std::vector<std::pair<PathCmd, PathArgs>>& GetCaches() const;
1303     std::string ToString() const;
1304 
1305 private:
1306     std::vector<std::pair<PathCmd, PathArgs>> caches_;
1307 };
1308 
1309 } // namespace OHOS::Ace
1310 
1311 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H
1312