Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: remoting/host/touch_injector_win.h

Issue 991643002: Windows Host Touch Injection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/input_injector_win.cc ('k') | remoting/host/touch_injector_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef REMOTING_HOST_TOUCH_INJECTOR_WIN_H_
6 #define REMOTING_HOST_TOUCH_INJECTOR_WIN_H_
7
8 #include <windows.h>
9 #include <map>
10 #include <vector>
11
12 #include "base/memory/scoped_ptr.h"
13 #include "base/scoped_native_library.h"
14
15 namespace remoting {
16
17 namespace protocol {
18
19 class TouchEvent;
20
21 } // namespace protocol
22
23 // This class calls InitializeTouchInjection() and InjectTouchInput() functions.
24 // The methods are virtual for mocking.
25 class TouchInjectorWinDelegate {
26 public:
27 virtual ~TouchInjectorWinDelegate();
28
29 // Determines whether Windows touch injection functions can be used.
30 // Returns a non-null TouchInjectorWinDelegate on success.
31 static scoped_ptr<TouchInjectorWinDelegate> Create();
32
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);
37
38 protected:
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*));
45
46 private:
47 base::ScopedNativeLibrary library_module_;
48
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*);
52
53 DISALLOW_COPY_AND_ASSIGN(TouchInjectorWinDelegate);
54 };
55
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
58 // functions.
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 {
62 public:
63 TouchInjectorWin();
64 ~TouchInjectorWin();
65
66 // Returns false if initialization of touch injection APIs fails.
67 bool Init();
68
69 // Deinitializes the object so that it can be reinitialized.
70 void Deinitialize();
71
72 // Inject touch events.
73 void InjectTouchEvent(const protocol::TouchEvent& event);
74
75 void SetInjectorDelegateForTest(
76 scoped_ptr<TouchInjectorWinDelegate> functions);
77
78 private:
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);
87
88 // Set to null if touch injection is not available from the OS.
89 scoped_ptr<TouchInjectorWinDelegate> delegate_;
90
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_;
100
101 DISALLOW_COPY_AND_ASSIGN(TouchInjectorWin);
102 };
103
104 } // namespace remoting
105
106 #endif // REMOTING_HOST_TOUCH_INJECTOR_WIN_H_
OLDNEW
« no previous file with comments | « remoting/host/input_injector_win.cc ('k') | remoting/host/touch_injector_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698