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