• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OHOS_ROSEN_WINDOW_NODE_CONTAINER_H
17 #define OHOS_ROSEN_WINDOW_NODE_CONTAINER_H
18 
19 #include "animation_config.h"
20 #include "avoid_area_controller.h"
21 #include "display_info.h"
22 #include "minimize_app.h"
23 #include "display_group_controller.h"
24 #include "display_group_info.h"
25 #include "window_layout_policy.h"
26 #include "window_manager.h"
27 #include "window_node.h"
28 #include "window_zorder_policy.h"
29 #include "wm_common.h"
30 #include "wm_common_inner.h"
31 #include "window_pair.h"
32 #include "window_root.h"
33 
34 namespace OHOS {
35 namespace Rosen {
36 using WindowNodeOperationFunc = std::function<bool(sptr<WindowNode>)>; // return true indicates to stop traverse
37 class WindowNodeContainer : public RefBase {
38 public:
39     WindowNodeContainer(const sptr<DisplayInfo>& displayInfo, ScreenId displayGroupId);
40     ~WindowNodeContainer();
41     WMError ShowStartingWindow(sptr<WindowNode>& node);
42     WMError AddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode, bool afterAnimation = false);
43     WMError RemoveWindowNode(sptr<WindowNode>& node, bool fromAnimation = false);
44     WMError HandleRemoveWindow(sptr<WindowNode>& node);
45     WMError UpdateWindowNode(sptr<WindowNode>& node, WindowUpdateReason reason);
46     WMError DestroyWindowNode(sptr<WindowNode>& node, std::vector<uint32_t>& windowIds);
47     const std::vector<uint32_t>& Destroy();
48     void AssignZOrder();
49     WMError SetFocusWindow(uint32_t windowId);
50     uint32_t GetFocusWindow() const;
51     WMError SetActiveWindow(uint32_t windowId, bool byRemoved);
52     uint32_t GetActiveWindow() const;
53     void SetDisplayBrightness(float brightness);
54     float GetDisplayBrightness() const;
55     void SetBrightnessWindow(uint32_t windowId);
56     uint32_t GetBrightnessWindow() const;
57     uint32_t ToOverrideBrightness(float brightness);
58     void UpdateBrightness(uint32_t id, bool byRemoved);
59     void HandleKeepScreenOn(const sptr<WindowNode>& node, bool requireLock);
60     AvoidArea GetAvoidAreaByType(const sptr<WindowNode>& node, AvoidAreaType avoidAreaType,
61         const Rect& rect = Rect::EMPTY_RECT) const;
62     WMError MinimizeStructuredAppWindowsExceptSelf(const sptr<WindowNode>& node);
63     void TraverseContainer(std::vector<sptr<WindowNode>>& windowNodes) const;
64     std::unordered_map<WindowType, SystemBarProperty> GetExpectImmersiveProperty(DisplayId id,
65         sptr<WindowNode>& triggerWindow) const;
66     uint32_t GetWindowCountByType(WindowType windowType);
67     uint32_t GetMainFloatingWindowCount();
68     bool IsForbidDockSliceMove(DisplayId displayId) const;
69     bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const;
70     void ExitSplitMode(DisplayId displayId);
71 
72     bool IsVerticalDisplay(DisplayId displayId) const;
73     WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node, sptr<WindowNode>& parentNode);
74     sptr<WindowNode> GetNextFocusableWindow(uint32_t windowId) const;
75     sptr<WindowNode> GetNextRotatableWindow(uint32_t windowId) const;
76     sptr<WindowNode> GetNextActiveWindow(uint32_t windowId) const;
77     void MinimizeAllAppWindows(DisplayId displayId);
78     void MinimizeOldestAppWindow();
79     void MinimizeOldestMainFloatingWindow(uint32_t windowId);
80     WMError ToggleShownStateForAllAppWindows(std::function<bool(uint32_t, WindowMode)> restoreFunc, bool restore);
81     void BackUpAllAppWindows();
82     void RestoreAllAppWindows(std::function<bool(uint32_t, WindowMode)> restoreFunc);
83     bool IsAppWindowsEmpty() const;
84     void SetSurfaceNodeVisible(sptr<WindowNode>& node, int32_t topPriority, bool visible);
85     void SetBelowScreenlockVisible(sptr<WindowNode>& node, bool visible);
86     void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason);
87     void NotifySystemBarTints(std::vector<DisplayId> displayIdVec);
88     WMError MinimizeAppNodeExceptOptions(MinimizeReason reason, const std::vector<uint32_t>& exceptionalIds = {},
89                                          const std::vector<WindowMode>& exceptionalModes = {});
90     WMError SetWindowMode(sptr<WindowNode>& node, WindowMode dstMode);
91     WMError SwitchLayoutPolicy(WindowLayoutMode mode, DisplayId displayId, bool reorder = false);
92     void RaiseSplitRelatedWindowToTop(sptr<WindowNode>& node);
93     Rect GetDisplayGroupRect() const;
94     void TraverseWindowTree(const WindowNodeOperationFunc& func, bool isFromTopToBottom = true) const;
95     void UpdateSizeChangeReason(sptr<WindowNode>& node, WindowSizeChangeReason reason);
96     void DropShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
97 
98     void SetMinimizedByOther(bool isMinimizedByOther);
99     void GetModeChangeHotZones(DisplayId displayId,
100         ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config);
101 
102     // parentDisplayId is the same as displayId in single-display mode
103     bool AddNodeOnRSTree(sptr<WindowNode>& node, DisplayId displayId, DisplayId parentDisplayId,
104         WindowUpdateType type, bool animationPlayed = false);
105     // parentDisplayId is the same as displayId in single-display mode
106     bool RemoveNodeFromRSTree(sptr<WindowNode>& node, DisplayId displayId, DisplayId parentDisplayId,
107         WindowUpdateType type, bool animationPlayed = false);
108     bool AddAppSurfaceNodeOnRSTree(sptr<WindowNode>& node);
109 
110     sptr<WindowLayoutPolicy> GetLayoutPolicy() const;
111     sptr<AvoidAreaController> GetAvoidController() const;
112     sptr<DisplayGroupController> GetDisplayGroupController() const;
113     sptr<WindowNode> GetRootNode(WindowRootNodeType type) const;
114     void NotifyDockWindowStateChanged(sptr<WindowNode>& node, bool isEnable);
115     void NotifyDockWindowStateChanged(DisplayId displayId);
116     void UpdateCameraFloatWindowStatus(const sptr<WindowNode>& node, bool isShowing);
117     void UpdateAvoidAreaListener(sptr<WindowNode>& windowNode, bool haveAvoidAreaListener);
118     void BeforeProcessWindowAvoidAreaChangeWhenDisplayChange() const;
119     void ProcessWindowAvoidAreaChangeWhenDisplayChange() const;
120     WindowLayoutMode GetCurrentLayoutMode() const;
121     void RemoveSingleUserWindowNodes(int accountId);
122     WMError IsTileRectSatisfiedWithSizeLimits(sptr<WindowNode>& node);
123     bool HasPrivateWindow();
124     sptr<WindowNode> GetDeskTopWindow();
125     static AnimationConfig& GetAnimationConfigRef();
126     bool TakeWindowPairSnapshot(DisplayId displayId);
127     void ClearWindowPairSnapshot(DisplayId displayId);
128     bool IsScreenLocked();
129     void LayoutWhenAddWindowNode(sptr<WindowNode>& node, bool afterAnimation = false);
130     void UpdatePrivateStateAndNotify();
131     static void SetConfigMainFloatingWindowAbove(bool isAbove);
132     static void SetMaxMainFloatingWindowNumber(uint32_t maxNumber);
133     void SetDisplayOrientationFromWindow(sptr<WindowNode>& node, bool withAnimation);
134     bool HasMainFullScreenWindowShown();
135     static bool GetAnimateTransactionEnabled();
136     void SetWindowPairFrameGravity(DisplayId displayId, Gravity gravity);
137     static WindowUIType windowUIType_;
138 
139 private:
140     friend class WindowRoot;
141     void TraverseWindowNode(sptr<WindowNode>& root, std::vector<sptr<WindowNode>>& windowNodes) const;
142     sptr<WindowNode> FindRoot(WindowType type) const;
143     sptr<WindowNode> FindWindowNodeById(uint32_t id) const;
144     void UpdateFocusStatus(uint32_t id, bool focused);
145     void UpdateActiveStatus(uint32_t id, bool isActive);
146     void NotifyIfAvoidAreaChanged(const sptr<WindowNode>& node, const AvoidControlType avoidType) const;
147     void NotifyIfSystemBarTintChanged(DisplayId displayId) const;
148     void NotifyIfSystemBarRegionChanged(DisplayId displayId) const;
149     void NotifyIfKeyboardRegionChanged(const sptr<WindowNode>& node, const AvoidControlType avoidType) const;
150     void TraverseAndUpdateWindowState(WindowState state, int32_t topPriority);
151     void UpdateWindowTree(sptr<WindowNode>& node);
152     void UpdateWindowState(sptr<WindowNode> node, int32_t topPriority, WindowState state);
153     void HandleKeepScreenOn(const sptr<WindowNode>& node, WindowState state);
154     bool IsTopWindow(uint32_t windowId, sptr<WindowNode>& rootNode) const;
155     sptr<WindowNode> FindDividerNode() const;
156     void RaiseWindowToTop(uint32_t windowId, std::vector<sptr<WindowNode>>& windowNodes);
157     bool IsAboveSystemBarNode(sptr<WindowNode> node) const;
158     bool IsSplitImmersiveNode(sptr<WindowNode> node) const;
159     bool TraverseFromTopToBottom(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const;
160     bool TraverseFromBottomToTop(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const;
161     void RaiseOrderedWindowToTop(std::vector<sptr<WindowNode>>& orderedNodes,
162         std::vector<sptr<WindowNode>>& windowNodes);
163     void DumpScreenWindowTree();
164     void DumpScreenWindowTreeByWinId(uint32_t winid);
165     void RaiseInputMethodWindowPriorityIfNeeded(const sptr<WindowNode>& node) const;
166     void ReZOrderShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
167     void RaiseShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
168     void ReZOrderShowWhenLockedWindows(bool up);
169 
170     WMError AddWindowNodeOnWindowTree(sptr<WindowNode>& node, const sptr<WindowNode>& parentNode);
171     void RemoveWindowNodeFromWindowTree(sptr<WindowNode>& node);
172     void UpdateRSTreeWhenShowingDisplaysChange(sptr<WindowNode>& node,
173         const std::vector<DisplayId>& lastShowingDisplays);
174     bool CheckWindowNodeWhetherInWindowTree(const sptr<WindowNode>& node) const;
175     void UpdateWindowModeSupportTypeWhenKeyguardChange(const sptr<WindowNode>& node, bool up);
176     void RemoveFromRsTreeWhenRemoveWindowNode(sptr<WindowNode>& node, bool fromAnimation);
177     void UpdateSizeChangeReason(sptr<WindowNode>& node, WindowMode srcMode, WindowMode dstMode);
178     void UpdatePrivateWindowCount();
179     uint32_t GetAppWindowNum();
180     void ResetMainFloatingWindowPriorityIfNeeded(sptr<WindowNode>& node);
181     void ResetWindowZOrderPriorityWhenSetMode(sptr<WindowNode>& node,
182         const WindowMode& dstMode, const WindowMode& srcMode);
183     void ResetAllMainFloatingWindowZOrder(sptr<WindowNode>& rootNode);
184     void HandleRemoveWindowDisplayOrientation(sptr<WindowNode>& node, bool fromAnimation);
185     void OpenInputMethodSyncTransaction();
186     void CloseInputMethodSyncTransaction();
187 
188     void JudgeToReportSystemBarInfo(const sptr<WindowNode> window,
189         const std::unordered_map<WindowType, SystemBarProperty>& systemBarPropInfo) const;
190 
191     bool IsWindowFollowParent(WindowType type);
192 
193     float displayBrightness_ = UNDEFINED_BRIGHTNESS;
194     uint32_t brightnessWindow_ = INVALID_WINDOW_ID;
195     uint32_t zOrder_ { 0 };
196     uint32_t focusedWindow_ { INVALID_WINDOW_ID };
197     int32_t focusedPid_ = -1;
198     uint32_t activeWindow_ = INVALID_WINDOW_ID;
199     int32_t activePid_ = -1;
200     bool isScreenLocked_ = false;
201     uint32_t privateWindowCount_ = 0;
202 
203     std::vector<uint32_t> backupWindowIds_;
204     std::map<uint32_t, WindowMode> backupWindowMode_;
205     std::map<DisplayId, Rect> backupDividerWindowRect_;
206     std::map<DisplayId, std::set<WindowMode>> backupDisplaySplitWindowMode_;
207 
208     sptr<WindowZorderPolicy> zorderPolicy_ = new WindowZorderPolicy();
209     std::unordered_map<WindowLayoutMode, sptr<WindowLayoutPolicy>> layoutPolicies_;
210     WindowLayoutMode layoutMode_ = WindowLayoutMode::CASCADE;
211     std::vector<Rect> currentCoveredArea_;
212     std::vector<uint32_t> removedIds_;
213     static AnimationConfig animationConfig_;
214 
215     sptr<WindowNode> belowAppWindowNode_ = new WindowNode();
216     sptr<WindowNode> appWindowNode_ = new WindowNode();
217     sptr<WindowNode> aboveAppWindowNode_ = new WindowNode();
218     sptr<WindowLayoutPolicy> layoutPolicy_;
219     sptr<AvoidAreaController> avoidController_;
220     sptr<DisplayGroupController> displayGroupController_;
221 
222     // if isFloatWindowHigher_ is true, FloatWindow should be above the full screen window.
223     static bool isFloatWindowAboveFullWindow_;
224     static uint32_t maxMainFloatingWindowNumber_;
225     static bool isAnimateTransactionEnabled_;
226 };
227 } // namespace Rosen
228 } // namespace OHOS
229 #endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H
230