• 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     ACTION_UPDATE_SYSTEM_PRIVACY_MODE = 1 << 18,
88     ACTION_UPDATE_SNAPSHOT_SKIP = 1 << 19,
89 };
90 
91 struct ModeChangeHotZonesConfig {
92     bool isModeChangeHotZoneConfigured_;
93     uint32_t fullscreenRange_;
94     uint32_t primaryRange_;
95     uint32_t secondaryRange_;
96 };
97 
98 struct SystemConfig : public Parcelable {
99     bool isSystemDecorEnable_ = true;
100     uint32_t decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
101     bool isStretchable_ = false;
102     WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
103     KeyboardAnimationConfig keyboardAnimationConfig_;
104 
MarshallingSystemConfig105     virtual bool Marshalling(Parcel& parcel) const override
106     {
107         if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_) ||
108             !parcel.WriteUint32(decorModeSupportInfo_)) {
109             return false;
110         }
111 
112         if (!parcel.WriteUint32(static_cast<uint32_t>(defaultWindowMode_)) ||
113             !parcel.WriteParcelable(&keyboardAnimationConfig_)) {
114             return false;
115         }
116 
117         return true;
118     }
119 
UnmarshallingSystemConfig120     static SystemConfig* Unmarshalling(Parcel& parcel)
121     {
122         SystemConfig* config = new SystemConfig();
123         config->isSystemDecorEnable_ = parcel.ReadBool();
124         config->isStretchable_ = parcel.ReadBool();
125         config->decorModeSupportInfo_ = parcel.ReadUint32();
126         config->defaultWindowMode_ = static_cast<WindowMode>(parcel.ReadUint32());
127         sptr<KeyboardAnimationConfig> keyboardConfig = parcel.ReadParcelable<KeyboardAnimationConfig>();
128         config->keyboardAnimationConfig_ = *keyboardConfig;
129         return config;
130     }
131 };
132 
133 struct WindowSizeLimits {
134     uint32_t maxWidth_;
135     uint32_t maxHeight_;
136     uint32_t minWidth_;
137     uint32_t minHeight_;
138     float maxRatio_;
139     float minRatio_;
WindowSizeLimitsWindowSizeLimits140     WindowSizeLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX),
141         minWidth_(0),  minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {}
WindowSizeLimitsWindowSizeLimits142     WindowSizeLimits(uint32_t maxWidth, uint32_t maxHeight,
143         uint32_t minWidth, uint32_t minHeight, float maxRatio, float minRatio)
144         : maxWidth_(maxWidth), maxHeight_(maxHeight),
145         minWidth_(minWidth), minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {}
146 
IsEmptyWindowSizeLimits147     bool IsEmpty() const
148     {
149         return (maxWidth_ == 0 || minWidth_ == 0 || maxHeight_ == 0 || minHeight_ == 0);
150     }
151 };
152 
153 struct ModeChangeHotZones {
154     Rect fullscreen_;
155     Rect primary_;
156     Rect secondary_;
157 };
158 
159 struct SplitRatioConfig {
160     // when divider reaches this position, the top/left window will hide. Valid range: (0, 0.5)
161     float exitSplitStartRatio;
162     // when divider reaches this position, the bottom/right window will hide. Valid range: (0.5, 1)
163     float exitSplitEndRatio;
164     std::vector<float> splitRatios;
165 };
166 
167 enum class DragType : uint32_t {
168     DRAG_UNDEFINED,
169     DRAG_LEFT_OR_RIGHT,
170     DRAG_BOTTOM_OR_TOP,
171     DRAG_LEFT_TOP_CORNER,
172     DRAG_RIGHT_TOP_CORNER,
173 };
174 
175 enum class TraceTaskId : int32_t {
176     STARTING_WINDOW = 0,
177     REMOTE_ANIMATION,
178     CONNECT_EXTENSION,
179     REMOTE_ANIMATION_HOME,
180     START_WINDOW_ANIMATION,
181 };
182 
183 enum class PersistentStorageType : uint32_t {
184     UKNOWN = 0,
185     ASPECT_RATIO,
186     MAXIMIZE_STATE,
187 };
188 
189 struct MoveDragProperty : public Parcelable {
190     int32_t startPointPosX_;
191     int32_t startPointPosY_;
192     int32_t startPointerId_;
193     int32_t targetDisplayId_;
194     int32_t sourceType_;
195     bool startDragFlag_;
196     bool startMoveFlag_;
197     bool pointEventStarted_;
198     DragType dragType_;
199     Rect startPointRect_;
200     Rect startRectExceptFrame_;
201     Rect startRectExceptCorner_;
202 
MoveDragPropertyMoveDragProperty203     MoveDragProperty() : startPointPosX_(0), startPointPosY_(0), startPointerId_(0), targetDisplayId_(0),
204         sourceType_(0), startDragFlag_(false), startMoveFlag_(false), pointEventStarted_(false),
205         dragType_(DragType::DRAG_UNDEFINED)
206     {
207         startPointRect_ = {0, 0, 0, 0};
208         startRectExceptFrame_ = {0, 0, 0, 0};
209         startRectExceptCorner_ = {0, 0, 0, 0};
210     }
211 
MoveDragPropertyMoveDragProperty212     MoveDragProperty(int32_t startPointPosX, int32_t startPointPosY, int32_t startPointerId, int32_t targetDisplayId,
213         int32_t sourceType, bool startDragFlag, bool startMoveFlag, bool pointEventStarted, DragType dragType,
214         Rect startPointRect, Rect startRectExceptFrame, Rect startRectExceptCorner)
215         : startPointPosX_(startPointPosX), startPointPosY_(startPointPosY), startPointerId_(startPointerId),
216         targetDisplayId_(targetDisplayId), sourceType_(sourceType), startDragFlag_(startDragFlag),
217         startMoveFlag_(startMoveFlag), pointEventStarted_(pointEventStarted), dragType_(dragType),
218         startPointRect_(startPointRect), startRectExceptFrame_(startRectExceptFrame),
219         startRectExceptCorner_(startRectExceptCorner) {}
220 
MarshallingMoveDragProperty221     virtual bool Marshalling(Parcel& parcel) const override
222     {
223         if (!parcel.WriteInt32(startPointPosX_) || !parcel.WriteInt32(startPointPosY_) ||
224             !parcel.WriteInt32(startPointerId_) || !parcel.WriteInt32(targetDisplayId_) ||
225             !parcel.WriteInt32(sourceType_) || !parcel.WriteBool(startDragFlag_) ||
226             !parcel.WriteBool(startMoveFlag_) || !parcel.WriteBool(pointEventStarted_) ||
227             !parcel.WriteUint32(static_cast<uint32_t>(dragType_))) {
228             return false;
229         }
230 
231         if (!parcel.WriteInt32(startPointRect_.posX_) || !parcel.WriteInt32(startPointRect_.posY_) ||
232             !parcel.WriteUint32(startPointRect_.width_) || !parcel.WriteUint32(startPointRect_.height_)) {
233             return false;
234         }
235 
236         if (!parcel.WriteInt32(startRectExceptFrame_.posX_) || !parcel.WriteInt32(startRectExceptFrame_.posY_) ||
237             !parcel.WriteUint32(startRectExceptFrame_.width_) || !parcel.WriteUint32(startRectExceptFrame_.height_)) {
238             return false;
239         }
240 
241         if (!parcel.WriteInt32(startRectExceptCorner_.posX_) || !parcel.WriteInt32(startRectExceptCorner_.posY_) ||
242             !parcel.WriteUint32(startRectExceptCorner_.width_) || !parcel.WriteUint32(startRectExceptCorner_.height_)) {
243             return false;
244         }
245 
246         return true;
247     }
248 
UnmarshallingMoveDragProperty249     static MoveDragProperty* Unmarshalling(Parcel& parcel)
250     {
251         MoveDragProperty* info = new MoveDragProperty();
252         info->startPointPosX_ = parcel.ReadInt32();
253         info->startPointPosY_ = parcel.ReadInt32();
254         info->startPointerId_ = parcel.ReadInt32();
255         info->targetDisplayId_ = parcel.ReadInt32();
256         info->sourceType_ = parcel.ReadInt32();
257         info->startDragFlag_ = parcel.ReadBool();
258         info->startMoveFlag_ = parcel.ReadBool();
259         info->pointEventStarted_ = parcel.ReadBool();
260         info->dragType_ = static_cast<DragType>(parcel.ReadUint32());
261         Rect startPointRect = { parcel.ReadInt32(), parcel.ReadInt32(),
262                                 parcel.ReadUint32(), parcel.ReadUint32() };
263         Rect startRectExceptFrame = { parcel.ReadInt32(), parcel.ReadInt32(),
264                                       parcel.ReadUint32(), parcel.ReadUint32() };
265         Rect startRectExceptCorner = { parcel.ReadInt32(), parcel.ReadInt32(),
266                                        parcel.ReadUint32(), parcel.ReadUint32() };
267         info->startPointRect_ = startPointRect;
268         info->startRectExceptFrame_ = startRectExceptFrame;
269         info->startRectExceptCorner_ = startRectExceptCorner;
270         return info;
271     }
272 
CopyFromMoveDragProperty273     void CopyFrom(const sptr<MoveDragProperty>& property)
274     {
275         startPointPosX_ = property->startPointPosX_;
276         startPointPosY_ = property->startPointPosY_;
277         startPointerId_ = property->startPointerId_;
278         targetDisplayId_ = property->targetDisplayId_;
279         sourceType_ = property->sourceType_;
280         startDragFlag_ = property->startDragFlag_;
281         startMoveFlag_ = property->startMoveFlag_;
282         pointEventStarted_ = property->pointEventStarted_;
283         dragType_ = property->dragType_;
284         startPointRect_ = property->startPointRect_;
285         startRectExceptFrame_ = property->startRectExceptFrame_;
286         startRectExceptCorner_ = property->startRectExceptCorner_;
287     }
288 };
289 
290 struct AbilityInfo {
291     std::string bundleName_ = "";
292     std::string abilityName_ = "";
293     int32_t missionId_ = -1;
294 };
295 
296 namespace {
297     constexpr float DEFAULT_SPLIT_RATIO = 0.5;
298     constexpr float DEFAULT_ASPECT_RATIO = 0.67;
299     constexpr float DISPLAY_ZOOM_OFF_SCALE = 1.0;
300     constexpr float DISPLAY_ZOOM_MIN_SCALE = 2.0;
301     constexpr float DISPLAY_ZOOM_MAX_SCALE = 8.0;
302     constexpr int32_t IVALID_DIALOG_WINDOW_ID = -1;
303     constexpr uint32_t DIVIDER_WIDTH = 8;
304     constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48;
305     constexpr uint32_t WINDOW_FRAME_WIDTH = 5;
306     constexpr uint32_t WINDOW_FRAME_CORNER_WIDTH = 16; // the frame width of corner
307     constexpr uint32_t HOTZONE_TOUCH = 20;
308     constexpr uint32_t HOTZONE_POINTER = 4;
309     constexpr uint32_t MIN_FLOATING_WIDTH = 320;
310     constexpr uint32_t MIN_FLOATING_HEIGHT = 240;
311     constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240;
312     constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320;
313     constexpr unsigned int WMS_WATCHDOG_CHECK_INTERVAL = 6; // actual check interval is 3000ms(6 * 500)
314     const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0};
315     const Rect DEFAULT_PLACE_HOLDER_RECT = {0, 0, 512, 512};
316     constexpr int32_t SNAPSHOT_TIMEOUT_MS = 300;
317     const std::unordered_set<WindowType> INPUT_WINDOW_TYPE_SKIPPED {
318         WindowType::WINDOW_TYPE_POINTER,
319         WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
320     };
321 }
322 }
323 }
324 #endif // OHOS_ROSEN_WM_COMMON_INNER_H