• 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     bool hasCanceledAnimation { false };
73     bool hasCoordinateCorrected { false };
74     std::map<std::string, int64_t> summarys;
75 
76     bool operator == (const DragData &other) const
77     {
78         return shadowInfos == other.shadowInfos && buffer == other.buffer && udKey == other.udKey &&
79                filterInfo == other.filterInfo && extraInfo == other.extraInfo && sourceType == other.sourceType &&
80                dragNum == other.dragNum && pointerId == other.pointerId && displayX == other.displayX &&
81                displayY == other.displayY && displayId == other.displayId &&
82                hasCanceledAnimation == other.hasCanceledAnimation && summarys == other.summarys;
83     }
84 
85     bool operator != (const DragData &other) const
86     {
87         return !(*this == other);
88     }
89 };
90 
91 enum class DragState {
92     ERROR = 0,
93     START = 1,
94     STOP = 2,
95     CANCEL = 3,
96     MOTION_DRAGGING = 4
97 };
98 
99 enum class DragResult {
100     DRAG_SUCCESS = 0,
101     DRAG_FAIL = 1,
102     DRAG_CANCEL = 2,
103     DRAG_EXCEPTION = 3
104 };
105 
106 struct DragDropResult {
107     DragResult result { DragResult::DRAG_FAIL };
108     bool hasCustomAnimation { false };
109     int32_t windowId { -1 };
110 };
111 
112 struct DragAnimationData {
113     int32_t displayX { -1 };
114     int32_t displayY { -1 };
115     int32_t offsetX { -1 };
116     int32_t offsetY { -1 };
117     std::shared_ptr<OHOS::Media::PixelMap> pixelMap { nullptr };
118 };
119 
120 struct DragNotifyMsg {
121     int32_t displayX { -1 };
122     int32_t displayY { -1 };
123     int32_t targetPid { -1 };
124     DragResult result { DragResult::DRAG_FAIL };
125 };
126 
127 enum class PreviewType {
128     FOREGROUND_COLOR = 0,
129     OPACITY = 1,
130     RADIUS = 2,
131     SCALE = 3
132 };
133 
134 struct PreviewStyle {
135     std::vector<PreviewType> types;
136     uint32_t foregroundColor { 0 };
137     int32_t opacity { -1 };
138     float radius { -1.0F };
139     float scale { -1.0F };
140 
141     bool operator == (const PreviewStyle &other) const
142     {
143         return types == other.types && foregroundColor == other.foregroundColor && opacity == other.opacity &&
144                radius == other.radius && fabsf(scale - other.scale) < EPSILON;
145     }
146 
147     bool operator!=(const PreviewStyle &other) const
148     {
149         return !(*this == other);
150     }
151 };
152 
153 struct PreviewAnimation {
154     int32_t duration { -1 };
155     std::string curveName;
156     std::vector<float> curve;
157 };
158 
159 enum class DragCursorStyle {
160     DEFAULT = 0,
161     FORBIDDEN,
162     COPY,
163     MOVE
164 };
165 
166 enum class DragAction {
167     INVALID = -1,
168     MOVE = 0,
169     COPY = 1
170 };
171 } // namespace DeviceStatus
172 } // namespace Msdp
173 } // namespace OHOS
174 #endif // DRAG_DATA_H