• 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_NAVROUTER_NAVDESTINATION_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_PATTERN_H
18 
19 #include "base/memory/referenced.h"
20 #include "base/system_bar/system_bar_style.h"
21 #include "base/utils/utils.h"
22 #include "core/common/autofill/auto_fill_trigger_state_holder.h"
23 #include "core/components_ng/base/ui_node.h"
24 #include "core/components_ng/pattern/navigation/navdestination_pattern_base.h"
25 #include "core/components_ng/pattern/navigation/navigation_event_hub.h"
26 #include "core/components_ng/pattern/navigation/navigation_stack.h"
27 #include "core/components_ng/pattern/navrouter/navdestination_context.h"
28 #include "core/components_ng/pattern/navrouter/navdestination_event_hub.h"
29 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h"
30 #include "core/components_ng/pattern/navigation/navdestination_pattern_base.h"
31 #include "core/components_ng/pattern/navrouter/navdestination_layout_algorithm.h"
32 #include "core/components_ng/pattern/navrouter/navdestination_layout_property.h"
33 #include "core/components_ng/pattern/pattern.h"
34 #include "core/components_ng/syntax/shallow_builder.h"
35 #include "core/components_v2/inspector/inspector_constants.h"
36 
37 namespace OHOS::Ace::NG {
38 
39 class NavDestinationPattern : public NavDestinationPatternBase, public AutoFillTriggerStateHolder {
40     DECLARE_ACE_TYPE(NavDestinationPattern, NavDestinationPatternBase, AutoFillTriggerStateHolder);
41 
42 public:
43     explicit NavDestinationPattern(const RefPtr<ShallowBuilder>& shallowBuilder);
44     NavDestinationPattern();
45     ~NavDestinationPattern() override;
46 
CreateLayoutProperty()47     RefPtr<LayoutProperty> CreateLayoutProperty() override
48     {
49         return MakeRefPtr<NavDestinationLayoutProperty>();
50     }
51 
CreateLayoutAlgorithm()52     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
53     {
54         auto layout = MakeRefPtr<NavDestinationLayoutAlgorithm>();
55         layout->SetIsShown(isOnShow_);
56         return layout;
57     }
58 
CreateEventHub()59     RefPtr<EventHub> CreateEventHub() override
60     {
61         return MakeRefPtr<NavDestinationEventHub>();
62     }
63 
64     void OnActive() override;
65 
66     void OnModifyDone() override;
67 
GetShallowBuilder()68     const RefPtr<ShallowBuilder>& GetShallowBuilder() const
69     {
70         return shallowBuilder_;
71     }
72 
SetName(const std::string & name)73     void SetName(const std::string& name)
74     {
75         name_ = name;
76         auto eventHub = GetEventHub<NavDestinationEventHub>();
77         CHECK_NULL_VOID(eventHub);
78         eventHub->SetName(name);
79     }
80 
GetName()81     const std::string& GetName()
82     {
83         return name_;
84     }
85 
SetNavPathInfo(const RefPtr<NavPathInfo> & pathInfo)86     void SetNavPathInfo(const RefPtr<NavPathInfo>& pathInfo)
87     {
88         if (navDestinationContext_) {
89             navDestinationContext_->SetNavPathInfo(pathInfo);
90         }
91     }
92 
GetNavPathInfo()93     RefPtr<NavPathInfo> GetNavPathInfo() const
94     {
95         return navDestinationContext_ ? navDestinationContext_->GetNavPathInfo() : nullptr;
96     }
97 
SetNavigationStack(const WeakPtr<NavigationStack> & stack)98     void SetNavigationStack(const WeakPtr<NavigationStack>& stack)
99     {
100         if (navDestinationContext_) {
101             navDestinationContext_->SetNavigationStack(stack);
102         }
103     }
104 
GetNavigationStack()105     WeakPtr<NavigationStack> GetNavigationStack() const
106     {
107         return navDestinationContext_ ? navDestinationContext_->GetNavigationStack() : nullptr;
108     }
109 
SetIndex(int32_t index)110     void SetIndex(int32_t index)
111     {
112         if (navDestinationContext_) {
113             navDestinationContext_->SetIndex(index);
114         }
115     }
116 
SetNavDestinationContext(const RefPtr<NavDestinationContext> & context)117     void SetNavDestinationContext(const RefPtr<NavDestinationContext>& context)
118     {
119         navDestinationContext_ = context;
120         if (navDestinationContext_) {
121             navDestinationContext_->SetNavDestinationId(navDestinationId_);
122         }
123     }
124 
GetNavDestinationContext()125     RefPtr<NavDestinationContext> GetNavDestinationContext() const
126     {
127         return navDestinationContext_;
128     }
129 
SetCustomNode(const RefPtr<UINode> & customNode)130     void SetCustomNode(const RefPtr<UINode>& customNode)
131     {
132         customNode_ = customNode;
133     }
134 
GetCustomNode()135     RefPtr<UINode> GetCustomNode()
136     {
137         return customNode_;
138     }
139 
SetIsOnShow(bool isOnShow)140     void SetIsOnShow(bool isOnShow)
141     {
142         isOnShow_ = isOnShow;
143     }
144 
GetIsOnShow()145     bool GetIsOnShow()
146     {
147         return isOnShow_;
148     }
149 
150     bool GetBackButtonState();
151 
GetNavigationNode()152     RefPtr<UINode> GetNavigationNode()
153     {
154         return navigationNode_.Upgrade();
155     }
156 
GetNavDestinationState()157     NavDestinationState GetNavDestinationState() const
158     {
159         auto eventHub = GetEventHub<NavDestinationEventHub>();
160         CHECK_NULL_RETURN(eventHub, NavDestinationState::NONE);
161         auto state = eventHub->GetState();
162         return state;
163     }
164 
165     void DumpInfo() override;
166 
GetNavDestinationId()167     uint64_t GetNavDestinationId() const
168     {
169         return navDestinationId_;
170     }
171 
SetNavigationNode(const RefPtr<UINode> & navigationNode)172     void SetNavigationNode(const RefPtr<UINode>& navigationNode)
173     {
174         navigationNode_ = AceType::WeakClaim(RawPtr(navigationNode));
175     }
176 
OnDetachFromMainTree()177     void OnDetachFromMainTree() override
178     {
179         backupStyle_.reset();
180         currStyle_.reset();
181     }
182 
183     bool OverlayOnBackPressed();
184 
CreateOverlayManager(bool isShow)185     void CreateOverlayManager(bool isShow)
186     {
187         if (!overlayManager_ && isShow) {
188             overlayManager_ = MakeRefPtr<OverlayManager>(GetHost());
189         }
190     }
191 
GetOverlayManager()192     const RefPtr<OverlayManager>& GetOverlayManager()
193     {
194         return overlayManager_;
195     }
196 
DeleteOverlayManager()197     void DeleteOverlayManager()
198     {
199         overlayManager_.Reset();
200     }
201 
202     int32_t GetTitlebarZIndex() const;
203 
SetNavigationId(const std::string & id)204     void SetNavigationId(const std::string& id)
205     {
206         inspectorId_= id;
207     }
208 
GetNavigationId()209     std::string GetNavigationId() const
210     {
211         return inspectorId_;
212     }
213 
SetIsUserDefinedBgColor(bool isUserDefinedBgColor)214     void SetIsUserDefinedBgColor(bool isUserDefinedBgColor)
215     {
216         isUserDefinedBgColor_ = isUserDefinedBgColor;
217     }
218 
IsUserDefinedBgColor()219     bool IsUserDefinedBgColor() const
220     {
221         return isUserDefinedBgColor_;
222     }
223 
224     void OnLanguageConfigurationUpdate() override;
225 
226     bool NeedIgnoreKeyboard();
227 
228     void SetSystemBarStyle(const RefPtr<SystemBarStyle>& style);
GetBackupStyle()229     const std::optional<RefPtr<SystemBarStyle>>& GetBackupStyle() const
230     {
231         return backupStyle_;
232     }
GetCurrentStyle()233     const std::optional<RefPtr<SystemBarStyle>>& GetCurrentStyle() const
234     {
235         return currStyle_;
236     }
237 
238     void OnWindowHide() override;
239 
240 private:
241     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
242     void UpdateNameIfNeeded(RefPtr<NavDestinationGroupNode>& hostNode);
243     void UpdateBackgroundColorIfNeeded(RefPtr<NavDestinationGroupNode>& hostNode);
244     void MountTitleBar(
245         RefPtr<NavDestinationGroupNode>& hostNode, bool& needRunTitleBarAnimation);
246     void OnFontScaleConfigurationUpdate() override;
247     void OnAttachToFrameNode() override;
248     void OnDetachFromFrameNode(FrameNode* frameNode) override;
249 
250     RefPtr<ShallowBuilder> shallowBuilder_;
251     std::string name_;
252     std::string inspectorId_;
253     RefPtr<NavDestinationContext> navDestinationContext_;
254     RefPtr<UINode> customNode_;
255     WeakPtr<UINode> navigationNode_;
256     RefPtr<OverlayManager> overlayManager_;
257     bool isOnShow_ = false;
258     bool isUserDefinedBgColor_ = false;
259     bool isRightToLeft_ = false;
260     uint64_t navDestinationId_ = 0;
261 
262     std::optional<RefPtr<SystemBarStyle>> backupStyle_;
263     std::optional<RefPtr<SystemBarStyle>> currStyle_;
264 };
265 } // namespace OHOS::Ace::NG
266 
267 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_PATTERN_H
268