• 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 INPUT_EVENT_H
17 #define INPUT_EVENT_H
18 
19 #include <functional>
20 #include <memory>
21 #include <mutex>
22 #include "nocopyable.h"
23 #include "parcel.h"
24 
25 namespace OHOS {
26 namespace MMI {
27 class InputEvent {
28 public:
29     // Unknown action. Usually used to indicate the initial value of the input event action
30     static constexpr int32_t ACTION_UNKNOWN = 0;
31     // Cancel the action. Used to indicate that a continuous input event is cancelled
32     static constexpr int32_t ACTION_CANCEL = 1;
33 
34     // The actual type of the current input event is the basic type (InputEvent type)
35     static constexpr int32_t EVENT_TYPE_BASE = 0X00000000;
36     // The actual type of the current input event is the KeyEvent type or its derived class
37     static constexpr int32_t EVENT_TYPE_KEY = 0X00010000;
38     // The actual type of the current input event is the PointerEvent type or its derived class
39     static constexpr int32_t EVENT_TYPE_POINTER = 0X00020000;
40     // The actual type of the current input event is the AxisEvent type or its derived class
41     static constexpr int32_t EVENT_TYPE_AXIS = 0X00030000;
42 
43     static constexpr uint32_t EVENT_FLAG_NONE = 0x00000000;
44     static constexpr uint32_t EVENT_FLAG_NO_INTERCEPT = 0x00000001;
45     static constexpr uint32_t EVENT_FLAG_NO_MONITOR = 0x00000002;
46 
47     static constexpr int32_t DEFALUTID = -1;
48 
49 public:
50     InputEvent(const InputEvent& other);
51     virtual ~InputEvent();
52     virtual InputEvent& operator=(const InputEvent& other) = delete;
53     DISALLOW_MOVE(InputEvent);
54     static std::shared_ptr<InputEvent> Create();
55 
56     void Reset();
57     /*
58      * Get or set the unique identifier of the input event,
59      * which is globally unique after being processed by the input service
60      * Under normal circumstances, do not need to set
61      */
62     int32_t GetId() const;
63     void SetId(int32_t id);
64 
65     /* *
66      * Get or set the time when the current action occurred.
67      * The default value is the object creation time
68      * Under normal circumstances, do not need to set
69      */
70     int64_t GetActionTime() const;
71     void SetActionTime(int64_t actionTime);
72 
73     /*
74      * Get or set the current action
75      */
76     int32_t GetAction() const;
77     void SetAction(int32_t action);
78 
79     /*
80      * Action start time.
81      * For instantaneous actions, it is consistent with the time when the action occurred.
82      * For continuous actions, it indicates the start time of the continuous action
83      */
84     int64_t GetActionStartTime() const;
85     void SetActionStartTime(int64_t time);
86 
87     /*
88      * Get or set the unique identifier of the input device that reports the input event
89      * The default value is 0, which means that the non-real device reports
90      */
91     int32_t GetDeviceId() const;
92     void SetDeviceId(int32_t deviceId);
93 
94     /*
95      * Gets or sets the target display ID of the input event.
96      * The default is -1, which means that it is dynamically determined by the input service
97      */
98     int32_t GetTargetDisplayId() const;
99     void SetTargetDisplayId(int32_t displayId);
100 
101     /*
102      * Gets or sets the description window id of the input event.
103      * The default value is -1, and the target window is determined by the input service.
104      */
105     int32_t GetTargetWindowId() const;
106     void SetTargetWindowId(int32_t windowId);
107 
108     /*
109      * Gets or sets the id of the input event agent window.
110      * The input event originally sent to the target window will be sent to the proxy window.
111      * The default value is -1. Indicates determined by the input service. External users should not set this value.
112      */
113     int32_t GetAgentWindowId() const;
114     void SetAgentWindowId(int32_t windowId);
115 
116     /*
117      * The actual type of the current input event.
118      * Valid values are EVENT_TYPE_BASE, EVENT_TYPE_KEY, EVENT_TYPE_POINTER, EVENT_TYPE_AXIS
119      */
120     int32_t GetEventType() const;
121     const char* DumpEventType() const;
122 
123     uint32_t GetFlag() const;
124 
125     bool HasFlag(uint32_t flag);
126 
127     void AddFlag(uint32_t flag);
128 
129     void ClearFlag();
130 
131     void UpdateId();
132 
133     /*
134      * Mark input event processing completed.
135      * This method can only be called once.
136      */
137     void MarkProcessed();
138 
139     /*
140      * Set the callback function when the input event is processed.
141      * External users should not call this interface
142      */
143     void SetProcessedCallback(std::function<void(int32_t)> callback);
144 
145 public:
146     bool WriteToParcel(Parcel &out) const;
147     bool ReadFromParcel(Parcel &in);
148 
149 protected:
150     explicit InputEvent(int32_t eventType);
151 
152 protected:
153     int32_t eventType_;
154     int32_t id_;
155     int64_t actionTime_;
156     int32_t action_;
157     int64_t actionStartTime_;
158     int32_t deviceId_;
159     int32_t targetDisplayId_;
160     int32_t targetWindowId_;
161     int32_t agentWindowId_;
162     uint32_t bitwise_;
163     std::function<void(int32_t)> processedCallback_;
164 };
165 } // namespace MMI
166 } // namespace OHOS
167 #endif // INPUT_EVENT_H