wayland_keyboard_delegate.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2018 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 COMPONENTS_EXO_WAYLAND_WAYLAND_KEYBOARD_DELEGATE_H_
  5. #define COMPONENTS_EXO_WAYLAND_WAYLAND_KEYBOARD_DELEGATE_H_
  6. #include "base/containers/flat_map.h"
  7. #include "base/time/time.h"
  8. #include "build/buildflag.h"
  9. #include "components/exo/keyboard_delegate.h"
  10. #include "components/exo/keyboard_modifiers.h"
  11. #include "components/exo/wayland/server_util.h"
  12. #include "components/exo/wayland/wayland_input_delegate.h"
  13. #include "ui/base/buildflags.h"
  14. #include "ui/events/keycodes/dom/keycode_converter.h"
  15. struct wl_client;
  16. struct wl_resource;
  17. namespace exo {
  18. namespace wayland {
  19. class SerialTracker;
  20. // Keyboard delegate class that accepts events for surfaces owned by the same
  21. // client as a keyboard resource.
  22. class WaylandKeyboardDelegate : public WaylandInputDelegate,
  23. public KeyboardDelegate {
  24. #if BUILDFLAG(USE_XKBCOMMON)
  25. public:
  26. WaylandKeyboardDelegate(wl_resource* keyboard_resource,
  27. SerialTracker* serial_tracker);
  28. WaylandKeyboardDelegate(const WaylandKeyboardDelegate&) = delete;
  29. WaylandKeyboardDelegate& operator=(const WaylandKeyboardDelegate) = delete;
  30. ~WaylandKeyboardDelegate() override;
  31. // Overridden from KeyboardDelegate:
  32. bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override;
  33. void OnKeyboardEnter(
  34. Surface* surface,
  35. const base::flat_map<ui::DomCode, KeyState>& pressed_keys) override;
  36. void OnKeyboardLeave(Surface* surface) override;
  37. uint32_t OnKeyboardKey(base::TimeTicks time_stamp,
  38. ui::DomCode key,
  39. bool pressed) override;
  40. void OnKeyboardModifiers(const KeyboardModifiers& modifiers) override;
  41. void OnKeyRepeatSettingsChanged(bool enabled,
  42. base::TimeDelta delay,
  43. base::TimeDelta interval) override;
  44. void OnKeyboardLayoutUpdated(base::StringPiece keymap) override;
  45. private:
  46. // Sends the current modifiers to the client.
  47. void SendKeyboardModifiers();
  48. // The client who own this keyboard instance.
  49. wl_client* client() const;
  50. // The keyboard resource associated with the keyboard.
  51. wl_resource* const keyboard_resource_;
  52. // Owned by Server, which always outlives this delegate.
  53. SerialTracker* const serial_tracker_;
  54. // Tracks the latest modifiers.
  55. KeyboardModifiers current_modifiers_{};
  56. #endif
  57. };
  58. // Exposed for testing.
  59. int32_t GetWaylandRepeatRateForTesting(bool enabled, base::TimeDelta interval);
  60. } // namespace wayland
  61. } // namespace exo
  62. #endif // COMPONENTS_EXO_WAYLAND_WAYLAND_KEYBOARD_DELEGATE_H_