• 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_DRAG_EVENT_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_DRAG_EVENT_H
17 
18 #include <map>
19 #include <string_view>
20 
21 #include "base/geometry/rect.h"
22 #include "base/image/pixel_map.h"
23 #include "base/memory/ace_type.h"
24 #include "core/common/udmf/data_load_params.h"
25 #include "core/common/udmf/unified_data.h"
26 #include "core/event/ace_events.h"
27 #if defined(ACE_STATIC)
28 #include "core/gestures/gesture_info.h"
29 #endif
30 #include "core/gestures/velocity.h"
31 #include "core/components_ng/manager/drag_drop/drag_drop_related_configuration.h"
32 
33 namespace OHOS::Ace {
34 constexpr Dimension DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD = 10.0_vp;
35 constexpr float DEFAULT_DRAG_START_SCALE = 0.2;
36 class PasteData : public AceType {
37     DECLARE_ACE_TYPE(PasteData, AceType);
38 
39 public:
40     PasteData() = default;
41     ~PasteData() override = default;
42 
SetPlainText(const std::string & plainText)43     void SetPlainText(const std::string& plainText)
44     {
45         plainText_ = plainText;
46     }
47 
GetPlainText()48     const std::string& GetPlainText() const
49     {
50         return plainText_;
51     }
52 
53 private:
54     std::string plainText_;
55 };
56 
57 enum class DragDropInitiatingStatus : int32_t {
58     IDLE = 0,
59     READY,
60     PRESS,
61     LIFTING,
62     MOVING,
63 };
64 
65 enum class DragSpringLoadingState {
66     BEGIN = 0,
67     UPDATE,
68     END,
69     CANCEL,
70 };
71 
72 enum class DragRet {
73     DRAG_DEFAULT = -1,
74     DRAG_SUCCESS = 0,
75     DRAG_FAIL,
76     DRAG_CANCEL,
77     ENABLE_DROP,
78     DISABLE_DROP,
79 };
80 
81 enum class PreDragStatus {
82     ACTION_DETECTING_STATUS = 0,
83     READY_TO_TRIGGER_DRAG_ACTION,
84     PREVIEW_LIFT_STARTED,
85     PREVIEW_LIFT_FINISHED,
86     PREVIEW_LANDING_STARTED,
87     PREVIEW_LANDING_FINISHED,
88     ACTION_CANCELED_BEFORE_DRAG,
89     PREPARING_FOR_DRAG_DETECTION,
90 };
91 
92 enum class DragStartRequestStatus : int32_t {
93     WAITING = 0,
94     READY
95 };
96 
97 enum class DragBehavior {
98     UNKNOWN = -1,
99     COPY = 0,
100     MOVE = 1,
101 };
102 
103 class ACE_FORCE_EXPORT DragEvent : public AceType {
104     DECLARE_ACE_TYPE(DragEvent, AceType);
105 
106 public:
107     DragEvent() = default;
108     ~DragEvent() override = default;
109 
SetPasteData(const RefPtr<PasteData> & pasteData)110     void SetPasteData(const RefPtr<PasteData>& pasteData)
111     {
112         pasteData_ = pasteData;
113     }
114 
GetPasteData()115     RefPtr<PasteData> GetPasteData() const
116     {
117         return pasteData_;
118     }
119 
GetScreenX()120     double GetScreenX() const
121     {
122         return screenX_;
123     }
124 
GetScreenY()125     double GetScreenY() const
126     {
127         return screenY_;
128     }
129 
SetScreenX(double x)130     void SetScreenX(double x)
131     {
132         screenX_ = x;
133     }
134 
SetScreenY(double y)135     void SetScreenY(double y)
136     {
137         screenY_ = y;
138     }
139 
GetX()140     double GetX() const
141     {
142         return x_;
143     }
144 
GetY()145     double GetY() const
146     {
147         return y_;
148     }
149 
SetX(double x)150     void SetX(double x)
151     {
152         x_ = x;
153     }
154 
SetY(double y)155     void SetY(double y)
156     {
157         y_ = y;
158     }
159 
GetDisplayX()160     double GetDisplayX() const
161     {
162         return displayX_;
163     }
164 
GetDisplayY()165     double GetDisplayY() const
166     {
167         return displayY_;
168     }
169 
SetDisplayX(double x)170     void SetDisplayX(double x)
171     {
172         displayX_ = x;
173     }
174 
SetDisplayY(double y)175     void SetDisplayY(double y)
176     {
177         displayY_ = y;
178     }
179 
GetGlobalDisplayX()180     double GetGlobalDisplayX() const
181     {
182         return globalDisplayX_;
183     }
184 
GetGlobalDisplayY()185     double GetGlobalDisplayY() const
186     {
187         return globalDisplayY_;
188     }
189 
SetGlobalDisplayX(double x)190     void SetGlobalDisplayX(double x)
191     {
192         globalDisplayX_ = x;
193     }
194 
SetGlobalDisplayY(double y)195     void SetGlobalDisplayY(double y)
196     {
197         globalDisplayY_ = y;
198     }
199 
SetDescription(const std::string & description)200     void SetDescription(const std::string& description)
201     {
202         description_ = description;
203     }
204 
GetDescription()205     const std::string& GetDescription() const
206     {
207         return description_;
208     }
209 
SetPixmap(const RefPtr<PixelMap> & pixelMap)210     void SetPixmap(const RefPtr<PixelMap>& pixelMap)
211     {
212         pixelMap_ = pixelMap;
213     }
214 
GetPixmap()215     RefPtr<PixelMap> GetPixmap() const
216     {
217         return pixelMap_;
218     }
219 
SetSummary(std::map<std::string,int64_t> & summary)220     void SetSummary(std::map<std::string, int64_t>& summary)
221     {
222         summary_ = summary;
223     }
224 
GetSummary()225     std::map<std::string, int64_t>& GetSummary()
226     {
227         return summary_;
228     }
229 
SetResult(DragRet dragRet)230     void SetResult(DragRet dragRet)
231     {
232         dragRet_ = dragRet;
233     }
234 
GetResult()235     DragRet GetResult()
236     {
237         return dragRet_;
238     }
239 
GetPreviewRect()240     Rect GetPreviewRect()
241     {
242         return previewRect_;
243     }
244 
SetPreviewRect(Rect previewRect)245     void SetPreviewRect(Rect previewRect)
246     {
247         previewRect_ = previewRect;
248     }
249 
UseCustomAnimation(bool useCustomAnimation)250     void UseCustomAnimation(bool useCustomAnimation)
251     {
252         useCustomAnimation_ = useCustomAnimation;
253     }
254 
IsUseCustomAnimation()255     bool IsUseCustomAnimation()
256     {
257         return useCustomAnimation_;
258     }
259 
SetCopy(bool copy)260     void SetCopy(bool copy)
261     {
262         copy_ = copy;
263     }
264 
IsCopy()265     bool IsCopy()
266     {
267         return copy_;
268     }
269 
SetDragBehavior(DragBehavior dragBehavior)270     void SetDragBehavior(DragBehavior dragBehavior)
271     {
272         dragBehavior_ = dragBehavior;
273     }
274 
GetDragBehavior()275     DragBehavior GetDragBehavior() const
276     {
277         return dragBehavior_;
278     }
279 
SetUdKey(const std::string & udKey)280     void SetUdKey(const std::string& udKey)
281     {
282         udKey_ = udKey;
283     }
284 
GetUdKey()285     const std::string& GetUdKey()
286     {
287         return udKey_;
288     }
289 
SetIsGetDataSuccess(bool isGetDataSuccess)290     void SetIsGetDataSuccess(bool isGetDataSuccess)
291     {
292         isGetDataSuccess_ = isGetDataSuccess;
293     }
294 
IsGetDataSuccess()295     bool IsGetDataSuccess()
296     {
297         return isGetDataSuccess_;
298     }
299 
300     void SetData(const RefPtr<UnifiedData>& unifiedData);
301 
302     RefPtr<UnifiedData>& GetData();
303 
304     void SetDragInfo(const RefPtr<UnifiedData>& dragInfo);
305 
306     RefPtr<UnifiedData>& GetDragInfo();
SetVelocity(const Velocity & velocity)307     void SetVelocity(const Velocity& velocity)
308     {
309         velocity_ = velocity;
310     }
311 
GetVelocity()312     const Velocity& GetVelocity() const
313     {
314         return velocity_;
315     }
316 
SetSourceTool(SourceTool sourceTool)317     void SetSourceTool(SourceTool sourceTool)
318     {
319         sourceTool_ = sourceTool;
320     }
321 
GetSourceTool()322     SourceTool GetSourceTool() const
323     {
324         return sourceTool_;
325     }
326 
GetPressedKeyCodes()327     const std::vector<KeyCode>& GetPressedKeyCodes() const
328     {
329         return pressedKeyCodes_;
330     }
331 
SetPressedKeyCodes(const std::vector<KeyCode> & pressedKeyCodes)332     void SetPressedKeyCodes(const std::vector<KeyCode>& pressedKeyCodes)
333     {
334         pressedKeyCodes_ = pressedKeyCodes;
335     }
336 
SetCapi(bool isCapi)337     void SetCapi(bool isCapi)
338     {
339         isCapi_ = isCapi;
340     }
341 
IsCapi()342     bool IsCapi()
343     {
344         return isCapi_;
345     }
346 
SetDropAnimation(std::function<void ()> && executeDropAnimation)347     void SetDropAnimation(std::function<void()>&& executeDropAnimation)
348     {
349         executeDropAnimation_ = std::move(executeDropAnimation);
350     }
351 
HasDropAnimation()352     bool HasDropAnimation() const
353     {
354         return (executeDropAnimation_ != nullptr);
355     }
356 
ExecuteDropAnimation()357     void ExecuteDropAnimation()
358     {
359         if (executeDropAnimation_) {
360             auto executeDropAnimation = executeDropAnimation_;
361             executeDropAnimation();
362         }
363     }
364 
SetIsDragEndPending(bool isDragEndPending)365     void SetIsDragEndPending(bool isDragEndPending)
366     {
367         isDragEndPending_ = isDragEndPending;
368     }
369 
IsDragEndPending()370     bool IsDragEndPending() const
371     {
372         return isDragEndPending_;
373     }
374 
SetRequestIdentify(int32_t requestId)375     void SetRequestIdentify(int32_t requestId)
376     {
377         requestId_ = requestId;
378     }
379 
GetRequestIdentify()380     int32_t GetRequestIdentify() const
381     {
382         return requestId_;
383     }
384 
SetDragSource(const std::string & bundleName)385     void SetDragSource(const std::string& bundleName)
386     {
387         bundleName_ = bundleName;
388     }
389 
GetDragSource()390     const std::string& GetDragSource() const
391     {
392         return bundleName_;
393     }
394 
395 
SetRemoteDev(bool isRemoteDev)396     void SetRemoteDev(bool isRemoteDev)
397     {
398         isRemoteDev_ = isRemoteDev;
399     }
400 
isRemoteDev()401     bool isRemoteDev() const
402     {
403         return isRemoteDev_;
404     }
405 
SetDisplayId(int32_t displayId)406     void SetDisplayId(int32_t displayId)
407     {
408         displayId_ = displayId;
409     }
410 
GetDisplayId()411     int32_t GetDisplayId() const
412     {
413         return displayId_;
414     }
415 
SetNeedDoInternalDropAnimation(bool needDoInternalDropAnimation)416     void SetNeedDoInternalDropAnimation(bool needDoInternalDropAnimation)
417     {
418         needDoInternalDropAnimation_ = needDoInternalDropAnimation;
419     }
420 
GetNeedDoInternalDropAnimation()421     bool GetNeedDoInternalDropAnimation() const
422     {
423         return needDoInternalDropAnimation_;
424     }
425 
SetDataLoadParams(const RefPtr<DataLoadParams> & dataLoadParams)426     void SetDataLoadParams(const RefPtr<DataLoadParams>& dataLoadParams)
427     {
428         dataLoadParams_ = dataLoadParams;
429     }
430 
GetDataLoadParams()431     RefPtr<DataLoadParams> GetDataLoadParams() const
432     {
433         return dataLoadParams_;
434     }
435 
SetUseDataLoadParams(bool useDataLoadParams)436     void SetUseDataLoadParams(bool useDataLoadParams)
437     {
438         useDataLoadParams_ = useDataLoadParams;
439     }
440 
IsUseDataLoadParams()441     bool IsUseDataLoadParams() const
442     {
443         return useDataLoadParams_;
444     }
445 
446 #if defined(ACE_STATIC)
447     RefPtr<PixelMap> GetDragDropInfoPixelMap() const;
448     void* GetDragDropInfoCustomNode() const;
449     std::string GetDragDropInfoExtraInfo() const;
450     void SetDragDropInfoPixelMap(RefPtr<PixelMap> pixelMap);
451     void SetDragDropInfoCustomNode(void* customNode);
452     void SetDragDropInfoExtraInfo(std::string& extraInfo);
453 #endif
454 
455 private:
456     RefPtr<PasteData> pasteData_;
457     double screenX_ = 0.0;
458     double screenY_ = 0.0;
459     double x_ = 0.0;
460     double y_ = 0.0;
461     double displayX_ = 0.0;
462     double displayY_ = 0.0;
463     double globalDisplayX_ = 0.0;
464     double globalDisplayY_ = 0.0;
465     std::string description_;
466     RefPtr<PixelMap> pixelMap_;
467     std::map<std::string, int64_t> summary_;
468     std::string udKey_ = "";
469     DragRet dragRet_ = DragRet::DRAG_DEFAULT;
470     SourceTool sourceTool_ = { SourceTool::UNKNOWN };
471     Rect previewRect_;
472     bool useCustomAnimation_ = false;
473     bool isGetDataSuccess_ = false;
474     bool copy_ = true;
475     DragBehavior dragBehavior_ = DragBehavior::UNKNOWN;
476     RefPtr<UnifiedData> unifiedData_;
477     RefPtr<UnifiedData> dragInfo_;
478     Velocity velocity_;
479     std::vector<KeyCode> pressedKeyCodes_;
480     bool isCapi_ = false;
481     std::function<void()> executeDropAnimation_;
482     int32_t requestId_ = -1;
483     bool isDragEndPending_ = false;
484     std::string bundleName_;
485     bool isRemoteDev_ { false };
486     int32_t displayId_ = -1;
487     bool needDoInternalDropAnimation_ = false;
488     RefPtr<DataLoadParams> dataLoadParams_ = nullptr;
489     bool useDataLoadParams_ { false };
490 #if defined(ACE_STATIC)
491     RefPtr<PixelMap> dragDropInfoPixelMap_;
492     void* dragDropInfoCustomNode_;
493     std::string dragDropInfoExtraInfo_;
494 #endif
495 };
496 
497 class NotifyDragEvent : public DragEvent {
498     DECLARE_ACE_TYPE(NotifyDragEvent, DragEvent);
499 
500 public:
501     NotifyDragEvent() = default;
502     ~NotifyDragEvent() = default;
503 };
504 
505 class ItemDragInfo : public BaseEventInfo {
506     DECLARE_RELATIONSHIP_OF_CLASSES(ItemDragInfo, BaseEventInfo);
507 
508 public:
ItemDragInfo()509     ItemDragInfo() : BaseEventInfo("itemDrag") {}
510     ~ItemDragInfo() override = default;
511 
GetX()512     double GetX() const
513     {
514         return x_;
515     }
516 
GetY()517     double GetY() const
518     {
519         return y_;
520     }
521 
SetX(double x)522     void SetX(double x)
523     {
524         x_ = x;
525     }
526 
SetY(double y)527     void SetY(double y)
528     {
529         y_ = y;
530     }
531 
532 private:
533     double x_ = 0.0;
534     double y_ = 0.0;
535 };
536 
537 class DragSpringLoadingContext : public AceType {
538     DECLARE_ACE_TYPE(DragSpringLoadingContext, AceType);
539 public:
540     explicit DragSpringLoadingContext() = default;
541     ~DragSpringLoadingContext() override = default;
542 
SetState(DragSpringLoadingState state)543     void SetState(DragSpringLoadingState state)
544     {
545         state_ = state;
546     }
547 
GetState()548     DragSpringLoadingState GetState() const
549     {
550         return state_;
551     }
552 
SetCurrentNotifySequence(int32_t currentNotifySequence)553     void SetCurrentNotifySequence(int32_t currentNotifySequence)
554     {
555         currentNotifySequence_ = currentNotifySequence;
556     }
557 
GetCurrentNotifySequence()558     int32_t GetCurrentNotifySequence() const
559     {
560         return currentNotifySequence_;
561     }
562 
SetExtraInfos(std::string_view extraInfos)563     void SetExtraInfos(std::string_view extraInfos)
564     {
565         extraInfos_ = extraInfos.data();
566     }
567 
GetExtraInfos()568     const std::string& GetExtraInfos() const
569     {
570         return extraInfos_;
571     }
572 
SetSummary(const std::map<std::string,int64_t> & summary)573     void SetSummary(const std::map<std::string, int64_t>& summary)
574     {
575         summary_ = summary;
576     }
577 
GetSummary()578     const std::map<std::string, int64_t>& GetSummary() const
579     {
580         return summary_;
581     }
582 
SetSpringLoadingAborted()583     void SetSpringLoadingAborted()
584     {
585         isSpringLoadingAborted_ = true;
586     }
587 
IsSpringLoadingAborted()588     bool IsSpringLoadingAborted() const
589     {
590         return isSpringLoadingAborted_;
591     }
592 
GetDragSpringLoadingConfiguration()593     const RefPtr<NG::DragSpringLoadingConfiguration>& GetDragSpringLoadingConfiguration() const
594     {
595         return DragSpringLoadingConfiguration_;
596     }
597 
SetDragSpringLoadingConfiguration(const RefPtr<NG::DragSpringLoadingConfiguration> & dragSpringLoadingConfiguration)598     void SetDragSpringLoadingConfiguration(
599         const RefPtr<NG::DragSpringLoadingConfiguration>& dragSpringLoadingConfiguration)
600     {
601         DragSpringLoadingConfiguration_ = dragSpringLoadingConfiguration;
602     }
603 
604 private:
605     DragSpringLoadingState state_;
606     int32_t currentNotifySequence_ = 0;
607     std::string extraInfos_;
608     std::map<std::string, int64_t> summary_;
609     bool isSpringLoadingAborted_ = false;
610     RefPtr<NG::DragSpringLoadingConfiguration> DragSpringLoadingConfiguration_;
611 };
612 } // namespace OHOS::Ace
613 
614 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_CLICK_RECOGNIZER_H