• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_DRAG_EVENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_DRAG_EVENT_H
18 
19 #include <list>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 #include "core/components_ng/event/gesture_event_actuator.h"
24 #include "core/components_ng/gestures/gesture_info.h"
25 #include "core/components_ng/gestures/recognizers/sequenced_recognizer.h"
26 
27 namespace OHOS::Ace::NG {
28 
29 class GestureEventHub;
30 class PanRecognizer;
31 class LongPressRecognizer;
32 class FrameNode;
33 
34 class DragEvent : public AceType {
DECLARE_ACE_TYPE(DragEvent,AceType)35     DECLARE_ACE_TYPE(DragEvent, AceType)
36 public:
37     DragEvent(GestureEventFunc&& actionStart, GestureEventFunc&& actionUpdate, GestureEventFunc&& actionEnd,
38         GestureEventNoParameter&& actionCancel)
39         : actionStart_(std::move(actionStart)), actionUpdate_(std::move(actionUpdate)),
40           actionEnd_(std::move(actionEnd)), actionCancel_(std::move(actionCancel))
41     {}
42     ~DragEvent() override = default;
43 
GetActionStartEventFunc()44     const GestureEventFunc& GetActionStartEventFunc() const
45     {
46         return actionStart_;
47     }
48 
GetActionUpdateEventFunc()49     const GestureEventFunc& GetActionUpdateEventFunc() const
50     {
51         return actionUpdate_;
52     }
53 
GetActionEndEventFunc()54     const GestureEventFunc& GetActionEndEventFunc() const
55     {
56         return actionEnd_;
57     }
58 
GetActionCancelEventFunc()59     const GestureEventNoParameter& GetActionCancelEventFunc() const
60     {
61         return actionCancel_;
62     }
63 
64 private:
65     GestureEventFunc actionStart_;
66     GestureEventFunc actionUpdate_;
67     GestureEventFunc actionEnd_;
68     GestureEventNoParameter actionCancel_;
69 };
70 
71 class ACE_EXPORT DragEventActuator : public GestureEventActuator {
72     DECLARE_ACE_TYPE(DragEventActuator, GestureEventActuator)
73 public:
74     DragEventActuator(
75         const WeakPtr<GestureEventHub>& gestureEventHub, PanDirection direction, int32_t fingers, float distance);
76     ~DragEventActuator() override = default;
77 
ReplaceDragEvent(const RefPtr<DragEvent> & dragEvent)78     void ReplaceDragEvent(const RefPtr<DragEvent>& dragEvent)
79     {
80         if (userCallback_) {
81             userCallback_.Reset();
82         }
83         userCallback_ = dragEvent;
84     }
85 
SetCustomDragEvent(const RefPtr<DragEvent> & dragEvent)86     void SetCustomDragEvent(const RefPtr<DragEvent>& dragEvent)
87     {
88         if (customCallback_) {
89             customCallback_.Reset();
90         }
91         customCallback_ = dragEvent;
92     }
93 
ClearDragEvent()94     void ClearDragEvent()
95     {
96         if (userCallback_) {
97             userCallback_.Reset();
98         }
99         if (customCallback_) {
100             customCallback_.Reset();
101         }
102     }
103 
104     void OnCollectTouchTarget(const OffsetF& coordinateOffset, const TouchRestrict& touchRestrict,
105         const GetEventTargetImpl& getEventTargetImpl, TouchTestResult& result) override;
106 #ifdef ENABLE_DRAG_FRAMEWORK
107     void SetThumbnailCallback(std::function<void(Offset)>&& callback);
108     void SetFilter(const RefPtr<DragEventActuator>& actuator);
109     void SetPixelMap(const RefPtr<DragEventActuator>& actuator);
110     void SetEventColumn(const RefPtr<DragEventActuator>& actuator);
111     void HideFilter();
112     void HidePixelMap(bool startDrag = false, double x = 0, double y = 0);
113     void HideEventColumn();
114     void BindClickEvent(const RefPtr<FrameNode>& columnNode);
115     void ShowPixelMapAnimation(const RefPtr<FrameNode>& imageNode);
116     void SetTextAnimation(const RefPtr<GestureEventHub>& gestureHub, const Offset& globalLocation);
117     void HideTextAnimation(bool startDrag = false, double globalX = 0, double globalY = 0);
118     bool GetIsBindOverlayValue(const RefPtr<DragEventActuator>& actuator);
119     bool IsAllowedDrag();
120     void GetTextPixelMap(bool startDrag);
121     OffsetF GetFloatImageOffset(const RefPtr<FrameNode>& frameNode);
122 #endif // ENABLE_DRAG_FRAMEWORK
GetDirection()123     PanDirection GetDirection() const
124     {
125         return direction_;
126     }
127 
128     void StartDragTaskForWeb(const GestureEvent& info);
129     void StartLongPressActionForWeb();
130     void CancelDragForWeb();
ResetDragActionForWeb()131     void ResetDragActionForWeb() {
132         if (isReceivedLongPress_) {
133             isReceivedLongPress_ = false;
134         }
135     }
136 
SetIsNotInPreviewState(bool isNotInPreviewState)137     void SetIsNotInPreviewState(bool isNotInPreviewState)
138     {
139         isNotInPreviewState_ = isNotInPreviewState;
140     }
141 
GetIsNotInPreviewState()142     bool GetIsNotInPreviewState() const
143     {
144         return isNotInPreviewState_;
145     }
146 
ResetTextReceivedLongPress()147     void ResetTextReceivedLongPress()
148     {
149         isTextReceivedLongPress_ = false;
150     }
151 
152 private:
153     WeakPtr<GestureEventHub> gestureEventHub_;
154     RefPtr<DragEvent> userCallback_;
155     RefPtr<DragEvent> customCallback_;
156     RefPtr<PanRecognizer> panRecognizer_;
157     RefPtr<LongPressRecognizer> longPressRecognizer_;
158     RefPtr<LongPressRecognizer> previewLongPressRecognizer_;
159     RefPtr<SequencedRecognizer> SequencedRecognizer_;
160     std::function<void(GestureEvent&)> actionStart_;
161 
162     std::function<void(GestureEvent&)> longPressUpdate_;
163     std::function<void()> actionCancel_;
164     std::function<void(Offset)> textDragCallback_;
165     GestureEvent longPressInfo_;
166     bool isReceivedLongPress_ = false;
167     bool isNotInPreviewState_ = false;
168     bool isTextReceivedLongPress_ = false;
169 
170     PanDirection direction_;
171     int32_t fingers_ = 1;
172     float distance_ = 0.0f;
173 };
174 
175 } // namespace OHOS::Ace::NG
176 
177 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_DRAG_EVENT_H
178