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