haptics_util.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2021 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. #include "ash/utility/haptics_util.h"
  5. #include "ui/events/devices/haptic_touchpad_effects.h"
  6. #include "ui/ozone/public/input_controller.h"
  7. #include "ui/ozone/public/ozone_platform.h"
  8. namespace ash {
  9. namespace haptics_util {
  10. namespace {
  11. ui::InputController* g_test_input_controller = nullptr;
  12. } // namespace
  13. void SetInputControllerForTesting(ui::InputController* input_controller) {
  14. g_test_input_controller = input_controller;
  15. }
  16. void PlayHapticTouchpadEffect(ui::HapticTouchpadEffect effect,
  17. ui::HapticTouchpadEffectStrength strength) {
  18. ui::InputController* input_controller =
  19. g_test_input_controller
  20. ? g_test_input_controller
  21. : ui::OzonePlatform::GetInstance()->GetInputController();
  22. DCHECK(input_controller);
  23. input_controller->PlayHapticTouchpadEffect(effect, strength);
  24. }
  25. void PlayHapticToggleEffect(bool on,
  26. ui::HapticTouchpadEffectStrength strength) {
  27. PlayHapticTouchpadEffect(on ? ui::HapticTouchpadEffect::kToggleOn
  28. : ui::HapticTouchpadEffect::kToggleOff,
  29. strength);
  30. }
  31. } // namespace haptics_util
  32. } // namespace ash