• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_EVENT_ACE_EVENTS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_ACE_EVENTS_H
18 
19 #include <chrono>
20 #include <cstdint>
21 #include <string>
22 #include <optional>
23 
24 #include "base/geometry/dimension_offset.h"
25 #include "base/geometry/dimension_rect.h"
26 #include "base/memory/type_info_base.h"
27 #include "base/utils/type_definition.h"
28 
29 namespace OHOS::Ace {
30 
31 enum class KeyCode : int32_t;
32 
33 enum class SourceType : int32_t {
34     NONE = 0,
35     MOUSE = 1,
36     TOUCH = 2,
37     TOUCH_PAD = 3,
38     KEYBOARD = 4,
39     JOYSTICK = 5,
40 };
41 
42 enum class SourceTool : int32_t {
43     UNKNOWN = 0,
44     FINGER = 1,
45     PEN = 2,
46     RUBBER = 3,
47     BRUSH = 4,
48     PENCIL = 5,
49     AIRBRUSH = 6,
50     MOUSE = 7,
51     LENS = 8,
52     TOUCHPAD = 9,
53     JOYSTICK = 10,
54 };
55 
56 struct EventTarget final {
57     std::string id;
58     std::string type;
59     DimensionRect area;
60     DimensionOffset origin;
61 };
62 
63 class BaseEventInfo : public virtual TypeInfoBase {
64     DECLARE_RELATIONSHIP_OF_CLASSES(BaseEventInfo, TypeInfoBase);
65 
66 public:
BaseEventInfo(const std::string & type)67     explicit BaseEventInfo(const std::string& type) : type_(type) {}
68     ~BaseEventInfo() override = default;
69 
GetType()70     const std::string& GetType() const
71     {
72         return type_;
73     }
SetType(const std::string & type)74     void SetType(const std::string& type)
75     {
76         type_ = type;
77     }
78 
GetTimeStamp()79     const TimeStamp& GetTimeStamp() const
80     {
81         return timeStamp_;
82     }
SetTimeStamp(const TimeStamp & timeStamp)83     BaseEventInfo& SetTimeStamp(const TimeStamp& timeStamp)
84     {
85         timeStamp_ = timeStamp;
86         return *this;
87     }
88 
GetTarget()89     const EventTarget& GetTarget() const
90     {
91         return target_;
92     }
GetTargetWithModify()93     EventTarget& GetTargetWithModify()
94     {
95         return target_;
96     }
97 
SetTarget(const EventTarget & target)98     BaseEventInfo& SetTarget(const EventTarget& target)
99     {
100         target_ = target;
101         return *this;
102     }
103 
GetDeviceId()104     int64_t GetDeviceId() const
105     {
106         return deviceId_;
107     }
SetDeviceId(int64_t deviceId)108     void SetDeviceId(int64_t deviceId)
109     {
110         deviceId_ = deviceId;
111     }
112 
GetTargetDisplayId()113     int32_t GetTargetDisplayId() const
114     {
115         return targetDisplayId_;
116     }
SetTargetDisplayId(int32_t targetDisplayId)117     void SetTargetDisplayId(int32_t targetDisplayId)
118     {
119         targetDisplayId_ = targetDisplayId;
120     }
121 
GetSourceDevice()122     SourceType GetSourceDevice() const
123     {
124         return deviceType_;
125     }
SetSourceDevice(SourceType deviceType)126     void SetSourceDevice(SourceType deviceType)
127     {
128         deviceType_ = deviceType;
129     }
130 
SetForce(float force)131     void SetForce(float force)
132     {
133         force_ = force;
134     }
GetForce()135     float GetForce() const
136     {
137         return force_;
138     }
139 
SetTiltX(float tiltX)140     void SetTiltX(float tiltX)
141     {
142         tiltX_ = tiltX;
143     }
GetTiltX()144     std::optional<float> GetTiltX() const
145     {
146         return tiltX_;
147     }
148 
SetTiltY(float tiltY)149     void SetTiltY(float tiltY)
150     {
151         tiltY_ = tiltY;
152     }
GetTiltY()153     std::optional<float> GetTiltY() const
154     {
155         return tiltY_;
156     }
157 
SetSourceTool(SourceTool tool)158     void SetSourceTool(SourceTool tool)
159     {
160         sourceTool_ = tool;
161     }
GetSourceTool()162     SourceTool GetSourceTool() const
163     {
164         return sourceTool_;
165     }
166 
IsStopPropagation()167     bool IsStopPropagation() const
168     {
169         return stopPropagation_;
170     }
SetStopPropagation(bool stopPropagation)171     void SetStopPropagation(bool stopPropagation)
172     {
173         stopPropagation_ = stopPropagation;
174     }
175 
IsPreventDefault()176     bool IsPreventDefault() const
177     {
178         return preventDefault_;
179     }
SetPreventDefault(bool preventDefault)180     void SetPreventDefault(bool preventDefault)
181     {
182         preventDefault_ = preventDefault;
183     }
184 
GetPatternName()185     const std::string& GetPatternName() const
186     {
187         return patternName_;
188     }
SetPatternName(const std::string & patternName)189     void SetPatternName(const std::string& patternName)
190     {
191         patternName_ = patternName;
192     }
193 
GetPressedKeyCodes()194     const std::vector<KeyCode>& GetPressedKeyCodes() const
195     {
196         return pressedKeyCodes_;
197     }
198 
SetPressedKeyCodes(const std::vector<KeyCode> & pressedKeyCodes)199     void SetPressedKeyCodes(const std::vector<KeyCode>& pressedKeyCodes)
200     {
201         pressedKeyCodes_ = pressedKeyCodes;
202     }
203 
GetPostEventNodeId()204     int32_t GetPostEventNodeId() const
205     {
206         return postEventNodeId_;
207     }
208 
SetPostEventNodeId(int32_t postEventNodeId)209     void SetPostEventNodeId(int32_t postEventNodeId)
210     {
211         postEventNodeId_ = postEventNodeId;
212     }
213 
GetIsPostEventResult()214     bool GetIsPostEventResult() const
215     {
216         return isPostEventResult_;
217     }
218 
SetIsPostEventResult(bool isPostEventResult)219     void SetIsPostEventResult(bool isPostEventResult)
220     {
221         isPostEventResult_ = isPostEventResult;
222     }
223 
GetOperatingHand()224     int32_t GetOperatingHand() const
225     {
226         return operatingHand_;
227     }
228 
SetOperatingHand(int32_t operatingHand)229     void SetOperatingHand(int32_t operatingHand)
230     {
231         operatingHand_ = operatingHand;
232     }
233 
234 protected:
235     // Event type like onTouchDown, onClick and so on.
236     std::string type_;
237     // The origin event time stamp.
238     TimeStamp timeStamp_;
239     EventTarget target_;
240     // Will be used in drag.
241     SourceType deviceType_ = SourceType::NONE;
242     float force_ = 0.0f;
243     std::optional<float> tiltX_;
244     std::optional<float> tiltY_;
245     SourceTool sourceTool_ = SourceTool::UNKNOWN;
246     int64_t deviceId_ = 0;
247     // Will be used in drag.
248     int32_t targetDisplayId_ = 0;
249     bool stopPropagation_ = false;
250     bool preventDefault_ = false;
251     std::string patternName_;
252     std::vector<KeyCode> pressedKeyCodes_;
253     bool isPostEventResult_ = false;
254     int32_t postEventNodeId_ = -1;
255     int32_t operatingHand_ = 0;
256 };
257 
258 class PropagationEventInfo : public virtual TypeInfoBase {
259     DECLARE_RELATIONSHIP_OF_CLASSES(PropagationEventInfo, TypeInfoBase);
260 
261 public:
IsStopPropagation()262     bool IsStopPropagation() const
263     {
264         return stopPropagation_;
265     }
SetStopPropagation(bool stopPropagation)266     void SetStopPropagation(bool stopPropagation)
267     {
268         stopPropagation_ = stopPropagation;
269     }
270 
271 private:
272     bool stopPropagation_ = false;
273 };
274 
275 class EventToJSONStringAdapter : public virtual TypeInfoBase {
276     DECLARE_RELATIONSHIP_OF_CLASSES(EventToJSONStringAdapter, TypeInfoBase);
277 
278 public:
279     EventToJSONStringAdapter() = default;
280     ~EventToJSONStringAdapter() = default;
281 
282     virtual std::string ToJSONString() const = 0;
283 };
284 
285 } // namespace OHOS::Ace
286 
287 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_ACE_EVENTS_H
288