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_POPUP_POPUP_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_COMPONENT_H 18 19 #include "core/components/common/properties/border.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components/common/properties/edge.h" 22 #include "core/components/common/properties/placement.h" 23 #include "core/pipeline/base/component.h" 24 #include "core/pipeline/base/composed_component.h" 25 #include "core/pipeline/base/sole_child_component.h" 26 27 namespace OHOS::Ace { 28 29 using PopupImpl = std::function<void()>; 30 31 class PopupParam : public AceType { 32 DECLARE_ACE_TYPE(PopupParam, AceType) 33 34 public: 35 PopupParam() = default; 36 ~PopupParam() override = default; 37 SetIsShow(bool isShow)38 void SetIsShow(bool isShow) 39 { 40 isShow_ = isShow; 41 } 42 IsShow()43 bool IsShow() const 44 { 45 return isShow_; 46 } 47 SetHasAction(bool hasAction)48 void SetHasAction(bool hasAction) 49 { 50 hasAction_ = hasAction; 51 } 52 HasAction()53 bool HasAction() const 54 { 55 return hasAction_; 56 } 57 SetPlacement(const Placement placement)58 void SetPlacement(const Placement placement) 59 { 60 placement_ = placement; 61 } 62 SetMaskColor(const Color & maskColor)63 void SetMaskColor(const Color& maskColor) 64 { 65 maskColor_ = maskColor; 66 isMaskColorSetted_ = true; 67 } 68 SetBackgroundColor(const Color & backgroundColor)69 void SetBackgroundColor(const Color& backgroundColor) 70 { 71 backgroundColor_ = backgroundColor; 72 isBackgrouhdColorSetted_ = true; 73 } 74 SetOnVisibilityChange(const EventMarker & onVisibilityChange)75 void SetOnVisibilityChange(const EventMarker& onVisibilityChange) 76 { 77 onVisibilityChange_ = onVisibilityChange; 78 } 79 GetPlacement()80 Placement GetPlacement() const 81 { 82 return placement_; 83 } 84 GetMaskColor()85 const Color& GetMaskColor() const 86 { 87 return maskColor_; 88 } 89 GetBackgroundColor()90 const Color& GetBackgroundColor() const 91 { 92 return backgroundColor_; 93 } 94 GetOnVisibilityChange()95 const EventMarker& GetOnVisibilityChange() const 96 { 97 return onVisibilityChange_; 98 } 99 GetMargin()100 const Edge& GetMargin() const 101 { 102 return margin_; 103 } 104 SetMargin(const Edge & margin)105 void SetMargin(const Edge& margin) 106 { 107 margin_ = margin; 108 } 109 GetTargetMargin()110 const Edge& GetTargetMargin() const 111 { 112 return targetMargin_; 113 } 114 SetTargetMargin(const Edge & targetMargin)115 void SetTargetMargin(const Edge& targetMargin) 116 { 117 targetMargin_ = targetMargin; 118 } 119 GetPadding()120 const Edge& GetPadding() const 121 { 122 return padding_; 123 } 124 SetPadding(const Edge & padding)125 void SetPadding(const Edge& padding) 126 { 127 padding_ = padding; 128 } 129 GetBorder()130 const Border& GetBorder() const 131 { 132 return border_; 133 } 134 SetBorder(const Border & border)135 void SetBorder(const Border& border) 136 { 137 border_ = border; 138 } 139 GetArrowOffset()140 const Dimension& GetArrowOffset() const 141 { 142 return arrowOffset_; 143 } 144 SetArrowOffset(const Dimension & arrowOffset)145 void SetArrowOffset(const Dimension& arrowOffset) 146 { 147 arrowOffset_ = arrowOffset; 148 } 149 GetTargetId()150 const ComposeId& GetTargetId() const 151 { 152 return targetId_; 153 } 154 SetTargetId(const ComposeId & targetId)155 void SetTargetId(const ComposeId& targetId) 156 { 157 targetId_ = targetId; 158 } 159 IsMaskColorSetted()160 bool IsMaskColorSetted() const 161 { 162 return isMaskColorSetted_; 163 } 164 IsBackgroundColorSetted()165 bool IsBackgroundColorSetted() const 166 { 167 return isBackgrouhdColorSetted_; 168 } 169 EnableArrow()170 bool EnableArrow() const 171 { 172 return enableArrow_; 173 } 174 SetEnableArrow(bool enableArrow)175 void SetEnableArrow(bool enableArrow) 176 { 177 enableArrow_ = enableArrow; 178 } 179 IsUseCustom()180 bool IsUseCustom() const 181 { 182 return useCustom_; 183 } 184 SetUseCustomComponent(bool useCustom)185 void SetUseCustomComponent(bool useCustom) 186 { 187 useCustom_ = useCustom; 188 } 189 190 private: 191 bool isShow_ = true; 192 bool hasAction_ = false; 193 bool enableArrow_ = true; 194 bool isMaskColorSetted_ = false; 195 bool isBackgrouhdColorSetted_ = false; 196 bool useCustom_ = false; 197 Color maskColor_; 198 Color backgroundColor_; 199 Placement placement_ = Placement::BOTTOM; 200 EventMarker onVisibilityChange_; 201 Edge padding_; 202 Edge margin_; 203 Edge targetMargin_; 204 Border border_; 205 Dimension arrowOffset_; 206 ComposeId targetId_; 207 }; 208 209 class PopupController : public virtual AceType { 210 DECLARE_ACE_TYPE(PopupController, AceType); 211 212 public: ShowPopup()213 void ShowPopup() 214 { 215 if (showPopupImpl_) { 216 showPopupImpl_(); 217 } 218 } 219 SetShowPopupImpl(const PopupImpl & showPopupImpl)220 void SetShowPopupImpl(const PopupImpl& showPopupImpl) 221 { 222 showPopupImpl_ = showPopupImpl; 223 } 224 CancelPopup()225 void CancelPopup() 226 { 227 if (cancelPopupImpl_) { 228 cancelPopupImpl_(); 229 } 230 } 231 SetCancelPopupImpl(const PopupImpl & cancelPopupImpl)232 void SetCancelPopupImpl(const PopupImpl& cancelPopupImpl) 233 { 234 cancelPopupImpl_ = cancelPopupImpl; 235 } 236 237 private: 238 PopupImpl showPopupImpl_; 239 PopupImpl cancelPopupImpl_; 240 }; 241 242 class PopupComponent : public ComposedComponent { 243 DECLARE_ACE_TYPE(PopupComponent, ComposedComponent); 244 245 public: PopupComponent(const ComposeId & id,const std::string & name,const RefPtr<Component> & child)246 PopupComponent(const ComposeId& id, const std::string& name, const RefPtr<Component>& child) 247 : ComposedComponent(id, name, child) 248 { 249 popupParam_ = MakeRefPtr<PopupParam>(); 250 popupController_ = MakeRefPtr<PopupController>(); 251 }; PopupComponent(const ComposeId & id,const std::string & name)252 PopupComponent(const ComposeId& id, const std::string& name) : ComposedComponent(id, name) 253 { 254 popupParam_ = MakeRefPtr<PopupParam>(); 255 popupController_ = MakeRefPtr<PopupController>(); 256 }; 257 ~PopupComponent() override = default; 258 259 RefPtr<Element> CreateElement() override; 260 GetPopupController()261 const RefPtr<PopupController>& GetPopupController() const 262 { 263 return popupController_; 264 } 265 GetPopupParam()266 const RefPtr<PopupParam>& GetPopupParam() const 267 { 268 return popupParam_; 269 } 270 IsShow()271 bool IsShow() const 272 { 273 if (popupParam_) { 274 return popupParam_->IsShow(); 275 } 276 return true; 277 } 278 279 private: 280 RefPtr<PopupParam> popupParam_; 281 RefPtr<PopupController> popupController_; 282 }; 283 284 } // namespace OHOS::Ace 285 286 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_COMPONENT_H 287