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
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_TOUCH_INJECTOR_WIN_H_
6 #define REMOTING_HOST_TOUCH_INJECTOR_WIN_H_
12 #include "base/memory/scoped_ptr.h"
13 #include "base/scoped_native_library.h"
21 } // namespace protocol
23 // This class calls InitializeTouchInjection() and InjectTouchInput() functions.
24 // The methods are virtual for mocking.
25 class TouchInjectorWinDelegate
{
27 virtual ~TouchInjectorWinDelegate();
29 // Determines whether Windows touch injection functions can be used.
30 // Returns a non-null TouchInjectorWinDelegate on success.
31 static scoped_ptr
<TouchInjectorWinDelegate
> Create();
33 // These match the functions in MSDN.
34 virtual BOOL
InitializeTouchInjection(UINT32 max_count
, DWORD dw_mode
);
35 virtual DWORD
InjectTouchInput(UINT32 count
,
36 const POINTER_TOUCH_INFO
* contacts
);
39 // Ctor in protected scope for mocking.
40 // This object takes ownership of the |library|.
41 TouchInjectorWinDelegate(
42 base::NativeLibrary library
,
43 BOOL(NTAPI
* initialize_touch_injection_func
)(UINT32
, DWORD
),
44 BOOL(NTAPI
* inject_touch_input_func
)(UINT32
, const POINTER_TOUCH_INFO
*));
47 base::ScopedNativeLibrary library_module_
;
49 // Pointers to Windows touch injection functions.
50 BOOL(NTAPI
* initialize_touch_injection_func_
)(UINT32
, DWORD
);
51 BOOL(NTAPI
* inject_touch_input_func_
)(UINT32
, const POINTER_TOUCH_INFO
*);
53 DISALLOW_COPY_AND_ASSIGN(TouchInjectorWinDelegate
);
56 // This class converts TouchEvent objects to POINTER_TOUCH_INFO so that it can
57 // be injected using the Windows touch injection API, and calls the injection
59 // This class expects good inputs and does not sanity check the inputs.
60 // This class just converts the object and hands it off to the Windows API.
61 class TouchInjectorWin
{
66 // Returns false if initialization of touch injection APIs fails.
69 // Deinitializes the object so that it can be reinitialized.
72 // Inject touch events.
73 void InjectTouchEvent(const protocol::TouchEvent
& event
);
75 void SetInjectorDelegateForTest(
76 scoped_ptr
<TouchInjectorWinDelegate
> functions
);
79 // Helper methods called from InjectTouchEvent().
80 // These helpers adapt Chromoting touch events, which convey changes to touch
81 // points, to Windows touch descriptions, which must include descriptions for
82 // all currently-active touch points, not just the changed ones.
83 void AddNewTouchPoints(const protocol::TouchEvent
& event
);
84 void MoveTouchPoints(const protocol::TouchEvent
& event
);
85 void EndTouchPoints(const protocol::TouchEvent
& event
);
86 void CancelTouchPoints(const protocol::TouchEvent
& event
);
88 // Set to null if touch injection is not available from the OS.
89 scoped_ptr
<TouchInjectorWinDelegate
> delegate_
;
91 // TODO(rkuroiwa): crbug.com/470203
92 // This is a naive implementation. Check if we can achieve
93 // better performance by reducing the number of copies.
94 // To reduce the number of copies, we can have a vector of
95 // POINTER_TOUCH_INFO and a map from touch ID to index in the vector.
96 // When removing points from the vector, just swap it with the last element
97 // and resize the vector.
98 // All the POINTER_TOUCH_INFOs are stored as "move" points.
99 std::map
<uint32_t, POINTER_TOUCH_INFO
> touches_in_contact_
;
101 DISALLOW_COPY_AND_ASSIGN(TouchInjectorWin
);
104 } // namespace remoting
106 #endif // REMOTING_HOST_TOUCH_INJECTOR_WIN_H_