Bring the browser window to the front when clicking on deprecated accelerator notific...
[chromium-blink-merge.git] / remoting / host / touch_injector_win.h
blob2b429dea46ed01b138b7f4cb2e36ed5e813cfcab
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_
8 #include <windows.h>
9 #include <map>
10 #include <vector>
12 #include "base/memory/scoped_ptr.h"
13 #include "base/scoped_native_library.h"
15 namespace remoting {
17 namespace protocol {
19 class TouchEvent;
21 } // namespace protocol
23 // This class calls InitializeTouchInjection() and InjectTouchInput() functions.
24 // The methods are virtual for mocking.
25 class TouchInjectorWinDelegate {
26 public:
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);
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*));
46 private:
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
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();
66 // Returns false if initialization of touch injection APIs fails.
67 bool Init();
69 // Deinitializes the object so that it can be reinitialized.
70 void Deinitialize();
72 // Inject touch events.
73 void InjectTouchEvent(const protocol::TouchEvent& event);
75 void SetInjectorDelegateForTest(
76 scoped_ptr<TouchInjectorWinDelegate> functions);
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);
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_