haptics_tracking_test_input_controller.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2022 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 ASH_UTILITY_HAPTICS_TRACKING_TEST_INPUT_CONTROLLER_H_
  5. #define ASH_UTILITY_HAPTICS_TRACKING_TEST_INPUT_CONTROLLER_H_
  6. #include "base/containers/flat_map.h"
  7. #include "ui/events/devices/haptic_touchpad_effects.h"
  8. #include "ui/ozone/public/input_controller.h"
  9. namespace ash {
  10. // Test input controller that can be used to track haptics events sent out in
  11. // tests. The input controller will be set as the input controller that should
  12. // be used by haptics util using `haptics_util::SetInputControllerForTesting()`.
  13. // Only one should be initialized at a time.
  14. class HapticsTrackingTestInputController : public ui::InputController {
  15. public:
  16. HapticsTrackingTestInputController();
  17. HapticsTrackingTestInputController(
  18. const HapticsTrackingTestInputController&) = delete;
  19. HapticsTrackingTestInputController& operator=(
  20. const HapticsTrackingTestInputController&) = delete;
  21. ~HapticsTrackingTestInputController() override;
  22. // ui::InputController:
  23. bool HasMouse() override;
  24. bool HasPointingStick() override;
  25. bool HasTouchpad() override;
  26. bool HasHapticTouchpad() override;
  27. bool IsCapsLockEnabled() override;
  28. void SetCapsLockEnabled(bool enabled) override;
  29. void SetNumLockEnabled(bool enabled) override;
  30. bool IsAutoRepeatEnabled() override;
  31. void SetAutoRepeatEnabled(bool enabled) override;
  32. void SetAutoRepeatRate(const base::TimeDelta& delay,
  33. const base::TimeDelta& interval) override;
  34. void GetAutoRepeatRate(base::TimeDelta* delay,
  35. base::TimeDelta* interval) override;
  36. void SetCurrentLayoutByName(const std::string& layout_name) override;
  37. void SetKeyboardKeyBitsMapping(
  38. base::flat_map<int, std::vector<uint64_t>> key_bits_mapping) override;
  39. std::vector<uint64_t> GetKeyboardKeyBits(int id) override;
  40. void SetTouchpadSensitivity(int value) override;
  41. void SetTouchpadScrollSensitivity(int value) override;
  42. void SetTapToClick(bool enabled) override;
  43. void SetThreeFingerClick(bool enabled) override;
  44. void SetTapDragging(bool enabled) override;
  45. void SetNaturalScroll(bool enabled) override;
  46. void SetTouchpadAcceleration(bool enabled) override;
  47. void SetTouchpadScrollAcceleration(bool enabled) override;
  48. void SetTouchpadHapticFeedback(bool enabled) override;
  49. void SetTouchpadHapticClickSensitivity(int value) override;
  50. void SetMouseSensitivity(int value) override;
  51. void SetMouseScrollSensitivity(int value) override;
  52. void SetPrimaryButtonRight(bool right) override;
  53. void SetMouseReverseScroll(bool enabled) override;
  54. void SetMouseAcceleration(bool enabled) override;
  55. void SuspendMouseAcceleration() override;
  56. void EndMouseAccelerationSuspension() override;
  57. void SetMouseScrollAcceleration(bool enabled) override;
  58. void SetPointingStickSensitivity(int value) override;
  59. void SetPointingStickPrimaryButtonRight(bool right) override;
  60. void SetPointingStickAcceleration(bool enabled) override;
  61. void SetGamepadKeyBitsMapping(
  62. base::flat_map<int, std::vector<uint64_t>> key_bits_mapping) override;
  63. std::vector<uint64_t> GetGamepadKeyBits(int id) override;
  64. void GetTouchDeviceStatus(GetTouchDeviceStatusReply reply) override;
  65. void GetTouchEventLog(const base::FilePath& out_dir,
  66. GetTouchEventLogReply reply) override;
  67. void SetTouchEventLoggingEnabled(bool enabled) override;
  68. void SetTapToClickPaused(bool state) override;
  69. void SetInternalTouchpadEnabled(bool enabled) override;
  70. bool IsInternalTouchpadEnabled() const override;
  71. void SetTouchscreensEnabled(bool enabled) override;
  72. void GetStylusSwitchState(GetStylusSwitchStateReply reply) override;
  73. void PlayVibrationEffect(int id,
  74. uint8_t amplitude,
  75. uint16_t duration_millis) override;
  76. void StopVibration(int id) override;
  77. void PlayHapticTouchpadEffect(
  78. ui::HapticTouchpadEffect effect,
  79. ui::HapticTouchpadEffectStrength strength) override;
  80. void SetHapticTouchpadEffectForNextButtonRelease(
  81. ui::HapticTouchpadEffect effect,
  82. ui::HapticTouchpadEffectStrength strength) override;
  83. void SetInternalKeyboardFilter(
  84. bool enable_filter,
  85. std::vector<ui::DomCode> allowed_keys) override;
  86. void GetGesturePropertiesService(
  87. mojo::PendingReceiver<ui::ozone::mojom::GesturePropertiesService>
  88. receiver) override;
  89. // Returns haptic count for effect/strength combination for testing.
  90. int GetSentHapticCount(ui::HapticTouchpadEffect effect,
  91. ui::HapticTouchpadEffectStrength strength) const;
  92. private:
  93. // A map of map that stores counts for given haptic effect/strength.
  94. // This is used for testing only.
  95. base::flat_map<ui::HapticTouchpadEffect,
  96. base::flat_map<ui::HapticTouchpadEffectStrength, int>>
  97. sent_haptic_count_;
  98. };
  99. } // namespace ash
  100. #endif // ASH_UTILITY_HAPTICS_TRACKING_TEST_INPUT_CONTROLLER_H_