• 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     STATUS_EMPTY,
33     STATUS_SINGLE_PRIMARY,
34     STATUS_SINGLE_SECONDARY,
35     STATUS_PAIRING,
36     STATUS_PAIRED_DONE
37 };
38 
39 /**
40  * @brief Enumerates the message of split event.
41  */
42 enum class SplitEventMsgType : uint32_t {
43     MSG_SHOW_PRIMARY,
44     MSG_SHOW_SECONDARY,
45     MSG_SHOW_DIVIDER,
46     MSG_DESTROY_DIVIDER,
47 };
48 
49 class WindowPair : public RefBase {
50 public:
51     /**
52      * @brief Constructor used to create an empty WindowPair instance.
53      *
54      * @param displayId the display of window pair
55      */
WindowPair(const DisplayId & displayId)56     explicit WindowPair(const DisplayId& displayId) : displayId_(displayId) {};
57 
58     /**
59      * @brief Deconstructor used to deconstruct.
60      *
61      */
62     ~WindowPair();
63 
64     /**
65      * @brief Clear window pair.
66      *
67      */
68     void Clear();
69 
70     /**
71      * @brief Set split ratio.
72      *
73      * @param ratio split ratio
74      */
75     void SetSplitRatio(float ratio);
76 
77     /**
78      * @brief Get split ratio.
79      *
80      * @return split ratio
81      */
82     float GetSplitRatio() const;
83 
84     /**
85      * @brief Get whether the window pair is paired..
86      *
87      * @return the pair state of window pair
88      */
89     bool IsPaired() const;
90 
91     /**
92      * @brief Handle changes in the state of the window pair
93      *
94      * @param node trigger window node
95      */
96     void UpdateIfSplitRelated(sptr<WindowNode>& node);
97 
98     /**
99      * @brief Handle remove window from pair.
100      *
101      * @param node target node
102      */
103     void HandleRemoveWindow(sptr<WindowNode>& node);
104 
105     /**
106      * @brief Find window node from window pair.
107      *
108      * @param node target window node
109      * @return window node
110      */
111     sptr<WindowNode> Find(sptr<WindowNode>& node);
112 
113     /**
114      * @brief Get divider window node.
115      *
116      * @return divider window node
117      */
118     sptr<WindowNode> GetDividerWindow() const;
119 
120     /**
121      * @brief Get pair status.
122      *
123      * @return the pair status of window pair
124      */
125     WindowPairStatus GetPairStatus() const;
126 
127     /**
128      * @brief Get all window node form pair in Z order.
129      *
130      * @return the list window form pair
131      */
132     std::vector<sptr<WindowNode>> GetOrderedPair(sptr<WindowNode>& node);
133 
134     /**
135      * @brief Get all window node form pair.
136      *
137      * @return the list window form pair
138      */
139     std::vector<sptr<WindowNode>> GetPairedWindows();
140 
141     /**
142      * @brief Get whether dock slice is forbidden to move.
143      *
144      * @return whether dock slice is forbidden to move
145      */
146     bool IsForbidDockSliceMove() const;
147 
148     /**
149      * @brief Exit split screen mode when dock slice in exit split screen mode area.
150      */
151     void ExitSplitMode();
152 
153     /**
154      * @brief whether dock slice in exit split screen mode area
155      */
156     bool IsDockSliceInExitSplitModeArea(const std::vector<int32_t>& exitSplitPoints);
157 
158     /**
159      * @brief Set the initial rect of divider window.
160      *
161      * @param rect divider window rect
162      */
163     void SetDividerRect(const Rect& rect);
164 
165     /**
166      * @brief Update divider window rect when display orientation changed.
167      *
168      * @param rect default divider rect
169      */
170     void RotateDividerWindow(const Rect& rect);
171 
172     /**
173      * @brief Take window pair node snapshot.
174      */
175     bool TakePairSnapshot();
176 
177     /**
178      * @brief Clear window pair node snapshot.
179      */
180     void ClearPairSnapshot();
181 
182 private:
183     /**
184      * @brief Gets whether the window is related to split window.
185      *
186      * @param node target node
187      * @return Whether target node is related to the split window
188      */
189     bool IsSplitRelated(sptr<WindowNode>& node) const;
190 
191     /**
192      * @brief Replace paired window.
193      *
194      * @param node current node
195      */
196     void Insert(sptr<WindowNode>& node);
197 
198     /**
199      * @brief Update paired window node
200      *
201      */
202     void HandlePairedNodesChange();
203 
204     /**
205      * @brief Update pair status
206      *
207      */
208     void UpdateWindowPairStatus();
209 
210     /**
211      * @brief Switch the position of two paired window.
212      *
213      */
214     void SwitchPosition();
215 
216     /**
217      * @brief Dump the info of pair.
218      *
219      */
220     void DumpPairInfo();
221 
222     /**
223      * @brief Send split screen event.
224      *
225      * @param msgType split event message type
226      * @param missionId mission id
227      */
228     void SendSplitScreenCommonEvent(SplitEventMsgType msgType, int32_t missionId);
229 
230     /**
231      * @brief Send split screen event to notify create recent view.
232      *
233      * @param node split node
234      */
235     void NotifyShowRecent(sptr<WindowNode> node);
236 
237     /**
238      * @brief Send split screen event to notify create or destroy divider window.
239      *
240      * @param node split node
241      * @param isDestroy destroy or create divider window flag
242      */
243     void NotifyCreateOrDestroyDivider(sptr<WindowNode> node, bool isDestroy);
244 
245 private:
246     float ratio_ = DEFAULT_SPLIT_RATIO;
247     DisplayId displayId_;
248     sptr<WindowNode> primary_;
249     sptr<WindowNode> secondary_;
250     sptr<WindowNode> divider_;
251     WindowPairStatus status_ = {WindowPairStatus::STATUS_EMPTY};
252     Rect dividerRect_ {0, 0, 0, 0};
253     DEFINE_VAR_DEFAULT_FUNC_SET(bool, AllSplitAppWindowsRestoring, isAllSplitAppWindowsRestoring, false)
254 };
255 } // namespace Rosen
256 } // namespace OHOS
257 #endif // OHOS_ROSEN_WINDOW_PAIR_H