1 /*
2 * Copyright (C) 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 #define private public
17 #define protected public
18 #include "pointer_event.h"
19 #undef private
20 #undef protected
21 #include "mock_pointer_event.h"
22
23 namespace OHOS {
24 namespace MMI {
PointerItem()25 PointerEvent::PointerItem::PointerItem()
26 {}
27
~PointerItem()28 PointerEvent::PointerItem::~PointerItem()
29 {}
30
SetPointerId(int32_t pointerId)31 void PointerEvent::PointerItem::SetPointerId(int32_t pointerId)
32 {
33 pointerId_ = pointerId;
34 }
35
GetPointerId() const36 int32_t PointerEvent::PointerItem::GetPointerId() const
37 {
38 return pointerId_;
39 }
40
SetDownTime(int64_t downTime)41 void PointerEvent::PointerItem::SetDownTime(int64_t downTime)
42 {
43 downTime_ = downTime;
44 }
45
GetDownTime() const46 int64_t PointerEvent::PointerItem::GetDownTime() const
47 {
48 return downTime_;
49 }
50
SetPressed(bool pressed)51 void PointerEvent::PointerItem::SetPressed(bool pressed)
52 {
53 pressed_ = pressed;
54 }
55
IsPressed() const56 bool PointerEvent::PointerItem::IsPressed() const
57 {
58 return pressed_;
59 }
60
SetDisplayX(int32_t x)61 void PointerEvent::PointerItem::SetDisplayX(int32_t x)
62 {
63 displayX_ = x;
64 }
65
GetDisplayX() const66 int32_t PointerEvent::PointerItem::GetDisplayX() const
67 {
68 return displayX_;
69 }
70
SetDisplayY(int32_t y)71 void PointerEvent::PointerItem::SetDisplayY(int32_t y)
72 {
73 displayY_ = y;
74 }
75
GetDisplayY() const76 int32_t PointerEvent::PointerItem::GetDisplayY() const
77 {
78 return displayY_;
79 }
80
SetWindowX(int32_t x)81 void PointerEvent::PointerItem::SetWindowX(int32_t x)
82 {
83 windowX_ = x;
84 }
85
GetWindowX() const86 int32_t PointerEvent::PointerItem::GetWindowX() const
87 {
88 return windowX_;
89 }
90
SetWindowY(int32_t y)91 void PointerEvent::PointerItem::SetWindowY(int32_t y)
92 {
93 windowY_ = y;
94 }
95
GetWindowY() const96 int32_t PointerEvent::PointerItem::GetWindowY() const
97 {
98 return windowY_;
99 }
100
SetWidth(int32_t width)101 void PointerEvent::PointerItem::SetWidth(int32_t width)
102 {
103 width_ = width;
104 }
105
GetWidth() const106 int32_t PointerEvent::PointerItem::GetWidth() const
107 {
108 return width_;
109 }
110
SetHeight(int32_t height)111 void PointerEvent::PointerItem::SetHeight(int32_t height)
112 {
113 height_ = height;
114 }
115
GetHeight() const116 int32_t PointerEvent::PointerItem::GetHeight() const
117 {
118 return height_;
119 }
120
SetPressure(double pressure)121 void PointerEvent::PointerItem::SetPressure(double pressure)
122 {
123 pressure_ = pressure;
124 }
125
GetPressure() const126 double PointerEvent::PointerItem::GetPressure() const
127 {
128 return pressure_;
129 }
130
SetDeviceId(int32_t deviceId)131 void PointerEvent::PointerItem::SetDeviceId(int32_t deviceId)
132 {
133 deviceId_ = deviceId;
134 }
135
GetDeviceId() const136 int32_t PointerEvent::PointerItem::GetDeviceId() const
137 {
138 return deviceId_;
139 }
140
PointerEvent(int32_t eventType)141 PointerEvent::PointerEvent(int32_t eventType) : InputEvent(eventType)
142 {}
143
PointerEvent(const PointerEvent & other)144 PointerEvent::PointerEvent(const PointerEvent& other)
145 : InputEvent(other),
146 pointerId_(other.pointerId_),
147 pointers_(other.pointers_),
148 pressedButtons_(other.pressedButtons_),
149 pointerAction_(other.pointerAction_),
150 buttonId_(other.buttonId_),
151 axes_(other.axes_),
152 axisValues_(other.axisValues_),
153 pressedKeys_(other.pressedKeys_)
154 {}
155
~PointerEvent()156 PointerEvent::~PointerEvent()
157 {
158 pointers_.clear();
159 pressedButtons_.clear();
160 pressedKeys_.clear();
161 }
162
Create()163 std::shared_ptr<PointerEvent> PointerEvent::Create()
164 {
165 return std::make_shared<PointerEvent>(InputEvent::EVENT_TYPE_POINTER);
166 }
167
ToString()168 std::string PointerEvent::ToString()
169 {
170 return "";
171 }
172
GetPointerAction() const173 int32_t PointerEvent::GetPointerAction() const
174 {
175 return pointerAction_;
176 }
177
SetPointerAction(int32_t pointerAction)178 void PointerEvent::SetPointerAction(int32_t pointerAction)
179 {
180 pointerAction_ = pointerAction;
181 }
182
GetPointerId() const183 int32_t PointerEvent::GetPointerId() const
184 {
185 return pointerId_;
186 }
187
SetPointerId(int32_t pointerId)188 void PointerEvent::SetPointerId(int32_t pointerId)
189 {
190 pointerId_ = pointerId;
191 }
192
GetPointerItem(int32_t pointerId,PointerItem & pointerItem) const193 bool PointerEvent::GetPointerItem(int32_t pointerId, PointerItem& pointerItem) const
194 {
195 for (auto& item : pointers_) {
196 if (item.GetPointerId() == pointerId) {
197 pointerItem = item;
198 return true;
199 }
200 }
201 return false;
202 }
203
RemovePointerItem(int32_t pointerId)204 void PointerEvent::RemovePointerItem(int32_t pointerId)
205 {
206 for (auto it = pointers_.begin(); it != pointers_.end(); it++) {
207 if (it->GetPointerId() == pointerId) {
208 pointers_.erase(it);
209 break;
210 }
211 }
212 }
213
AddPointerItem(PointerItem & pointerItem)214 void PointerEvent::AddPointerItem(PointerItem& pointerItem)
215 {
216 pointers_.push_back(pointerItem);
217 }
218
GetPointerIds() const219 std::vector<int32_t> PointerEvent::GetPointerIds() const
220 {
221 std::vector<int32_t> pointerIdList;
222
223 for (auto& item : pointers_) {
224 pointerIdList.push_back(item.GetPointerId());
225 }
226
227 return pointerIdList;
228 }
229
Reset()230 void PointerEvent::Reset()
231 {
232 }
233
SetButtonId(int32_t buttonId)234 void PointerEvent::SetButtonId(int32_t buttonId)
235 {
236 buttonId_ = buttonId;
237 }
238
SetButtonPressed(int32_t buttonId)239 void PointerEvent::SetButtonPressed(int32_t buttonId)
240 {
241 pressedButtons_.insert(buttonId);
242 }
243
UpdatePointerItem(int32_t pointerId,PointerItem & pointerItem)244 void PointerEvent::UpdatePointerItem(int32_t pointerId, PointerItem &pointerItem)
245 {
246 for (auto &item : pointers_) {
247 if (item.GetPointerId() == pointerId) {
248 item = pointerItem;
249 return;
250 }
251 }
252 pointers_.push_back(pointerItem);
253 }
254 } // namespace MMI
255 } // namespace OHOS