• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LAYOUT_POLICY_H
17 #define OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H
18 
19 #include <map>
20 #include <refbase.h>
21 #include <set>
22 
23 #include "display_group_info.h"
24 #include "display_info.h"
25 #include "window_node.h"
26 #include "wm_common.h"
27 
28 
29 namespace OHOS {
30 namespace Rosen {
31 using DisplayGroupWindowTree = std::map<DisplayId,
32     std::map<WindowRootNodeType, std::unique_ptr<std::vector<sptr<WindowNode>>>>>;
33 enum class DockWindowShowState : uint32_t {
34     NOT_SHOWN = 0,
35     SHOWN_IN_BOTTOM = 1,
36     SHOWN_IN_LEFT = 2,
37     SHOWN_IN_RIGHT = 3,
38     SHOWN_IN_TOP = 4,
39 };
40 class WindowLayoutPolicy : public RefBase {
41 public:
42     WindowLayoutPolicy() = delete;
43     WindowLayoutPolicy(DisplayGroupWindowTree& displayGroupWindowTree);
44     ~WindowLayoutPolicy() = default;
45     virtual void Launch();
46     virtual void Reorder();
47     virtual void PerformWindowLayout(const sptr<WindowNode>& node, WindowUpdateType type) = 0;
48     void ProcessDisplayCreate(DisplayId displayId, const std::map<DisplayId, Rect>& displayRectMap);
49     void ProcessDisplayDestroy(DisplayId displayId, const std::map<DisplayId, Rect>& displayRectMap);
50     void ProcessDisplaySizeChangeOrRotation(DisplayId displayId, const std::map<DisplayId, Rect>& displayRectMap);
51     void ProcessDisplayVprChange(DisplayId displayId);
52 
SetSplitDividerWindowRects(std::map<DisplayId,Rect> dividerWindowRects)53     virtual void SetSplitDividerWindowRects(std::map<DisplayId, Rect> dividerWindowRects) {};
54     virtual Rect GetDividerRect(DisplayId displayId) const;
55     virtual bool IsTileRectSatisfiedWithSizeLimits(const sptr<WindowNode>& node);
56     bool IsMultiDisplay();
57     Rect GetDisplayGroupRect() const;
58     void SetSplitRatioPoints(DisplayId displayId, const std::vector<int32_t>& splitRatioPoints);
59     void NotifyClientAndAnimation(const sptr<WindowNode>& node, const Rect& winRect, WindowSizeChangeReason reason);
60     // methods for setting bottom posY limit for cascade rect on pc
61     static void SetCascadeRectBottomPosYLimit(uint32_t floatingBottomPosY);
62     static void SetMaxFloatingWindowSize(uint32_t maxSize);
63     static void CalcAndSetNodeHotZone(const Rect& winRect, const sptr<WindowNode>& node);
64     virtual void GetMaximizeRect(const sptr<WindowNode>& node, Rect& maxRect);
65 
66 protected:
67     /*
68      * methods for calculate window rect
69      */
70     virtual void UpdateLayoutRect(const sptr<WindowNode>& node) = 0;
71     void LayoutWindowTree(DisplayId displayId);
72     void LayoutWindowNode(const sptr<WindowNode>& node);
73     void LayoutWindowNodesByRootType(const std::vector<sptr<WindowNode>>& nodeVec);
74     void FixWindowRectWithinDisplay(const sptr<WindowNode>& node) const;
75 
76     /*
77      * methods for get/update display information or limit information
78      */
79     AvoidPosType GetAvoidPosType(const Rect& rect, DisplayId displayId) const;
80     void UpdateDisplayLimitRect(const sptr<WindowNode>& node, Rect& limitRect);
81     bool IsVerticalDisplay(DisplayId displayId) const;
82     bool IsFullScreenRecentWindowExist(const std::vector<sptr<WindowNode>>& nodeVec) const;
83     void UpdateWindowSizeLimits(const sptr<WindowNode>& node);
84     WindowSizeLimits GetSystemSizeLimits(const sptr<WindowNode>& node, const Rect& displayRect, float vpr);
85 
86     /*
87      * methods for multiDisplay
88      */
89     void UpdateMultiDisplayFlag();
90     void UpdateDisplayGroupRect();
91     void UpdateDisplayGroupLimitRect();
92     void PostProcessWhenDisplayChange();
93     void LimitWindowToBottomRightCorner(const sptr<WindowNode>& node);
94     void UpdateRectInDisplayGroupForAllNodes(DisplayId displayId, const Rect& oriDisplayRect,
95         const Rect& newDisplayRect);
96     void UpdateRectInDisplayGroup(const sptr<WindowNode>& node, const Rect& oriDisplayRect,
97         const Rect& newDisplayRect);
98     void UpdateDisplayRectAndDisplayGroupInfo(const std::map<DisplayId, Rect>& displayRectMap);
99 
100     /*
101      * methods for update node latest information, include:
102      * 1. notify client and animation
103      * 2. update hot zone
104      * 3. update surface bounds
105      */
106     void NotifyAnimationSizeChangeIfNeeded();
107     static Rect CalcEntireWindowHotZone(const sptr<WindowNode>& node, const Rect& winRect, uint32_t hotZone,
108         float vpr, TransformHelper::Vector2 hotZoneScale);
109     void UpdateSurfaceBounds(const sptr<WindowNode>& node, const Rect& winRect, const Rect& preRect);
110 
111     void GetStoragedAspectRatio(const sptr<WindowNode>& node);
112     bool IsNeedAnimationSync(WindowType type);
113 
114     Rect displayGroupRect_;
115     Rect displayGroupLimitRect_;
116     bool isMultiDisplay_ = false;
117     mutable std::map<DisplayId, Rect> limitRectMap_;
118     DisplayGroupWindowTree& displayGroupWindowTree_;
119     std::map<DisplayId, Rect> restoringDividerWindowRects_;
120     mutable std::map<DisplayId, std::vector<int32_t>> splitRatioPointsMap_;
121     // bottom posY limit for cascade rect on pc
122     static uint32_t floatingBottomPosY_;
123     // max size of floating window in config
124     static uint32_t maxFloatingWindowSize_;
125 };
126 }
127 }
128 #endif // OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H
129