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