InputSource.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashTable.h>
  8. #include <AK/Optional.h>
  9. #include <AK/String.h>
  10. #include <AK/Variant.h>
  11. #include <AK/Vector.h>
  12. #include <LibWeb/Forward.h>
  13. #include <LibWeb/PixelUnits.h>
  14. #include <LibWeb/UIEvents/KeyCode.h>
  15. #include <LibWeb/UIEvents/MouseButton.h>
  16. #include <LibWeb/WebDriver/Error.h>
  17. namespace Web::WebDriver {
  18. enum class InputSourceType {
  19. None,
  20. Key,
  21. Pointer,
  22. Wheel,
  23. };
  24. // https://w3c.github.io/webdriver/#dfn-null-input-source
  25. struct NullInputSource {
  26. };
  27. // https://w3c.github.io/webdriver/#dfn-key-input-source
  28. struct KeyInputSource {
  29. HashTable<String> pressed;
  30. bool alt { false };
  31. bool ctrl { false };
  32. bool meta { false };
  33. bool shift { false };
  34. };
  35. // https://w3c.github.io/webdriver/#dfn-pointer-input-source
  36. struct PointerInputSource {
  37. enum class Subtype {
  38. Mouse,
  39. Pen,
  40. Touch,
  41. };
  42. PointerInputSource(InputState const&, Subtype);
  43. Subtype subtype { Subtype::Mouse };
  44. u32 pointer_id { 0 };
  45. UIEvents::MouseButton pressed { UIEvents::MouseButton::None };
  46. CSSPixelPoint position;
  47. };
  48. // https://w3c.github.io/webdriver/#dfn-wheel-input-source
  49. struct WheelInputSource {
  50. };
  51. // https://w3c.github.io/webdriver/#dfn-input-source
  52. using InputSource = Variant<NullInputSource, KeyInputSource, PointerInputSource, WheelInputSource>;
  53. // https://w3c.github.io/webdriver/#dfn-global-key-state
  54. struct GlobalKeyState {
  55. UIEvents::KeyModifier modifiers() const;
  56. HashTable<String> pressed;
  57. bool alt_key { false };
  58. bool ctrl_key { false };
  59. bool meta_key { false };
  60. bool shift_key { false };
  61. };
  62. Optional<InputSourceType> input_source_type_from_string(StringView);
  63. Optional<PointerInputSource::Subtype> pointer_input_source_subtype_from_string(StringView);
  64. InputSource create_input_source(InputState const&, InputSourceType, Optional<PointerInputSource::Subtype>);
  65. void add_input_source(InputState&, String id, InputSource);
  66. void remove_input_source(InputState&, StringView id);
  67. Optional<InputSource&> get_input_source(InputState&, StringView id);
  68. ErrorOr<InputSource*, WebDriver::Error> get_or_create_input_source(InputState&, InputSourceType, StringView id, Optional<PointerInputSource::Subtype>);
  69. GlobalKeyState get_global_key_state(InputState const&);
  70. }