1 /* 2 * Copyright (c) 2021 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_RENDER_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_RENDER_COMPONENT_H 18 19 #include "base/geometry/animatable_dimension.h" 20 #include "base/geometry/dimension_rect.h" 21 #include "base/memory/ace_type.h" 22 #include "core/components/common/layout/layout_param.h" 23 #include "core/components/common/layout/position_param.h" 24 #include "core/components/common/properties/motion_path_option.h" 25 #include "core/event/ace_event_handler.h" 26 #include "core/pipeline/base/component.h" 27 28 namespace OHOS::Ace { 29 30 class RenderNode; 31 32 // RenderComponent is visible Component which can create an RenderNode. 33 class RenderComponent : public Component { 34 DECLARE_ACE_TYPE(RenderComponent, Component); 35 36 public: 37 RenderComponent() = default; 38 ~RenderComponent() override = default; 39 IsTakeBoundary()40 bool IsTakeBoundary() const 41 { 42 return takeBoundary_; 43 } 44 SetTakeBoundary(bool takeBoundary)45 void SetTakeBoundary(bool takeBoundary) 46 { 47 takeBoundary_ = takeBoundary; 48 } 49 SetZIndex(int32_t zIndex)50 void SetZIndex(int32_t zIndex) 51 { 52 zIndex_ = zIndex; 53 } 54 GetZIndex()55 int32_t GetZIndex() const 56 { 57 return zIndex_; 58 } 59 SetIsPercentSize(bool isPercentSize)60 void SetIsPercentSize(bool isPercentSize) 61 { 62 isPercentSize_ = isPercentSize; 63 } 64 GetIsPercentSize()65 bool GetIsPercentSize() const 66 { 67 return isPercentSize_; 68 } 69 GetAccessibilityText()70 const std::string& GetAccessibilityText() const 71 { 72 return accessibilityText_; 73 } 74 SetAccessibilityText(const std::string & accessibilityText)75 void SetAccessibilityText(const std::string& accessibilityText) 76 { 77 accessibilityText_ = accessibilityText; 78 } 79 SetLeft(const Dimension & left)80 virtual void SetLeft(const Dimension& left) 81 { 82 positionParam_.left.first = AnimatableDimension(left); 83 positionParam_.left.second = true; 84 } 85 SetLeft(const AnimatableDimension & left)86 virtual void SetLeft(const AnimatableDimension& left) 87 { 88 positionParam_.left.first = left; 89 positionParam_.left.second = true; 90 } 91 SetAnchorX(const Dimension & anchorX)92 void SetAnchorX(const Dimension& anchorX) 93 { 94 positionParam_.anchor.first = anchorX; 95 } 96 SetRight(const Dimension & right)97 virtual void SetRight(const Dimension& right) 98 { 99 positionParam_.right.first = AnimatableDimension(right); 100 positionParam_.right.second = true; 101 } 102 SetRight(const AnimatableDimension & right)103 virtual void SetRight(const AnimatableDimension& right) 104 { 105 positionParam_.right.first = right; 106 positionParam_.right.second = true; 107 } 108 SetAnchorY(const Dimension & anchorY)109 void SetAnchorY(const Dimension& anchorY) 110 { 111 positionParam_.anchor.second = anchorY; 112 } 113 SetTop(const Dimension & top)114 virtual void SetTop(const Dimension& top) 115 { 116 positionParam_.top.first = AnimatableDimension(top); 117 positionParam_.top.second = true; 118 } 119 SetTop(const AnimatableDimension & top)120 virtual void SetTop(const AnimatableDimension& top) 121 { 122 positionParam_.top.first = top; 123 positionParam_.top.second = true; 124 } 125 SetBottom(const Dimension & bottom)126 virtual void SetBottom(const Dimension& bottom) 127 { 128 positionParam_.bottom.first = bottom; 129 positionParam_.bottom.second = true; 130 } 131 SetBottom(const AnimatableDimension & bottom)132 virtual void SetBottom(const AnimatableDimension& bottom) 133 { 134 positionParam_.bottom.first = AnimatableDimension(bottom); 135 positionParam_.bottom.second = true; 136 } 137 SetHasLeft(bool hasLeft)138 void SetHasLeft(bool hasLeft) 139 { 140 positionParam_.left.second = hasLeft; 141 } 142 SetHasRight(bool hasRight)143 void SetHasRight(bool hasRight) 144 { 145 positionParam_.right.second = hasRight; 146 } 147 SetHasTop(bool hasTop)148 void SetHasTop(bool hasTop) 149 { 150 positionParam_.top.second = hasTop; 151 } 152 SetHasBottom(bool hasBottom)153 void SetHasBottom(bool hasBottom) 154 { 155 positionParam_.bottom.second = hasBottom; 156 } 157 GetLeft()158 virtual const Dimension& GetLeft() const 159 { 160 return positionParam_.left.first; 161 } 162 GetRight()163 virtual const Dimension& GetRight() const 164 { 165 return positionParam_.right.first; 166 } 167 GetTop()168 virtual const Dimension& GetTop() const 169 { 170 return positionParam_.top.first; 171 } 172 GetBottom()173 virtual const Dimension& GetBottom() const 174 { 175 return positionParam_.bottom.first; 176 } 177 HasLeft()178 virtual bool HasLeft() const 179 { 180 return positionParam_.left.second; 181 } 182 HasRight()183 virtual bool HasRight() const 184 { 185 return positionParam_.right.second; 186 } 187 HasTop()188 virtual bool HasTop() const 189 { 190 return positionParam_.top.second; 191 } 192 HasBottom()193 virtual bool HasBottom() const 194 { 195 return positionParam_.bottom.second; 196 } 197 GetPositionType()198 PositionType GetPositionType() const 199 { 200 return positionParam_.type; 201 } 202 SetPositionType(PositionType positionType)203 void SetPositionType(PositionType positionType) 204 { 205 positionParam_.type = positionType; 206 } 207 GetPositionParam()208 const PositionParam& GetPositionParam() const 209 { 210 return positionParam_; 211 } 212 GetFlexWeight()213 double GetFlexWeight() const 214 { 215 return flexWeight_; 216 } 217 SetFlexWeight(double flexWeight)218 void SetFlexWeight(double flexWeight) 219 { 220 flexWeight_ = flexWeight; 221 } 222 GetDisplayIndex()223 int32_t GetDisplayIndex() const 224 { 225 return displayIndex_; 226 } 227 SetDisplayIndex(int32_t displayIndex)228 void SetDisplayIndex(int32_t displayIndex) 229 { 230 displayIndex_ = displayIndex; 231 displayIndexSetted_ = true; 232 } 233 GetDisplayIndexSetted()234 bool GetDisplayIndexSetted() const 235 { 236 return displayIndexSetted_; 237 } 238 GetMeasureType()239 MeasureType GetMeasureType() const 240 { 241 return measureType_; 242 } 243 SetMeasureType(MeasureType measureType)244 void SetMeasureType(MeasureType measureType) 245 { 246 measureType_ = measureType; 247 } 248 IsCustomComponent()249 bool IsCustomComponent() const 250 { 251 return isCustomComponent_; 252 } 253 SetIsCustomComponent(bool isCustomComponent)254 void SetIsCustomComponent(bool isCustomComponent) 255 { 256 isCustomComponent_ = isCustomComponent; 257 } 258 GetOnLayoutReadyMarker()259 const EventMarker& GetOnLayoutReadyMarker() const 260 { 261 return onLayoutReady_; 262 } 263 SetOnLayoutReadyMarker(const EventMarker & onLayoutReady)264 void SetOnLayoutReadyMarker(const EventMarker& onLayoutReady) 265 { 266 onLayoutReady_ = onLayoutReady; 267 } 268 IsIgnored()269 bool IsIgnored() const 270 { 271 return isIgnored_; 272 } 273 SetIsIgnored(bool ignore)274 void SetIsIgnored(bool ignore) 275 { 276 isIgnored_ = ignore; 277 } 278 InterceptEvent()279 bool InterceptEvent() const 280 { 281 return interceptEvent_; 282 } 283 SetInterceptEvent(bool interceptEvent)284 void SetInterceptEvent(bool interceptEvent) 285 { 286 interceptEvent_ = interceptEvent; 287 } 288 GetMotionPathOption()289 const MotionPathOption& GetMotionPathOption() const 290 { 291 return motionPathOption_; 292 } 293 SetMotionPathOption(const MotionPathOption & option)294 void SetMotionPathOption(const MotionPathOption& option) 295 { 296 motionPathOption_ = option; 297 } 298 299 virtual RefPtr<RenderNode> CreateRenderNode() = 0; 300 IsResponseRegion()301 bool IsResponseRegion() const 302 { 303 return isResponseRegion_; 304 } 305 MarkResponseRegion(bool isResponseRegion)306 void MarkResponseRegion(bool isResponseRegion) 307 { 308 isResponseRegion_ = isResponseRegion; 309 } 310 GetResponseRegion()311 const std::vector<DimensionRect>& GetResponseRegion() const 312 { 313 return responseRegion_; 314 } 315 SetResponseRegion(const std::vector<DimensionRect> & responseRegion)316 void SetResponseRegion(const std::vector<DimensionRect>& responseRegion) 317 { 318 responseRegion_ = responseRegion; 319 } 320 321 protected: 322 bool takeBoundary_ = true; 323 std::string accessibilityText_; 324 PositionParam positionParam_; 325 double flexWeight_ = 0.0; 326 int32_t displayIndex_ = 1; 327 bool displayIndexSetted_ = false; 328 MeasureType measureType_ = MeasureType::PARENT; 329 EventMarker onLayoutReady_; 330 bool isIgnored_ = false; 331 bool interceptEvent_ = false; 332 333 bool isCustomComponent_ = false; 334 bool isPercentSize_ = false; 335 int32_t zIndex_ = 0; 336 MotionPathOption motionPathOption_; 337 bool isResponseRegion_ = false; 338 std::vector<DimensionRect> responseRegion_; 339 }; 340 341 } // namespace OHOS::Ace 342 343 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_RENDER_COMPONENT_H 344