1 /* 2 * Copyright (c) 2022-2023 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_NG_PATTERNS_BUBBLE_BUBBLE_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUBBLE_BUBBLE_PATTERN_H 18 19 #include <optional> 20 21 #include "base/geometry/ng/offset_t.h" 22 #include "base/geometry/ng/size_t.h" 23 #include "base/memory/referenced.h" 24 #include "core/components/popup/popup_theme.h" 25 #include "core/components_ng/base/frame_node.h" 26 #include "core/components_ng/event/focus_hub.h" 27 #include "core/components_ng/pattern/bubble/bubble_event_hub.h" 28 #include "core/components_ng/pattern/bubble/bubble_layout_algorithm.h" 29 #include "core/components_ng/pattern/bubble/bubble_layout_property.h" 30 #include "core/components_ng/pattern/bubble/bubble_paint_method.h" 31 #include "core/components_ng/pattern/bubble/bubble_render_property.h" 32 #include "core/components_ng/pattern/overlay/popup_base_pattern.h" 33 34 namespace OHOS::Ace::NG { 35 36 enum class TransitionStatus { 37 INVISIABLE, 38 ENTERING, 39 NORMAL, 40 EXITING, 41 }; 42 class BubblePattern : public PopupBasePattern { 43 DECLARE_ACE_TYPE(BubblePattern, PopupBasePattern); 44 45 public: 46 BubblePattern() = default; BubblePattern(int32_t id,const std::string & tag)47 BubblePattern(int32_t id, const std::string& tag) : targetNodeId_(id), targetTag_(tag) {} 48 ~BubblePattern() override = default; 49 IsAtomicNode()50 bool IsAtomicNode() const override 51 { 52 return false; 53 } 54 CreateNodePaintMethod()55 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 56 { 57 auto bubbleMethod = AceType::MakeRefPtr<BubblePaintMethod>(); 58 bubbleMethod->SetArrowPosition(arrowPosition_); 59 bubbleMethod->SetChildOffset(childOffset_); 60 bubbleMethod->SetChildSize(childSize_); 61 bubbleMethod->SetShowArrow(showArrow_); 62 return bubbleMethod; 63 } 64 CreateLayoutProperty()65 RefPtr<LayoutProperty> CreateLayoutProperty() override 66 { 67 auto bubbleProp = AceType::MakeRefPtr<BubbleLayoutProperty>(); 68 bubbleProp->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE); 69 return bubbleProp; 70 } 71 CreateLayoutAlgorithm()72 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 73 { 74 return MakeRefPtr<BubbleLayoutAlgorithm>(targetNodeId_, targetTag_, targetOffset_, targetSize_); 75 } 76 CreatePaintProperty()77 RefPtr<PaintProperty> CreatePaintProperty() override 78 { 79 return MakeRefPtr<BubbleRenderProperty>(); 80 } 81 CreateEventHub()82 RefPtr<EventHub> CreateEventHub() override 83 { 84 return MakeRefPtr<BubbleEventHub>(); 85 } 86 GetChildOffset()87 OffsetF GetChildOffset() 88 { 89 return childOffset_; 90 } 91 GetFocusPattern()92 FocusPattern GetFocusPattern() const override 93 { 94 return { FocusType::SCOPE, true }; 95 } 96 97 void OnWindowHide() override; 98 void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override; 99 void StartEnteringAnimation(std::function<void()> finish); 100 void StartExitingAnimation(std::function<void()> finish); 101 bool IsOnShow(); 102 bool IsExiting(); 103 void OnColorConfigurationUpdate() override; 104 SetMessageNode(RefPtr<FrameNode> messageNode)105 void SetMessageNode(RefPtr<FrameNode> messageNode) 106 { 107 messageNode_ = messageNode; 108 } 109 SetCustomPopupTag(bool isCustomPopup)110 void SetCustomPopupTag(bool isCustomPopup) 111 { 112 isCustomPopup_ = isCustomPopup; 113 } 114 SetTransitionStatus(TransitionStatus transitionStatus)115 void SetTransitionStatus(TransitionStatus transitionStatus) 116 { 117 transitionStatus_ = transitionStatus; 118 } 119 GetTransitionStatus()120 TransitionStatus GetTransitionStatus() 121 { 122 return transitionStatus_; 123 } 124 SetSkipHotArea(bool skip)125 void SetSkipHotArea(bool skip) 126 { 127 skipHotArea_ = skip; 128 } 129 IsSkipHotArea()130 bool IsSkipHotArea() const 131 { 132 return skipHotArea_; 133 } 134 135 protected: 136 void OnDetachFromFrameNode(FrameNode* frameNode) override; 137 138 private: 139 void OnModifyDone() override; 140 void OnAttachToFrameNode() override; 141 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override; 142 143 RefPtr<FrameNode> GetButtonRowNode(); 144 RefPtr<PopupTheme> GetPopupTheme(); 145 void InitTouchEvent(); 146 void HandleTouchEvent(const TouchEventInfo& info); 147 void HandleTouchDown(const Offset& clickPosition); 148 void RegisterButtonOnHover(); 149 void RegisterButtonOnTouch(); 150 void ButtonOnHover(bool isHover, const RefPtr<NG::FrameNode>& buttonNode); 151 void ButtonOnPress(const TouchEventInfo& info, const RefPtr<NG::FrameNode>& buttonNode); 152 void PopBubble(); 153 void Animation( 154 RefPtr<RenderContext>& renderContext, const Color& endColor, int32_t duration, const RefPtr<Curve>& curve); 155 156 OffsetT<Dimension> GetInvisibleOffset(); 157 RefPtr<RenderContext> GetRenderContext(); 158 void ResetToInvisible(); 159 bool PostTask(const TaskExecutor::Task& task); 160 void StartOffsetEnteringAnimation(); 161 void StartAlphaEnteringAnimation(std::function<void()> finish); 162 void StartOffsetExitingAnimation(); 163 void StartAlphaExitingAnimation(std::function<void()> finish); 164 165 int32_t targetNodeId_ = -1; 166 std::string targetTag_; 167 168 RefPtr<TouchEventImpl> touchEvent_; 169 bool mouseEventInitFlag_ = false; 170 bool touchEventInitFlag_ = false; 171 bool isHover_ = false; 172 173 OffsetF childOffset_; 174 OffsetF arrowPosition_; 175 SizeF childSize_; 176 RectF touchRegion_; 177 std::optional<Placement> arrowPlacement_; 178 179 bool showArrow_ = false; 180 181 TransitionStatus transitionStatus_ = TransitionStatus::INVISIABLE; 182 183 bool delayShow_ = false; 184 bool skipHotArea_ = false; 185 186 std::optional<OffsetF> targetOffset_; 187 std::optional<SizeF> targetSize_; 188 189 bool isCustomPopup_ = false; 190 RefPtr<FrameNode> messageNode_; 191 ACE_DISALLOW_COPY_AND_MOVE(BubblePattern); 192 }; 193 } // namespace OHOS::Ace::NG 194 195 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUBBLE_BUBBLE_PATTERN_H 196