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