keyboard_util.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2019 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/keyboard/keyboard_util.h"
  5. #include "ash/public/cpp/keyboard/keyboard_controller.h"
  6. #include "ash/shell.h"
  7. #include "ash/system/model/system_tray_model.h"
  8. #include "ash/system/model/virtual_keyboard_model.h"
  9. #include "ash/wm/window_util.h"
  10. namespace ash {
  11. namespace keyboard_util {
  12. bool IsArrowKeyCode(const ui::KeyboardCode key_code) {
  13. return key_code == ui::VKEY_DOWN || key_code == ui::VKEY_RIGHT ||
  14. key_code == ui::VKEY_LEFT || key_code == ui::VKEY_UP;
  15. }
  16. bool CloseKeyboardIfActive() {
  17. // Close the Chrome VK if it is visible.
  18. auto* keyboard_controller = KeyboardController::Get();
  19. if (keyboard_controller->IsKeyboardVisible()) {
  20. keyboard_controller->HideKeyboard(HideReason::kUser);
  21. return true;
  22. }
  23. // Close the Android VK if it is visible by sending a back event.
  24. if (Shell::Get()
  25. ->system_tray_model()
  26. ->virtual_keyboard()
  27. ->arc_keyboard_visible()) {
  28. window_util::SendBackKeyEvent(Shell::GetPrimaryRootWindow());
  29. return true;
  30. }
  31. return false;
  32. }
  33. } // namespace keyboard_util
  34. } // namespace ash