• 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 <ui/rs_display_node.h>
20 #include "avoid_area_controller.h"
21 #include "window_layout_policy.h"
22 #include "window_manager.h"
23 #include "window_node.h"
24 #include "window_zorder_policy.h"
25 #include "wm_common.h"
26 #include "wm_common_inner.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 using WindowNodeOperationFunc = std::function<bool(sptr<WindowNode>)>; // return true indicates to stop traverse
31 class WindowNodeContainer : public RefBase {
32 public:
33     WindowNodeContainer(DisplayId displayId, uint32_t width, uint32_t height);
34     ~WindowNodeContainer();
35     WMError AddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode);
36     WMError RemoveWindowNode(sptr<WindowNode>& node);
37     WMError UpdateWindowNode(sptr<WindowNode>& node, WindowUpdateReason reason);
38     WMError DestroyWindowNode(sptr<WindowNode>& node, std::vector<uint32_t>& windowIds);
39     const std::vector<uint32_t>& Destroy();
40     void AssignZOrder();
41     WMError SetFocusWindow(uint32_t windowId);
42     uint32_t GetFocusWindow() const;
43     WMError SetActiveWindow(uint32_t windowId, bool byRemoved);
44     uint32_t GetActiveWindow() const;
45     void SetDisplayBrightness(float brightness);
46     float GetDisplayBrightness() const;
47     void SetBrightnessWindow(uint32_t windowId);
48     uint32_t GetBrightnessWindow() const;
49     uint32_t ToOverrideBrightness(float brightness);
50     void UpdateBrightness(uint32_t id, bool byRemoved);
51     void HandleKeepScreenOn(const sptr<WindowNode>& node, bool requireLock);
52     std::vector<Rect> GetAvoidAreaByType(AvoidAreaType avoidAreaType);
53     WMError MinimizeStructuredAppWindowsExceptSelf(const sptr<WindowNode>& node);
54     void TraverseContainer(std::vector<sptr<WindowNode>>& windowNodes) const;
55     uint64_t GetScreenId() const;
56     DisplayId GetDisplayId() const;
57     Rect GetDisplayRect() const;
58     Rect GetDisplayLimitRect() const;
59     std::unordered_map<WindowType, SystemBarProperty> GetExpectImmersiveProperty() const;
60     void NotifyAccessibilityWindowInfo(const sptr<WindowNode>& windowId, WindowUpdateType type) const;
61     void UpdateDisplayRect(uint32_t width, uint32_t height);
62 
63     void OnAvoidAreaChange(const std::vector<Rect>& avoidAreas);
64     bool isVerticalDisplay() const;
65     WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node, sptr<WindowNode>& parentNode);
66     sptr<WindowNode> GetNextFocusableWindow(uint32_t windowId) const;
67     sptr<WindowNode> GetNextActiveWindow(uint32_t windowId) const;
68     void MinimizeAllAppWindows();
69     void NotifyWindowStateChange(WindowState state, WindowStateChangeReason reason);
70     void NotifySystemBarTints();
71     void NotifySystemBarDismiss(sptr<WindowNode>& node);
72     WMError MinimizeAppNodeExceptOptions(bool fromUser, const std::vector<uint32_t> &exceptionalIds = {},
73                                          const std::vector<WindowMode> &exceptionalModes = {});
74     WMError EnterSplitWindowMode(sptr<WindowNode>& node);
75     WMError ExitSplitWindowMode(sptr<WindowNode>& node);
76     WMError SwitchLayoutPolicy(WindowLayoutMode mode, bool reorder = false);
77     void RaiseSplitRelatedWindowToTop(sptr<WindowNode>& node);
78     void MoveWindowNode(sptr<WindowNodeContainer>& container);
79     float GetVirtualPixelRatio() const;
80     void TraverseWindowTree(const WindowNodeOperationFunc& func, bool isFromTopToBottom = true) const;
81     void UpdateSizeChangeReason(sptr<WindowNode>& node, WindowSizeChangeReason reason);
82     void DropShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
83 
84 private:
85     void TraverseWindowNode(sptr<WindowNode>& root, std::vector<sptr<WindowNode>>& windowNodes) const;
86     sptr<WindowNode> FindRoot(WindowType type) const;
87     sptr<WindowNode> FindWindowNodeById(uint32_t id) const;
88     void UpdateFocusStatus(uint32_t id, bool focused) const;
89     void UpdateActiveStatus(uint32_t id, bool isActive) const;
90     void UpdateWindowTree(sptr<WindowNode>& node);
91     bool UpdateRSTree(sptr<WindowNode>& node, bool isAdd);
92 
93     void SendSplitScreenEvent(sptr<WindowNode>& node);
94     sptr<WindowNode> FindSplitPairNode(sptr<WindowNode>& node) const;
95     WMError UpdateWindowPairInfo(sptr<WindowNode>& triggerNode, sptr<WindowNode>& pairNode);
96     void NotifyIfSystemBarTintChanged();
97     void NotifyIfSystemBarRegionChanged();
98     void TraverseAndUpdateWindowState(WindowState state, int32_t topPriority);
99     void UpdateWindowState(sptr<WindowNode> node, int32_t topPriority, WindowState state);
100     void HandleKeepScreenOn(const sptr<WindowNode>& node, WindowState state);
101     bool IsTopWindow(uint32_t windowId, sptr<WindowNode>& rootNode) const;
102     sptr<WindowNode> FindDividerNode() const;
103     void RaiseWindowToTop(uint32_t windowId, std::vector<sptr<WindowNode>>& windowNodes);
104     void MinimizeWindowFromAbility(const sptr<WindowNode>& node, bool fromUser);
105     void ResetLayoutPolicy();
106     bool IsAboveSystemBarNode(sptr<WindowNode> node) const;
107     bool IsFullImmersiveNode(sptr<WindowNode> node) const;
108     bool IsSplitImmersiveNode(sptr<WindowNode> node) const;
109     bool TraverseFromTopToBottom(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const;
110     bool TraverseFromBottomToTop(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const;
111     void RcoveryScreenDefaultOrientationIfNeed();
112     // cannot determine in case of a window covered by union of several windows or with transparent value
113     void UpdateWindowVisibilityInfos(std::vector<sptr<WindowVisibilityInfo>>& infos);
114     void RaiseOrderedWindowToTop(std::vector<uint32_t> orderedIds, std::vector<sptr<WindowNode>>& windowNodes);
115     static bool ReadIsWindowAnimationEnabledProperty();
116     void GetWindowList(std::vector<sptr<WindowInfo>>& windowList) const;
117 
118     sptr<AvoidAreaController> avoidController_;
119     sptr<WindowZorderPolicy> zorderPolicy_ = new WindowZorderPolicy();
120     sptr<WindowNode> belowAppWindowNode_ = new WindowNode();
121     sptr<WindowNode> appWindowNode_ = new WindowNode();
122     sptr<WindowNode> aboveAppWindowNode_ = new WindowNode();
123     std::vector<uint32_t> removedIds_;
124     DisplayId displayId_ = 0;
125     Rect displayRect_;
126     std::vector<Rect> currentCoveredArea_;
127     std::unordered_map<WindowType, sptr<WindowNode>> sysBarNodeMap_ {
128         { WindowType::WINDOW_TYPE_STATUS_BAR,     nullptr },
129         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, nullptr },
130     };
131     std::unordered_map<WindowType, SystemBarRegionTint> sysBarTintMap_ {
132         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarRegionTint() },
133         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarRegionTint() },
134     };
135     std::unordered_map<WindowLayoutMode, sptr<WindowLayoutPolicy>> layoutPolicys_;
136     WindowLayoutMode layoutMode_ = WindowLayoutMode::CASCADE;
137     sptr<WindowLayoutPolicy> layoutPolicy_;
138     uint32_t zOrder_ { 0 };
139     uint32_t focusedWindow_ { INVALID_WINDOW_ID };
140     uint32_t activeWindow_ = INVALID_WINDOW_ID;
141     float displayBrightness_ = UNDEFINED_BRIGHTNESS; // UNDEFINED_BRIGHTNESS means system default brightness
142     uint32_t brightnessWindow_ = INVALID_WINDOW_ID;
143     void DumpScreenWindowTree();
144 
145     struct WindowPairInfo {
146         sptr<WindowNode> pairNode_;
147         float splitRatio_;
148     };
149     std::unordered_map<uint32_t, WindowPairInfo> pairedWindowMap_;
150     void RaiseInputMethodWindowPriorityIfNeeded(const sptr<WindowNode>& node) const;
151     void RaiseShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node);
152     void ReZOrderShowWhenLockedWindows(const sptr<WindowNode>& node, bool up);
153 };
154 } // namespace Rosen
155 } // namespace OHOS
156 #endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H
157