• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
23 #include "base/geometry/dimension_offset.h"
24 #include "base/geometry/dimension_rect.h"
25 #include "base/memory/type_info_base.h"
26 #include "base/utils/type_definition.h"
27 
28 namespace OHOS::Ace {
29 
30 enum class SourceType : int32_t {
31     NONE = 0,
32     MOUSE = 1,
33     TOUCH = 2,
34     TOUCH_PAD = 3,
35     KEYBOARD = 4
36 };
37 
38 struct EventTarget final {
39     std::string id;
40     std::string type;
41     DimensionRect area;
42     DimensionOffset origin;
43 };
44 
45 class BaseEventInfo : public virtual TypeInfoBase {
46     DECLARE_RELATIONSHIP_OF_CLASSES(BaseEventInfo, TypeInfoBase);
47 
48 public:
BaseEventInfo(const std::string & type)49     explicit BaseEventInfo(const std::string& type) : type_(type) {}
50     ~BaseEventInfo() override = default;
51 
GetType()52     const std::string& GetType() const
53     {
54         return type_;
55     }
56 
GetTimeStamp()57     const TimeStamp& GetTimeStamp() const
58     {
59         return timeStamp_;
60     }
SetTimeStamp(const TimeStamp & timeStamp)61     BaseEventInfo& SetTimeStamp(const TimeStamp& timeStamp)
62     {
63         timeStamp_ = timeStamp;
64         return *this;
65     }
66 
GetTarget()67     const EventTarget& GetTarget() const
68     {
69         return target_;
70     }
GetTargetWichModify()71     EventTarget& GetTargetWichModify()
72     {
73         return target_;
74     }
75 
SetTarget(const EventTarget & target)76     BaseEventInfo& SetTarget(const EventTarget& target)
77     {
78         target_ = target;
79         return *this;
80     }
81 
GetDeviceId()82     int64_t GetDeviceId() const
83     {
84         return deviceId_;
85     }
SetDeviceId(int64_t deviceId)86     void SetDeviceId(int64_t deviceId)
87     {
88         deviceId_ = deviceId;
89     }
90 
GetSourceDevice()91     SourceType GetSourceDevice() const
92     {
93         return deviceType_;
94     }
SetSourceDevice(SourceType deviceType)95     void SetSourceDevice(SourceType deviceType)
96     {
97         deviceType_ = deviceType;
98     }
99 
IsStopPropagation()100     bool IsStopPropagation() const
101     {
102         return stopPropagation_;
103     }
SetStopPropagation(bool stopPropagation)104     void SetStopPropagation(bool stopPropagation)
105     {
106         stopPropagation_ = stopPropagation;
107     }
108 
109 protected:
110     // Event type like onTouchDown, onClick and so on.
111     std::string type_;
112     // The origin event time stamp.
113     TimeStamp timeStamp_;
114     EventTarget target_;
115     SourceType deviceType_ = SourceType::NONE;
116     int64_t deviceId_ = 0;
117     bool stopPropagation_ = false;
118 };
119 
120 class PropagationEventInfo : public virtual TypeInfoBase {
121     DECLARE_RELATIONSHIP_OF_CLASSES(PropagationEventInfo, TypeInfoBase);
122 
123 public:
IsStopPropagation()124     bool IsStopPropagation() const
125     {
126         return stopPropagation_;
127     }
SetStopPropagation(bool stopPropagation)128     void SetStopPropagation(bool stopPropagation)
129     {
130         stopPropagation_ = stopPropagation;
131     }
132 
133 private:
134     bool stopPropagation_ = false;
135 };
136 
137 class EventToJSONStringAdapter : public virtual TypeInfoBase {
138     DECLARE_RELATIONSHIP_OF_CLASSES(EventToJSONStringAdapter, TypeInfoBase);
139 
140 public:
141     EventToJSONStringAdapter() = default;
142     ~EventToJSONStringAdapter() = default;
143 
144     virtual std::string ToJSONString() const = 0;
145 };
146 
147 } // namespace OHOS::Ace
148 
149 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_ACE_EVENTS_H
150