events_test_utils_x11.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2013 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 UI_EVENTS_TEST_EVENTS_TEST_UTILS_X11_H_
  5. #define UI_EVENTS_TEST_EVENTS_TEST_UTILS_X11_H_
  6. #include <memory>
  7. #include "ui/events/devices/x11/device_data_manager_x11.h"
  8. #include "ui/events/keycodes/keyboard_codes.h"
  9. #include "ui/events/types/event_type.h"
  10. #include "ui/gfx/geometry/point.h"
  11. #include "ui/gfx/x/event.h"
  12. namespace ui {
  13. struct Valuator {
  14. Valuator(DeviceDataManagerX11::DataType type, double v)
  15. : data_type(type), value(v) {}
  16. DeviceDataManagerX11::DataType data_type;
  17. double value;
  18. };
  19. class ScopedXI2Event {
  20. public:
  21. ScopedXI2Event();
  22. ScopedXI2Event(const ScopedXI2Event&) = delete;
  23. ScopedXI2Event& operator=(const ScopedXI2Event&) = delete;
  24. ~ScopedXI2Event();
  25. operator x11::Event*() { return &event_; }
  26. // Initializes a x11::Event with for the appropriate type with the specified
  27. // data. Note that ui::EF_ flags should be passed as |flags|, not the native
  28. // ones in <X11/X.h>.
  29. void InitKeyEvent(EventType type, KeyboardCode key_code, int flags);
  30. void InitMotionEvent(const gfx::Point& location,
  31. const gfx::Point& root_location,
  32. int flags);
  33. void InitButtonEvent(EventType type, const gfx::Point& location, int flags);
  34. // Initializes an Xinput2 key event.
  35. // |deviceid| is the master, and |sourceid| is the slave device.
  36. void InitGenericKeyEvent(int deviceid,
  37. int sourceid,
  38. EventType type,
  39. KeyboardCode key_code,
  40. int flags);
  41. void InitGenericButtonEvent(int deviceid,
  42. EventType type,
  43. const gfx::Point& location,
  44. int flags);
  45. void InitGenericMouseWheelEvent(int deviceid, int wheel_delta, int flags);
  46. void InitScrollEvent(int deviceid,
  47. int x_offset,
  48. int y_offset,
  49. int x_offset_ordinal,
  50. int y_offset_ordinal,
  51. int finger_count);
  52. void InitFlingScrollEvent(int deviceid,
  53. int x_velocity,
  54. int y_velocity,
  55. int x_velocity_ordinal,
  56. int y_velocity_ordinal,
  57. bool is_cancel);
  58. void InitTouchEvent(int deviceid,
  59. int evtype,
  60. int tracking_id,
  61. const gfx::Point& location,
  62. const std::vector<Valuator>& valuators);
  63. private:
  64. void Cleanup();
  65. void SetUpValuators(const std::vector<Valuator>& valuators);
  66. x11::Event event_;
  67. };
  68. // Initializes a test touchpad device for scroll events.
  69. void SetUpTouchPadForTest(int deviceid);
  70. // Initializes a list of touchscreen devices for touch events.
  71. void SetUpTouchDevicesForTest(const std::vector<int>& devices);
  72. // Initializes a list of non-touch, non-cmt pointer devices.
  73. void SetUpPointerDevicesForTest(const std::vector<int>& devices);
  74. } // namespace ui
  75. #endif // UI_EVENTS_TEST_EVENTS_TEST_UTILS_X11_H_