InputState.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/BrowsingContext.h>
  7. #include <LibWeb/WebDriver/Actions.h>
  8. #include <LibWeb/WebDriver/InputState.h>
  9. namespace Web::WebDriver {
  10. // https://w3c.github.io/webdriver/#dfn-browsing-context-input-state-map
  11. static HashMap<GC::RawPtr<HTML::BrowsingContext>, InputState> s_browsing_context_input_state_map;
  12. InputState::InputState() = default;
  13. InputState::~InputState() = default;
  14. // https://w3c.github.io/webdriver/#dfn-get-the-input-state
  15. InputState& get_input_state(HTML::BrowsingContext& browsing_context)
  16. {
  17. // 1. Assert: browsing context is a top-level browsing context.
  18. VERIFY(browsing_context.is_top_level());
  19. // 2. Let input state map be session's browsing context input state map.
  20. // 3. If input state map does not contain browsing context, set input state map[browsing context] to create an input state.
  21. auto& input_state = s_browsing_context_input_state_map.ensure(browsing_context);
  22. // 4. Return input state map[browsing context].
  23. return input_state;
  24. }
  25. // https://w3c.github.io/webdriver/#dfn-reset-the-input-state
  26. void reset_input_state(HTML::BrowsingContext& browsing_context)
  27. {
  28. // 1. Assert: browsing context is a top-level browsing context.
  29. VERIFY(browsing_context.is_top_level());
  30. // 2. Let input state map be session's browsing context input state map.
  31. // 3. If input state map[browsing context] exists, then remove input state map[browsing context].
  32. s_browsing_context_input_state_map.remove(browsing_context);
  33. }
  34. }