• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         bubbleMethod->SetClipPath(clipPath_);
63         bubbleMethod->SetClipFrameNode(clipFrameNode_);
64         bubbleMethod->SetArrowOffsetsFromClip(arrowOffsetsFromClip_);
65         bubbleMethod->SetArrowWidth(arrowWidth_);
66         bubbleMethod->SetArrowHeight(arrowHeight_);
67         return bubbleMethod;
68     }
69 
CreateLayoutProperty()70     RefPtr<LayoutProperty> CreateLayoutProperty() override
71     {
72         auto bubbleProp = AceType::MakeRefPtr<BubbleLayoutProperty>();
73         bubbleProp->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE);
74         return bubbleProp;
75     }
76 
CreateLayoutAlgorithm()77     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
78     {
79         return MakeRefPtr<BubbleLayoutAlgorithm>(targetNodeId_, targetTag_, targetOffset_, targetSize_);
80     }
81 
CreatePaintProperty()82     RefPtr<PaintProperty> CreatePaintProperty() override
83     {
84         return MakeRefPtr<BubbleRenderProperty>();
85     }
86 
CreateEventHub()87     RefPtr<EventHub> CreateEventHub() override
88     {
89         return MakeRefPtr<BubbleEventHub>();
90     }
91 
GetChildOffset()92     OffsetF GetChildOffset()
93     {
94         return childOffset_;
95     }
96 
GetFocusPattern()97     FocusPattern GetFocusPattern() const override
98     {
99         return { FocusType::SCOPE, true };
100     }
101 
102     void OnWindowHide() override;
103     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
104     void StartEnteringAnimation(std::function<void()> finish);
105     void StartExitingAnimation(std::function<void()> finish);
106     bool IsOnShow();
107     bool IsExiting();
108     void OnColorConfigurationUpdate() override;
109 
SetMessageNode(RefPtr<FrameNode> messageNode)110     void SetMessageNode(RefPtr<FrameNode> messageNode)
111     {
112         messageNode_ = messageNode;
113     }
114 
SetCustomPopupTag(bool isCustomPopup)115     void SetCustomPopupTag(bool isCustomPopup)
116     {
117         isCustomPopup_ = isCustomPopup;
118     }
119 
SetTransitionStatus(TransitionStatus transitionStatus)120     void SetTransitionStatus(TransitionStatus transitionStatus)
121     {
122         transitionStatus_ = transitionStatus;
123     }
124 
GetTransitionStatus()125     TransitionStatus GetTransitionStatus() const
126     {
127         return transitionStatus_;
128     }
129 
130 protected:
131     void OnDetachFromFrameNode(FrameNode* frameNode) override;
132 
AvoidKeyboard()133     bool AvoidKeyboard() const override
134     {
135         return false;
136     }
137 private:
138     void OnModifyDone() override;
139     void OnAttachToFrameNode() override;
140     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override;
141 
142     RefPtr<FrameNode> GetButtonRowNode();
143     RefPtr<PopupTheme> GetPopupTheme();
144     void InitTouchEvent();
145     void HandleTouchEvent(const TouchEventInfo& info);
146     void HandleTouchDown(const Offset& clickPosition);
147     void RegisterButtonOnHover();
148     void RegisterButtonOnTouch();
149     void ButtonOnHover(bool isHover, const RefPtr<NG::FrameNode>& buttonNode);
150     void ButtonOnPress(const TouchEventInfo& info, const RefPtr<NG::FrameNode>& buttonNode);
151     void PopBubble();
152     void Animation(
153         RefPtr<RenderContext>& renderContext, const Color& endColor, int32_t duration, const RefPtr<Curve>& curve);
154 
155     OffsetT<Dimension> GetInvisibleOffset();
156     RefPtr<RenderContext> GetRenderContext();
157     void ResetToInvisible();
158     bool PostTask(const TaskExecutor::Task& task);
159     void StartOffsetEnteringAnimation();
160     void StartAlphaEnteringAnimation(std::function<void()> finish);
161     void StartOffsetExitingAnimation();
162     void StartAlphaExitingAnimation(std::function<void()> finish);
163 
164     int32_t targetNodeId_ = -1;
165     std::string targetTag_;
166 
167     RefPtr<TouchEventImpl> touchEvent_;
168     bool mouseEventInitFlag_ = false;
169     bool touchEventInitFlag_ = false;
170     bool isHover_ = false;
171 
172     OffsetF childOffset_;
173     OffsetF arrowPosition_;
174     SizeF childSize_;
175     RectF touchRegion_;
176     std::optional<Placement> arrowPlacement_;
177     std::vector<std::vector<float>> arrowOffsetsFromClip_
178         = { {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f} };
179     float arrowWidth_ = Dimension(16.0_vp).ConvertToPx();
180     float arrowHeight_ = Dimension(8.0_vp).ConvertToPx();
181 
182     bool showArrow_ = false;
183 
184     TransitionStatus transitionStatus_ = TransitionStatus::INVISIABLE;
185 
186     bool delayShow_ = false;
187 
188     std::optional<OffsetF> targetOffset_;
189     std::optional<SizeF> targetSize_;
190 
191     bool isCustomPopup_ = false;
192     RefPtr<FrameNode> messageNode_;
193 
194     std::string clipPath_;
195     RefPtr<FrameNode> clipFrameNode_;
196     ACE_DISALLOW_COPY_AND_MOVE(BubblePattern);
197 };
198 } // namespace OHOS::Ace::NG
199 
200 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUBBLE_BUBBLE_PATTERN_H
201