stylus_utils.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2017 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/public/cpp/stylus_utils.h"
  5. #include "ash/constants/ash_switches.h"
  6. #include "base/command_line.h"
  7. #include "ui/display/display.h"
  8. #include "ui/events/devices/device_data_manager.h"
  9. #include "ui/events/devices/touchscreen_device.h"
  10. #include "ui/gfx/geometry/point.h"
  11. namespace ash {
  12. namespace stylus_utils {
  13. namespace {
  14. // If true the device performs as if it is hardware reports that it is stylus
  15. // capable.
  16. bool g_has_stylus_input_for_testing = false;
  17. } // namespace
  18. bool HasForcedStylusInput() {
  19. return base::CommandLine::ForCurrentProcess()->HasSwitch(
  20. switches::kAshForceEnableStylusTools);
  21. }
  22. bool HasStylusInput() {
  23. if (g_has_stylus_input_for_testing)
  24. return true;
  25. // Allow the user to force enable or disable by passing a switch. If both are
  26. // present, enabling takes precedence over disabling.
  27. if (HasForcedStylusInput())
  28. return true;
  29. // Check to see if the hardware reports it is stylus capable.
  30. for (const ui::TouchscreenDevice& device :
  31. ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices()) {
  32. if (device.has_stylus &&
  33. (device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL ||
  34. device.type == ui::InputDeviceType::INPUT_DEVICE_USB)) {
  35. return true;
  36. }
  37. }
  38. return false;
  39. }
  40. bool IsPaletteEnabledOnEveryDisplay() {
  41. return base::CommandLine::ForCurrentProcess()->HasSwitch(
  42. switches::kAshEnablePaletteOnAllDisplays);
  43. }
  44. bool HasInternalStylus() {
  45. return base::CommandLine::ForCurrentProcess()->HasSwitch(
  46. switches::kHasInternalStylus);
  47. }
  48. void SetHasStylusInputForTesting() {
  49. g_has_stylus_input_for_testing = true;
  50. }
  51. void SetNoStylusInputForTesting() {
  52. g_has_stylus_input_for_testing = false;
  53. }
  54. } // namespace stylus_utils
  55. } // namespace ash