1 /*
2  * Copyright (c) 2022-2024 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_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_H
18 
19 #include "core/components/container_modal/container_modal_constants.h"
20 #include "core/components_ng/pattern/container_modal/container_modal_accessibility_property.h"
21 #include "core/components_ng/pattern/custom/custom_title_node.h"
22 #include "core/components_ng/pattern/pattern.h"
23 #include "core/pipeline_ng/pipeline_context.h"
24 
25 namespace OHOS::Ace::NG {
26 class ACE_EXPORT ContainerModalPattern : public Pattern {
27     DECLARE_ACE_TYPE(ContainerModalPattern, Pattern);
28 
29 public:
30     ContainerModalPattern() = default;
31     ~ContainerModalPattern() override = default;
32 
33      void OnColorConfigurationUpdate() override;
34 
CreateAccessibilityProperty()35     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
36     {
37         return MakeRefPtr<ContainerModalAccessibilityProperty>();
38     }
39 
IsMeasureBoundary()40     bool IsMeasureBoundary() const override
41     {
42         return true;
43     }
44 
IsAtomicNode()45     bool IsAtomicNode() const override
46     {
47         return false;
48     }
49 
OnAttachToFrameNode()50     void OnAttachToFrameNode() override
51     {
52         auto pipeline = PipelineContext::GetCurrentContext();
53         CHECK_NULL_VOID(pipeline);
54         auto host = GetHost();
55         CHECK_NULL_VOID(host);
56         pipeline->AddWindowFocusChangedCallback(host->GetId());
57     }
58 
59     void OnWindowFocused() override;
60 
61     void OnWindowUnfocused() override;
62 
63     virtual void OnWindowForceUnfocused();
64 
65     void Init();
66 
67     virtual void ShowTitle(bool isShow, bool hasDeco = true, bool needUpdate = false);
68 
69     void SetAppTitle(const std::string& title);
70 
71     void SetAppIcon(const RefPtr<PixelMap>& icon);
72 
73     virtual void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose);
74 
75     void SetCloseButtonStatus(bool isEnabled);
76 
GetIsFocus()77     bool GetIsFocus() const
78     {
79         return isFocus_;
80     }
81 
SetIsFocus(bool isFocus)82     void SetIsFocus(bool isFocus)
83     {
84         isFocus_ = isFocus;
85     }
86 
GetAppLabel()87     std::string GetAppLabel()
88     {
89         return appLabel_;
90     }
91 
GetColumnNode()92     RefPtr<FrameNode> GetColumnNode()
93     {
94         auto host = GetHost();
95         CHECK_NULL_RETURN(host, nullptr);
96         return AceType::DynamicCast<FrameNode>(host->GetChildren().front());
97     }
98 
GetFloatingTitleRow()99     RefPtr<FrameNode> GetFloatingTitleRow()
100     {
101         auto host = GetHost();
102         CHECK_NULL_RETURN(host, nullptr);
103         return AceType::DynamicCast<FrameNode>(host->GetChildAtIndex(1));
104     }
105 
GetControlButtonRow()106     RefPtr<FrameNode> GetControlButtonRow()
107     {
108         auto host = GetHost();
109         CHECK_NULL_RETURN(host, nullptr);
110         return AceType::DynamicCast<FrameNode>(host->GetChildren().back());
111     }
112 
GetCustomTitleRow()113     RefPtr<FrameNode> GetCustomTitleRow()
114     {
115         auto columnNode = GetColumnNode();
116         CHECK_NULL_RETURN(columnNode, nullptr);
117         return AceType::DynamicCast<FrameNode>(columnNode->GetChildren().front());
118     }
119 
GetCustomTitleNode()120     RefPtr<CustomTitleNode> GetCustomTitleNode()
121     {
122         auto row = GetCustomTitleRow();
123         CHECK_NULL_RETURN(row, nullptr);
124         return AceType::DynamicCast<CustomTitleNode>(row->GetChildren().front());
125     }
126 
GetStackNode()127     RefPtr<FrameNode> GetStackNode()
128     {
129         auto columnNode = GetColumnNode();
130         CHECK_NULL_RETURN(columnNode, nullptr);
131         return AceType::DynamicCast<FrameNode>(columnNode->GetChildAtIndex(1));
132     }
133 
GetContentNode()134     RefPtr<FrameNode> GetContentNode()
135     {
136         auto stack = GetStackNode();
137         CHECK_NULL_RETURN(stack, nullptr);
138         return AceType::DynamicCast<FrameNode>(stack->GetChildren().front());
139     }
140 
GetFloatingTitleNode()141     RefPtr<CustomTitleNode> GetFloatingTitleNode()
142     {
143         auto row = GetFloatingTitleRow();
144         CHECK_NULL_RETURN(row, nullptr);
145         return AceType::DynamicCast<CustomTitleNode>(row->GetChildren().front());
146     }
147 
GetGestureRow()148     RefPtr<FrameNode> GetGestureRow()
149     {
150         auto column = GetColumnNode();
151         CHECK_NULL_RETURN(column, nullptr);
152         return AceType::DynamicCast<FrameNode>(column->GetChildAtIndex(2));
153     }
154 
155     void UpdateGestureRowVisible();
156     void SetContainerModalTitleVisible(bool customTitleSettedShow, bool floatingTitleSettedShow);
157     void SetContainerModalTitleHeight(int32_t height);
158     int32_t GetContainerModalTitleHeight();
159     bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons);
160     void SubscribeContainerModalButtonsRectChange(
161         std::function<void(RectF& containerModal, RectF& buttons)>&& callback);
162     void GetWindowPaintRectWithoutMeasureAndLayout(RectInt& rect);
163     void CallButtonsRectChange();
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> &,const DirtySwapConfig &)164     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>&, const DirtySwapConfig&) override
165     {
166         CallButtonsRectChange();
167         return false;
168     }
169 
170     void OnLanguageConfigurationUpdate() override;
171 
172     void InitColumnTouchTestFunc();
173 
SetIsHoveredMenu(bool isHoveredMenu)174     void SetIsHoveredMenu(bool isHoveredMenu)
175     {
176         isHoveredMenu_ = isHoveredMenu;
177     }
178 
GetIsHoveredMenu()179     bool GetIsHoveredMenu()
180     {
181         return isHoveredMenu_;
182     }
183 
184     Dimension GetCustomTitleHeight();
185     Dimension GetStackNodeRadius();
186 
EnableContainerModalGesture(bool isEnable)187     virtual void EnableContainerModalGesture(bool isEnable) {}
188 
GetFloatingTitleVisible()189     virtual bool GetFloatingTitleVisible()
190     {
191         return false;
192     }
193 
GetCustomTitleVisible()194     virtual bool GetCustomTitleVisible()
195     {
196         return false;
197     }
198 
GetControlButtonVisible()199     virtual bool GetControlButtonVisible()
200     {
201         return false;
202     }
203 protected:
GetTitleItemByIndex(const RefPtr<FrameNode> & controlButtonsNode,int32_t originIndex)204     virtual RefPtr<UINode> GetTitleItemByIndex(const RefPtr<FrameNode>& controlButtonsNode, int32_t originIndex)
205     {
206         return controlButtonsNode->GetChildAtIndex(originIndex);
207     }
208 
209     virtual void AddPanEvent(const RefPtr<FrameNode>& controlButtonsNode);
210 
211     virtual void RemovePanEvent(const RefPtr<FrameNode>& controlButtonsNode);
212 
213     virtual void ChangeFloatingTitle(bool isFocus);
214 
215     virtual void ChangeCustomTitle(bool isFocus);
216 
217     virtual void ChangeControlButtons(bool isFocus);
218 
219     virtual void ChangeTitleButtonIcon(
220         const RefPtr<FrameNode>& buttonNode, InternalResource::ResourceId icon, bool isFocus, bool isCloseBtn);
221 
CanHideFloatingTitle()222     virtual bool CanHideFloatingTitle()
223     {
224         return true;
225     }
226 
227     bool CanShowFloatingTitle();
228     bool CanShowCustomTitle();
229     void TrimFloatingWindowLayout();
230 
231     WindowMode windowMode_;
232     bool customTitleSettedShow_ = true;
233     bool floatingTitleSettedShow_ = true;
234     std::function<void(RectF&, RectF&)> controlButtonsRectChangeCallback_;
235     RectF buttonsRect_;
236     Dimension titleHeight_ = CONTAINER_TITLE_HEIGHT;
237     void InitTitleRowLayoutProperty(RefPtr<FrameNode> titleRow);
238 private:
239     void WindowFocus(bool isFocus);
240     void SetTitleButtonHide(
241         const RefPtr<FrameNode>& controlButtonsNode, bool hideSplit, bool hideMaximize, bool hideMinimize,
242             bool hideClose);
243     CalcLength GetControlButtonRowWidth();
244     void InitTitle();
245     void InitContainerEvent();
246     void InitLayoutProperty();
247 
248     void InitButtonsLayoutProperty();
249 
250     std::string appLabel_;
251     RefPtr<PanEvent> panEvent_ = nullptr;
252 
253     float moveX_ = 0.0f;
254     float moveY_ = 0.0f;
255     bool hasDeco_ = true;
256     bool isFocus_ = false;
257     bool hideSplitButton_ = false;
258     bool isHoveredMenu_;
259 };
260 } // namespace OHOS::Ace::NG
261 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_H
262