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 }; // JSGesture 49 50 class JSTapGesture : public JSGesture { 51 DECLARE_ACE_TYPE(JSTapGesture, JSGesture); 52 53 public: 54 JSTapGesture() = default; 55 ~JSTapGesture() override = default; 56 57 static void Create(const JSCallbackInfo& args); 58 }; 59 60 class JSLongPressGesture : public JSGesture { 61 DECLARE_ACE_TYPE(JSLongPressGesture, JSGesture); 62 63 public: 64 JSLongPressGesture() = default; 65 ~JSLongPressGesture() override = default; 66 67 static void Create(const JSCallbackInfo& args); 68 }; 69 70 class JSPanGestureOption final : public Referenced { 71 public: 72 JSPanGestureOption() = default; 73 ~JSPanGestureOption() override = default; 74 75 static void JSBind(BindingTarget globalObj); 76 static void Constructor(const JSCallbackInfo& args); 77 static void Destructor(JSPanGestureOption* panGestureOption); 78 void SetDirection(const JSCallbackInfo& args); 79 void SetDistance(const JSCallbackInfo& args); 80 void SetFingers(const JSCallbackInfo& args); 81 void GetDirection(const JSCallbackInfo& args); 82 SetPanGestureOption(const RefPtr<PanGestureOption> & panGestureOption)83 void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption) 84 { 85 panGestureOption_ = panGestureOption; 86 } 87 GetPanGestureOption()88 RefPtr<PanGestureOption> GetPanGestureOption() const 89 { 90 return panGestureOption_; 91 } 92 93 private: 94 RefPtr<PanGestureOption> panGestureOption_; 95 }; 96 97 class JSPanGesture : public JSGesture { 98 DECLARE_ACE_TYPE(JSPanGesture, JSGesture); 99 100 public: 101 JSPanGesture() = default; 102 ~JSPanGesture() override = default; 103 104 static void Create(const JSCallbackInfo& args); 105 }; 106 107 class JSSwipeGesture : public JSGesture { 108 DECLARE_ACE_TYPE(JSSwipeGesture, JSGesture); 109 public: 110 JSSwipeGesture() = default; 111 ~JSSwipeGesture() override = default; 112 113 static void Create(const JSCallbackInfo& args); 114 }; 115 116 class JSPinchGesture : public JSGesture { 117 DECLARE_ACE_TYPE(JSPinchGesture, JSGesture); 118 119 public: 120 JSPinchGesture() = default; 121 ~JSPinchGesture() override = default; 122 123 static void Create(const JSCallbackInfo& args); 124 }; 125 126 class JSRotationGesture : public JSGesture { 127 DECLARE_ACE_TYPE(JSRotationGesture, JSGesture); 128 129 public: 130 JSRotationGesture() = default; 131 ~JSRotationGesture() override = default; 132 133 static void Create(const JSCallbackInfo& args); 134 }; 135 136 class JSGestureGroup : public JSGesture { 137 DECLARE_ACE_TYPE(JSGestureGroup, JSGesture); 138 139 public: 140 JSGestureGroup() = default; 141 ~JSGestureGroup() override = default; 142 143 static void Create(const JSCallbackInfo& args); 144 }; 145 146 class JSParallelGesture : public JSGesture { 147 DECLARE_ACE_TYPE(JSParallelGesture, JSGesture) 148 public: 149 static void Create(); 150 static void JSBind(BindingTarget globalObj); 151 }; 152 153 class JSTimeoutGesture : public JSGesture { 154 DECLARE_ACE_TYPE(JSTimeoutGesture, JSGesture) 155 public: 156 static void Create(const JSCallbackInfo& args); 157 static void Pop(); 158 static void JSBind(BindingTarget globalObj); 159 }; 160 } // namespace OHOS::Ace::Framework 161 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H 162 163