1 /*
2  * Copyright (c) 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 DRAG_DATA_H
17 #define DRAG_DATA_H
18 
19 #include <cmath>
20 #include <functional>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "pixel_map.h"
27 
28 namespace OHOS {
29 namespace Msdp {
30 namespace DeviceStatus {
31 constexpr size_t MAX_BUFFER_SIZE { 512 };
32 constexpr size_t MAX_UDKEY_SIZE { 100 };
33 constexpr size_t MAX_SUMMARY_SIZE { 200 };
34 constexpr int32_t SHADOW_NUM_LIMIT { 3 };
35 constexpr float EPSILON { 1E-6 };
36 constexpr int32_t MAX_ANIMATION_DURATION_MS { 1000 };
37 
38 struct ShadowInfo {
39     std::shared_ptr<OHOS::Media::PixelMap> pixelMap { nullptr };
40     int32_t x { -1 };
41     int32_t y { -1 };
42 
43     bool operator == (const ShadowInfo &other) const
44     {
45         if (pixelMap == nullptr && other.pixelMap == nullptr) {
46             return x == other.x && y == other.y;
47         }
48         if (pixelMap == nullptr || other.pixelMap == nullptr) {
49             return false;
50         }
51         return pixelMap->IsSameImage(*(other.pixelMap)) && x == other.x && y == other.y;
52     }
53 
54     bool operator != (const ShadowInfo &other) const
55     {
56         return !(*this == other);
57     }
58 };
59 
60 struct DragData {
61     std::vector<ShadowInfo> shadowInfos;
62     std::vector<uint8_t> buffer;
63     std::string udKey;
64     std::string extraInfo;
65     std::string filterInfo;
66     int32_t sourceType { -1 };
67     int32_t dragNum { -1 };
68     int32_t pointerId { -1 };
69     int32_t displayX { -1 };
70     int32_t displayY { -1 };
71     int32_t displayId { -1 };
72     int32_t mainWindow { -1 };
73     bool hasCanceledAnimation { false };
74     bool hasCoordinateCorrected { false };
75     std::map<std::string, int64_t> summarys;
76 
77     bool operator == (const DragData &other) const
78     {
79         return shadowInfos == other.shadowInfos && buffer == other.buffer && udKey == other.udKey &&
80                filterInfo == other.filterInfo && extraInfo == other.extraInfo && sourceType == other.sourceType &&
81                dragNum == other.dragNum && pointerId == other.pointerId && displayX == other.displayX &&
82                displayY == other.displayY && displayId == other.displayId &&
83                hasCanceledAnimation == other.hasCanceledAnimation &&
84                hasCoordinateCorrected == other.hasCoordinateCorrected && summarys == other.summarys;
85     }
86 
87     bool operator != (const DragData &other) const
88     {
89         return !(*this == other);
90     }
91 };
92 
93 enum class DragState {
94     ERROR = 0,
95     START = 1,
96     STOP = 2,
97     CANCEL = 3,
98     MOTION_DRAGGING = 4
99 };
100 
101 enum class DragResult {
102     DRAG_SUCCESS = 0,
103     DRAG_FAIL = 1,
104     DRAG_CANCEL = 2,
105     DRAG_EXCEPTION = 3
106 };
107 
108 struct DragEventInfo {
109     std::string sourcePkgName;
110     std::string targetPkgName;
111 };
112 
113 enum class DragBehavior {
114     UNKNOWN = -1,
115     COPY = 0,
116     MOVE = 1
117 };
118 
119 struct DragDropResult {
120     DragResult result { DragResult::DRAG_FAIL };
121     bool hasCustomAnimation { false };
122     int32_t mainWindow { -1 };
123     DragBehavior dragBehavior { DragBehavior::UNKNOWN };
124 };
125 
126 struct DragAnimationData {
127     int32_t displayX { -1 };
128     int32_t displayY { -1 };
129     int32_t offsetX { -1 };
130     int32_t offsetY { -1 };
131     std::shared_ptr<OHOS::Media::PixelMap> pixelMap { nullptr };
132 };
133 
134 struct DragNotifyMsg {
135     int32_t displayX { -1 };
136     int32_t displayY { -1 };
137     int32_t targetPid { -1 };
138     DragResult result { DragResult::DRAG_FAIL };
139     DragBehavior dragBehavior { DragBehavior::UNKNOWN };
140 };
141 
142 struct DragItemStyle {
143     uint32_t foregroundColor { 0 };
144     int32_t radius { 0 };
145     uint32_t alpha { 0 };
146 
147     bool operator == (const DragItemStyle &style) const
148     {
149         return foregroundColor == style.foregroundColor &&
150                radius == style.radius && alpha == style.alpha;
151     }
152 
153     bool operator!=(const DragItemStyle &style) const
154     {
155         return !(*this == style);
156     }
157 };
158 
159 enum class PreviewType {
160     FOREGROUND_COLOR = 0,
161     OPACITY = 1,
162     RADIUS = 2,
163     SCALE = 3
164 };
165 
166 struct PreviewStyle {
167     std::vector<PreviewType> types;
168     uint32_t foregroundColor { 0 };
169     int32_t opacity { -1 };
170     float radius { -1.0F };
171     float scale { -1.0F };
172 
173     bool operator == (const PreviewStyle &other) const
174     {
175         return types == other.types && foregroundColor == other.foregroundColor && opacity == other.opacity &&
176                radius == other.radius && fabsf(scale - other.scale) < EPSILON;
177     }
178 
179     bool operator != (const PreviewStyle &other) const
180     {
181         return !(*this == other);
182     }
183 };
184 
185 struct ShadowOffset {
186     int32_t offsetX { -1 };
187     int32_t offsetY { -1 };
188     int32_t width { -1 };
189     int32_t height { -1 };
190 
191     bool operator == (const ShadowOffset &other) const
192     {
193         return offsetX == other.offsetX && offsetY == other.offsetY &&
194                width == other.width && height == other.height;
195     }
196 
197     bool operator != (const ShadowOffset &other) const
198     {
199         return !(*this == other);
200     }
201 };
202 
203 struct PreviewAnimation {
204     int32_t duration { -1 };
205     std::string curveName;
206     std::vector<float> curve;
207 };
208 
209 enum class DragCursorStyle {
210     DEFAULT = 0,
211     FORBIDDEN,
212     COPY,
213     MOVE
214 };
215 
216 enum class DragAction {
217     INVALID = -1,
218     MOVE = 0,
219     COPY = 1
220 };
221 } // namespace DeviceStatus
222 } // namespace Msdp
223 } // namespace OHOS
224 #endif // DRAG_DATA_H