• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     bool isDragDelay { false };
77     std::map<std::string, int64_t> detailedSummarys;
78     std::map<std::string, std::vector<int32_t>> summaryFormat;
79     int32_t summaryVersion { 0 };
80     int64_t summaryTotalSize { -1 };
81     std::string appCallee;
82     std::string appCaller;
83 
84     bool operator == (const DragData &other) const
85     {
86         return shadowInfos == other.shadowInfos && buffer == other.buffer && udKey == other.udKey &&
87                filterInfo == other.filterInfo && extraInfo == other.extraInfo && sourceType == other.sourceType &&
88                dragNum == other.dragNum && pointerId == other.pointerId && displayX == other.displayX &&
89                displayY == other.displayY && displayId == other.displayId &&
90                hasCanceledAnimation == other.hasCanceledAnimation &&
91                hasCoordinateCorrected == other.hasCoordinateCorrected && summarys == other.summarys &&
92                appCallee == other.appCallee && appCaller == other.appCaller && isDragDelay == other.isDragDelay &&
93                detailedSummarys == other.detailedSummarys && summaryFormat == other.summaryFormat &&
94                summaryTotalSize == other.summaryTotalSize && summaryVersion == other.summaryVersion;
95     }
96 
97     bool operator != (const DragData &other) const
98     {
99         return !(*this == other);
100     }
101 };
102 
103 enum class DragState {
104     ERROR = 0,
105     START = 1,
106     STOP = 2,
107     CANCEL = 3,
108     MOTION_DRAGGING = 4
109 };
110 
111 enum class DragResult {
112     DRAG_SUCCESS = 0,
113     DRAG_FAIL = 1,
114     DRAG_CANCEL = 2,
115     DRAG_EXCEPTION = 3
116 };
117 
118 struct DragEventInfo {
119     std::string sourcePkgName;
120     std::string targetPkgName;
121 };
122 
123 enum class DragBehavior {
124     UNKNOWN = -1,
125     COPY = 0,
126     MOVE = 1
127 };
128 
129 struct DragDropResult {
130     DragResult result { DragResult::DRAG_FAIL };
131     bool hasCustomAnimation { false };
132     int32_t mainWindow { -1 };
133     DragBehavior dragBehavior { DragBehavior::UNKNOWN };
134 };
135 
136 struct DragAnimationData {
137     int32_t displayX { -1 };
138     int32_t displayY { -1 };
139     int32_t offsetX { -1 };
140     int32_t offsetY { -1 };
141     std::shared_ptr<OHOS::Media::PixelMap> pixelMap { nullptr };
142 };
143 
144 struct DragNotifyMsg {
145     int32_t displayX { -1 };
146     int32_t displayY { -1 };
147     int32_t targetPid { -1 };
148     DragResult result { DragResult::DRAG_FAIL };
149     DragBehavior dragBehavior { DragBehavior::UNKNOWN };
150 };
151 
152 struct DragItemStyle {
153     uint32_t foregroundColor { 0 };
154     int32_t radius { 0 };
155     uint32_t alpha { 0 };
156 
157     bool operator == (const DragItemStyle &style) const
158     {
159         return foregroundColor == style.foregroundColor &&
160                radius == style.radius && alpha == style.alpha;
161     }
162 
163     bool operator!=(const DragItemStyle &style) const
164     {
165         return !(*this == style);
166     }
167 };
168 
169 enum class PreviewType {
170     FOREGROUND_COLOR = 0,
171     OPACITY = 1,
172     RADIUS = 2,
173     SCALE = 3
174 };
175 
176 struct PreviewStyle {
177     std::vector<PreviewType> types;
178     uint32_t foregroundColor { 0 };
179     int32_t opacity { -1 };
180     float radius { -1.0F };
181     float scale { -1.0F };
182 
183     bool operator == (const PreviewStyle &other) const
184     {
185         return types == other.types && foregroundColor == other.foregroundColor && opacity == other.opacity &&
186                radius == other.radius && fabsf(scale - other.scale) < EPSILON;
187     }
188 
189     bool operator != (const PreviewStyle &other) const
190     {
191         return !(*this == other);
192     }
193 };
194 
195 struct ShadowOffset {
196     int32_t offsetX { -1 };
197     int32_t offsetY { -1 };
198     int32_t width { -1 };
199     int32_t height { -1 };
200 
201     bool operator == (const ShadowOffset &other) const
202     {
203         return offsetX == other.offsetX && offsetY == other.offsetY &&
204                width == other.width && height == other.height;
205     }
206 
207     bool operator != (const ShadowOffset &other) const
208     {
209         return !(*this == other);
210     }
211 };
212 
213 struct PreviewAnimation {
214     int32_t duration { -1 };
215     std::string curveName;
216     std::vector<float> curve;
217 };
218 
219 enum class DragCursorStyle {
220     DEFAULT = 0,
221     FORBIDDEN,
222     COPY,
223     MOVE
224 };
225 
226 enum class DragAction {
227     INVALID = -1,
228     MOVE = 0,
229     COPY = 1
230 };
231 
232 struct DragBundleInfo {
233     std::string bundleName;
234     bool isCrossDevice { false };
235 };
236 
237 struct DragRadarPackageName {
238     std::string packageName;
239     std::string appCallee;
240     std::string appCaller;
241     std::string peerNetId;
242     int32_t dragNum { -1 };
243 };
244 
245 struct DragSummaryInfo {
246     std::map<std::string, int64_t> summarys;
247     std::map<std::string, int64_t> detailedSummarys;
248     std::map<std::string, std::vector<int32_t>> summaryFormat;
249     int32_t version { 0 };
250     int64_t totalSize { -1 };
251 };
252 } // namespace DeviceStatus
253 } // namespace Msdp
254 } // namespace OHOS
255 #endif // DRAG_DATA_H