/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ROSEN_WINDOW_NODE_CONTAINER_H #define OHOS_ROSEN_WINDOW_NODE_CONTAINER_H #include "animation_config.h" #include "avoid_area_controller.h" #include "display_info.h" #include "minimize_app.h" #include "display_group_controller.h" #include "display_group_info.h" #include "window_layout_policy.h" #include "window_manager.h" #include "window_node.h" #include "window_zorder_policy.h" #include "wm_common.h" #include "wm_common_inner.h" #include "window_pair.h" #include "window_root.h" namespace OHOS { namespace Rosen { using WindowNodeOperationFunc = std::function)>; // return true indicates to stop traverse class WindowNodeContainer : public RefBase { public: WindowNodeContainer(const sptr& displayInfo, ScreenId displayGroupId); ~WindowNodeContainer(); WMError ShowStartingWindow(sptr& node); WMError AddWindowNode(sptr& node, sptr& parentNode, bool afterAnimation = false); WMError RemoveWindowNode(sptr& node, bool fromAnimation = false); WMError HandleRemoveWindow(sptr& node); WMError UpdateWindowNode(sptr& node, WindowUpdateReason reason); WMError DestroyWindowNode(sptr& node, std::vector& windowIds); const std::vector& Destroy(); void AssignZOrder(); WMError SetFocusWindow(uint32_t windowId); uint32_t GetFocusWindow() const; WMError SetActiveWindow(uint32_t windowId, bool byRemoved); uint32_t GetActiveWindow() const; void SetDisplayBrightness(float brightness); float GetDisplayBrightness() const; void SetBrightnessWindow(uint32_t windowId); uint32_t GetBrightnessWindow() const; uint32_t ToOverrideBrightness(float brightness); void UpdateBrightness(uint32_t id, bool byRemoved); void HandleKeepScreenOn(const sptr& node, bool requireLock); AvoidArea GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType) const; WMError MinimizeStructuredAppWindowsExceptSelf(const sptr& node); void TraverseContainer(std::vector>& windowNodes) const; std::unordered_map GetExpectImmersiveProperty(DisplayId id, sptr& triggerWindow) const; uint32_t GetWindowCountByType(WindowType windowType); uint32_t GetMainFloatingWindowCount(); bool IsForbidDockSliceMove(DisplayId displayId) const; bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const; void ExitSplitMode(DisplayId displayId); bool IsVerticalDisplay(DisplayId displayId) const; WMError RaiseZOrderForAppWindow(sptr& node, sptr& parentNode); sptr GetNextFocusableWindow(uint32_t windowId) const; sptr GetNextRotatableWindow(uint32_t windowId) const; sptr GetNextActiveWindow(uint32_t windowId) const; void MinimizeAllAppWindows(DisplayId displayId); void MinimizeOldestAppWindow(); void MinimizeOldestMainFloatingWindow(uint32_t windowId); WMError ToggleShownStateForAllAppWindows(std::function restoreFunc, bool restore); void BackUpAllAppWindows(); void RestoreAllAppWindows(std::function restoreFunc); bool IsAppWindowsEmpty() const; void SetSurfaceNodeVisible(sptr& node, int32_t topPriority, bool visible); void SetBelowScreenlockVisible(sptr& node, bool visible); void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); void NotifySystemBarTints(std::vector displayIdVec); WMError MinimizeAppNodeExceptOptions(MinimizeReason reason, const std::vector &exceptionalIds = {}, const std::vector &exceptionalModes = {}); WMError SetWindowMode(sptr& node, WindowMode dstMode); WMError SwitchLayoutPolicy(WindowLayoutMode mode, DisplayId displayId, bool reorder = false); void RaiseSplitRelatedWindowToTop(sptr& node); Rect GetDisplayGroupRect() const; void TraverseWindowTree(const WindowNodeOperationFunc& func, bool isFromTopToBottom = true) const; void UpdateSizeChangeReason(sptr& node, WindowSizeChangeReason reason); void DropShowWhenLockedWindowIfNeeded(const sptr& node); void SetMinimizedByOther(bool isMinimizedByOther); void GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config); // parentDisplayId is the same as displayId in single-display mode bool AddNodeOnRSTree(sptr& node, DisplayId displayId, DisplayId parentDisplayId, WindowUpdateType type, bool animationPlayed = false); // parentDisplayId is the same as displayId in single-display mode bool RemoveNodeFromRSTree(sptr& node, DisplayId displayId, DisplayId parentDisplayId, WindowUpdateType type, bool animationPlayed = false); bool AddAppSurfaceNodeOnRSTree(sptr& node); sptr GetLayoutPolicy() const; sptr GetAvoidController() const; sptr GetDisplayGroupController() const; sptr GetRootNode(WindowRootNodeType type) const; void NotifyDockWindowStateChanged(sptr& node, bool isEnable); void NotifyDockWindowStateChanged(DisplayId displayId); void UpdateCameraFloatWindowStatus(const sptr& node, bool isShowing); void UpdateAvoidAreaListener(sptr& windowNode, bool haveAvoidAreaListener); void BeforeProcessWindowAvoidAreaChangeWhenDisplayChange() const; void ProcessWindowAvoidAreaChangeWhenDisplayChange() const; WindowLayoutMode GetCurrentLayoutMode() const; void RemoveSingleUserWindowNodes(int accountId); WMError IsTileRectSatisfiedWithSizeLimits(sptr& node); bool HasPrivateWindow(); sptr GetDeskTopWindow(); static AnimationConfig& GetAnimationConfigRef(); bool TakeWindowPairSnapshot(DisplayId displayId); void ClearWindowPairSnapshot(DisplayId displayId); bool IsScreenLocked(); void LayoutWhenAddWindowNode(sptr& node, bool afterAnimation = false); void UpdatePrivateStateAndNotify(); static void SetConfigMainFloatingWindowAbove(bool isAbove); static void SetMaxMainFloatingWindowNumber(uint32_t maxNumber); void SetDisplayOrientationFromWindow(sptr& node, bool withAnimation); bool HasMainFullScreenWindowShown(); static bool GetAnimateTransactionEnabled(); void SetWindowPairFrameGravity(DisplayId displayId, Gravity gravity); static std::string uiType_; private: friend class WindowRoot; void TraverseWindowNode(sptr& root, std::vector>& windowNodes) const; sptr FindRoot(WindowType type) const; sptr FindWindowNodeById(uint32_t id) const; void UpdateFocusStatus(uint32_t id, bool focused); void UpdateActiveStatus(uint32_t id, bool isActive); void NotifyIfAvoidAreaChanged(const sptr& node, const AvoidControlType avoidType) const; void NotifyIfSystemBarTintChanged(DisplayId displayId) const; void NotifyIfSystemBarRegionChanged(DisplayId displayId) const; void NotifyIfKeyboardRegionChanged(const sptr& node, const AvoidControlType avoidType) const; void TraverseAndUpdateWindowState(WindowState state, int32_t topPriority); void UpdateWindowTree(sptr& node); void UpdateWindowState(sptr node, int32_t topPriority, WindowState state); void HandleKeepScreenOn(const sptr& node, WindowState state); bool IsTopWindow(uint32_t windowId, sptr& rootNode) const; sptr FindDividerNode() const; void RaiseWindowToTop(uint32_t windowId, std::vector>& windowNodes); bool IsAboveSystemBarNode(sptr node) const; bool IsSplitImmersiveNode(sptr node) const; bool TraverseFromTopToBottom(sptr node, const WindowNodeOperationFunc& func) const; bool TraverseFromBottomToTop(sptr node, const WindowNodeOperationFunc& func) const; void RaiseOrderedWindowToTop(std::vector>& orderedNodes, std::vector>& windowNodes); void DumpScreenWindowTree(); void DumpScreenWindowTreeByWinId(uint32_t winid); void RaiseInputMethodWindowPriorityIfNeeded(const sptr& node) const; void ReZOrderShowWhenLockedWindowIfNeeded(const sptr& node); void RaiseShowWhenLockedWindowIfNeeded(const sptr& node); void ReZOrderShowWhenLockedWindows(bool up); WMError AddWindowNodeOnWindowTree(sptr& node, const sptr& parentNode); void RemoveWindowNodeFromWindowTree(sptr& node); void UpdateRSTreeWhenShowingDisplaysChange(sptr& node, const std::vector& lastShowingDisplays); bool CheckWindowNodeWhetherInWindowTree(const sptr& node) const; void UpdateWindowModeSupportTypeWhenKeyguardChange(const sptr& node, bool up); void RemoveFromRsTreeWhenRemoveWindowNode(sptr& node, bool fromAnimation); void UpdateSizeChangeReason(sptr& node, WindowMode srcMode, WindowMode dstMode); void UpdatePrivateWindowCount(); uint32_t GetAppWindowNum(); void ResetMainFloatingWindowPriorityIfNeeded(sptr& node); void ResetWindowZOrderPriorityWhenSetMode(sptr& node, const WindowMode& dstMode, const WindowMode& srcMode); void ResetAllMainFloatingWindowZOrder(sptr& rootNode); void HandleRemoveWindowDisplayOrientation(sptr& node, bool fromAnimation); void OpenInputMethodSyncTransaction(); void CloseInputMethodSyncTransaction(); void JudgeToReportSystemBarInfo(const sptr window, const std::unordered_map& systemBarPropInfo) const; bool IsWindowFollowParent(WindowType type); float displayBrightness_ = UNDEFINED_BRIGHTNESS; uint32_t brightnessWindow_ = INVALID_WINDOW_ID; uint32_t zOrder_ { 0 }; uint32_t focusedWindow_ { INVALID_WINDOW_ID }; int32_t focusedPid_ = -1; uint32_t activeWindow_ = INVALID_WINDOW_ID; int32_t activePid_ = -1; bool isScreenLocked_ = false; uint32_t privateWindowCount_ = 0; std::vector backupWindowIds_; std::map backupWindowMode_; std::map backupDividerWindowRect_; std::map> backupDisplaySplitWindowMode_; sptr zorderPolicy_ = new WindowZorderPolicy(); std::unordered_map> layoutPolicies_; WindowLayoutMode layoutMode_ = WindowLayoutMode::CASCADE; std::vector currentCoveredArea_; std::vector removedIds_; static AnimationConfig animationConfig_; sptr belowAppWindowNode_ = new WindowNode(); sptr appWindowNode_ = new WindowNode(); sptr aboveAppWindowNode_ = new WindowNode(); sptr layoutPolicy_; sptr avoidController_; sptr displayGroupController_; // if isFloatWindowHigher_ is true, FloatWindow should be above the full screen window. static bool isFloatWindowAboveFullWindow_; static uint32_t maxMainFloatingWindowNumber_; static bool isAnimateTransactionEnabled_; }; } // namespace Rosen } // namespace OHOS #endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H