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