Chromium Code Reviews| Index: remoting/host/touch_injector_win.h |
| diff --git a/remoting/host/touch_injector_win.h b/remoting/host/touch_injector_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cd07516ccf488e9ebb82c3bc967f8eae71a8f2e9 |
| --- /dev/null |
| +++ b/remoting/host/touch_injector_win.h |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef REMOTING_HOST_TOUCH_INJECTOR_WIN_H_ |
| +#define REMOTING_HOST_TOUCH_INJECTOR_WIN_H_ |
| + |
| +#include <windows.h> |
| +#include <map> |
| +#include <vector> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| + |
| +namespace remoting { |
| + |
| +namespace protocol { |
| + |
| +class TouchEvent; |
| + |
| +} // namespace protocol |
| + |
| +// This class calls InitializeTouchInjection() and InjectTouchInput() functions. |
| +// The methods are virtual for mocking. |
|
Wez
2015/03/17 03:06:24
If you make this a pure interface, with a TouchInj
Rintaro Kuroiwa
2015/03/18 01:33:31
It wasn't necessary to remove the virtual init* fu
|
| +class TouchInjectFunctionsWin { |
|
Wez
2015/03/17 03:06:24
Suggest TouchInjectorWinDelegate, or TouchInjector
Rintaro Kuroiwa
2015/03/18 01:33:31
Done.
|
| + public: |
| + TouchInjectFunctionsWin(); |
| + virtual ~TouchInjectFunctionsWin(); |
| + |
| + // Initializes this object. This gets the handle to the injection functions. |
| + // Returns false when the functions cannot be used. |
| + // This can be called multiple times. |
| + virtual bool Init(); |
|
Wez
2015/03/17 03:06:23
Suggest Initialized()
Rintaro Kuroiwa
2015/03/18 01:33:31
Moved to private scope.
|
| + |
| + // Returns true if previous call to Init() returned true, false otherwise. |
| + virtual bool Initialized(); |
|
Wez
2015/03/17 03:06:24
IsInitialized()
Rintaro Kuroiwa
2015/03/18 01:33:31
Dropped.
|
| + |
| + // These match the functions in MSDN. |
| + virtual BOOL InitializeTouchInjection(UINT32 max_count, DWORD dw_mode); |
|
Wez
2015/03/17 03:06:23
It's confusing to have both this and the Initializ
Rintaro Kuroiwa
2015/03/18 01:33:31
That is a great idea.
Then the capabilities can be
|
| + virtual DWORD InjectTouchInput(UINT32 count, |
| + const POINTER_TOUCH_INFO* contacts); |
| + |
| + private: |
| + BOOL(NTAPI* initialize_touch_injection_func_)(UINT32, DWORD); |
| + BOOL(NTAPI* inject_touch_input_func_)(UINT32, const POINTER_TOUCH_INFO*); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TouchInjectFunctionsWin); |
| +}; |
| + |
| +// This class converts TouchEvent objects to POINTER_TOUCH_INFO so that it can |
| +// be injected using the Windows touch injection API, and calls the injection |
| +// functions. |
| +// This class does not handle bad inputs. For example, a touch end event |
|
Wez
2015/03/17 03:06:24
I think you mean that it expects good inputs, and
Rintaro Kuroiwa
2015/03/18 01:33:31
Right. Reworded.
|
| +// arriving before touch start event. This just converts the object and hands |
| +// it off to the Windows API. |
| +class TouchInjectorWin { |
| + public: |
| + TouchInjectorWin(); |
| + ~TouchInjectorWin(); |
| + |
| + // Initializes this object. If this returns false, calling InjectTouchEvent() |
| + // may silently fail. |
|
Wez
2015/03/17 03:06:24
I think it's fine to say "Returns false if initial
Rintaro Kuroiwa
2015/03/18 01:33:31
Done.
|
| + bool Init(); |
| + |
| + // Deinitializes the object so that it can be reinitialized. |
| + void Deinitialize(); |
| + |
| + // Inject touch events. |
| + void InjectTouchEvent(const protocol::TouchEvent& event); |
| + |
| + void SetInjectFunctionsForTest(scoped_ptr<TouchInjectFunctionsWin> functions); |
| + |
| + private: |
| + void AddNewTouchPoints(const protocol::TouchEvent& event); |
| + void MoveTouchPoints(const protocol::TouchEvent& event); |
| + void EndTouchPoints(const protocol::TouchEvent& event); |
| + void CancelTouchPoints(const protocol::TouchEvent& event); |
|
Wez
2015/03/17 03:06:24
Need a brief comment on this block to explain how
Rintaro Kuroiwa
2015/03/18 01:33:31
Done.
|
| + |
| + scoped_ptr<TouchInjectFunctionsWin> delegate_; |
|
Wez
2015/03/17 03:06:24
nit: Blank line between this and the subsequent co
Rintaro Kuroiwa
2015/03/18 01:33:31
Done.
|
| + // TODO(rkuroiwa): This is a naive implementation. Check if we can achieve |
| + // better performance by reducing the number of copies. |
| + // To reduce the number of copies, we can have a vector of |
| + // POINTER_TOUCH_INFO and a map from touch ID to index in the vector. |
| + // When removing points from the vector, just swap it with the last element |
| + // and resize the vector. |
| + std::map<uint32_t, POINTER_TOUCH_INFO> touches_in_contact_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TouchInjectorWin); |
| +}; |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_HOST_TOUCH_INJECTOR_WIN_H_ |