• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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     Rect GetDisplayRect(DisplayId displayId) const;
63     std::unordered_map<WindowType, SystemBarProperty> GetExpectImmersiveProperty() const;
64     uint32_t GetWindowCountByType(WindowType windowType);
65     bool IsForbidDockSliceMove(DisplayId displayId) const;
66     bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const;
67     void ExitSplitMode(DisplayId displayId);
68 
69     bool IsVerticalDisplay(DisplayId displayId) const;
70     WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node, sptr<WindowNode>& parentNode);
71     sptr<WindowNode> GetNextFocusableWindow(uint32_t windowId) const;
72     sptr<WindowNode> GetNextRotatableWindow(uint32_t windowId) const;
73     sptr<WindowNode> GetNextActiveWindow(uint32_t windowId) const;
74     void MinimizeAllAppWindows(DisplayId displayId);
75     void MinimizeOldestAppWindow();
76     WMError ToggleShownStateForAllAppWindows(std::function<bool(uint32_t, WindowMode)> restoreFunc, bool restore);
77     void BackUpAllAppWindows();
78     void RestoreAllAppWindows(std::function<bool(uint32_t, WindowMode)> restoreFunc);
79     bool IsAppWindowsEmpty() const;
80     void SetSurfaceNodeVisible(sptr<WindowNode>& node, int32_t topPriority, bool visible);
81     void SetBelowScreenlockVisible(sptr<WindowNode>& node, bool visible);
82     void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason);
83     void NotifySystemBarTints(std::vector<DisplayId> displayIdVec);
84     WMError MinimizeAppNodeExceptOptions(MinimizeReason reason, const std::vector<uint32_t> &exceptionalIds = {},
85                                          const std::vector<WindowMode> &exceptionalModes = {});
86     WMError SetWindowMode(sptr<WindowNode>& node, WindowMode dstMode);
87     WMError SwitchLayoutPolicy(WindowLayoutMode mode, DisplayId displayId, bool reorder = false);
88     void RaiseSplitRelatedWindowToTop(sptr<WindowNode>& node);
89     float GetVirtualPixelRatio(DisplayId displayId) const;
90     Rect GetDisplayGroupRect() const;
91     void TraverseWindowTree(const WindowNodeOperationFunc& func, bool isFromTopToBottom = true) const;
92     void UpdateSizeChangeReason(sptr<WindowNode>& node, WindowSizeChangeReason reason);
93     void DropShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
94 
95     void SetMinimizedByOther(bool isMinimizedByOther);
96     void GetModeChangeHotZones(DisplayId displayId,
97         ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config);
98     sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId);
99     void UpdateDisplayInfo(sptr<DisplayInfo> displayInfo);
100     std::vector<sptr<DisplayInfo>> GetAllDisplayInfo();
101     float GetDisplayVirtualPixelRatio(DisplayId displayId) const;
102 
103     // parentDisplayId is the same as displayId in single-display mode
104     bool AddNodeOnRSTree(sptr<WindowNode>& node, DisplayId displayId, DisplayId parentDisplayId,
105         WindowUpdateType type, bool animationPlayed = false);
106     // parentDisplayId is the same as displayId in single-display mode
107     bool RemoveNodeFromRSTree(sptr<WindowNode>& node, DisplayId displayId, DisplayId parentDisplayId,
108         WindowUpdateType type, bool animationPlayed = false);
109     bool AddAppSurfaceNodeOnRSTree(sptr<WindowNode>& node);
110 
111     sptr<WindowLayoutPolicy> GetLayoutPolicy() const;
112     sptr<AvoidAreaController> GetAvoidController() const;
113     sptr<DisplayGroupController> GetMultiDisplayController() const;
114     sptr<WindowNode> GetRootNode(WindowRootNodeType type) const;
115     void NotifyDockWindowStateChanged(sptr<WindowNode>& node, bool isEnable);
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 private:
131     void TraverseWindowNode(sptr<WindowNode>& root, std::vector<sptr<WindowNode>>& windowNodes) const;
132     sptr<WindowNode> FindRoot(WindowType type) const;
133     sptr<WindowNode> FindWindowNodeById(uint32_t id) const;
134     void UpdateFocusStatus(uint32_t id, bool focused);
135     void UpdateActiveStatus(uint32_t id, bool isActive);
136     void NotifyIfAvoidAreaChanged(const sptr<WindowNode>& node, const AvoidControlType avoidType) const;
137     void NotifyIfSystemBarTintChanged(DisplayId displayId) const;
138     void NotifyIfSystemBarRegionChanged(DisplayId displayId) const;
139     void NotifyIfKeyboardRegionChanged(const sptr<WindowNode>& node, const AvoidControlType avoidType) const;
140     void TraverseAndUpdateWindowState(WindowState state, int32_t topPriority);
141     void UpdateWindowTree(sptr<WindowNode>& node);
142     void UpdateWindowState(sptr<WindowNode> node, int32_t topPriority, WindowState state);
143     void HandleKeepScreenOn(const sptr<WindowNode>& node, WindowState state);
144     bool IsTopWindow(uint32_t windowId, sptr<WindowNode>& rootNode) const;
145     sptr<WindowNode> FindDividerNode() const;
146     void RaiseWindowToTop(uint32_t windowId, std::vector<sptr<WindowNode>>& windowNodes);
147     void ResetLayoutPolicy();
148     bool IsAboveSystemBarNode(sptr<WindowNode> node) const;
149     bool IsSplitImmersiveNode(sptr<WindowNode> node) const;
150     bool TraverseFromTopToBottom(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const;
151     bool TraverseFromBottomToTop(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const;
152     void RaiseOrderedWindowToTop(std::vector<sptr<WindowNode>>& orderedNodes,
153         std::vector<sptr<WindowNode>>& windowNodes);
154     void DumpScreenWindowTree();
155     void RaiseInputMethodWindowPriorityIfNeeded(const sptr<WindowNode>& node) const;
156     void ReZOrderShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
157     void RaiseShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
158     void ReZOrderShowWhenLockedWindows(bool up);
159 
160     WMError AddWindowNodeOnWindowTree(sptr<WindowNode>& node, const sptr<WindowNode>& parentNode);
161     void RemoveWindowNodeFromWindowTree(sptr<WindowNode>& node);
162     void UpdateRSTreeWhenShowingDisplaysChange(sptr<WindowNode>& node,
163         const std::vector<DisplayId>& lastShowingDisplays);
164     bool CheckWindowNodeWhetherInWindowTree(const sptr<WindowNode>& node) const;
165     void UpdateModeSupportInfoWhenKeyguardChange(const sptr<WindowNode>& node, bool up);
166     void RemoveFromRsTreeWhenRemoveWindowNode(sptr<WindowNode>& node, bool fromAnimation);
167     void ProcessInputMethodWindowAddAnimation(sptr<WindowNode>& node, std::function<void()> updateRSTreeFunc);
168     uint32_t GetAppWindowNum();
169 
170     float displayBrightness_ = UNDEFINED_BRIGHTNESS;
171     uint32_t brightnessWindow_ = INVALID_WINDOW_ID;
172     uint32_t zOrder_ { 0 };
173     uint32_t focusedWindow_ { INVALID_WINDOW_ID };
174     int32_t focusedPid_ = -1;
175     uint32_t activeWindow_ = INVALID_WINDOW_ID;
176     int32_t activePid_ = -1;
177     bool isScreenLocked_ = false;
178 
179     std::vector<uint32_t> backupWindowIds_;
180     std::map<uint32_t, WindowMode> backupWindowMode_;
181     std::map<DisplayId, Rect> backupDividerWindowRect_;
182     std::map<DisplayId, std::set<WindowMode>> backupDisplaySplitWindowMode_;
183     sptr<WindowZorderPolicy> zorderPolicy_ = new WindowZorderPolicy();
184     std::unordered_map<WindowLayoutMode, sptr<WindowLayoutPolicy>> layoutPolicies_;
185     WindowLayoutMode layoutMode_ = WindowLayoutMode::CASCADE;
186     std::vector<Rect> currentCoveredArea_;
187     std::vector<uint32_t> removedIds_;
188     static AnimationConfig animationConfig_;
189 
190     sptr<WindowNode> belowAppWindowNode_ = new WindowNode();
191     sptr<WindowNode> appWindowNode_ = new WindowNode();
192     sptr<WindowNode> aboveAppWindowNode_ = new WindowNode();
193     sptr<WindowLayoutPolicy> layoutPolicy_;
194     sptr<AvoidAreaController> avoidController_;
195     sptr<DisplayGroupController> displayGroupController_;
196     sptr<DisplayGroupInfo> displayGroupInfo_;
197 };
198 } // namespace Rosen
199 } // namespace OHOS
200 #endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H
201