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 }; 108 109 class JSSwipeGesture : public JSGesture { 110 DECLARE_ACE_TYPE(JSSwipeGesture, JSGesture); 111 public: 112 JSSwipeGesture() = default; 113 ~JSSwipeGesture() override = default; 114 115 static void Create(const JSCallbackInfo& args); 116 }; 117 118 class JSPinchGesture : public JSGesture { 119 DECLARE_ACE_TYPE(JSPinchGesture, JSGesture); 120 121 public: 122 JSPinchGesture() = default; 123 ~JSPinchGesture() override = default; 124 125 static void Create(const JSCallbackInfo& args); 126 }; 127 128 class JSRotationGesture : public JSGesture { 129 DECLARE_ACE_TYPE(JSRotationGesture, JSGesture); 130 131 public: 132 JSRotationGesture() = default; 133 ~JSRotationGesture() override = default; 134 135 static void Create(const JSCallbackInfo& args); 136 }; 137 138 class JSGestureGroup : public JSGesture { 139 DECLARE_ACE_TYPE(JSGestureGroup, JSGesture); 140 141 public: 142 JSGestureGroup() = default; 143 ~JSGestureGroup() override = default; 144 145 static void Create(const JSCallbackInfo& args); 146 }; 147 148 class JSParallelGesture : public JSGesture { 149 DECLARE_ACE_TYPE(JSParallelGesture, JSGesture) 150 public: 151 static void Create(); 152 static void JSBind(BindingTarget globalObj); 153 }; 154 155 class JSTimeoutGesture : public JSGesture { 156 DECLARE_ACE_TYPE(JSTimeoutGesture, JSGesture) 157 public: 158 static void Create(const JSCallbackInfo& args); 159 static void Pop(); 160 static void JSBind(BindingTarget globalObj); 161 }; 162 } // namespace OHOS::Ace::Framework 163 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H 164 165