• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(GestureTypeName type)40     explicit GestureInfo(GestureTypeName type) : type_(type) {}
GestureInfo(bool isSystemGesture)41     explicit GestureInfo(bool isSystemGesture) : isSystemGesture_(isSystemGesture) {}
~GestureInfo()42     ~GestureInfo() override
43     {
44         if (isCapi_) {
45             return;
46         }
47         if (disposeNotifyFunc_) {
48             disposeNotifyFunc_(userData_);
49         }
50         if (disposeJSRecognizerInfoFunc_) {
51             disposeJSRecognizerInfoFunc_();
52         }
53     }
54 
GetTag()55     std::optional<std::string> GetTag() const
56     {
57         return tag_;
58     }
59 
GetType()60     GestureTypeName GetType() const
61     {
62         return type_;
63     }
64 
GetInputEventType()65     InputEventType GetInputEventType() const
66     {
67         return inputEventType_;
68     }
69 
IsSystemGesture()70     bool IsSystemGesture() const
71     {
72         return isSystemGesture_;
73     }
74 
SetTag(std::string tag)75     void SetTag(std::string tag)
76     {
77         tag_ = std::move(tag);
78     }
79 
SetType(GestureTypeName type)80     void SetType(GestureTypeName type)
81     {
82         type_ = type;
83     }
84 
SetRecognizerType(GestureTypeName trueType)85     void SetRecognizerType(GestureTypeName trueType)
86     {
87         recognizerType_ = trueType;
88     }
89 
GetRecognizerType()90     GestureTypeName GetRecognizerType() const
91     {
92         return recognizerType_;
93     }
94 
SetInputEventType(InputEventType type)95     void SetInputEventType(InputEventType type)
96     {
97         inputEventType_ = type;
98     }
99 
SetIsSystemGesture(bool isSystemGesture)100     void SetIsSystemGesture(bool isSystemGesture)
101     {
102         isSystemGesture_ = isSystemGesture;
103     }
104 
SetUserData(void * userData)105     void SetUserData(void* userData)
106     {
107         userData_ = userData;
108     }
109 
GetUserData()110     void* GetUserData()
111     {
112         return userData_;
113     }
114 
SetDisposeTag(bool tag)115     void SetDisposeTag(bool tag)
116     {
117         disposeTag_ = tag;
118     }
119 
GetDisposeTag()120     bool GetDisposeTag()
121     {
122         return disposeTag_;
123     }
124 
SetIsCapi(bool isCapi)125     void SetIsCapi(bool isCapi)
126     {
127         isCapi_ = isCapi;
128     }
129 
IsCapi()130     bool IsCapi() const
131     {
132         return isCapi_;
133     }
134 
SetDisposeNotifyFunc(std::function<void (void *)> && func)135     void SetDisposeNotifyFunc(std::function<void(void*)>&& func)
136     {
137         disposeNotifyFunc_ = std::move(func);
138     }
139 
SetDisposeJSRecognizerInfoFunc(std::function<void ()> && func)140     void SetDisposeJSRecognizerInfoFunc(std::function<void()>&& func)
141     {
142         disposeJSRecognizerInfoFunc_ = std::move(func);
143     }
144 
145 private:
146     std::optional<std::string> tag_;
147     GestureTypeName type_ = GestureTypeName::UNKNOWN;
148     // used in onGestureRecognizerJudgeBegin
149     GestureTypeName recognizerType_ = GestureTypeName::UNKNOWN;
150     InputEventType inputEventType_ = InputEventType::TOUCH_SCREEN;
151     bool isSystemGesture_ = false;
152     void* userData_ = nullptr;
153     bool disposeTag_ = false;
154     bool isCapi_ = true;
155     std::function<void(void*)> disposeNotifyFunc_;
156     std::function<void()> disposeJSRecognizerInfoFunc_;
157 };
158 } // namespace OHOS::Ace::NG
159 
160 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_INFO_H
161