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