• 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 KeyboardAnimationCurve;
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     USER_SWITCH,
40     ABILITY_CALL,
41 };
42 
43 enum class WindowUpdateReason : uint32_t {
44     NEED_SWITCH_CASCADE_BASE,
45     UPDATE_ALL = NEED_SWITCH_CASCADE_BASE,
46     UPDATE_MODE,
47     UPDATE_RECT,
48     UPDATE_FLAGS,
49     UPDATE_TYPE,
50     UPDATE_ASPECT_RATIO,
51     NEED_SWITCH_CASCADE_END,
52     UPDATE_OTHER_PROPS,
53     UPDATE_TRANSFORM,
54 };
55 
56 enum class AvoidPosType : uint32_t {
57     AVOID_POS_LEFT,
58     AVOID_POS_TOP,
59     AVOID_POS_RIGHT,
60     AVOID_POS_BOTTOM,
61     AVOID_POS_UNKNOWN
62 };
63 
64 enum class WindowRootNodeType : uint32_t {
65     APP_WINDOW_NODE,
66     ABOVE_WINDOW_NODE,
67     BELOW_WINDOW_NODE,
68 };
69 
70 enum class PropertyChangeAction : uint32_t {
71     ACTION_UPDATE_RECT = 1,
72     ACTION_UPDATE_MODE = 1 << 1,
73     ACTION_UPDATE_FLAGS = 1 << 2,
74     ACTION_UPDATE_OTHER_PROPS = 1 << 3,
75     ACTION_UPDATE_FOCUSABLE = 1 << 4,
76     ACTION_UPDATE_TOUCHABLE = 1 << 5,
77     ACTION_UPDATE_CALLING_WINDOW = 1 << 6,
78     ACTION_UPDATE_ORIENTATION = 1 << 7,
79     ACTION_UPDATE_TURN_SCREEN_ON = 1 << 8,
80     ACTION_UPDATE_KEEP_SCREEN_ON = 1 << 9,
81     ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10,
82     ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11,
83     ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12,
84     ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13,
85     ACTION_UPDATE_ANIMATION_FLAG = 1 << 14,
86     ACTION_UPDATE_PRIVACY_MODE = 1 << 15,
87     ACTION_UPDATE_ASPECT_RATIO = 1 << 16,
88     ACTION_UPDATE_MAXIMIZE_STATE = 1 << 17,
89     ACTION_UPDATE_SYSTEM_PRIVACY_MODE = 1 << 18,
90     ACTION_UPDATE_SNAPSHOT_SKIP = 1 << 19,
91     ACTION_UPDATE_TEXTFIELD_AVOID_INFO = 1 << 20,
92 };
93 
94 struct ModeChangeHotZonesConfig {
95     bool isModeChangeHotZoneConfigured_;
96     uint32_t fullscreenRange_;
97     uint32_t primaryRange_;
98     uint32_t secondaryRange_;
99 };
100 
101 struct SystemConfig : public Parcelable {
102     bool isSystemDecorEnable_ = true;
103     uint32_t decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
104     bool isStretchable_ = false;
105     WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
106     KeyboardAnimationCurve animationIn_;
107     KeyboardAnimationCurve animationOut_;
108     WindowUIType windowUIType_ = WindowUIType::INVALID_WINDOW;
109     bool supportTypeFloatWindow_ = false;
110 
MarshallingSystemConfig111     virtual bool Marshalling(Parcel& parcel) const override
112     {
113         if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_) ||
114             !parcel.WriteUint32(decorWindowModeSupportType_)) {
115             return false;
116         }
117 
118         if (!parcel.WriteUint32(static_cast<uint32_t>(defaultWindowMode_)) ||
119             !parcel.WriteParcelable(&animationIn_) || !parcel.WriteParcelable(&animationOut_)) {
120             return false;
121         }
122 
123         if (!parcel.WriteUint8(static_cast<uint8_t>(windowUIType_))) {
124             return false;
125         }
126 
127         if (!parcel.WriteBool(supportTypeFloatWindow_)) {
128             return false;
129         }
130 
131         return true;
132     }
133 
UnmarshallingSystemConfig134     static SystemConfig* Unmarshalling(Parcel& parcel)
135     {
136         SystemConfig* config = new SystemConfig();
137         config->isSystemDecorEnable_ = parcel.ReadBool();
138         config->isStretchable_ = parcel.ReadBool();
139         config->decorWindowModeSupportType_ = parcel.ReadUint32();
140         config->defaultWindowMode_ = static_cast<WindowMode>(parcel.ReadUint32());
141         sptr<KeyboardAnimationCurve> animationIn = parcel.ReadParcelable<KeyboardAnimationCurve>();
142         if (animationIn == nullptr) {
143             delete config;
144             return nullptr;
145         }
146         config->animationIn_ = *animationIn;
147         sptr<KeyboardAnimationCurve> animationOut = parcel.ReadParcelable<KeyboardAnimationCurve>();
148         if (animationOut == nullptr) {
149             delete config;
150             return nullptr;
151         }
152         config->animationOut_ = *animationOut;
153         config->windowUIType_ = static_cast<WindowUIType>(parcel.ReadUint8());
154         config->supportTypeFloatWindow_ = parcel.ReadBool();
155         return config;
156     }
157 
IsPhoneWindowSystemConfig158     bool IsPhoneWindow() const
159     {
160         return windowUIType_ == WindowUIType::PHONE_WINDOW;
161     }
162 
IsPcWindowSystemConfig163     bool IsPcWindow() const
164     {
165         return windowUIType_ == WindowUIType::PC_WINDOW;
166     }
167 
IsPadWindowSystemConfig168     bool IsPadWindow() const
169     {
170         return windowUIType_ == WindowUIType::PAD_WINDOW;
171     }
172 };
173 
174 struct ModeChangeHotZones {
175     Rect fullscreen_;
176     Rect primary_;
177     Rect secondary_;
178 };
179 
180 struct SplitRatioConfig {
181     // when divider reaches this position, the top/left window will hide. Valid range: (0, 0.5)
182     float exitSplitStartRatio;
183     // when divider reaches this position, the bottom/right window will hide. Valid range: (0.5, 1)
184     float exitSplitEndRatio;
185     std::vector<float> splitRatios;
186 };
187 
188 enum class DragType : uint32_t {
189     DRAG_UNDEFINED,
190     DRAG_LEFT_OR_RIGHT,
191     DRAG_BOTTOM_OR_TOP,
192     DRAG_LEFT_TOP_CORNER,
193     DRAG_RIGHT_TOP_CORNER,
194 };
195 
196 enum class TraceTaskId : int32_t {
197     STARTING_WINDOW = 0,
198     REMOTE_ANIMATION,
199     CONNECT_EXTENSION,
200     REMOTE_ANIMATION_HOME,
201     START_WINDOW_ANIMATION,
202 };
203 
204 enum class PersistentStorageType : uint32_t {
205     UKNOWN = 0,
206     ASPECT_RATIO,
207     MAXIMIZE_STATE,
208 };
209 
210 struct MoveDragProperty : public Parcelable {
211     int32_t startPointPosX_;
212     int32_t startPointPosY_;
213     int32_t startPointerId_;
214     int32_t targetDisplayId_;
215     int32_t sourceType_;
216     bool startDragFlag_;
217     bool startMoveFlag_;
218     bool pointEventStarted_;
219     DragType dragType_;
220     Rect startPointRect_;
221     Rect startRectExceptFrame_;
222     Rect startRectExceptCorner_;
223 
MoveDragPropertyMoveDragProperty224     MoveDragProperty() : startPointPosX_(0), startPointPosY_(0), startPointerId_(0), targetDisplayId_(0),
225         sourceType_(0), startDragFlag_(false), startMoveFlag_(false), pointEventStarted_(false),
226         dragType_(DragType::DRAG_UNDEFINED)
227     {
228         startPointRect_ = {0, 0, 0, 0};
229         startRectExceptFrame_ = {0, 0, 0, 0};
230         startRectExceptCorner_ = {0, 0, 0, 0};
231     }
232 
MoveDragPropertyMoveDragProperty233     MoveDragProperty(int32_t startPointPosX, int32_t startPointPosY, int32_t startPointerId, int32_t targetDisplayId,
234         int32_t sourceType, bool startDragFlag, bool startMoveFlag, bool pointEventStarted, DragType dragType,
235         Rect startPointRect, Rect startRectExceptFrame, Rect startRectExceptCorner)
236         : startPointPosX_(startPointPosX), startPointPosY_(startPointPosY), startPointerId_(startPointerId),
237         targetDisplayId_(targetDisplayId), sourceType_(sourceType), startDragFlag_(startDragFlag),
238         startMoveFlag_(startMoveFlag), pointEventStarted_(pointEventStarted), dragType_(dragType),
239         startPointRect_(startPointRect), startRectExceptFrame_(startRectExceptFrame),
240         startRectExceptCorner_(startRectExceptCorner) {}
241 
MarshallingMoveDragProperty242     virtual bool Marshalling(Parcel& parcel) const override
243     {
244         if (!parcel.WriteInt32(startPointPosX_) || !parcel.WriteInt32(startPointPosY_) ||
245             !parcel.WriteInt32(startPointerId_) || !parcel.WriteInt32(targetDisplayId_) ||
246             !parcel.WriteInt32(sourceType_) || !parcel.WriteBool(startDragFlag_) ||
247             !parcel.WriteBool(startMoveFlag_) || !parcel.WriteBool(pointEventStarted_) ||
248             !parcel.WriteUint32(static_cast<uint32_t>(dragType_))) {
249             return false;
250         }
251 
252         if (!parcel.WriteInt32(startPointRect_.posX_) || !parcel.WriteInt32(startPointRect_.posY_) ||
253             !parcel.WriteUint32(startPointRect_.width_) || !parcel.WriteUint32(startPointRect_.height_)) {
254             return false;
255         }
256 
257         if (!parcel.WriteInt32(startRectExceptFrame_.posX_) || !parcel.WriteInt32(startRectExceptFrame_.posY_) ||
258             !parcel.WriteUint32(startRectExceptFrame_.width_) || !parcel.WriteUint32(startRectExceptFrame_.height_)) {
259             return false;
260         }
261 
262         if (!parcel.WriteInt32(startRectExceptCorner_.posX_) || !parcel.WriteInt32(startRectExceptCorner_.posY_) ||
263             !parcel.WriteUint32(startRectExceptCorner_.width_) || !parcel.WriteUint32(startRectExceptCorner_.height_)) {
264             return false;
265         }
266 
267         return true;
268     }
269 
UnmarshallingMoveDragProperty270     static MoveDragProperty* Unmarshalling(Parcel& parcel)
271     {
272         MoveDragProperty* info = new MoveDragProperty();
273         info->startPointPosX_ = parcel.ReadInt32();
274         info->startPointPosY_ = parcel.ReadInt32();
275         info->startPointerId_ = parcel.ReadInt32();
276         info->targetDisplayId_ = parcel.ReadInt32();
277         info->sourceType_ = parcel.ReadInt32();
278         info->startDragFlag_ = parcel.ReadBool();
279         info->startMoveFlag_ = parcel.ReadBool();
280         info->pointEventStarted_ = parcel.ReadBool();
281         info->dragType_ = static_cast<DragType>(parcel.ReadUint32());
282         Rect startPointRect = { parcel.ReadInt32(), parcel.ReadInt32(),
283                                 parcel.ReadUint32(), parcel.ReadUint32() };
284         Rect startRectExceptFrame = { parcel.ReadInt32(), parcel.ReadInt32(),
285                                       parcel.ReadUint32(), parcel.ReadUint32() };
286         Rect startRectExceptCorner = { parcel.ReadInt32(), parcel.ReadInt32(),
287                                        parcel.ReadUint32(), parcel.ReadUint32() };
288         info->startPointRect_ = startPointRect;
289         info->startRectExceptFrame_ = startRectExceptFrame;
290         info->startRectExceptCorner_ = startRectExceptCorner;
291         return info;
292     }
293 
CopyFromMoveDragProperty294     void CopyFrom(const sptr<MoveDragProperty>& property)
295     {
296         startPointPosX_ = property->startPointPosX_;
297         startPointPosY_ = property->startPointPosY_;
298         startPointerId_ = property->startPointerId_;
299         targetDisplayId_ = property->targetDisplayId_;
300         sourceType_ = property->sourceType_;
301         startDragFlag_ = property->startDragFlag_;
302         startMoveFlag_ = property->startMoveFlag_;
303         pointEventStarted_ = property->pointEventStarted_;
304         dragType_ = property->dragType_;
305         startPointRect_ = property->startPointRect_;
306         startRectExceptFrame_ = property->startRectExceptFrame_;
307         startRectExceptCorner_ = property->startRectExceptCorner_;
308     }
309 };
310 
311 struct AbilityInfo {
312     std::string bundleName_ = "";
313     std::string abilityName_ = "";
314     int32_t missionId_ = -1;
315 };
316 
317 namespace {
318     constexpr float DEFAULT_SPLIT_RATIO = 0.5;
319     constexpr float DEFAULT_ASPECT_RATIO = 0.67;
320     constexpr float DISPLAY_ZOOM_OFF_SCALE = 1.0;
321     constexpr float DISPLAY_ZOOM_MIN_SCALE = 2.0;
322     constexpr float DISPLAY_ZOOM_MAX_SCALE = 8.0;
323     constexpr int32_t IVALID_DIALOG_WINDOW_ID = -1;
324     constexpr uint32_t DIVIDER_WIDTH = 8;
325     constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48;
326     constexpr uint32_t WINDOW_FRAME_WIDTH = 5;
327     constexpr uint32_t WINDOW_FRAME_CORNER_WIDTH = 16; // the frame width of corner
328     constexpr uint32_t HOTZONE_TOUCH = 24;
329     constexpr uint32_t HOTZONE_POINTER = 4;
330     constexpr uint32_t MIN_FLOATING_WIDTH = 320;
331     constexpr uint32_t MIN_FLOATING_HEIGHT = 240;
332     constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240;
333     constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320;
334     constexpr unsigned int WMS_WATCHDOG_CHECK_INTERVAL = 6; // actual check interval is 3000ms(6 * 500)
335     const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0};
336     const Rect DEFAULT_PLACE_HOLDER_RECT = {0, 0, 512, 512};
337     constexpr int32_t SNAPSHOT_TIMEOUT_MS = 300;
338     const std::unordered_set<WindowType> INPUT_WINDOW_TYPE_SKIPPED {
339         WindowType::WINDOW_TYPE_POINTER,
340         WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
341     };
342 }
343 }
344 }
345 #endif // OHOS_ROSEN_WM_COMMON_INNER_H