cursor_manager_chromeos.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2014 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/wm/cursor_manager_chromeos.h"
  5. #include <utility>
  6. #include "ash/keyboard/ui/keyboard_ui_controller.h"
  7. #include "ash/keyboard/ui/keyboard_util.h"
  8. #include "ash/shell.h"
  9. #include "ui/aura/env.h"
  10. #include "ui/events/event.h"
  11. #include "ui/wm/core/cursor_manager.h"
  12. #include "ui/wm/core/native_cursor_manager.h"
  13. namespace ash {
  14. CursorManager::CursorManager(
  15. std::unique_ptr<::wm::NativeCursorManager> delegate)
  16. : ::wm::CursorManager(std::move(delegate)) {}
  17. CursorManager::~CursorManager() = default;
  18. bool CursorManager::ShouldHideCursorOnKeyEvent(
  19. const ui::KeyEvent& event) const {
  20. if (event.type() != ui::ET_KEY_PRESSED)
  21. return false;
  22. // Pressing one key repeatedly will not hide the cursor.
  23. // To deal with the issue 855163 (http://crbug.com/855163).
  24. if (event.is_repeat())
  25. return false;
  26. // Do not hide cursor when clicking the key with mouse button pressed.
  27. if (aura::Env::GetInstance()->IsMouseButtonDown())
  28. return false;
  29. // Clicking on a key when the accessibility virtual keyboard is enabled should
  30. // not hide the cursor.
  31. if (keyboard::GetAccessibilityKeyboardEnabled())
  32. return false;
  33. // Clicking on a key in the virtual keyboard should not hide the cursor.
  34. if (keyboard::KeyboardUIController::HasInstance() &&
  35. keyboard::KeyboardUIController::Get()->IsKeyboardVisible()) {
  36. return false;
  37. }
  38. // All alt, control and command key commands are ignored.
  39. if (event.IsAltDown() || event.IsControlDown() || event.IsCommandDown())
  40. return false;
  41. ui::KeyboardCode code = event.key_code();
  42. if (code >= ui::VKEY_F1 && code <= ui::VKEY_F24)
  43. return false;
  44. if (code >= ui::VKEY_BROWSER_BACK && code <= ui::VKEY_MEDIA_LAUNCH_APP2)
  45. return false;
  46. switch (code) {
  47. // Modifiers.
  48. case ui::VKEY_SHIFT:
  49. case ui::VKEY_CONTROL:
  50. case ui::VKEY_MENU:
  51. // Search key == VKEY_LWIN.
  52. case ui::VKEY_LWIN:
  53. case ui::VKEY_WLAN:
  54. case ui::VKEY_POWER:
  55. case ui::VKEY_BRIGHTNESS_DOWN:
  56. case ui::VKEY_BRIGHTNESS_UP:
  57. case ui::VKEY_KBD_BRIGHTNESS_UP:
  58. case ui::VKEY_KBD_BRIGHTNESS_DOWN:
  59. case ui::VKEY_PRIVACY_SCREEN_TOGGLE:
  60. case ui::VKEY_ZOOM:
  61. return false;
  62. default:
  63. return true;
  64. }
  65. }
  66. } // namespace ash