keyboard_layout.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2016 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 UI_EVENTS_TEST_KEYBOARD_LAYOUT_H_
  5. #define UI_EVENTS_TEST_KEYBOARD_LAYOUT_H_
  6. #include "build/build_config.h"
  7. #if BUILDFLAG(IS_WIN)
  8. #include <windows.h>
  9. #elif BUILDFLAG(IS_MAC)
  10. #include <Carbon/Carbon.h>
  11. #include "base/mac/scoped_cftyperef.h"
  12. #elif defined(USE_OZONE)
  13. #include "ui/events/ozone/layout/scoped_keyboard_layout_engine.h" // nogncheck
  14. #endif
  15. namespace ui {
  16. enum KeyboardLayout {
  17. KEYBOARD_LAYOUT_ENGLISH_US,
  18. #if BUILDFLAG(IS_WIN)
  19. KEYBOARD_LAYOUT_FRENCH,
  20. KEYBOARD_LAYOUT_GERMAN,
  21. KEYBOARD_LAYOUT_GREEK,
  22. KEYBOARD_LAYOUT_JAPANESE,
  23. KEYBOARD_LAYOUT_KOREAN,
  24. KEYBOARD_LAYOUT_RUSSIAN,
  25. #endif
  26. };
  27. #if BUILDFLAG(IS_WIN)
  28. using PlatformKeyboardLayout = HKL;
  29. #elif BUILDFLAG(IS_MAC)
  30. using PlatformKeyboardLayout = base::ScopedCFTypeRef<TISInputSourceRef>;
  31. #endif
  32. #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
  33. PlatformKeyboardLayout GetPlatformKeyboardLayout(KeyboardLayout layout);
  34. #endif
  35. // Changes the active keyboard layout for the scope of this object.
  36. class ScopedKeyboardLayout {
  37. public:
  38. explicit ScopedKeyboardLayout(KeyboardLayout layout);
  39. ScopedKeyboardLayout(const ScopedKeyboardLayout&) = delete;
  40. ScopedKeyboardLayout& operator=(const ScopedKeyboardLayout&) = delete;
  41. ~ScopedKeyboardLayout();
  42. private:
  43. #if defined(USE_OZONE)
  44. std::unique_ptr<ScopedKeyboardLayoutEngine> scoped_keyboard_layout_engine_;
  45. #endif
  46. #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
  47. static PlatformKeyboardLayout GetActiveLayout();
  48. static void ActivateLayout(PlatformKeyboardLayout layout);
  49. PlatformKeyboardLayout original_layout_;
  50. #endif
  51. };
  52. } // namespace ui
  53. #endif // UI_EVENTS_TEST_KEYBOARD_LAYOUT_H_