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/layout/position_param.h" 22 #include "core/components/common/properties/clip_path.h" 23 #include "core/components/common/properties/color.h" 24 #include "core/components/common/properties/decoration.h" 25 #include "core/components/common/properties/shadow.h" 26 #include "core/components/common/properties/blend_mode.h" 27 #include "core/components_ng/base/inspector_filter.h" 28 #include "core/components_ng/property/border_property.h" 29 #include "core/components_ng/property/gradient_property.h" 30 #include "core/components_ng/property/overlay_property.h" 31 #include "core/components_ng/property/property.h" 32 #include "core/components_ng/property/transition_property.h" 33 #include "core/image/image_source_info.h" 34 35 namespace OHOS::Ace { 36 enum class BlurStyle; 37 } // namespace OHOS::Ace 38 39 namespace OHOS::Ace::NG { 40 41 struct BackgroundProperty { 42 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImage, ImageSourceInfo); 43 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImageRepeat, ImageRepeat); 44 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImageSize, BackgroundImageSize); 45 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImagePosition, BackgroundImagePosition); 46 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImageResizableSlice, ImageResizableSlice); CheckBlurStyleOptionBackgroundProperty47 bool CheckBlurStyleOption(const std::optional<BlurStyleOption>& option) const 48 { 49 if (!option.has_value()) { 50 return false; 51 } 52 if (!propBlurStyleOption.has_value()) { 53 return false; 54 } 55 return NearEqual(propBlurStyleOption.value(), option.value()); 56 } CheckBlurRadiusChangedBackgroundProperty57 bool CheckBlurRadiusChanged(const Dimension& radius) const 58 { 59 if (!propBlurRadius.has_value()) { 60 return false; 61 } 62 return NearEqual(propBlurRadius.value(), radius); 63 } CheckBlurOptionChangedBackgroundProperty64 bool CheckBlurOptionChanged(const BlurOption& blurOption) const 65 { 66 if (!propBackdropBlurOption.has_value()) { 67 return false; 68 } 69 return NearEqual(propBackdropBlurOption->grayscale[0], blurOption.grayscale[0]) 70 && NearEqual(propBackdropBlurOption->grayscale[1], blurOption.grayscale[1]); 71 } CheckEffectOptionBackgroundProperty72 bool CheckEffectOption(const std::optional<EffectOption>& effectOption) const 73 { 74 if (!effectOption.has_value()) { 75 return false; 76 } 77 if (!propEffectOption.has_value()) { 78 return false; 79 } 80 return NearEqual(propEffectOption.value(), effectOption.value()); 81 } 82 std::optional<BlurStyleOption> propBlurStyleOption; 83 std::optional<Dimension> propBlurRadius; 84 std::optional<EffectOption> propEffectOption; 85 std::optional<BlurOption> propBackdropBlurOption; 86 87 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 88 }; 89 90 struct CustomBackgroundProperty { 91 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundPixelMap, RefPtr<PixelMap>); 92 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundAlign, Alignment); 93 94 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 95 }; 96 97 struct ForegroundProperty { 98 ACE_DEFINE_PROPERTY_GROUP_ITEM(MotionBlur, MotionBlurOption); CheckBlurStyleOptionForegroundProperty99 bool CheckBlurStyleOption(const std::optional<BlurStyleOption>& option) const 100 { 101 if (!option.has_value()) { 102 return false; 103 } 104 if (!propBlurStyleOption.has_value()) { 105 return false; 106 } 107 return NearEqual(propBlurStyleOption.value(), option.value()); 108 } CheckBlurRadiusChangedForegroundProperty109 bool CheckBlurRadiusChanged(const Dimension& radius) const 110 { 111 if (!propBlurRadius.has_value()) { 112 return false; 113 } 114 return NearEqual(propBlurRadius.value(), radius); 115 } 116 std::optional<BlurStyleOption> propBlurStyleOption; 117 std::optional<Dimension> propBlurRadius; 118 ACE_DEFINE_PROPERTY_GROUP_ITEM(ForegroundEffect, float); 119 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 120 }; 121 122 struct BorderImageProperty { 123 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderImage, RefPtr<BorderImage>); 124 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderImageSource, ImageSourceInfo); 125 ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageSlice, bool); 126 ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageWidth, bool); 127 ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageOutset, bool); 128 ACE_DEFINE_PROPERTY_GROUP_ITEM(HasBorderImageRepeat, bool); 129 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderImageGradient, Gradient); 130 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderSourceFromImage, bool); 131 ToJsonValueBorderImageProperty132 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const 133 { 134 static const char* REPEAT_MODE[] = { 135 "RepeatMode.Space", 136 "RepeatMode.Stretch", 137 "RepeatMode.Repeat", 138 "RepeatMode.Round", 139 }; 140 auto jsonBorderImage = JsonUtil::Create(true); 141 jsonBorderImage->Put("source", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())->GetSrc().c_str()); 142 jsonBorderImage->Put( 143 "slice", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())->SliceToString().c_str()); 144 jsonBorderImage->Put( 145 "width", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())->WidthToString().c_str()); 146 jsonBorderImage->Put( 147 "outset", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())->OutsetToString().c_str()); 148 jsonBorderImage->Put("repeat", REPEAT_MODE[static_cast<int>( 149 propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>())->GetRepeatMode())]); 150 jsonBorderImage->Put("fill", propBorderImage.value_or(AceType::MakeRefPtr<BorderImage>()) 151 ->GetNeedFillCenter() ? "true" : "false"); 152 json->PutExtAttr("borderImage", jsonBorderImage->ToString().c_str(), filter); 153 } 154 }; 155 156 struct BorderProperty { 157 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderRadius, BorderRadiusProperty); 158 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderColor, BorderColorProperty); 159 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderStyle, BorderStyleProperty); 160 ACE_DEFINE_PROPERTY_GROUP_ITEM(BorderWidth, BorderWidthProperty); 161 ACE_DEFINE_PROPERTY_GROUP_ITEM(DashGap, BorderWidthProperty); 162 ACE_DEFINE_PROPERTY_GROUP_ITEM(DashWidth, BorderWidthProperty); 163 164 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 165 }; 166 167 struct PointLightProperty { 168 ACE_DEFINE_PROPERTY_GROUP_ITEM(LightPosition, TranslateOptions); 169 ACE_DEFINE_PROPERTY_GROUP_ITEM(LightIntensity, float); 170 ACE_DEFINE_PROPERTY_GROUP_ITEM(LightColor, Color); 171 ACE_DEFINE_PROPERTY_GROUP_ITEM(LightIlluminated, uint32_t); 172 ACE_DEFINE_PROPERTY_GROUP_ITEM(IlluminatedBorderWidth, Dimension); 173 ACE_DEFINE_PROPERTY_GROUP_ITEM(Bloom, float); 174 175 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 176 }; 177 178 struct OuterBorderProperty { 179 ACE_DEFINE_PROPERTY_GROUP_ITEM(OuterBorderRadius, BorderRadiusProperty); 180 ACE_DEFINE_PROPERTY_GROUP_ITEM(OuterBorderColor, BorderColorProperty); 181 ACE_DEFINE_PROPERTY_GROUP_ITEM(OuterBorderStyle, BorderStyleProperty); 182 ACE_DEFINE_PROPERTY_GROUP_ITEM(OuterBorderWidth, BorderWidthProperty); 183 184 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 185 }; 186 187 struct TransformProperty { 188 ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformScale, VectorF); 189 ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformCenter, DimensionOffset); 190 ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformTranslate, TranslateOptions); 191 ACE_DEFINE_PROPERTY_GROUP_ITEM(TransformRotate, Vector5F); 192 193 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 194 }; 195 196 struct GraphicsProperty { 197 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontBrightness, Dimension); 198 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontGrayScale, Dimension); 199 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontContrast, Dimension); 200 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontSaturate, Dimension); 201 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontSepia, Dimension); 202 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontInvert, InvertVariant); 203 ACE_DEFINE_PROPERTY_GROUP_ITEM(SystemBarEffect, bool); 204 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontHueRotate, float); 205 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontColorBlend, Color); 206 ACE_DEFINE_PROPERTY_GROUP_ITEM(FrontBlurRadius, Dimension); 207 ACE_DEFINE_PROPERTY_GROUP_ITEM(LinearGradientBlur, NG::LinearGradientBlurPara); 208 ACE_DEFINE_PROPERTY_GROUP_ITEM(Magnifier, MagnifierParams); 209 ACE_DEFINE_PROPERTY_GROUP_ITEM(DynamicLightUpRate, float); 210 ACE_DEFINE_PROPERTY_GROUP_ITEM(DynamicLightUpDegree, float); 211 ACE_DEFINE_PROPERTY_GROUP_ITEM(BgDynamicBrightnessOption, BrightnessOption); 212 ACE_DEFINE_PROPERTY_GROUP_ITEM(FgDynamicBrightnessOption, BrightnessOption); 213 ACE_DEFINE_PROPERTY_GROUP_ITEM(DynamicDimDegree, float); 214 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackShadow, Shadow); 215 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackBlendMode, BlendMode); 216 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackBlendApplyType, BlendApplyType); 217 218 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 219 }; 220 221 struct RenderPositionProperty { 222 ACE_DEFINE_PROPERTY_GROUP_ITEM(Position, OffsetT<Dimension>); 223 ACE_DEFINE_PROPERTY_GROUP_ITEM(Offset, OffsetT<Dimension>); 224 ACE_DEFINE_PROPERTY_GROUP_ITEM(PositionEdges, EdgesParam); 225 ACE_DEFINE_PROPERTY_GROUP_ITEM(OffsetEdges, EdgesParam); 226 ACE_DEFINE_PROPERTY_GROUP_ITEM(Anchor, OffsetT<Dimension>); 227 228 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 229 }; 230 231 struct ClipProperty { 232 ACE_DEFINE_PROPERTY_GROUP_ITEM(ClipShape, RefPtr<BasicShape>); 233 ACE_DEFINE_PROPERTY_GROUP_ITEM(ClipEdge, bool); 234 ACE_DEFINE_PROPERTY_GROUP_ITEM(ClipMask, RefPtr<BasicShape>); 235 236 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 237 }; 238 239 struct GradientProperty { 240 ACE_DEFINE_PROPERTY_GROUP_ITEM(LinearGradient, NG::Gradient); 241 ACE_DEFINE_PROPERTY_GROUP_ITEM(SweepGradient, NG::Gradient); 242 ACE_DEFINE_PROPERTY_GROUP_ITEM(RadialGradient, NG::Gradient); 243 ACE_DEFINE_PROPERTY_GROUP_ITEM(LastGradientType, NG::GradientType); 244 245 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 246 }; 247 248 struct OverlayProperty { 249 ACE_DEFINE_PROPERTY_GROUP_ITEM(OverlayText, OverlayOptions); 250 ToJsonValueOverlayProperty251 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const 252 { 253 propOverlayText.value_or(OverlayOptions()).ToJsonValue(json, filter); 254 } 255 }; 256 257 struct MotionPathProperty { 258 ACE_DEFINE_PROPERTY_GROUP_ITEM(MotionPath, MotionPathOption); 259 }; 260 261 } // namespace OHOS::Ace::NG 262 263 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_RENDER_PROPERTY_H 264