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