InputEvent.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <AK/Variant.h>
  9. #include <LibGfx/Point.h>
  10. #include <LibIPC/Forward.h>
  11. #include <LibWeb/PixelUnits.h>
  12. // FIXME: These should not be included outside of Serenity. This FIXME appears in several locations across the Ladybird
  13. // chromes. The classes in this file provide a good opportunity to remove LibGUI and Kernel types from LibWeb.
  14. #include <Kernel/API/KeyCode.h>
  15. #include <LibGUI/Event.h>
  16. namespace Web {
  17. struct ChromeInputData {
  18. virtual ~ChromeInputData() = default;
  19. };
  20. struct KeyEvent {
  21. public:
  22. enum class Type {
  23. KeyDown,
  24. KeyUp,
  25. };
  26. KeyEvent clone_without_chrome_data() const;
  27. Type type;
  28. KeyCode key { KeyCode::Key_Invalid };
  29. KeyModifier modifiers { KeyModifier::Mod_None };
  30. u32 code_point { 0 };
  31. OwnPtr<ChromeInputData> chrome_data;
  32. };
  33. struct MouseEvent {
  34. public:
  35. enum class Type {
  36. MouseDown,
  37. MouseUp,
  38. MouseMove,
  39. MouseWheel,
  40. DoubleClick,
  41. };
  42. MouseEvent clone_without_chrome_data() const;
  43. Type type;
  44. Web::DevicePixelPoint position;
  45. Web::DevicePixelPoint screen_position;
  46. GUI::MouseButton button { GUI::MouseButton::None };
  47. GUI::MouseButton buttons { GUI::MouseButton::None };
  48. KeyModifier modifiers { KeyModifier::Mod_None };
  49. int wheel_delta_x { 0 };
  50. int wheel_delta_y { 0 };
  51. OwnPtr<ChromeInputData> chrome_data;
  52. };
  53. using InputEvent = Variant<KeyEvent, MouseEvent>;
  54. }
  55. namespace IPC {
  56. template<>
  57. ErrorOr<void> encode(Encoder&, Web::KeyEvent const&);
  58. template<>
  59. ErrorOr<Web::KeyEvent> decode(Decoder&);
  60. template<>
  61. ErrorOr<void> encode(Encoder&, Web::MouseEvent const&);
  62. template<>
  63. ErrorOr<Web::MouseEvent> decode(Decoder&);
  64. }