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