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