• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
~PointerItem()22 PointerEvent::PointerItem::~PointerItem() {}
23 
GetPointerId() const24 int32_t PointerEvent::PointerItem::GetPointerId() const
25 {
26     return pointerId_;
27 }
28 
SetPointerId(int32_t pointerId)29 void PointerEvent::PointerItem::SetPointerId(int32_t pointerId)
30 {
31     pointerId_ = pointerId;
32 }
33 
GetDownTime() const34 int64_t PointerEvent::PointerItem::GetDownTime() const
35 {
36     return downTime_;
37 }
38 
SetDownTime(int64_t downTime)39 void PointerEvent::PointerItem::SetDownTime(int64_t downTime)
40 {
41     downTime_ = downTime;
42 }
43 
IsPressed() const44 bool PointerEvent::PointerItem::IsPressed() const
45 {
46     return pressed_;
47 }
48 
SetPressed(bool pressed)49 void PointerEvent::PointerItem::SetPressed(bool pressed)
50 {
51     pressed_ = pressed;
52 }
53 
GetGlobalX() const54 int32_t PointerEvent::PointerItem::GetGlobalX() const
55 {
56     return globalX_;
57 }
58 
SetGlobalX(int32_t x)59 void PointerEvent::PointerItem::SetGlobalX(int32_t x)
60 {
61     globalX_ = x;
62 }
63 
GetGlobalY() const64 int32_t PointerEvent::PointerItem::GetGlobalY() const
65 {
66     return globalY_;
67 }
68 
SetGlobalY(int32_t y)69 void PointerEvent::PointerItem::SetGlobalY(int32_t y)
70 {
71     globalY_ = y;
72 }
73 
GetLocalX() const74 int32_t PointerEvent::PointerItem::GetLocalX() const
75 {
76     return localX_;
77 }
78 
SetLocalX(int32_t x)79 void PointerEvent::PointerItem::SetLocalX(int32_t x)
80 {
81     localX_ = x;
82 }
83 
GetLocalY() const84 int32_t PointerEvent::PointerItem::GetLocalY() const
85 {
86     return localY_;
87 }
88 
SetLocalY(int32_t y)89 void PointerEvent::PointerItem::SetLocalY(int32_t y)
90 {
91     localY_ = y;
92 }
93 
GetWidth() const94 int32_t PointerEvent::PointerItem::GetWidth() const
95 {
96     return width_;
97 }
98 
SetWidth(int32_t width)99 void PointerEvent::PointerItem::SetWidth(int32_t width)
100 {
101     width_ = width;
102 }
103 
GetHeight() const104 int32_t PointerEvent::PointerItem::GetHeight() const
105 {
106     return height_;
107 }
108 
SetHeight(int32_t height)109 void PointerEvent::PointerItem::SetHeight(int32_t height)
110 {
111     height_ = height;
112 }
113 
GetPressure() const114 int32_t PointerEvent::PointerItem::GetPressure() const
115 {
116     return pressure_;
117 }
118 
SetPressure(int32_t pressure)119 void PointerEvent::PointerItem::SetPressure(int32_t pressure)
120 {
121     pressure_ = pressure;
122 }
123 
GetDeviceId() const124 int32_t PointerEvent::PointerItem::GetDeviceId() const
125 {
126     return deviceId_;
127 }
128 
SetDeviceId(int32_t deviceId)129 void PointerEvent::PointerItem::SetDeviceId(int32_t deviceId)
130 {
131     deviceId_ = deviceId;
132 }
133 
PointerEvent(int32_t eventType)134 PointerEvent::PointerEvent(int32_t eventType) : InputEvent(eventType) {}
135 
PointerEvent(const PointerEvent & other)136 PointerEvent::PointerEvent(const PointerEvent& other)
137     : InputEvent(other), pointerId_(other.pointerId_), pointers_(other.pointers_),
138     pressedButtons_(other.pressedButtons_), sourceType_(other.sourceType_),
139     pointerAction_(other.pointerAction_), buttonId_(other.buttonId_),
140     axes_(other.axes_), axisValues_(other.axisValues_),
141     pressedKeys_(other.pressedKeys_) {}
142 
~PointerEvent()143 PointerEvent::~PointerEvent()
144 {
145     pointers_.clear();
146     pressedButtons_.clear();
147     pressedKeys_.clear();
148 }
149 
Create()150 std::shared_ptr<PointerEvent> PointerEvent::Create()
151 {
152     return std::shared_ptr<PointerEvent>(new PointerEvent(InputEvent::EVENT_TYPE_POINTER));
153 }
154 
GetSourceType() const155 int32_t PointerEvent::GetSourceType() const
156 {
157     return sourceType_;
158 }
159 
SetSourceType(int32_t sourceType)160 void PointerEvent::SetSourceType(int32_t sourceType)
161 {
162     sourceType_ = sourceType;
163 }
164 
GetPointerAction() const165 int32_t PointerEvent::GetPointerAction() const
166 {
167     return pointerAction_;
168 }
169 
SetPointerAction(int32_t pointerAction)170 void PointerEvent::SetPointerAction(int32_t pointerAction)
171 {
172     pointerAction_ = pointerAction;
173 }
174 
GetPointerId() const175 int32_t PointerEvent::GetPointerId() const
176 {
177     return pointerId_;
178 }
179 
SetPointerId(int32_t pointerId)180 void PointerEvent::SetPointerId(int32_t pointerId)
181 {
182     pointerId_ = pointerId;
183 }
184 
GetPointerItem(int32_t pointerId,PointerItem & pointerItem)185 bool PointerEvent::GetPointerItem(int32_t pointerId, PointerItem &pointerItem)
186 {
187     for (auto &item : pointers_) {
188         if (item.GetPointerId() == pointerId) {
189             pointerItem = item;
190             return true;
191         }
192     }
193     return false;
194 }
195 
RemovePointerItem(int32_t pointerId)196 void PointerEvent::RemovePointerItem(int32_t pointerId)
197 {
198     for (auto it = pointers_.begin(); it != pointers_.end(); it++) {
199         if (it->GetPointerId() == pointerId) {
200             pointers_.erase(it);
201             break;
202         }
203     }
204 }
205 
AddPointerItem(PointerItem & pointerItem)206 void PointerEvent::AddPointerItem(PointerItem &pointerItem)
207 {
208     pointers_.push_back(pointerItem);
209 }
210 
GetPointersIdList() const211 std::vector<int32_t> PointerEvent::GetPointersIdList() const
212 {
213     std::vector<int32_t> pointerIdList;
214 
215     for (auto &item : pointers_) {
216         pointerIdList.push_back(item.GetPointerId());
217     }
218 
219     return pointerIdList;
220 }
221 }
222 }