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