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 } 232 GetMeasureType()233 MeasureType GetMeasureType() const 234 { 235 return measureType_; 236 } 237 SetMeasureType(MeasureType measureType)238 void SetMeasureType(MeasureType measureType) 239 { 240 measureType_ = measureType; 241 } 242 IsCustomComponent()243 bool IsCustomComponent() const 244 { 245 return isCustomComponent_; 246 } 247 SetIsCustomComponent(bool isCustomComponent)248 void SetIsCustomComponent(bool isCustomComponent) 249 { 250 isCustomComponent_ = isCustomComponent; 251 } 252 GetOnLayoutReadyMarker()253 const EventMarker& GetOnLayoutReadyMarker() const 254 { 255 return onLayoutReady_; 256 } 257 SetOnLayoutReadyMarker(const EventMarker & onLayoutReady)258 void SetOnLayoutReadyMarker(const EventMarker& onLayoutReady) 259 { 260 onLayoutReady_ = onLayoutReady; 261 } 262 IsIgnored()263 bool IsIgnored() const 264 { 265 return isIgnored_; 266 } 267 SetIsIgnored(bool ignore)268 void SetIsIgnored(bool ignore) 269 { 270 isIgnored_ = ignore; 271 } 272 InterceptEvent()273 bool InterceptEvent() const 274 { 275 return interceptEvent_; 276 } 277 SetInterceptEvent(bool interceptEvent)278 void SetInterceptEvent(bool interceptEvent) 279 { 280 interceptEvent_ = interceptEvent; 281 } 282 GetMotionPathOption()283 const MotionPathOption& GetMotionPathOption() const 284 { 285 return motionPathOption_; 286 } 287 SetMotionPathOption(const MotionPathOption & option)288 void SetMotionPathOption(const MotionPathOption& option) 289 { 290 motionPathOption_ = option; 291 } 292 293 virtual RefPtr<RenderNode> CreateRenderNode() = 0; 294 IsResponseRegion()295 bool IsResponseRegion() const 296 { 297 return isResponseRegion_; 298 } 299 MarkResponseRegion(bool isResponseRegion)300 void MarkResponseRegion(bool isResponseRegion) 301 { 302 isResponseRegion_ = isResponseRegion; 303 } 304 GetResponseRegion()305 const std::vector<DimensionRect>& GetResponseRegion() const 306 { 307 return responseRegion_; 308 } 309 SetResponseRegion(const std::vector<DimensionRect> & responseRegion)310 void SetResponseRegion(const std::vector<DimensionRect>& responseRegion) 311 { 312 responseRegion_ = responseRegion; 313 } 314 315 protected: 316 bool takeBoundary_ = true; 317 std::string accessibilityText_; 318 PositionParam positionParam_; 319 double flexWeight_ = 0.0; 320 int32_t displayIndex_ = 1; 321 MeasureType measureType_ = MeasureType::PARENT; 322 EventMarker onLayoutReady_; 323 bool isIgnored_ = false; 324 bool interceptEvent_ = false; 325 326 bool isCustomComponent_ = false; 327 bool isPercentSize_ = false; 328 int32_t zIndex_ = 0; 329 MotionPathOption motionPathOption_; 330 bool isResponseRegion_ = false; 331 std::vector<DimensionRect> responseRegion_; 332 }; 333 334 } // namespace OHOS::Ace 335 336 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_RENDER_COMPONENT_H 337