1 /*
2  * Copyright (c) 2024 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 FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_GESTURE_H
17 #define FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_GESTURE_H
18 
19 #include "bridge/cj_frontend/cppview/view_abstract.h"
20 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_macro.h"
21 #include "core/event/ace_event_handler.h"
22 #include "core/gestures/gesture_info.h"
23 
24 namespace OHOS::Ace::Framework {
25 
26 class ACE_EXPORT Gesture : public virtual AceType {
27 public:
28     enum class CJGestureEvent { ACTION, START, UPDATE, END, CANCEL };
29 
30     static void Create(GesturePriority priority, GestureMask gestureMask);
31     static void Pop();
32     static void Finish();
33 
34     static void HandlerOnAction(const std::function<void(const GestureEvent& event)>& callback);
35     static void HandlerOnActionStart(const std::function<void(const GestureEvent& event)>& callback);
36     static void HandlerOnActionUpdate(const std::function<void(const GestureEvent& event)>& callback);
37     static void HandlerOnActionEnd(const std::function<void(const GestureEvent& event)>& callback);
38     static void HandlerOnActionCancel(const std::function<void(const GestureEvent& event)>& callback);
39     static void HandlerOnGestureEvent(
40         const CJGestureEvent& action, const std::function<void(const GestureEvent& event)>& callback);
41 }; // Gesture
42 
43 class ACE_EXPORT TapGesture : public Gesture {
44 public:
45     static void Create(int32_t count, int32_t fingers);
46 };
47 
48 class ACE_EXPORT LongPressGesture : public Gesture {
49 public:
50     static void Create(int32_t fingers, bool repeat, int32_t duration);
51 };
52 
53 class ACE_EXPORT PinchGesture : public Gesture {
54 public:
55     static void Create(int32_t fingers, double distance);
56 };
57 
58 class ACE_EXPORT SwipeGesture : public Gesture {
59 public:
60     static void Create(int32_t fingers, const SwipeDirection& swipeDirection, double speed);
61 };
62 
63 class ACE_EXPORT RotationGesture : public Gesture {
64 public:
65     static void Create(int32_t fingers, double angle);
66 };
67 
68 class ACE_EXPORT GestureGroup : public Gesture {
69 public:
70     static void Create(const GestureMode& mode);
71 };
72 
73 class ACE_EXPORT NativePanGestureOption : public OHOS::FFI::FFIData {
74     DECL_TYPE(NativePanGestureOption, OHOS::FFI::FFIData)
75 public:
76     NativePanGestureOption(int32_t fingers, const PanDirection& panDirection, double distance);
77     ~NativePanGestureOption() override;
78     void SetDirection(const PanDirection& panDirection);
79     void SetDistance(double distance);
80     void SetFingers(int32_t fingers);
81 
SetPanGestureOption(const RefPtr<PanGestureOption> & panGestureOption)82     void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption)
83     {
84         panGestureOption_ = panGestureOption;
85     }
86 
GetPanGestureOption()87     RefPtr<PanGestureOption> GetPanGestureOption() const
88     {
89         return panGestureOption_;
90     }
91 
92 private:
93     RefPtr<PanGestureOption> panGestureOption_;
94 };
95 
96 class ACE_EXPORT PanGesture : public Gesture {
97 public:
98     static void Create(int32_t fingers, const PanDirection& panDirection, double distance);
99     static void Create(const sptr<NativePanGestureOption>& panGestureOption);
100 };
101 
102 } // namespace OHOS::Ace::Framework
103 
104 #endif // FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_GESTURE_H
105