• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_PAIR_H
17 #define OHOS_ROSEN_WINDOW_PAIR_H
18 
19 #include <refbase.h>
20 #include "class_var_definition.h"
21 #include "window_node.h"
22 #include "window_layout_policy.h"
23 #include "wm_common_inner.h"
24 #include "wm_common.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 /**
29  * @brief Enumerates the status of window pair.
30  */
31 enum class WindowPairStatus : uint32_t {
32     EMPTY,
33     SINGLE_PRIMARY,
34     SINGLE_SECONDARY,
35     SINGLE_SPLIT,
36     PRIMARY_AND_SECONDARY,
37     PRIMARY_AND_DIVIDER,
38     SECONDARY_AND_DIVIDER,
39     PAIRED_DONE
40 };
41 
42 /**
43  * @brief Enumerates the message of split event.
44  */
45 enum class SplitEventMsgType : uint32_t {
46     MSG_SHOW_PRIMARY,
47     MSG_SHOW_SECONDARY,
48     MSG_SHOW_DIVIDER,
49     MSG_DESTROY_DIVIDER,
50 };
51 
52 class WindowPair : public RefBase {
53 public:
54     /**
55      * @brief Constructor used to create an empty WindowPair instance.
56      *
57      * @param displayId the display of window pair
58      */
WindowPair(const DisplayId & displayId)59     explicit WindowPair(const DisplayId& displayId) : displayId_(displayId) {};
60 
61     /**
62      * @brief Deconstructor used to deconstruct.
63      *
64      */
65     ~WindowPair();
66 
67     /**
68      * @brief Clear window pair.
69      *
70      */
71     void Clear();
72 
73     /**
74      * @brief Set split ratio.
75      *
76      * @param ratio split ratio
77      */
78     void SetSplitRatio(float ratio);
79 
80     /**
81      * @brief Get split ratio.
82      *
83      * @return split ratio
84      */
85     float GetSplitRatio() const;
86 
87     /**
88      * @brief Get whether the window pair is paired.
89      *
90      * @return the pair state of window pair
91      */
92     bool IsPaired() const;
93 
94     /**
95      * @brief Get whether the window status_ is valid.
96      */
97     bool IsAbnormalStatus() const;
98 
99     /**
100      * @brief Check pair status support recent update
101      *
102      * @param node trigger window node
103      */
104     bool StatusSupprtedWhenRecentUpdate(sptr<WindowNode>& node);
105 
106     /**
107      * @brief Handle changes in the state of the window pair
108      *
109      * @param node trigger window node
110      */
111     void UpdateIfSplitRelated(sptr<WindowNode>& node);
112 
113     /**
114      * @brief Handle remove window from pair.
115      *
116      * @param node target node
117      */
118     void HandleRemoveWindow(sptr<WindowNode>& node);
119 
120     /**
121      * @brief Find window node from window pair.
122      *
123      * @param node target window node
124      * @return window node
125      */
126     sptr<WindowNode> Find(sptr<WindowNode>& node);
127 
128     /**
129      * @brief Get divider window node.
130      *
131      * @return divider window node
132      */
133     sptr<WindowNode> GetDividerWindow() const;
134 
135     /**
136      * @brief Get pair status.
137      *
138      * @return the pair status of window pair
139      */
140     WindowPairStatus GetPairStatus() const;
141 
142     /**
143      * @brief Get all window node form pair in Z order.
144      *
145      * @return the list window form pair
146      */
147     std::vector<sptr<WindowNode>> GetOrderedPair(sptr<WindowNode>& node);
148 
149     /**
150      * @brief Get all window node form pair.
151      *
152      * @return the list window form pair
153      */
154     std::vector<sptr<WindowNode>> GetPairedWindows();
155 
156     /**
157      * @brief Get whether dock slice is forbidden to move.
158      *
159      * @return whether dock slice is forbidden to move
160      */
161     bool IsForbidDockSliceMove() const;
162 
163     /**
164      * @brief Exit split screen mode when dock slice in exit split screen mode area.
165      */
166     void ExitSplitMode();
167 
168     /**
169      * @brief whether dock slice in exit split screen mode area
170      */
171     bool IsDockSliceInExitSplitModeArea(const std::vector<int32_t>& exitSplitPoints);
172 
173     /**
174      * @brief Set the initial rect of divider window.
175      *
176      * @param rect divider window rect
177      */
178     void SetDividerRect(const Rect& rect);
179 
180     /**
181      * @brief Update divider window rect when display orientation changed.
182      *
183      * @param rect default divider rect
184      */
185     void RotateDividerWindow(const Rect& rect);
186 
187     /**
188      * @brief Take window pair node snapshot.
189      */
190     bool TakePairSnapshot();
191 
192     /**
193      * @brief Clear window pair node snapshot.
194      */
195     void ClearPairSnapshot();
196 
197     /**
198      * @brief Set split ratio config.
199      */
200     void SetSplitRatioConfig(const SplitRatioConfig& splitRatioConfig);
201 
202     /**
203      * @brief Calculate split ratio points.
204      */
205     void CalculateSplitRatioPoints(const Rect& displayRect);
206 
207     /**
208      * @brief Get exit split points.
209      */
210     std::vector<int32_t> GetExitSplitPoints();
211 
212     /**
213      * @brief Get split ratio points.
214      */
215     std::vector<int32_t> GetSplitRatioPoints();
216 
217     /**
218      * @brief is during split.
219      * @return true means existing recent or status is not PARI_DONE.
220      */
221     bool IsDuringSplit();
222 
223 private:
224     /**
225      * @brief Gets whether the window is related to split window.
226      *
227      * @param node target node
228      * @return Whether target node is related to the split window
229      */
230     bool IsSplitRelated(sptr<WindowNode>& node) const;
231 
232     /**
233      * @brief Check Z order for window node form pair.
234      *
235      * @return the Z order of window form pair
236      */
237     void CheckOrderedPairZorder(
238         sptr<WindowNode>& node, bool& hasPrimaryDialog, bool& hasSecondaryDialog, bool& isPrimaryAbove);
239 
240     /**
241      * @brief Create all window node form pair.
242      *
243      * @return the list window form pair
244      */
245     std::vector<sptr<WindowNode>> CreateOrderedPair(
246         sptr<WindowNode>& bottom, sptr<WindowNode>& mid, sptr<WindowNode>& top);
247 
248     /**
249      * @brief Replace paired window.
250      *
251      * @param node current node
252      */
253     void Insert(sptr<WindowNode>& node);
254 
255     /**
256      * @brief Update paired window node
257      *
258      */
259     void HandlePairedNodesChange();
260 
261     /**
262      * @brief Update pair status
263      *
264      */
265     void UpdateWindowPairStatus();
266 
267     /**
268      * @brief Switch the position of two paired window.
269      *
270      */
271     void SwitchPosition();
272 
273     /**
274      * @brief Dump the info of pair.
275      *
276      */
277     void DumpPairInfo();
278 
279     /**
280      * @brief Send split screen event.
281      *
282      * @param msgType split event message type
283      * @param missionId mission id
284      */
285     void SendSplitScreenCommonEvent(SplitEventMsgType msgType, int32_t missionId);
286 
287     /**
288      * @brief Send split screen event to notify create recent view.
289      *
290      * @param node split node
291      */
292     void NotifyShowRecent(sptr<WindowNode> node);
293 
294     /**
295      * @brief Send split screen event to notify create or destroy divider window.
296      *
297      * @param node split node
298      * @param isDestroy destroy or create divider window flag
299      */
300     void NotifyCreateOrDestroyDivider(sptr<WindowNode> node, bool isDestroy);
301 
302     /**
303      * @brief Calculate and Get split ratio point
304      */
305     int32_t GetSplitRatioPoint(float ratio, const Rect& displayRect);
306 
307 private:
308     float ratio_ = DEFAULT_SPLIT_RATIO;
309     DisplayId displayId_;
310     sptr<WindowNode> primary_;
311     sptr<WindowNode> secondary_;
312     sptr<WindowNode> divider_;
313     WindowPairStatus status_ = {WindowPairStatus::EMPTY};
314     Rect dividerRect_ {0, 0, 0, 0};
315     std::vector<int32_t> exitSplitPoints_; // 2 element, first element < second element
316     std::vector<int32_t> splitRatioPoints_;
317     SplitRatioConfig splitRatioConfig_;
318     DEFINE_VAR_DEFAULT_FUNC_SET(bool, AllSplitAppWindowsRestoring, isAllSplitAppWindowsRestoring, false)
319 };
320 } // namespace Rosen
321 } // namespace OHOS
322 #endif // OHOS_ROSEN_WINDOW_PAIR_H