• 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_WM_COMMON_INNER_H
17 #define OHOS_ROSEN_WM_COMMON_INNER_H
18 
19 #include <cfloat>
20 #include <cinttypes>
21 #include <unordered_set>
22 #include "wm_common.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class KeyboardAnimationConfig;
27 
28 enum class LifeCycleEvent : uint32_t {
29     CREATE_EVENT,
30     SHOW_EVENT,
31     HIDE_EVENT,
32     DESTROY_EVENT,
33 };
34 
35 enum class WindowStateChangeReason : uint32_t {
36     NORMAL,
37     KEYGUARD,
38     TOGGLING,
39 };
40 
41 enum class WindowUpdateReason : uint32_t {
42     NEED_SWITCH_CASCADE_BASE,
43     UPDATE_ALL = NEED_SWITCH_CASCADE_BASE,
44     UPDATE_MODE,
45     UPDATE_RECT,
46     UPDATE_FLAGS,
47     UPDATE_TYPE,
48     UPDATE_ASPECT_RATIO,
49     NEED_SWITCH_CASCADE_END,
50     UPDATE_OTHER_PROPS,
51     UPDATE_TRANSFORM,
52 };
53 
54 enum class AvoidPosType : uint32_t {
55     AVOID_POS_LEFT,
56     AVOID_POS_TOP,
57     AVOID_POS_RIGHT,
58     AVOID_POS_BOTTOM,
59     AVOID_POS_UNKNOWN
60 };
61 
62 enum class WindowRootNodeType : uint32_t {
63     APP_WINDOW_NODE,
64     ABOVE_WINDOW_NODE,
65     BELOW_WINDOW_NODE,
66 };
67 
68 enum class PropertyChangeAction : uint32_t {
69     ACTION_UPDATE_RECT = 1,
70     ACTION_UPDATE_MODE = 1 << 1,
71     ACTION_UPDATE_FLAGS = 1 << 2,
72     ACTION_UPDATE_OTHER_PROPS = 1 << 3,
73     ACTION_UPDATE_FOCUSABLE = 1 << 4,
74     ACTION_UPDATE_TOUCHABLE = 1 << 5,
75     ACTION_UPDATE_CALLING_WINDOW = 1 << 6,
76     ACTION_UPDATE_ORIENTATION = 1 << 7,
77     ACTION_UPDATE_TURN_SCREEN_ON = 1 << 8,
78     ACTION_UPDATE_KEEP_SCREEN_ON = 1 << 9,
79     ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10,
80     ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11,
81     ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12,
82     ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13,
83     ACTION_UPDATE_ANIMATION_FLAG = 1 << 14,
84     ACTION_UPDATE_PRIVACY_MODE = 1 << 15,
85     ACTION_UPDATE_ASPECT_RATIO = 1 << 16,
86     ACTION_UPDATE_MAXIMIZE_STATE = 1 << 17,
87 };
88 
89 struct ModeChangeHotZonesConfig {
90     bool isModeChangeHotZoneConfigured_;
91     uint32_t fullscreenRange_;
92     uint32_t primaryRange_;
93     uint32_t secondaryRange_;
94 };
95 
96 struct SystemConfig : public Parcelable {
97     bool isSystemDecorEnable_ = true;
98     uint32_t decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
99     bool isStretchable_ = false;
100     WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
101     KeyboardAnimationConfig keyboardAnimationConfig_;
102 
MarshallingSystemConfig103     virtual bool Marshalling(Parcel& parcel) const override
104     {
105         if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_) ||
106             !parcel.WriteUint32(decorModeSupportInfo_)) {
107             return false;
108         }
109 
110         if (!parcel.WriteUint32(static_cast<uint32_t>(defaultWindowMode_)) ||
111             !parcel.WriteParcelable(&keyboardAnimationConfig_)) {
112             return false;
113         }
114 
115         return true;
116     }
117 
UnmarshallingSystemConfig118     static SystemConfig* Unmarshalling(Parcel& parcel)
119     {
120         SystemConfig* config = new SystemConfig();
121         config->isSystemDecorEnable_ = parcel.ReadBool();
122         config->isStretchable_ = parcel.ReadBool();
123         config->decorModeSupportInfo_ = parcel.ReadUint32();
124         config->defaultWindowMode_ = static_cast<WindowMode>(parcel.ReadUint32());
125         sptr<KeyboardAnimationConfig> keyboardConfig = parcel.ReadParcelable<KeyboardAnimationConfig>();
126         config->keyboardAnimationConfig_ = *keyboardConfig;
127         return config;
128     }
129 };
130 
131 struct WindowSizeLimits {
132     uint32_t maxWidth_;
133     uint32_t maxHeight_;
134     uint32_t minWidth_;
135     uint32_t minHeight_;
136     float maxRatio_;
137     float minRatio_;
WindowSizeLimitsWindowSizeLimits138     WindowSizeLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX),
139         minWidth_(0),  minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {}
WindowSizeLimitsWindowSizeLimits140     WindowSizeLimits(uint32_t maxWidth, uint32_t maxHeight,
141         uint32_t minWidth, uint32_t minHeight, float maxRatio, float minRatio)
142         : maxWidth_(maxWidth), maxHeight_(maxHeight),
143         minWidth_(minWidth), minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {}
144 
IsEmptyWindowSizeLimits145     bool IsEmpty() const
146     {
147         return (maxWidth_ == 0 || minWidth_ == 0 || maxHeight_ == 0 || minHeight_ == 0);
148     }
149 };
150 
151 struct ModeChangeHotZones {
152     Rect fullscreen_;
153     Rect primary_;
154     Rect secondary_;
155 };
156 
157 struct SplitRatioConfig {
158     // when divider reaches this position, the top/left window will hide. Valid range: (0, 0.5)
159     float exitSplitStartRatio;
160     // when divider reaches this position, the bottom/right window will hide. Valid range: (0.5, 1)
161     float exitSplitEndRatio;
162     std::vector<float> splitRatios;
163 };
164 
165 enum class DragType : uint32_t {
166     DRAG_UNDEFINED,
167     DRAG_LEFT_OR_RIGHT,
168     DRAG_BOTTOM_OR_TOP,
169     DRAG_LEFT_TOP_CORNER,
170     DRAG_RIGHT_TOP_CORNER,
171 };
172 
173 enum class TraceTaskId : int32_t {
174     STARTING_WINDOW = 0,
175     REMOTE_ANIMATION,
176     CONNECT_EXTENSION,
177     REMOTE_ANIMATION_HOME,
178     START_WINDOW_ANIMATION,
179 };
180 
181 enum class PersistentStorageType : uint32_t {
182     UKNOWN = 0,
183     ASPECT_RATIO,
184     MAXIMIZE_STATE,
185 };
186 
187 struct MoveDragProperty : public Parcelable {
188     int32_t startPointPosX_;
189     int32_t startPointPosY_;
190     int32_t startPointerId_;
191     int32_t targetDisplayId_;
192     int32_t sourceType_;
193     bool startDragFlag_;
194     bool startMoveFlag_;
195     bool pointEventStarted_;
196     DragType dragType_;
197     Rect startPointRect_;
198     Rect startRectExceptFrame_;
199     Rect startRectExceptCorner_;
200 
MoveDragPropertyMoveDragProperty201     MoveDragProperty() : startPointPosX_(0), startPointPosY_(0), startPointerId_(0), targetDisplayId_(0),
202         sourceType_(0), startDragFlag_(false), startMoveFlag_(false), pointEventStarted_(false),
203         dragType_(DragType::DRAG_UNDEFINED)
204     {
205         startPointRect_ = {0, 0, 0, 0};
206         startRectExceptFrame_ = {0, 0, 0, 0};
207         startRectExceptCorner_ = {0, 0, 0, 0};
208     }
209 
MoveDragPropertyMoveDragProperty210     MoveDragProperty(int32_t startPointPosX, int32_t startPointPosY, int32_t startPointerId, int32_t targetDisplayId,
211         int32_t sourceType, bool startDragFlag, bool startMoveFlag, bool pointEventStarted, DragType dragType,
212         Rect startPointRect, Rect startRectExceptFrame, Rect startRectExceptCorner)
213         : startPointPosX_(startPointPosX), startPointPosY_(startPointPosY), startPointerId_(startPointerId),
214         targetDisplayId_(targetDisplayId), sourceType_(sourceType), startDragFlag_(startDragFlag),
215         startMoveFlag_(startMoveFlag), pointEventStarted_(pointEventStarted), dragType_(dragType),
216         startPointRect_(startPointRect), startRectExceptFrame_(startRectExceptFrame),
217         startRectExceptCorner_(startRectExceptCorner) {}
218 
MarshallingMoveDragProperty219     virtual bool Marshalling(Parcel& parcel) const override
220     {
221         if (!parcel.WriteInt32(startPointPosX_) || !parcel.WriteInt32(startPointPosY_) ||
222             !parcel.WriteInt32(startPointerId_) || !parcel.WriteInt32(targetDisplayId_) ||
223             !parcel.WriteInt32(sourceType_) || !parcel.WriteBool(startDragFlag_) ||
224             !parcel.WriteBool(startMoveFlag_) || !parcel.WriteBool(pointEventStarted_) ||
225             !parcel.WriteUint32(static_cast<uint32_t>(dragType_))) {
226             return false;
227         }
228 
229         if (!parcel.WriteInt32(startPointRect_.posX_) || !parcel.WriteInt32(startPointRect_.posY_) ||
230             !parcel.WriteUint32(startPointRect_.width_) || !parcel.WriteUint32(startPointRect_.height_)) {
231             return false;
232         }
233 
234         if (!parcel.WriteInt32(startRectExceptFrame_.posX_) || !parcel.WriteInt32(startRectExceptFrame_.posY_) ||
235             !parcel.WriteUint32(startRectExceptFrame_.width_) || !parcel.WriteUint32(startRectExceptFrame_.height_)) {
236             return false;
237         }
238 
239         if (!parcel.WriteInt32(startRectExceptCorner_.posX_) || !parcel.WriteInt32(startRectExceptCorner_.posY_) ||
240             !parcel.WriteUint32(startRectExceptCorner_.width_) || !parcel.WriteUint32(startRectExceptCorner_.height_)) {
241             return false;
242         }
243 
244         return true;
245     }
246 
UnmarshallingMoveDragProperty247     static MoveDragProperty* Unmarshalling(Parcel& parcel)
248     {
249         MoveDragProperty* info = new MoveDragProperty();
250         info->startPointPosX_ = parcel.ReadInt32();
251         info->startPointPosY_ = parcel.ReadInt32();
252         info->startPointerId_ = parcel.ReadInt32();
253         info->targetDisplayId_ = parcel.ReadInt32();
254         info->sourceType_ = parcel.ReadInt32();
255         info->startDragFlag_ = parcel.ReadBool();
256         info->startMoveFlag_ = parcel.ReadBool();
257         info->pointEventStarted_ = parcel.ReadBool();
258         info->dragType_ = static_cast<DragType>(parcel.ReadUint32());
259         Rect startPointRect = { parcel.ReadInt32(), parcel.ReadInt32(),
260                                 parcel.ReadUint32(), parcel.ReadUint32() };
261         Rect startRectExceptFrame = { parcel.ReadInt32(), parcel.ReadInt32(),
262                                       parcel.ReadUint32(), parcel.ReadUint32() };
263         Rect startRectExceptCorner = { parcel.ReadInt32(), parcel.ReadInt32(),
264                                        parcel.ReadUint32(), parcel.ReadUint32() };
265         info->startPointRect_ = startPointRect;
266         info->startRectExceptFrame_ = startRectExceptFrame;
267         info->startRectExceptCorner_ = startRectExceptCorner;
268         return info;
269     }
270 
CopyFromMoveDragProperty271     void CopyFrom(const sptr<MoveDragProperty>& property)
272     {
273         startPointPosX_ = property->startPointPosX_;
274         startPointPosY_ = property->startPointPosY_;
275         startPointerId_ = property->startPointerId_;
276         targetDisplayId_ = property->targetDisplayId_;
277         sourceType_ = property->sourceType_;
278         startDragFlag_ = property->startDragFlag_;
279         startMoveFlag_ = property->startMoveFlag_;
280         pointEventStarted_ = property->pointEventStarted_;
281         dragType_ = property->dragType_;
282         startPointRect_ = property->startPointRect_;
283         startRectExceptFrame_ = property->startRectExceptFrame_;
284         startRectExceptCorner_ = property->startRectExceptCorner_;
285     }
286 };
287 
288 struct AbilityInfo {
289     std::string bundleName_ = "";
290     std::string abilityName_ = "";
291     int32_t missionId_ = -1;
292 };
293 
294 namespace {
295     constexpr float DEFAULT_SPLIT_RATIO = 0.5;
296     constexpr float DEFAULT_ASPECT_RATIO = 0.67;
297     constexpr float DISPLAY_ZOOM_OFF_SCALE = 1.0;
298     constexpr float DISPLAY_ZOOM_MIN_SCALE = 2.0;
299     constexpr float DISPLAY_ZOOM_MAX_SCALE = 8.0;
300     constexpr int32_t IVALID_DIALOG_WINDOW_ID = -1;
301     constexpr uint32_t DIVIDER_WIDTH = 8;
302     constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 37;
303     constexpr uint32_t WINDOW_FRAME_WIDTH = 5;
304     constexpr uint32_t WINDOW_FRAME_CORNER_WIDTH = 16; // the frame width of corner
305     constexpr uint32_t HOTZONE_TOUCH = 20;
306     constexpr uint32_t HOTZONE_POINTER = 4;
307     constexpr uint32_t MIN_FLOATING_WIDTH = 320;
308     constexpr uint32_t MIN_FLOATING_HEIGHT = 240;
309     constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240;
310     constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320;
311     constexpr unsigned int WMS_WATCHDOG_CHECK_INTERVAL = 6; // actual check interval is 3000ms(6 * 500)
312     const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0};
313     const Rect DEFAULT_PLACE_HOLDER_RECT = {0, 0, 512, 512};
314     constexpr int32_t SNAPSHOT_TIMEOUT_MS = 300;
315     const std::unordered_set<WindowType> INPUT_WINDOW_TYPE_SKIPPED {
316         WindowType::WINDOW_TYPE_POINTER,
317         WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
318     };
319 }
320 }
321 }
322 #endif // OHOS_ROSEN_WM_COMMON_INNER_H