1 /* 2 * Copyright (c) 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_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_INFO_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_INFO_H 18 19 #include <optional> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components/common/layout/constants.h" 23 #include "core/gestures/gesture_info.h" 24 25 namespace OHOS::Ace::NG { 26 27 class ACE_EXPORT GestureInfo : public virtual AceType { 28 DECLARE_ACE_TYPE(GestureInfo, AceType); 29 30 public: 31 GestureInfo() = default; GestureInfo(std::string tag,GestureTypeName type,bool isSystemGesture)32 GestureInfo(std::string tag, GestureTypeName type, bool isSystemGesture) 33 : tag_(std::move(tag)), type_(type), isSystemGesture_(isSystemGesture) 34 {} GestureInfo(GestureTypeName type,bool isSystemGesture)35 GestureInfo(GestureTypeName type, bool isSystemGesture) : type_(type), isSystemGesture_(isSystemGesture) {} GestureInfo(GestureTypeName type,GestureTypeName trueType,bool isSystemGesture)36 GestureInfo(GestureTypeName type, GestureTypeName trueType, bool isSystemGesture) 37 : type_(type), recognizerType_(trueType), isSystemGesture_(isSystemGesture) 38 {} GestureInfo(std::string tag)39 explicit GestureInfo(std::string tag) : tag_(std::move(tag)) {} GestureInfo(std::set<SourceTool> allowedTypes)40 explicit GestureInfo(std::set<SourceTool> allowedTypes) : allowedTypes_(std::move(allowedTypes)) {} GestureInfo(GestureTypeName type)41 explicit GestureInfo(GestureTypeName type) : type_(type) {} GestureInfo(bool isSystemGesture)42 explicit GestureInfo(bool isSystemGesture) : isSystemGesture_(isSystemGesture) {} ~GestureInfo()43 ~GestureInfo() override 44 { 45 if (isCapi_) { 46 return; 47 } 48 if (disposeNotifyFunc_) { 49 disposeNotifyFunc_(userData_); 50 } 51 if (disposeJSRecognizerInfoFunc_) { 52 disposeJSRecognizerInfoFunc_(); 53 } 54 } 55 GetTag()56 std::optional<std::string> GetTag() const 57 { 58 return tag_; 59 } 60 GetAllowedTypes()61 const std::set<SourceTool>& GetAllowedTypes() const 62 { 63 return allowedTypes_; 64 } 65 GetType()66 GestureTypeName GetType() const 67 { 68 return type_; 69 } 70 GetInputEventType()71 InputEventType GetInputEventType() const 72 { 73 return inputEventType_; 74 } 75 IsSystemGesture()76 bool IsSystemGesture() const 77 { 78 return isSystemGesture_; 79 } 80 SetTag(std::string tag)81 void SetTag(std::string tag) 82 { 83 tag_ = std::move(tag); 84 } 85 SetAllowedTypes(std::set<SourceTool> allowedTypes)86 void SetAllowedTypes(std::set<SourceTool> allowedTypes) 87 { 88 allowedTypes_ = std::move(allowedTypes); 89 } 90 SetType(GestureTypeName type)91 void SetType(GestureTypeName type) 92 { 93 type_ = type; 94 } 95 SetRecognizerType(GestureTypeName trueType)96 void SetRecognizerType(GestureTypeName trueType) 97 { 98 recognizerType_ = trueType; 99 } 100 GetRecognizerType()101 GestureTypeName GetRecognizerType() const 102 { 103 return recognizerType_; 104 } 105 SetInputEventType(InputEventType type)106 void SetInputEventType(InputEventType type) 107 { 108 inputEventType_ = type; 109 } 110 SetIsSystemGesture(bool isSystemGesture)111 void SetIsSystemGesture(bool isSystemGesture) 112 { 113 isSystemGesture_ = isSystemGesture; 114 } 115 SetUserData(void * userData)116 void SetUserData(void* userData) 117 { 118 userData_ = userData; 119 } 120 GetUserData()121 void* GetUserData() 122 { 123 return userData_; 124 } 125 SetDisposeTag(bool tag)126 void SetDisposeTag(bool tag) 127 { 128 disposeTag_ = tag; 129 } 130 GetDisposeTag()131 bool GetDisposeTag() 132 { 133 return disposeTag_; 134 } 135 SetIsCapi(bool isCapi)136 void SetIsCapi(bool isCapi) 137 { 138 isCapi_ = isCapi; 139 } 140 IsCapi()141 bool IsCapi() const 142 { 143 return isCapi_; 144 } 145 SetDisposeNotifyFunc(std::function<void (void *)> && func)146 void SetDisposeNotifyFunc(std::function<void(void*)>&& func) 147 { 148 disposeNotifyFunc_ = std::move(func); 149 } 150 SetDisposeJSRecognizerInfoFunc(std::function<void ()> && func)151 void SetDisposeJSRecognizerInfoFunc(std::function<void()>&& func) 152 { 153 disposeJSRecognizerInfoFunc_ = std::move(func); 154 } 155 156 private: 157 std::optional<std::string> tag_; 158 std::set<SourceTool> allowedTypes_{}; 159 GestureTypeName type_ = GestureTypeName::UNKNOWN; 160 // used in onGestureRecognizerJudgeBegin 161 GestureTypeName recognizerType_ = GestureTypeName::UNKNOWN; 162 InputEventType inputEventType_ = InputEventType::TOUCH_SCREEN; 163 bool isSystemGesture_ = false; 164 void* userData_ = nullptr; 165 bool disposeTag_ = false; 166 bool isCapi_ = true; 167 std::function<void(void*)> disposeNotifyFunc_; 168 std::function<void()> disposeJSRecognizerInfoFunc_; 169 }; 170 } // namespace OHOS::Ace::NG 171 172 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_INFO_H 173