input_event_tracker.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_PROTOCOL_INPUT_EVENT_TRACKER_H_
  5. #define REMOTING_PROTOCOL_INPUT_EVENT_TRACKER_H_
  6. #include <stdint.h>
  7. #include <set>
  8. #include "base/compiler_specific.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "remoting/protocol/input_stub.h"
  11. #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
  12. #include "ui/events/keycodes/dom/dom_code.h"
  13. namespace remoting {
  14. namespace protocol {
  15. // Filtering InputStub which tracks mouse and keyboard input events before
  16. // passing them on to |input_stub|, and can dispatch release events to
  17. // |input_stub| for all currently-pressed keys and buttons when necessary.
  18. class InputEventTracker : public InputStub {
  19. public:
  20. InputEventTracker();
  21. explicit InputEventTracker(InputStub* input_stub);
  22. InputEventTracker(const InputEventTracker&) = delete;
  23. InputEventTracker& operator=(const InputEventTracker&) = delete;
  24. ~InputEventTracker() override;
  25. void set_input_stub(InputStub* input_stub) {
  26. input_stub_ = input_stub;
  27. }
  28. // Returns true if the key with the specified USB code is currently pressed.
  29. bool IsKeyPressed(ui::DomCode usb_keycode) const;
  30. // Returns the count of keys currently pressed.
  31. int PressedKeyCount() const;
  32. // Dispatch release events for all currently-pressed keys, mouse buttons, and
  33. // touch points to the InputStub.
  34. void ReleaseAll();
  35. // Similar to ReleaseAll, but conditional on a modifier key tracked by this
  36. // class being pressed without the corresponding parameter indicating that it
  37. // should be.
  38. void ReleaseAllIfModifiersStuck(bool alt_expected, bool ctrl_expected,
  39. bool os_expected, bool shift_expected);
  40. // InputStub interface.
  41. void InjectKeyEvent(const KeyEvent& event) override;
  42. void InjectTextEvent(const TextEvent& event) override;
  43. void InjectMouseEvent(const MouseEvent& event) override;
  44. void InjectTouchEvent(const TouchEvent& event) override;
  45. private:
  46. raw_ptr<InputStub> input_stub_ = nullptr;
  47. std::set<ui::DomCode> pressed_keys_;
  48. webrtc::DesktopVector mouse_pos_;
  49. uint32_t mouse_button_state_ = 0;
  50. std::set<uint32_t> touch_point_ids_;
  51. };
  52. } // namespace protocol
  53. } // namespace remoting
  54. #endif // REMOTING_PROTOCOL_INPUT_EVENT_TRACKER_H_