local_input_monitor.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2012 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. #ifndef REMOTING_HOST_INPUT_MONITOR_LOCAL_INPUT_MONITOR_H_
  5. #define REMOTING_HOST_INPUT_MONITOR_LOCAL_INPUT_MONITOR_H_
  6. #include <memory>
  7. #include "base/callback_forward.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "ui/events/event.h"
  11. namespace base {
  12. class SingleThreadTaskRunner;
  13. } // namespace base
  14. namespace webrtc {
  15. class DesktopVector;
  16. } // namespace webrtc
  17. namespace remoting {
  18. class ClientSessionControl;
  19. // Monitors local input and sends notifications for mouse and touch movements
  20. // and keyboard shortcuts when they are detected.
  21. class LocalInputMonitor {
  22. public:
  23. using PointerMoveCallback =
  24. base::RepeatingCallback<void(const webrtc::DesktopVector&,
  25. ui::EventType)>;
  26. using KeyPressedCallback = base::RepeatingCallback<void(uint32_t)>;
  27. virtual ~LocalInputMonitor() = default;
  28. // Creates a platform-specific instance of LocalInputMonitor.
  29. // |caller_task_runner| is used for all callbacks and notifications.
  30. static std::unique_ptr<LocalInputMonitor> Create(
  31. scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
  32. scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
  33. scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
  34. // Start monitoring and notify using |client_session_control|. In this mode
  35. // the LocalInputMonitor will listen for session disconnect hotkeys and mouse
  36. // and keyboard events (and touch, on some platforms) for input filtering.
  37. virtual void StartMonitoringForClientSession(
  38. base::WeakPtr<ClientSessionControl> client_session_control) = 0;
  39. // Start monitoring and notify using the callbacks specified.
  40. // Monitors are only started if the respective callback is provided. This
  41. // means that callbacks are optional, but at least one must be valid.
  42. // |on_pointer_input| is called for each mouse or touch movement detected.
  43. // |on_keyboard_input| is called for each keypress detected.
  44. // |on_error| is called if any of the child input monitors fail.
  45. virtual void StartMonitoring(PointerMoveCallback on_pointer_input,
  46. KeyPressedCallback on_keyboard_input,
  47. base::RepeatingClosure on_error) = 0;
  48. protected:
  49. LocalInputMonitor() = default;
  50. };
  51. } // namespace remoting
  52. #endif // REMOTING_HOST_INPUT_MONITOR_LOCAL_INPUT_MONITOR_H_