1 /*
2  * Copyright (c) 2021-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 
16 #ifndef FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H
17 #define FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H
18 
19 #include "core/components_ng/pattern/gesture/gesture_model.h"
20 #include "core/event/ace_event_handler.h"
21 #include "core/gestures/gesture_info.h"
22 
23 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
24 
25 namespace OHOS::Ace::Framework {
26 class JSGesture : public virtual AceType {
27     DECLARE_ACE_TYPE(JSGesture, AceType);
28 
29 public:
30     JSGesture() = default;
31     ~JSGesture() override = default;
32 
33     enum class JSGestureEvent { ACTION, START, UPDATE, END, CANCEL };
34 
35     static void JSBind(BindingTarget globalObj);
36 
37     static void Create(const JSCallbackInfo& info);
38     static void Pop();
39     static void Finish();
40 
41     static void JsHandlerOnAction(const JSCallbackInfo& args);
42     static void JsHandlerOnActionStart(const JSCallbackInfo& args);
43     static void JsHandlerOnActionUpdate(const JSCallbackInfo& args);
44     static void JsHandlerOnActionEnd(const JSCallbackInfo& args);
45     static void JsHandlerOnActionCancel(const JSCallbackInfo& args);
46     static void JsHandlerOnGestureEvent(Ace::GestureEventAction action, const JSCallbackInfo& args);
47     static void SetTag(const JSCallbackInfo& args);
48     static void SetAllowedTypes(const JSCallbackInfo& args);
49 }; // JSGesture
50 
51 class JSTapGesture : public JSGesture {
52     DECLARE_ACE_TYPE(JSTapGesture, JSGesture);
53 
54 public:
55     JSTapGesture() = default;
56     ~JSTapGesture() override = default;
57 
58     static void Create(const JSCallbackInfo& args);
59 };
60 
61 class JSLongPressGesture : public JSGesture {
62     DECLARE_ACE_TYPE(JSLongPressGesture, JSGesture);
63 
64 public:
65     JSLongPressGesture() = default;
66     ~JSLongPressGesture() override = default;
67 
68     static void Create(const JSCallbackInfo& args);
69 };
70 
71 class JSPanGestureOption final : public Referenced {
72 public:
73     JSPanGestureOption() = default;
74     ~JSPanGestureOption() override = default;
75 
76     static void JSBind(BindingTarget globalObj);
77     static void Constructor(const JSCallbackInfo& args);
78     static void Destructor(JSPanGestureOption* panGestureOption);
79     void SetDirection(const JSCallbackInfo& args);
80     void SetDistance(const JSCallbackInfo& args);
81     void SetFingers(const JSCallbackInfo& args);
82     void GetDirection(const JSCallbackInfo& args);
83 
SetPanGestureOption(const RefPtr<PanGestureOption> & panGestureOption)84     void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption)
85     {
86         panGestureOption_ = panGestureOption;
87     }
88 
GetPanGestureOption()89     RefPtr<PanGestureOption> GetPanGestureOption() const
90     {
91         return panGestureOption_;
92     }
93 
94 private:
95     RefPtr<PanGestureOption> panGestureOption_;
96 };
97 
98 class JSPanGesture : public JSGesture {
99     DECLARE_ACE_TYPE(JSPanGesture, JSGesture);
100 
101 public:
102     JSPanGesture() = default;
103     ~JSPanGesture() override = default;
104 
105     static void Create(const JSCallbackInfo& args);
106 };
107 
108 class JSSwipeGesture : public JSGesture {
109     DECLARE_ACE_TYPE(JSSwipeGesture, JSGesture);
110 public:
111     JSSwipeGesture() = default;
112     ~JSSwipeGesture() override = default;
113 
114     static void Create(const JSCallbackInfo& args);
115 };
116 
117 class JSPinchGesture : public JSGesture {
118     DECLARE_ACE_TYPE(JSPinchGesture, JSGesture);
119 
120 public:
121     JSPinchGesture() = default;
122     ~JSPinchGesture() override = default;
123 
124     static void Create(const JSCallbackInfo& args);
125 };
126 
127 class JSRotationGesture : public JSGesture {
128     DECLARE_ACE_TYPE(JSRotationGesture, JSGesture);
129 
130 public:
131     JSRotationGesture() = default;
132     ~JSRotationGesture() override = default;
133 
134     static void Create(const JSCallbackInfo& args);
135 };
136 
137 class JSGestureGroup : public JSGesture {
138     DECLARE_ACE_TYPE(JSGestureGroup, JSGesture);
139 
140 public:
141     JSGestureGroup() = default;
142     ~JSGestureGroup() override = default;
143 
144     static void Create(const JSCallbackInfo& args);
145 };
146 
147 class JSParallelGesture : public JSGesture {
148     DECLARE_ACE_TYPE(JSParallelGesture, JSGesture)
149 public:
150     static void Create();
151     static void JSBind(BindingTarget globalObj);
152 };
153 
154 class JSTimeoutGesture : public JSGesture {
155     DECLARE_ACE_TYPE(JSTimeoutGesture, JSGesture)
156 public:
157     static void Create(const JSCallbackInfo& args);
158     static void Pop();
159     static void JSBind(BindingTarget globalObj);
160 };
161 } // namespace OHOS::Ace::Framework
162 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H
163 
164