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_DECLARATION_COMMON_STYLE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_COMMON_STYLE_H 18 19 #include "base/geometry/dimension.h" 20 #include "base/geometry/calc_dimension.h" 21 22 #include "core/animation/animation_pub.h" 23 #include "core/animation/shared_transition_effect.h" 24 #include "core/components/common/properties/border.h" 25 #include "core/components/common/properties/border_image.h" 26 #include "core/components/common/properties/clip_path.h" 27 #include "core/components/common/properties/color.h" 28 #include "core/components/common/properties/decoration.h" 29 #include "core/components/common/properties/radius.h" 30 #include "core/components/common/properties/shadow.h" 31 #include "core/components/common/properties/tween_option.h" 32 #include "core/pipeline/base/constants.h" 33 34 namespace OHOS::Ace { 35 36 enum class StyleTag { 37 COMMON_STYLE = 0, 38 COMMON_SIZE_STYLE, 39 COMMON_MARGIN_STYLE, 40 COMMON_PADDING_STYLE, 41 COMMON_BORDER_STYLE, 42 COMMON_BACKGROUND_STYLE, 43 COMMON_FLEX_STYLE, 44 COMMON_POSITION_STYLE, 45 COMMON_OPACITY_STYLE, 46 COMMON_VISIBILITY_STYLE, 47 COMMON_DISPLAY_STYLE, 48 COMMON_SHADOW_STYLE, 49 COMMON_OVERFLOW_STYLE, 50 COMMON_FILTER_STYLE, 51 COMMON_ANIMATION_STYLE, 52 COMMON_SHARE_TRANSITION_STYLE, 53 COMMON_CARD_TRANSITION_STYLE, 54 COMMON_PAGE_TRANSITION_STYLE, 55 COMMON_CLIP_PATH_STYLE, 56 COMMON_MASK_STYLE, 57 COMMON_IMAGE_STYLE, 58 COMMON_PATTERN_STYLE, 59 SPECIALIZED_STYLE, 60 UNKNOWN, 61 DEFAULT, 62 }; 63 64 struct Style { IsValidStyle65 bool IsValid() const 66 { 67 return tag != StyleTag::UNKNOWN; 68 } 69 IsSharedStyle70 bool IsShared() const 71 { 72 return isShared; 73 } 74 75 bool isShared = true; 76 StyleTag tag = StyleTag::DEFAULT; 77 }; 78 79 struct CommonStyle : Style { 80 std::string alignSelf; 81 bool layoutInBox = false; 82 int32_t zIndex = 0; 83 }; 84 85 struct CommonSizeStyle : Style { 86 CalcDimension width = Dimension(-1.0, DimensionUnit::PX); 87 CalcDimension height = Dimension(-1.0, DimensionUnit::PX); 88 CalcDimension minWidth = Dimension(0.0); 89 CalcDimension minHeight = Dimension(0.0); 90 CalcDimension maxWidth = Dimension(Size::INFINITE_SIZE); 91 CalcDimension maxHeight = Dimension(Size::INFINITE_SIZE); 92 double aspectRatio = 0.0; 93 BoxSizing boxSizing = BoxSizing::BORDER_BOX; 94 }; 95 96 struct CommonMarginStyle : Style { 97 Edge margin; 98 }; 99 100 struct CommonPaddingStyle : Style { 101 Edge padding; 102 }; 103 104 struct CommonBorderStyle : Style { 105 Border border; 106 }; 107 108 struct CommonFlexStyle : Style { 109 double flex = 0.0; 110 double flexGrow = 0.0; 111 double flexShrink = 1.0; 112 Dimension flexBasis = 0.0_px; 113 double flexWeight = 0.0; 114 int32_t displayIndex = 1; 115 }; 116 117 struct CommonPositionStyle : Style { 118 PositionType position { PositionType::PTRELATIVE }; 119 Dimension left; 120 Dimension top; 121 Dimension right; 122 Dimension bottom; 123 }; 124 125 struct CommonBackgroundStyle : Style { 126 Gradient gradient; 127 Gradient gradientBorderImage; 128 Color backgroundColor; 129 std::string backgroundSize; 130 RefPtr<BackgroundImage> backgroundImage; 131 RefPtr<BorderImage> borderImage; 132 ImageRepeat backgroundRepeat; 133 std::string backgroundPosition; 134 }; 135 136 struct CommonShadowStyle : Style { 137 Shadow shadow; 138 }; 139 140 struct CommonClipPathStyle : Style { 141 RefPtr<ClipPath> clipPath; 142 }; 143 144 struct CommonOverflowStyle : Style { 145 Overflow overflow = Overflow::OBSERVABLE; 146 std::pair<bool, Color> scrollBarColor; 147 std::pair<bool, Dimension> scrollBarWidth; 148 EdgeEffect edgeEffect = EdgeEffect::NONE; 149 }; 150 151 struct CommonFilterStyle : Style { 152 Dimension filter; 153 Dimension backdropFilter; 154 Dimension windowFilter; 155 }; 156 157 struct CommonOpacityStyle : Style { 158 double opacity = 1.0; 159 int32_t appearingDuration = 0; 160 }; 161 162 struct CommonVisibilityStyle : Style { 163 VisibilityType visibility { VisibilityType::NO_SETTING }; 164 }; 165 166 struct CommonDisplayStyle : Style { 167 DisplayType display { DisplayType::NO_SETTING }; 168 }; 169 170 struct CommonAnimationStyle : Style { 171 std::string transform; 172 std::string transformOrigin; 173 std::string animationName; 174 int32_t animationDelay = 0; 175 int32_t animationDuration = 0; 176 int32_t iteration = 1; 177 RefPtr<Curve> curve; 178 FillMode fillMode = FillMode::NONE; 179 180 Dimension transformOriginX; 181 Dimension transformOriginY; 182 TweenOption tweenOption; 183 184 AnimationOperation animationOperation = AnimationOperation::PLAY; 185 }; 186 187 struct CommonShareTransitionStyle : Style { 188 std::string transitionName; 189 RefPtr<SharedTransitionEffect> sharedEffect; 190 RefPtr<Curve> curve; 191 192 TweenOption sharedTransitionOption; 193 }; 194 195 struct CommonCardTransitionStyle : Style { 196 TransitionEffect transitionEffect = TransitionEffect::NONE; 197 }; 198 199 struct CommonPageTransitionStyle : Style { 200 TweenOption transitionEnterOption; 201 TweenOption transitionExitOption; 202 int32_t transitionDuration = 0; 203 RefPtr<Curve> curve; 204 }; 205 206 struct CommonMaskStyle : Style { 207 std::string maskImage; 208 std::string maskPosition; 209 std::string maskSize; 210 }; 211 212 struct CommonImageStyle : Style { 213 std::optional<Color> imageFill; 214 }; 215 216 } // namespace OHOS::Ace 217 218 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_COMMON_STYLE_H 219