• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_MANAGER_DRAG_DROP_DRAG_DROP_INITIATING_STATE_BASE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_INITIATING_STATE_BASE_H
18 
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components_ng/event/touch_event.h"
21 #include "core/components_ng/gestures/gesture_info.h"
22 #include "core/components_ng/manager/drag_drop/drag_drop_global_controller.h"
23 #include "core/event/pointer_event.h"
24 #include "core/gestures/gesture_info.h"
25 
26 namespace OHOS::Ace::NG {
27 namespace {
28 constexpr int32_t TIME_BASE = 1000 * 1000;
29 }
30 class DragDropInitiatingStateMachine;
31 
32 struct DragDropInitiatingParams {
33     int32_t idleFingerId = -1;
34     float preScaleValue = 1.0f;
35     bool isThumbnailCallbackTriggered = false;
36     bool isNeedGather = false;
37     bool hasGatherNode = false;
38     RefPtr<PixelMap> preScaledPixelMap;
39     std::function<void(Offset)> getTextThumbnailPixelMapCallback;
40     CancelableCallback<void()> getThumbnailPixelMapCallback;
41     CancelableCallback<void()> notifyPreDragCallback;
42     CancelableCallback<void()> showGatherCallback;
43     CancelableCallback<void()> preDragStatusCallback;
44     OptionsAfterApplied optionsAfterApplied;
45     WeakPtr<FrameNode> frameNode;
46     SourceType triggeredSourceType = SourceType::TOUCH;
47     Offset touchOffset { 0.0, 0.0 };
48 
GetFrameNodeDragDropInitiatingParams49     RefPtr<FrameNode> GetFrameNode()
50     {
51         return frameNode.Upgrade();
52     }
53 
ResetDragDropInitiatingParams54     void Reset()
55     {
56         idleFingerId = -1;
57         preScaleValue = 1.0f;
58         preScaledPixelMap = nullptr;
59         triggeredSourceType = SourceType::TOUCH;
60         isThumbnailCallbackTriggered = false;
61         isNeedGather = false;
62         hasGatherNode = false;
63         getThumbnailPixelMapCallback.Cancel();
64         notifyPreDragCallback.Cancel();
65         showGatherCallback.Cancel();
66         touchOffset.Reset();
67         preDragStatusCallback.Cancel();
68     }
69 };
70 
71 class DragDropInitiatingStateBase : public AceType {
72     DECLARE_ACE_TYPE(DragDropInitiatingStateBase, AceType);
73 
74 public:
DragDropInitiatingStateBase(const WeakPtr<DragDropInitiatingStateMachine> & machine)75     DragDropInitiatingStateBase(const WeakPtr<DragDropInitiatingStateMachine>& machine) : stateMachine_(machine) {};
76     ~DragDropInitiatingStateBase() = default;
77 
HandleLongPressOnAction(const GestureEvent & info)78     virtual void HandleLongPressOnAction(const GestureEvent& info) {}
HandleLongPressOnActionEnd(const GestureEvent & info)79     virtual void HandleLongPressOnActionEnd(const GestureEvent& info) {}
HandleLongPressOnActionCancel(const GestureEvent & info)80     virtual void HandleLongPressOnActionCancel(const GestureEvent& info) {}
HandlePreviewLongPressOnAction(const GestureEvent & info)81     virtual void HandlePreviewLongPressOnAction(const GestureEvent& info) {}
HandlePreviewLongPressOnActionEnd(const GestureEvent & info)82     virtual void HandlePreviewLongPressOnActionEnd(const GestureEvent& info) {}
HandlePreviewLongPressOnActionCancel(const GestureEvent & info)83     virtual void HandlePreviewLongPressOnActionCancel(const GestureEvent& info) {}
HandlePanOnActionStart(const GestureEvent & info)84     virtual void HandlePanOnActionStart(const GestureEvent& info) {}
HandlePanOnActionUpdate(const GestureEvent & info)85     virtual void HandlePanOnActionUpdate(const GestureEvent& info) {}
HandlePanOnActionEnd(const GestureEvent & info)86     virtual void HandlePanOnActionEnd(const GestureEvent& info) {}
HandlePanOnActionCancel(const GestureEvent & info)87     virtual void HandlePanOnActionCancel(const GestureEvent& info) {}
HandlePanOnReject()88     virtual void HandlePanOnReject() {}
HandleSequenceOnActionCancel(const GestureEvent & info)89     virtual void HandleSequenceOnActionCancel(const GestureEvent& info) {}
HandleHitTesting(const TouchEvent & touchEvent)90     virtual void HandleHitTesting(const TouchEvent& touchEvent) {}
HandleTouchEvent(const TouchEvent & touchEvent)91     virtual void HandleTouchEvent(const TouchEvent& touchEvent) {}
HandlePullEvent(const DragPointerEvent & dragPointerEvent)92     virtual void HandlePullEvent(const DragPointerEvent& dragPointerEvent) {}
HandleReStartDrag(const GestureEvent & info)93     virtual void HandleReStartDrag(const GestureEvent& info) {}
HandleDragStart()94     virtual void HandleDragStart() {}
HandlePreDragStatus(const PreDragStatus preDragStatus)95     virtual void HandlePreDragStatus(const PreDragStatus preDragStatus) {}
96 
Init(int32_t currentState)97     virtual void Init(int32_t currentState) {}
98 
99 protected:
GetStateMachine()100     RefPtr<DragDropInitiatingStateMachine> GetStateMachine()
101     {
102         return stateMachine_.Upgrade();
103     }
104     void UpdatePointInfoForFinger(const TouchEvent& touchEvent);
105     void OnActionEnd(const GestureEvent& info);
106     void OnActionCancel(const GestureEvent& info);
107     bool IsAllowedDrag();
108     void UpdateDragPreviewOptionFromModifier();
109     void ResetBorderRadiusAnimation();
110     void DoPixelMapScaleForDragThroughTouch(
111         DragDropInitiatingParams& params, const RefPtr<PixelMap>& pixelMap, float targetScale);
112     void PrepareFinalPixelMapForDragThroughTouch(const RefPtr<PixelMap>& pixelMap, bool immediately);
113     void HideEventColumn();
114     void HidePixelMap(bool startDrag = false, double x = 0, double y = 0, bool showAnimation = true);
115     bool CheckStatusForPanActionBegin(const RefPtr<FrameNode>& frameNode, const GestureEvent& info);
116     void SetTextPixelMap();
117     void HideTextAnimation(bool startDrag = false, double globalX = 0, double globalY = 0);
118     void HandleTextDragCallback();
119     int32_t GetCurDuration(const TouchEvent& touchEvent, int32_t curDuration);
120     void FireCustomerOnDragEnd();
121     void HandleTextDragStart(const RefPtr<FrameNode>& frameNode, const GestureEvent& info);
122 private:
123     WeakPtr<DragDropInitiatingStateMachine> stateMachine_;
124 };
125 } // namespace OHOS::Ace::NG
126 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_INITIATING_STATE_BASE_H