• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/geometry/dimension.h"
20 #include "base/memory/referenced.h"
21 #include "core/components/container_modal/container_modal_constants.h"
22 #include "core/components_ng/base/frame_node.h"
23 #include "core/components_ng/pattern/container_modal/container_modal_accessibility_property.h"
24 #include "core/components_ng/pattern/custom/custom_title_node.h"
25 #include "core/components_ng/pattern/pattern.h"
26 #include "core/pipeline_ng/pipeline_context.h"
27 
28 namespace OHOS::Ace::NG {
29 class ACE_EXPORT ContainerModalPattern : public Pattern {
30     DECLARE_ACE_TYPE(ContainerModalPattern, Pattern);
31 
32 public:
33     ContainerModalPattern() = default;
34     ~ContainerModalPattern() override = default;
35     void OnColorConfigurationUpdate() override;
CreateAccessibilityProperty()36     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
37     {
38         return MakeRefPtr<ContainerModalAccessibilityProperty>();
39     }
40 
IsMeasureBoundary()41     bool IsMeasureBoundary() const override
42     {
43         return true;
44     }
45 
IsAtomicNode()46     bool IsAtomicNode() const override
47     {
48         return false;
49     }
50 
51     void CallSetContainerWindow(bool considerFloatingWindow);
52 
OnAttachToFrameNode()53     void OnAttachToFrameNode() override
54     {
55         auto pipeline = PipelineContext::GetCurrentContext();
56         CHECK_NULL_VOID(pipeline);
57         auto host = GetHost();
58         CHECK_NULL_VOID(host);
59         pipeline->AddWindowActivateChangedCallback(host->GetId());
60     }
61 
62     void OnWindowActivated() override;
63 
64     void OnWindowDeactivated() override;
65 
66     virtual void OnWindowForceUnfocused();
67 
68     virtual void Init();
69 
70     virtual void ShowTitle(bool isShow, bool hasDeco = true, bool needUpdate = false);
71 
72     void SetAppTitle(const std::string& title);
73 
74     void SetAppIcon(const RefPtr<PixelMap>& icon);
75 
76     virtual void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose);
77 
78     virtual void SetCloseButtonStatus(bool isEnabled);
79 
80     virtual void SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor);
81 
GetIsFocus()82     bool GetIsFocus() const
83     {
84         return 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 
GetCustomButtonNode()155     RefPtr<CustomTitleNode> GetCustomButtonNode()
156     {
157         auto row = GetControlButtonRow();
158         CHECK_NULL_RETURN(row, nullptr);
159         return AceType::DynamicCast<CustomTitleNode>(row->GetChildren().front());
160     }
161     void UpdateRowHeight(const RefPtr<FrameNode>& row, Dimension height);
162     void UpdateGestureRowVisible();
163     void SetContainerModalTitleVisible(bool customTitleSettedShow, bool floatingTitleSettedShow);
164     bool GetContainerModalTitleVisible(bool isImmersive);
165     virtual void SetContainerModalTitleHeight(int32_t height);
166     int32_t GetContainerModalTitleHeight();
167     virtual bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons);
168     void SubscribeContainerModalButtonsRectChange(
169         std::function<void(RectF& containerModal, RectF& buttons)>&& callback);
CallContainerModalNative(const std::string & name,const std::string & value)170     virtual void CallContainerModalNative(const std::string& name, const std::string& value) {};
OnContainerModalEvent(const std::string & name,const std::string & value)171     virtual void OnContainerModalEvent(const std::string& name, const std::string& value) {};
172     void GetWindowPaintRectWithoutMeasureAndLayout(RectInt& rect);
173     void GetWindowPaintRectWithoutMeasureAndLayout(Rect& rect, bool isContainerModal);
174     void CallButtonsRectChange();
175     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>&, const DirtySwapConfig&) override;
176 
177     void OnLanguageConfigurationUpdate() override;
178 
179     void InitColumnTouchTestFunc();
180 
GetIsHoveredMenu()181     bool GetIsHoveredMenu()
182     {
183         return isHoveredMenu_;
184     }
185 
186     Dimension GetCustomTitleHeight();
187 
EnableContainerModalGesture(bool isEnable)188     virtual void EnableContainerModalGesture(bool isEnable) {}
189 
GetFloatingTitleVisible()190     virtual bool GetFloatingTitleVisible()
191     {
192         return false;
193     }
194 
GetCustomTitleVisible()195     virtual bool GetCustomTitleVisible()
196     {
197         return false;
198     }
199 
GetControlButtonVisible()200     virtual bool GetControlButtonVisible()
201     {
202         return false;
203     }
204 
205     void InitAllTitleRowLayoutProperty();
206 
SetEnableContainerModalCustomGesture(bool enable)207     void SetEnableContainerModalCustomGesture(bool enable)
208     {
209         this->enableContainerModalCustomGesture_ = enable;
210     }
211 
212     static void EnableContainerModalCustomGesture(RefPtr<PipelineContext> pipeline, bool enable);
213 
214 protected:
GetTitleItemByIndex(const RefPtr<FrameNode> & controlButtonsNode,int32_t originIndex)215     virtual RefPtr<UINode> GetTitleItemByIndex(const RefPtr<FrameNode>& controlButtonsNode, int32_t originIndex)
216     {
217         return controlButtonsNode->GetChildAtIndex(originIndex);
218     }
219 
220     virtual void AddPanEvent(const RefPtr<FrameNode>& controlButtonsNode);
221 
222     virtual void RemovePanEvent(const RefPtr<FrameNode>& controlButtonsNode);
223 
224     virtual void ChangeFloatingTitle(bool isFocus);
225 
226     virtual void ChangeCustomTitle(bool isFocus);
227 
228     virtual void ChangeControlButtons(bool isFocus);
229 
230     virtual void ChangeTitleButtonIcon(
231         const RefPtr<FrameNode>& buttonNode, InternalResource::ResourceId icon, bool isFocus, bool isCloseBtn);
232 
CanHideFloatingTitle()233     virtual bool CanHideFloatingTitle()
234     {
235         return true;
236     }
237 
238     bool CanShowFloatingTitle();
239     bool CanShowCustomTitle();
240     void TrimFloatingWindowLayout();
241     Color GetContainerColor(bool isFocus);
242 
243     WindowMode windowMode_;
244     bool customTitleSettedShow_ = true;
245     bool floatingTitleSettedShow_ = true;
246     std::function<void(RectF&, RectF&)> controlButtonsRectChangeCallback_;
247     RectF buttonsRect_;
248     bool isInitButtonsRect_ = false;
249     Dimension titleHeight_ = CONTAINER_TITLE_HEIGHT;
250     Color activeColor_;
251     Color inactiveColor_;
252     void InitTitleRowLayoutProperty(RefPtr<FrameNode> titleRow, bool isFloating);
253 protected:
254     void WindowFocus(bool isFocus);
255     void SetTitleButtonHide(
256         const RefPtr<FrameNode>& controlButtonsNode, bool hideSplit, bool hideMaximize, bool hideMinimize,
257             bool hideClose);
258     virtual CalcLength GetControlButtonRowWidth();
259     void InitTitle();
260     void InitContainerEvent();
261     void InitLayoutProperty();
262     void InitContainerColor();
263 
264     virtual void InitButtonsLayoutProperty();
NotifyButtonsRectChange(const RectF & containerModal,const RectF & buttonsRect)265     virtual void NotifyButtonsRectChange(const RectF& containerModal, const RectF& buttonsRect) {}
266 
267     std::string appLabel_;
268     RefPtr<PanEvent> panEvent_ = nullptr;
269 
270     float moveX_ = 0.0f;
271     float moveY_ = 0.0f;
272     bool hasDeco_ = true;
273     bool isFocus_ = false;
274     bool hideSplitButton_ = false;
275     bool isHoveredMenu_ = false;
276     bool isCustomColor_;
277     bool isTitleShow_ = false;
278     bool enableContainerModalCustomGesture_ = false;
279     RRect windowPaintRect_;
280 };
281 } // namespace OHOS::Ace::NG
282 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_H
283