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