• 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_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 
CreateAccessibilityProperty()33     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
34     {
35         return MakeRefPtr<ContainerModalAccessibilityProperty>();
36     }
37 
IsMeasureBoundary()38     bool IsMeasureBoundary() const override
39     {
40         return true;
41     }
42 
IsAtomicNode()43     bool IsAtomicNode() const override
44     {
45         return false;
46     }
47 
OnAttachToFrameNode()48     void OnAttachToFrameNode() override
49     {
50         auto pipeline = PipelineContext::GetCurrentContext();
51         CHECK_NULL_VOID(pipeline);
52         auto host = GetHost();
53         CHECK_NULL_VOID(host);
54         pipeline->AddWindowFocusChangedCallback(host->GetId());
55     }
56 
57     void OnWindowFocused() override;
58 
59     void OnWindowUnfocused() override;
60 
61     virtual void OnWindowForceUnfocused();
62 
63     void Init();
64 
65     virtual void ShowTitle(bool isShow, bool hasDeco = true, bool needUpdate = false);
66 
67     void SetAppTitle(const std::string& title);
68 
69     void SetAppIcon(const RefPtr<PixelMap>& icon);
70 
71     virtual void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize);
72 
73     void SetCloseButtonStatus(bool isEnabled);
74 
GetIsFocus()75     bool GetIsFocus() const
76     {
77         return isFocus_;
78     }
79 
SetIsFocus(bool isFocus)80     void SetIsFocus(bool isFocus)
81     {
82         isFocus_ = isFocus;
83     }
84 
GetAppLabel()85     std::string GetAppLabel()
86     {
87         return appLabel_;
88     }
89 
GetColumnNode()90     RefPtr<FrameNode> GetColumnNode()
91     {
92         auto host = GetHost();
93         CHECK_NULL_RETURN(host, nullptr);
94         return AceType::DynamicCast<FrameNode>(host->GetChildren().front());
95     }
96 
GetFloatingTitleRow()97     RefPtr<FrameNode> GetFloatingTitleRow()
98     {
99         auto host = GetHost();
100         CHECK_NULL_RETURN(host, nullptr);
101         return AceType::DynamicCast<FrameNode>(host->GetChildAtIndex(1));
102     }
103 
GetControlButtonRow()104     RefPtr<FrameNode> GetControlButtonRow()
105     {
106         auto host = GetHost();
107         CHECK_NULL_RETURN(host, nullptr);
108         return AceType::DynamicCast<FrameNode>(host->GetChildren().back());
109     }
110 
GetCustomTitleRow()111     RefPtr<FrameNode> GetCustomTitleRow()
112     {
113         auto columnNode = GetColumnNode();
114         CHECK_NULL_RETURN(columnNode, nullptr);
115         return AceType::DynamicCast<FrameNode>(columnNode->GetChildren().front());
116     }
117 
GetCustomTitleNode()118     RefPtr<CustomTitleNode> GetCustomTitleNode()
119     {
120         auto row = GetCustomTitleRow();
121         CHECK_NULL_RETURN(row, nullptr);
122         return AceType::DynamicCast<CustomTitleNode>(row->GetChildren().front());
123     }
124 
GetStackNode()125     RefPtr<FrameNode> GetStackNode()
126     {
127         auto columnNode = GetColumnNode();
128         CHECK_NULL_RETURN(columnNode, nullptr);
129         return AceType::DynamicCast<FrameNode>(columnNode->GetChildren().back());
130     }
131 
GetContentNode()132     RefPtr<FrameNode> GetContentNode()
133     {
134         auto stack = GetStackNode();
135         CHECK_NULL_RETURN(stack, nullptr);
136         return AceType::DynamicCast<FrameNode>(stack->GetChildren().front());
137     }
138 
GetFloatingTitleNode()139     RefPtr<CustomTitleNode> GetFloatingTitleNode()
140     {
141         auto row = GetFloatingTitleRow();
142         CHECK_NULL_RETURN(row, nullptr);
143         return AceType::DynamicCast<CustomTitleNode>(row->GetChildren().front());
144     }
145 
146     void SetContainerModalTitleVisible(bool customTitleSettedShow, bool floatingTitleSettedShow);
147     void SetContainerModalTitleHeight(int32_t height);
148     int32_t GetContainerModalTitleHeight();
149     bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons);
150     void SubscribeContainerModalButtonsRectChange(
151         std::function<void(RectF& containerModal, RectF& buttons)>&& callback);
152     void CallButtonsRectChange();
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> &,const DirtySwapConfig &)153     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>&, const DirtySwapConfig&) override
154     {
155         CallButtonsRectChange();
156         return false;
157     }
158 
OnLanguageConfigurationUpdate()159     void OnLanguageConfigurationUpdate() override
160     {
161         InitTitle();
162     }
163 
164 protected:
GetTitleItemByIndex(const RefPtr<FrameNode> & controlButtonsNode,int32_t originIndex)165     virtual RefPtr<UINode> GetTitleItemByIndex(const RefPtr<FrameNode>& controlButtonsNode, int32_t originIndex)
166     {
167         return controlButtonsNode->GetChildAtIndex(originIndex);
168     }
169 
170     virtual void AddOrRemovePanEvent(const RefPtr<FrameNode>& controlButtonsNode);
171 
172     virtual void ChangeFloatingTitle(bool isFocus);
173 
174     virtual void ChangeCustomTitle(bool isFocus);
175 
176     virtual void ChangeControlButtons(bool isFocus);
177 
178     virtual void ChangeTitleButtonIcon(
179         const RefPtr<FrameNode>& buttonNode, InternalResource::ResourceId icon, bool isFocus);
180 
CanHideFloatingTitle()181     virtual bool CanHideFloatingTitle()
182     {
183         return true;
184     }
185 
186     bool CanShowFloatingTitle();
187 
188     WindowMode windowMode_;
189     bool customTitleSettedShow_ = true;
190     bool floatingTitleSettedShow_ = true;
191     std::function<void(RectF&, RectF&)> controlButtonsRectChangeCallback_;
192     RectF buttonsRect_;
193     Dimension titleHeight_ = CONTAINER_TITLE_HEIGHT;
194 
195 private:
196     void WindowFocus(bool isFocus);
197     void SetTitleButtonHide(
198         const RefPtr<FrameNode>& controlButtonsNode, bool hideSplit, bool hideMaximize, bool hideMinimize);
199     CalcLength GetControlButtonRowWidth();
200     void InitTitle();
201     void InitContainerEvent();
202     void InitLayoutProperty();
203     void InitTitleRowLayoutProperty(RefPtr<FrameNode> titleRow);
204 
205     std::string appLabel_;
206     RefPtr<PanEvent> panEvent_ = nullptr;
207 
208     float moveX_ = 0.0f;
209     float moveY_ = 0.0f;
210     bool hasDeco_ = true;
211     bool isFocus_ = false;
212     bool hideSplitButton_ = false;
213 };
214 } // namespace OHOS::Ace::NG
215 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_H
216