1 /*
2  * Copyright (c) 2021-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 FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H
17 #define FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H
18 
19 #include "pointer_event.h"
20 #include "display_manager.h"
21 #include "window.h"
22 #include "window_layout_policy.h"
23 #include "window_option.h"
24 #include "window_scene.h"
25 #include "wm_common.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 struct SplitRects {
30     Rect primaryRect;
31     Rect secondaryRect;
32     Rect dividerRect;
33 };
34 
35 class WindowTestUtils {
36 public:
37     struct TestWindowInfo {
38         std::string name;
39         Rect rect;
40         WindowType type;
41         WindowMode mode;
42         bool needAvoid;
43         bool parentLimit;
44         bool forbidSplitMove {false};
45         bool showWhenLocked;
46         uint32_t parentId;
47         bool focusable_ { true };
48         Orientation orientation_ { Orientation::UNSPECIFIED };
49     };
50     static Rect displayRect_;
51     static Rect limitDisplayRect_;
52     static Rect statusBarRect_;
53     static Rect naviBarRect_;
54     static Rect customAppRect_;
55     static Rect customAppDecoRect_;
56     static Rect dockWindowRect_;
57     static SplitRects splitRects_;
58     static bool isVerticalDisplay_;
59     static Rect singleTileRect_;
60     static std::vector<Rect> doubleTileRects_;
61     static std::vector<Rect> tripleTileRects_;
62     static AvoidArea systemAvoidArea_;
63 
64     static void InitByDisplayRect(const Rect& displayRect);
65     static sptr<Window> CreateTestWindow(const TestWindowInfo& info);
66     static sptr<Window> CreateStatusBarWindow();
67     static sptr<Window> CreateNavigationBarWindow();
68     static sptr<Window> CreateDockWindow();
69     static sptr<WindowScene> CreateWindowScene();
70     static bool RectEqualTo(const sptr<Window>& window, const Rect& r);
71     static bool InitSplitRects();
72     static void UpdateSplitRects(const sptr<Window>& window);
73     static bool RectEqualToRect(const Rect& l, const Rect& r);
74     static Rect GetDefaultFloatingRect(const sptr<Window>& window, bool avoid);
75     static Rect CalcLimitedRect(const Rect& rect, float virtualPixelRatio);
76     static Rect GetDecorateRect(const Rect& rect, float virtualPixelRatio);
77     static Rect GetFloatingLimitedRect(const Rect& rect, float virtualPixelRatio);
78     static void InitTileWindowRects(const sptr<Window>& window, bool avoid);
79     static float GetVirtualPixelRatio(DisplayId displayId);
80     static std::shared_ptr<MMI::PointerEvent> CreatePointerEvent(int32_t posX, int32_t posY, uint32_t pointerId,
81         int32_t pointerAction);
82     static uint32_t GetMaxTileWinNum();
83 
84 private:
85     void UpdateLimitDisplayRect(const Rect& avoidRect);
86     static void UpdateLimitSplitRects(int32_t divPos);
87     static void UpdateLimitSplitRect(Rect& limitSplitRect);
88     static AvoidPosType GetAvoidPosType(const Rect& rect);
89     AvoidArea avoidArea_;
90 };
91 } // namespace ROSEN
92 } // namespace OHOS
93 #endif // FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H
94