• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void GetDistance(const JSCallbackInfo& args);
84 
SetPanGestureOption(const RefPtr<PanGestureOption> & panGestureOption)85     void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption)
86     {
87         panGestureOption_ = panGestureOption;
88     }
89 
GetPanGestureOption()90     RefPtr<PanGestureOption> GetPanGestureOption() const
91     {
92         return panGestureOption_;
93     }
94 
95 private:
96     RefPtr<PanGestureOption> panGestureOption_;
97 };
98 
99 class JSPanGesture : public JSGesture {
100     DECLARE_ACE_TYPE(JSPanGesture, JSGesture);
101 
102 public:
103     JSPanGesture() = default;
104     ~JSPanGesture() override = default;
105 
106     static void Create(const JSCallbackInfo& args);
107     static napi_value ParsePanDistanceMap(JSRef<JSVal> jsDistanceMap, PanDistanceMapDimension& distanceMap);
108     static void ParsePanDistance(const JSRef<JSObject>& obj, PanDistanceMapDimension& distanceMap);
109 };
110 
111 class JSSwipeGesture : public JSGesture {
112     DECLARE_ACE_TYPE(JSSwipeGesture, JSGesture);
113 public:
114     JSSwipeGesture() = default;
115     ~JSSwipeGesture() override = default;
116 
117     static void Create(const JSCallbackInfo& args);
118 };
119 
120 class JSPinchGesture : public JSGesture {
121     DECLARE_ACE_TYPE(JSPinchGesture, JSGesture);
122 
123 public:
124     JSPinchGesture() = default;
125     ~JSPinchGesture() override = default;
126 
127     static void Create(const JSCallbackInfo& args);
128 };
129 
130 class JSRotationGesture : public JSGesture {
131     DECLARE_ACE_TYPE(JSRotationGesture, JSGesture);
132 
133 public:
134     JSRotationGesture() = default;
135     ~JSRotationGesture() override = default;
136 
137     static void Create(const JSCallbackInfo& args);
138 };
139 
140 class JSGestureGroup : public JSGesture {
141     DECLARE_ACE_TYPE(JSGestureGroup, JSGesture);
142 
143 public:
144     JSGestureGroup() = default;
145     ~JSGestureGroup() override = default;
146 
147     static void Create(const JSCallbackInfo& args);
148 };
149 
150 class JSParallelGesture : public JSGesture {
151     DECLARE_ACE_TYPE(JSParallelGesture, JSGesture);
152 public:
153     static void Create();
154     static void JSBind(BindingTarget globalObj);
155 };
156 
157 class JSTimeoutGesture : public JSGesture {
158     DECLARE_ACE_TYPE(JSTimeoutGesture, JSGesture);
159 public:
160     static void Create(const JSCallbackInfo& args);
161     static void Pop();
162     static void JSBind(BindingTarget globalObj);
163 };
164 } // namespace OHOS::Ace::Framework
165 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H
166