OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/touch_injector_win.h" | 5 #include "remoting/host/touch_injector_win.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/native_library.h" | 9 #include "base/native_library.h" |
10 #include "base/stl_util.h" | |
11 #include "remoting/proto/event.pb.h" | 10 #include "remoting/proto/event.pb.h" |
12 | 11 |
13 namespace remoting { | 12 namespace remoting { |
14 | 13 |
15 using protocol::TouchEvent; | 14 using protocol::TouchEvent; |
16 using protocol::TouchEventPoint; | 15 using protocol::TouchEventPoint; |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 typedef BOOL(NTAPI* InitializeTouchInjectionFunction)(UINT32, DWORD); | 19 typedef BOOL(NTAPI* InitializeTouchInjectionFunction)(UINT32, DWORD); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_DOWN; | 206 POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_DOWN; |
208 ConvertToPointerTouchInfo(touch_point, &pointer_touch_info); | 207 ConvertToPointerTouchInfo(touch_point, &pointer_touch_info); |
209 touches.push_back(pointer_touch_info); | 208 touches.push_back(pointer_touch_info); |
210 | 209 |
211 // All points in the map should be a move point. | 210 // All points in the map should be a move point. |
212 pointer_touch_info.pointerInfo.pointerFlags = | 211 pointer_touch_info.pointerInfo.pointerFlags = |
213 POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE; | 212 POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE; |
214 touches_in_contact_[touch_point.id()] = pointer_touch_info; | 213 touches_in_contact_[touch_point.id()] = pointer_touch_info; |
215 } | 214 } |
216 | 215 |
217 if (delegate_->InjectTouchInput(touches.size(), | 216 if (delegate_->InjectTouchInput(touches.size(), touches.data()) == 0) { |
218 vector_as_array(&touches)) == 0) { | |
219 PLOG(ERROR) << "Failed to inject a touch start event."; | 217 PLOG(ERROR) << "Failed to inject a touch start event."; |
220 } | 218 } |
221 } | 219 } |
222 | 220 |
223 void TouchInjectorWin::MoveTouchPoints(const TouchEvent& event) { | 221 void TouchInjectorWin::MoveTouchPoints(const TouchEvent& event) { |
224 DCHECK_EQ(event.event_type(), TouchEvent::TOUCH_POINT_MOVE); | 222 DCHECK_EQ(event.event_type(), TouchEvent::TOUCH_POINT_MOVE); |
225 | 223 |
226 for (const TouchEventPoint& touch_point : event.touch_points()) { | 224 for (const TouchEventPoint& touch_point : event.touch_points()) { |
227 POINTER_TOUCH_INFO* pointer_touch_info = | 225 POINTER_TOUCH_INFO* pointer_touch_info = |
228 &touches_in_contact_[touch_point.id()]; | 226 &touches_in_contact_[touch_point.id()]; |
229 memset(pointer_touch_info, 0, sizeof(*pointer_touch_info)); | 227 memset(pointer_touch_info, 0, sizeof(*pointer_touch_info)); |
230 pointer_touch_info->pointerInfo.pointerFlags = | 228 pointer_touch_info->pointerInfo.pointerFlags = |
231 POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE; | 229 POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE; |
232 ConvertToPointerTouchInfo(touch_point, pointer_touch_info); | 230 ConvertToPointerTouchInfo(touch_point, pointer_touch_info); |
233 } | 231 } |
234 | 232 |
235 std::vector<POINTER_TOUCH_INFO> touches; | 233 std::vector<POINTER_TOUCH_INFO> touches; |
236 // Must inject already touching points as move events. | 234 // Must inject already touching points as move events. |
237 AppendMapValuesToVector(&touches_in_contact_, &touches); | 235 AppendMapValuesToVector(&touches_in_contact_, &touches); |
238 if (delegate_->InjectTouchInput(touches.size(), | 236 if (delegate_->InjectTouchInput(touches.size(), touches.data()) == 0) { |
239 vector_as_array(&touches)) == 0) { | |
240 PLOG(ERROR) << "Failed to inject a touch move event."; | 237 PLOG(ERROR) << "Failed to inject a touch move event."; |
241 } | 238 } |
242 } | 239 } |
243 | 240 |
244 void TouchInjectorWin::EndTouchPoints(const TouchEvent& event) { | 241 void TouchInjectorWin::EndTouchPoints(const TouchEvent& event) { |
245 DCHECK_EQ(event.event_type(), TouchEvent::TOUCH_POINT_END); | 242 DCHECK_EQ(event.event_type(), TouchEvent::TOUCH_POINT_END); |
246 | 243 |
247 std::vector<POINTER_TOUCH_INFO> touches; | 244 std::vector<POINTER_TOUCH_INFO> touches; |
248 for (const TouchEventPoint& touch_point : event.touch_points()) { | 245 for (const TouchEventPoint& touch_point : event.touch_points()) { |
249 POINTER_TOUCH_INFO pointer_touch_info = | 246 POINTER_TOUCH_INFO pointer_touch_info = |
250 touches_in_contact_[touch_point.id()]; | 247 touches_in_contact_[touch_point.id()]; |
251 pointer_touch_info.pointerInfo.pointerFlags = POINTER_FLAG_UP; | 248 pointer_touch_info.pointerInfo.pointerFlags = POINTER_FLAG_UP; |
252 | 249 |
253 touches_in_contact_.erase(touch_point.id()); | 250 touches_in_contact_.erase(touch_point.id()); |
254 touches.push_back(pointer_touch_info); | 251 touches.push_back(pointer_touch_info); |
255 } | 252 } |
256 | 253 |
257 AppendMapValuesToVector(&touches_in_contact_, &touches); | 254 AppendMapValuesToVector(&touches_in_contact_, &touches); |
258 if (delegate_->InjectTouchInput(touches.size(), | 255 if (delegate_->InjectTouchInput(touches.size(), touches.data()) == 0) { |
259 vector_as_array(&touches)) == 0) { | |
260 PLOG(ERROR) << "Failed to inject a touch end event."; | 256 PLOG(ERROR) << "Failed to inject a touch end event."; |
261 } | 257 } |
262 } | 258 } |
263 | 259 |
264 void TouchInjectorWin::CancelTouchPoints(const TouchEvent& event) { | 260 void TouchInjectorWin::CancelTouchPoints(const TouchEvent& event) { |
265 DCHECK_EQ(event.event_type(), TouchEvent::TOUCH_POINT_CANCEL); | 261 DCHECK_EQ(event.event_type(), TouchEvent::TOUCH_POINT_CANCEL); |
266 | 262 |
267 std::vector<POINTER_TOUCH_INFO> touches; | 263 std::vector<POINTER_TOUCH_INFO> touches; |
268 for (const TouchEventPoint& touch_point : event.touch_points()) { | 264 for (const TouchEventPoint& touch_point : event.touch_points()) { |
269 POINTER_TOUCH_INFO pointer_touch_info = | 265 POINTER_TOUCH_INFO pointer_touch_info = |
270 touches_in_contact_[touch_point.id()]; | 266 touches_in_contact_[touch_point.id()]; |
271 pointer_touch_info.pointerInfo.pointerFlags = | 267 pointer_touch_info.pointerInfo.pointerFlags = |
272 POINTER_FLAG_UP | POINTER_FLAG_CANCELED; | 268 POINTER_FLAG_UP | POINTER_FLAG_CANCELED; |
273 | 269 |
274 touches_in_contact_.erase(touch_point.id()); | 270 touches_in_contact_.erase(touch_point.id()); |
275 touches.push_back(pointer_touch_info); | 271 touches.push_back(pointer_touch_info); |
276 } | 272 } |
277 | 273 |
278 AppendMapValuesToVector(&touches_in_contact_, &touches); | 274 AppendMapValuesToVector(&touches_in_contact_, &touches); |
279 if (delegate_->InjectTouchInput(touches.size(), | 275 if (delegate_->InjectTouchInput(touches.size(), touches.data()) == 0) { |
280 vector_as_array(&touches)) == 0) { | |
281 PLOG(ERROR) << "Failed to inject a touch cancel event."; | 276 PLOG(ERROR) << "Failed to inject a touch cancel event."; |
282 } | 277 } |
283 } | 278 } |
284 | 279 |
285 } // namespace remoting | 280 } // namespace remoting |
OLD | NEW |