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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_DRAG_EVENT_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_DRAG_EVENT_H 17 18 #include <map> 19 20 #include "base/geometry/rect.h" 21 #include "base/image/pixel_map.h" 22 #include "base/memory/ace_type.h" 23 #include "core/common/udmf/unified_data.h" 24 #include "core/event/ace_events.h" 25 #include "core/gestures/velocity.h" 26 27 namespace OHOS::Ace { 28 constexpr Dimension DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD = 10.0_vp; 29 constexpr float DEFAULT_DRAG_START_SCALE = 0.2; 30 class PasteData : public AceType { 31 DECLARE_ACE_TYPE(PasteData, AceType); 32 33 public: 34 PasteData() = default; 35 ~PasteData() override = default; 36 SetPlainText(const std::string & plainText)37 void SetPlainText(const std::string& plainText) 38 { 39 plainText_ = plainText; 40 } 41 GetPlainText()42 const std::string& GetPlainText() const 43 { 44 return plainText_; 45 } 46 47 private: 48 std::string plainText_; 49 }; 50 51 enum class DragRet { 52 DRAG_DEFAULT = -1, 53 DRAG_SUCCESS = 0, 54 DRAG_FAIL, 55 DRAG_CANCEL, 56 ENABLE_DROP, 57 DISABLE_DROP, 58 }; 59 60 enum class PreDragStatus { 61 ACTION_DETECTING_STATUS = 0, 62 READY_TO_TRIGGER_DRAG_ACTION, 63 PREVIEW_LIFT_STARTED, 64 PREVIEW_LIFT_FINISHED, 65 PREVIEW_LANDING_STARTED, 66 PREVIEW_LANDING_FINISHED, 67 ACTION_CANCELED_BEFORE_DRAG, 68 }; 69 70 enum class DragBehavior { 71 UNKNOWN = -1, 72 COPY = 0, 73 MOVE = 1, 74 }; 75 76 class ACE_FORCE_EXPORT DragEvent : public AceType { 77 DECLARE_ACE_TYPE(DragEvent, AceType) 78 79 public: 80 DragEvent() = default; 81 ~DragEvent() override = default; 82 SetPasteData(const RefPtr<PasteData> & pasteData)83 void SetPasteData(const RefPtr<PasteData>& pasteData) 84 { 85 pasteData_ = pasteData; 86 } 87 GetPasteData()88 RefPtr<PasteData> GetPasteData() const 89 { 90 return pasteData_; 91 } 92 GetScreenX()93 double GetScreenX() const 94 { 95 return screenX_; 96 } 97 GetScreenY()98 double GetScreenY() const 99 { 100 return screenY_; 101 } 102 SetScreenX(double x)103 void SetScreenX(double x) 104 { 105 screenX_ = x; 106 } 107 SetScreenY(double y)108 void SetScreenY(double y) 109 { 110 screenY_ = y; 111 } 112 GetX()113 double GetX() const 114 { 115 return x_; 116 } 117 GetY()118 double GetY() const 119 { 120 return y_; 121 } 122 SetX(double x)123 void SetX(double x) 124 { 125 x_ = x; 126 } 127 SetY(double y)128 void SetY(double y) 129 { 130 y_ = y; 131 } 132 GetDisplayX()133 double GetDisplayX() const 134 { 135 return displayX_; 136 } 137 GetDisplayY()138 double GetDisplayY() const 139 { 140 return displayY_; 141 } 142 SetDisplayX(double x)143 void SetDisplayX(double x) 144 { 145 displayX_ = x; 146 } 147 SetDisplayY(double y)148 void SetDisplayY(double y) 149 { 150 displayY_ = y; 151 } 152 SetDescription(const std::string & description)153 void SetDescription(const std::string& description) 154 { 155 description_ = description; 156 } 157 GetDescription()158 const std::string& GetDescription() const 159 { 160 return description_; 161 } 162 SetPixmap(const RefPtr<PixelMap> & pixelMap)163 void SetPixmap(const RefPtr<PixelMap>& pixelMap) 164 { 165 pixelMap_ = pixelMap; 166 } 167 GetPixmap()168 RefPtr<PixelMap> GetPixmap() const 169 { 170 return pixelMap_; 171 } 172 SetSummary(std::map<std::string,int64_t> & summary)173 void SetSummary(std::map<std::string, int64_t>& summary) 174 { 175 summary_ = summary; 176 } 177 GetSummary()178 std::map<std::string, int64_t>& GetSummary() 179 { 180 return summary_; 181 } 182 SetResult(DragRet dragRet)183 void SetResult(DragRet dragRet) 184 { 185 dragRet_ = dragRet; 186 } 187 GetResult()188 DragRet GetResult() 189 { 190 return dragRet_; 191 } 192 GetPreviewRect()193 Rect GetPreviewRect() 194 { 195 return previewRect_; 196 } 197 SetPreviewRect(Rect previewRect)198 void SetPreviewRect(Rect previewRect) 199 { 200 previewRect_ = previewRect; 201 } 202 UseCustomAnimation(bool useCustomAnimation)203 void UseCustomAnimation(bool useCustomAnimation) 204 { 205 useCustomAnimation_ = useCustomAnimation; 206 } 207 IsUseCustomAnimation()208 bool IsUseCustomAnimation() 209 { 210 return useCustomAnimation_; 211 } 212 SetCopy(bool copy)213 void SetCopy(bool copy) 214 { 215 copy_ = copy; 216 } 217 IsCopy()218 bool IsCopy() 219 { 220 return copy_; 221 } 222 SetDragBehavior(DragBehavior dragBehavior)223 void SetDragBehavior(DragBehavior dragBehavior) 224 { 225 dragBehavior_ = dragBehavior; 226 } 227 GetDragBehavior()228 DragBehavior GetDragBehavior() const 229 { 230 return dragBehavior_; 231 } 232 SetUdKey(const std::string & udKey)233 void SetUdKey(const std::string& udKey) 234 { 235 udKey_ = udKey; 236 } 237 GetUdKey()238 std::string GetUdKey() 239 { 240 return udKey_; 241 } 242 SetIsGetDataSuccess(bool isGetDataSuccess)243 void SetIsGetDataSuccess(bool isGetDataSuccess) 244 { 245 isGetDataSuccess_ = isGetDataSuccess; 246 } 247 IsGetDataSuccess()248 bool IsGetDataSuccess() 249 { 250 return isGetDataSuccess_; 251 } 252 253 void SetData(const RefPtr<UnifiedData>& unifiedData); 254 255 RefPtr<UnifiedData>& GetData(); 256 257 void SetDragInfo(const RefPtr<UnifiedData>& dragInfo); 258 259 RefPtr<UnifiedData>& GetDragInfo(); SetVelocity(const Velocity & velocity)260 void SetVelocity(const Velocity& velocity) 261 { 262 velocity_ = velocity; 263 } 264 GetVelocity()265 const Velocity& GetVelocity() const 266 { 267 return velocity_; 268 } 269 SetSourceTool(SourceTool sourceTool)270 void SetSourceTool(SourceTool sourceTool) 271 { 272 sourceTool_ = sourceTool; 273 } 274 GetSourceTool()275 SourceTool GetSourceTool() const 276 { 277 return sourceTool_; 278 } 279 GetPressedKeyCodes()280 const std::vector<KeyCode>& GetPressedKeyCodes() const 281 { 282 return pressedKeyCodes_; 283 } 284 SetPressedKeyCodes(const std::vector<KeyCode> & pressedKeyCodes)285 void SetPressedKeyCodes(const std::vector<KeyCode>& pressedKeyCodes) 286 { 287 pressedKeyCodes_ = pressedKeyCodes; 288 } 289 SetCapi(bool isCapi)290 void SetCapi(bool isCapi) 291 { 292 isCapi_ = isCapi; 293 } 294 IsCapi()295 bool IsCapi() 296 { 297 return isCapi_; 298 } 299 300 private: 301 RefPtr<PasteData> pasteData_; 302 double screenX_ = 0.0; 303 double screenY_ = 0.0; 304 double x_ = 0.0; 305 double y_ = 0.0; 306 double displayX_ = 0.0; 307 double displayY_ = 0.0; 308 std::string description_; 309 RefPtr<PixelMap> pixelMap_; 310 std::map<std::string, int64_t> summary_; 311 std::string udKey_ = ""; 312 DragRet dragRet_ = DragRet::DRAG_DEFAULT; 313 SourceTool sourceTool_ = { SourceTool::UNKNOWN }; 314 Rect previewRect_; 315 bool useCustomAnimation_ = false; 316 bool isGetDataSuccess_ = false; 317 bool copy_ = true; 318 DragBehavior dragBehavior_ = DragBehavior::UNKNOWN; 319 RefPtr<UnifiedData> unifiedData_; 320 RefPtr<UnifiedData> dragInfo_; 321 Velocity velocity_; 322 std::vector<KeyCode> pressedKeyCodes_; 323 bool isCapi_ = false; 324 }; 325 326 class NotifyDragEvent : public DragEvent { 327 DECLARE_ACE_TYPE(NotifyDragEvent, DragEvent) 328 329 public: 330 NotifyDragEvent() = default; 331 ~NotifyDragEvent() = default; 332 }; 333 334 class ItemDragInfo : public BaseEventInfo { 335 DECLARE_RELATIONSHIP_OF_CLASSES(ItemDragInfo, BaseEventInfo); 336 337 public: ItemDragInfo()338 ItemDragInfo() : BaseEventInfo("itemDrag") {} 339 ~ItemDragInfo() override = default; 340 GetX()341 double GetX() const 342 { 343 return x_; 344 } 345 GetY()346 double GetY() const 347 { 348 return y_; 349 } 350 SetX(double x)351 void SetX(double x) 352 { 353 x_ = x; 354 } 355 SetY(double y)356 void SetY(double y) 357 { 358 y_ = y; 359 } 360 361 private: 362 double x_ = 0.0; 363 double y_ = 0.0; 364 }; 365 366 } // namespace OHOS::Ace 367 368 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_CLICK_RECOGNIZER_H