• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_NG_PAINTS_RENDER_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_RENDER_PROPERTY_H
18 
19 #include "base/geometry/ng/offset_t.h"
20 #include "base/geometry/ng/vector.h"
21 #include "core/components/common/properties/color.h"
22 #include "core/components/common/properties/decoration.h"
23 #include "core/components/common/properties/shadow.h"
24 #include "core/components/common/properties/clip_path.h"
25 #include "core/components_ng/property/border_property.h"
26 #include "core/components_ng/property/overlay_property.h"
27 #include "core/components_ng/property/property.h"
28 #include "core/components_ng/property/gradient_property.h"
29 #include "core/components_ng/property/transition_property.h"
30 #include "core/image/image_source_info.h"
31 
32 namespace OHOS::Ace {
33 enum class BlurStyle;
34 } // namespace OHOS::Ace
35 
36 namespace OHOS::Ace::NG {
37 
38 struct BackgroundProperty {
39     ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImage, ImageSourceInfo);
40     ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImageRepeat, ImageRepeat);
41     ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImageSize, BackgroundImageSize);
42     ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImagePosition, BackgroundImagePosition);
CheckBlurStyleOptionBackgroundProperty43     bool CheckBlurStyleOption(const BlurStyleOption& option) const
44     {
45         if (!propBlurStyleOption.has_value()) {
46             return false;
47         }
48         return NearEqual(propBlurStyleOption.value(), option);
49     }
CheckBlurRadiusBackgroundProperty50     bool CheckBlurRadius(const Dimension& radius) const
51     {
52         if (!propBlurRadius.has_value()) {
53             return false;
54         }
55         return NearEqual(propBlurRadius.value(), radius);
56     }
57     std::optional<BlurStyleOption> propBlurStyleOption;
58     std::optional<Dimension> propBlurRadius;
59     void ToJsonValue(std::unique_ptr<JsonValue>& json) const;
60 };
61 
62 struct BorderImageProperty {
63     ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderImage, RefPtr<BorderImage>);
64     ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderImageSource, ImageSourceInfo);
65     ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageSlice, bool);
66     ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageWidth, bool);
67     ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageOutset, bool);
68     ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageRepeat, bool);
69     ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderImageGradient, Gradient);
70 
ToJsonValueBorderImageProperty71     void ToJsonValue(std::unique_ptr<JsonValue>& json) const
72     {
73         static const char* REPEAT_MODE[] = {
74             "RepeatMode.Space",
75             "RepeatMode.Stretch",
76             "RepeatMode.Repeat",
77             "RepeatMode.Round",
78         };
79         auto jsonBorderImage = JsonUtil::Create(true);
80         jsonBorderImage->Put("source", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())->GetSrc().c_str());
81         jsonBorderImage->Put("slice", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())
82             ->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageSlice().ToString().c_str());
83         jsonBorderImage->Put("width", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())
84             ->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageWidth().ToString().c_str());
85         jsonBorderImage->Put("outset", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())
86             ->GetBorderImageEdge(BorderImageDirection::LEFT).GetBorderImageOutset().ToString().c_str());
87         jsonBorderImage->Put("repeat", REPEAT_MODE[static_cast<int>(
88             propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())->GetRepeatMode())]);
89         jsonBorderImage->Put("fill", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())
90             ->GetNeedFillCenter() ? "true" : "false");
91         json->Put("borderImage", jsonBorderImage->ToString().c_str());
92     }
93 };
94 
95 struct BorderProperty {
96     ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderRadius, BorderRadiusProperty);
97     ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderColor, BorderColorProperty);
98     ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderStyle, BorderStyleProperty);
99     ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderWidth, BorderWidthProperty);
100 
ToJsonValueBorderProperty101     void ToJsonValue(std::unique_ptr<JsonValue>& json) const
102     {
103         static const char* BORDER_STYLE[] = {
104             "BorderStyle.Solid",
105             "BorderStyle.Dashed",
106             "BorderStyle.Dotted",
107         };
108         json->Put("borderStyle",
109             BORDER_STYLE[static_cast<int>(
110                 propBorderStyle.value_or(BorderStyleProperty()).styleLeft.value_or(BorderStyle::SOLID))]);
111         json->Put("borderColor",
112             propBorderColor.value_or(BorderColorProperty()).leftColor.value_or(Color()).ColorToString().c_str());
113         json->Put("borderRadius", propBorderRadius.value_or(BorderRadiusProperty())
114                                       .radiusTopLeft.value_or(Dimension(0.0, DimensionUnit::VP)).ToString().c_str());
115         auto jsonBorder = JsonUtil::Create(true);
116         jsonBorder->Put("width", propBorderWidth.value_or(BorderWidthProperty())
117             .leftDimen.value_or(Dimension(0.0, DimensionUnit::VP)).ToString().c_str());
118         jsonBorder->Put("color",
119             propBorderColor.value_or(BorderColorProperty()).leftColor.value_or(Color()).ColorToString().c_str());
120         jsonBorder->Put("radius", propBorderRadius.value_or(BorderRadiusProperty())
121             .radiusTopLeft.value_or(Dimension(0.0, DimensionUnit::VP)).ToString().c_str());
122         jsonBorder->Put("style",
123             BORDER_STYLE[static_cast<int>(
124                 propBorderStyle.value_or(BorderStyleProperty()).styleLeft.value_or(BorderStyle::SOLID))]);
125         json->Put("border", jsonBorder->ToString().c_str());
126     }
127 };
128 
129 struct TransformProperty {
130     ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformScale, VectorF);
131     ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformCenter, DimensionOffset);
132     ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformTranslate, TranslateOptions);
133     ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformRotate, Vector4F);
134     void ToJsonValue(std::unique_ptr<JsonValue>& json) const;
135 };
136 
137 struct GraphicsProperty {
138     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontBrightness, Dimension);
139     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontGrayScale, Dimension);
140     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontContrast, Dimension);
141     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontSaturate, Dimension);
142     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontSepia, Dimension);
143     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontInvert, Dimension);
144     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontHueRotate, float);
145     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontColorBlend, Color);
146     ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontBlurRadius, Dimension);
147     ACE_DEFINE_PROPERTY_GROUP_ITEM(BlurRadius, Dimension);
148     ACE_DEFINE_PROPERTY_GROUP_ITEM(BackShadow, Shadow);
149     void ToJsonValue(std::unique_ptr<JsonValue>& json) const;
150 };
151 
152 struct RenderPositionProperty {
153     ACE_DEFINE_PROPERTY_GROUP_ITEM(Position, OffsetT<Dimension>);
154     ACE_DEFINE_PROPERTY_GROUP_ITEM(Offset, OffsetT<Dimension>);
155     ACE_DEFINE_PROPERTY_GROUP_ITEM(Anchor, OffsetT<Dimension>);
156     void ToJsonValue(std::unique_ptr<JsonValue>& json) const;
157 };
158 
159 struct ClipProperty {
160     ACE_DEFINE_PROPERTY_GROUP_ITEM(ClipShape, RefPtr<BasicShape>);
161     ACE_DEFINE_PROPERTY_GROUP_ITEM(ClipEdge, bool);
162     ACE_DEFINE_PROPERTY_GROUP_ITEM(ClipMask, RefPtr<BasicShape>);
163     void ToJsonValue(std::unique_ptr<JsonValue>& json) const;
164 };
165 
166 struct GradientProperty {
167     ACE_DEFINE_PROPERTY_GROUP_ITEM(LinearGradient, NG::Gradient);
168     ACE_DEFINE_PROPERTY_GROUP_ITEM(SweepGradient, NG::Gradient);
169     ACE_DEFINE_PROPERTY_GROUP_ITEM(RadialGradient, NG::Gradient);
170     void ToJsonValue(std::unique_ptr<JsonValue>& json) const;
171 };
172 
173 struct OverlayProperty {
174     ACE_DEFINE_PROPERTY_GROUP_ITEM(OverlayText, OverlayOptions);
ToJsonValueOverlayProperty175     void ToJsonValue(std::unique_ptr<JsonValue>& json) const
176     {
177         propOverlayText.value_or(OverlayOptions()).ToJsonValue(json);
178     }
179 };
180 
181 struct MotionPathProperty {
182     ACE_DEFINE_PROPERTY_GROUP_ITEM(MotionPath, MotionPathOption);
183 };
184 
185 } // namespace OHOS::Ace::NG
186 
187 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_RENDER_PROPERTY_H
188