• 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 
20 #include "base/geometry/rect.h"
21 #include "base/image/pixel_map.h"
22 #include "base/memory/ace_type.h"
23 #include "core/event/ace_events.h"
24 #include "core/gestures/velocity.h"
25 
26 #include "core/common/udmf/unified_data.h"
27 
28 namespace OHOS::Ace {
29 
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 enum class DragBehavior {
60     COPY = 0,
61     MOVE = 1,
62 };
63 
64 class ACE_FORCE_EXPORT DragEvent : public AceType {
65     DECLARE_ACE_TYPE(DragEvent, AceType)
66 
67 public:
68     DragEvent() = default;
69     ~DragEvent() override = default;
70 
SetPasteData(const RefPtr<PasteData> & pasteData)71     void SetPasteData(const RefPtr<PasteData>& pasteData)
72     {
73         pasteData_ = pasteData;
74     }
75 
GetPasteData()76     RefPtr<PasteData> GetPasteData() const
77     {
78         return pasteData_;
79     }
80 
GetScreenX()81     double GetScreenX() const
82     {
83         return screenX_;
84     }
85 
GetScreenY()86     double GetScreenY() const
87     {
88         return screenY_;
89     }
90 
SetScreenX(double x)91     void SetScreenX(double x)
92     {
93         screenX_ = x;
94     }
95 
SetScreenY(double y)96     void SetScreenY(double y)
97     {
98         screenY_ = y;
99     }
100 
GetX()101     double GetX() const
102     {
103         return x_;
104     }
105 
GetY()106     double GetY() const
107     {
108         return y_;
109     }
110 
SetX(double x)111     void SetX(double x)
112     {
113         x_ = x;
114     }
115 
SetY(double y)116     void SetY(double y)
117     {
118         y_ = y;
119     }
120 
SetDescription(const std::string & description)121     void SetDescription(const std::string& description)
122     {
123         description_ = description;
124     }
125 
GetDescription()126     const std::string& GetDescription() const
127     {
128         return description_;
129     }
130 
SetPixmap(const RefPtr<PixelMap> & pixelMap)131     void SetPixmap(const RefPtr<PixelMap>& pixelMap)
132     {
133         pixelMap_ = pixelMap;
134     }
135 
GetPixmap()136     RefPtr<PixelMap> GetPixmap() const
137     {
138         return pixelMap_;
139     }
140 
SetSummary(std::map<std::string,int64_t> & summary)141     void SetSummary(std::map<std::string, int64_t>& summary)
142     {
143         summary_ = summary;
144     }
145 
GetSummary()146     std::map<std::string, int64_t>& GetSummary()
147     {
148         return summary_;
149     }
150 
SetResult(DragRet dragRet)151     void SetResult(DragRet dragRet)
152     {
153         dragRet_ = dragRet;
154     }
155 
GetResult()156     DragRet GetResult()
157     {
158         return dragRet_;
159     }
160 
GetPreviewRect()161     Rect GetPreviewRect()
162     {
163         return previewRect_;
164     }
165 
SetPreviewRect(Rect previewRect)166     void SetPreviewRect(Rect previewRect)
167     {
168         previewRect_ = previewRect;
169     }
170 
UseCustomAnimation(bool useCustomAnimation)171     void UseCustomAnimation(bool useCustomAnimation)
172     {
173         useCustomAnimation_ = useCustomAnimation;
174     }
175 
IsUseCustomAnimation()176     bool IsUseCustomAnimation()
177     {
178         return useCustomAnimation_;
179     }
180 
SetCopy(bool copy)181     void SetCopy(bool copy)
182     {
183         copy_ = copy;
184     }
185 
IsCopy()186     bool IsCopy()
187     {
188         return copy_;
189     }
190 
SetUdKey(const std::string udKey)191     void SetUdKey(const std::string udKey)
192     {
193         udKey_ = udKey;
194     }
195 
GetUdKey()196     std::string GetUdKey()
197     {
198         return udKey_;
199     }
200 
SetIsGetDataSuccess(bool isGetDataSuccess)201     void SetIsGetDataSuccess(bool isGetDataSuccess)
202     {
203         isGetDataSuccess_ = isGetDataSuccess;
204     }
205 
IsGetDataSuccess()206     bool IsGetDataSuccess()
207     {
208         return isGetDataSuccess_;
209     }
210 
211     void SetData(const RefPtr<UnifiedData>& unifiedData);
212 
213     RefPtr<UnifiedData>& GetData();
214 
215     void SetDragInfo(const RefPtr<UnifiedData>& dragInfo);
216 
217     RefPtr<UnifiedData>& GetDragInfo();
SetVelocity(const Velocity & velocity)218     void SetVelocity(const Velocity& velocity)
219     {
220         velocity_ = velocity;
221     }
222 
GetVelocity()223     const Velocity& GetVelocity() const
224     {
225         return velocity_;
226     }
227 
228 private:
229     RefPtr<PasteData> pasteData_;
230     double screenX_ = 0.0;
231     double screenY_ = 0.0;
232     double x_ = 0.0;
233     double y_ = 0.0;
234     std::string description_;
235     RefPtr<PixelMap> pixelMap_;
236     std::map<std::string, int64_t> summary_;
237     std::string udKey_ = "";
238     DragRet dragRet_ = DragRet::DRAG_DEFAULT;
239     Rect previewRect_;
240     bool useCustomAnimation_ = false;
241     bool isGetDataSuccess_ = false;
242     bool copy_ = true;
243     RefPtr<UnifiedData> unifiedData_;
244     RefPtr<UnifiedData> dragInfo_;
245     Velocity velocity_;
246 };
247 
248 class NotifyDragEvent : public DragEvent {
249     DECLARE_ACE_TYPE(NotifyDragEvent, DragEvent)
250 
251 public:
252     NotifyDragEvent() = default;
253     ~NotifyDragEvent() = default;
254 };
255 
256 class ItemDragInfo : public BaseEventInfo {
257     DECLARE_RELATIONSHIP_OF_CLASSES(ItemDragInfo, BaseEventInfo);
258 
259 public:
ItemDragInfo()260     ItemDragInfo() : BaseEventInfo("itemDrag") {}
261     ~ItemDragInfo() override = default;
262 
GetX()263     double GetX() const
264     {
265         return x_;
266     }
267 
GetY()268     double GetY() const
269     {
270         return y_;
271     }
272 
SetX(double x)273     void SetX(double x)
274     {
275         x_ = x;
276     }
277 
SetY(double y)278     void SetY(double y)
279     {
280         y_ = y;
281     }
282 
283 private:
284     double x_ = 0.0;
285     double y_ = 0.0;
286 };
287 
288 } // namespace OHOS::Ace
289 
290 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_CLICK_RECOGNIZER_H