Event.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/TypeCasts.h>
  7. #include <LibWeb/DOM/Event.h>
  8. #include <LibWeb/DOM/Node.h>
  9. #include <LibWeb/DOM/ShadowRoot.h>
  10. namespace Web::DOM {
  11. void Event::append_to_path(EventTarget& invocation_target, RefPtr<EventTarget> shadow_adjusted_target, RefPtr<EventTarget> related_target, TouchTargetList& touch_targets, bool slot_in_closed_tree)
  12. {
  13. bool invocation_target_in_shadow_tree = false;
  14. bool root_of_closed_tree = false;
  15. if (is<Node>(invocation_target)) {
  16. auto& invocation_target_node = verify_cast<Node>(invocation_target);
  17. if (is<ShadowRoot>(invocation_target_node.root()))
  18. invocation_target_in_shadow_tree = true;
  19. if (is<ShadowRoot>(invocation_target_node)) {
  20. auto& invocation_target_shadow_root = verify_cast<ShadowRoot>(invocation_target_node);
  21. root_of_closed_tree = invocation_target_shadow_root.closed();
  22. }
  23. }
  24. m_path.append({ invocation_target, invocation_target_in_shadow_tree, shadow_adjusted_target, related_target, touch_targets, root_of_closed_tree, slot_in_closed_tree, m_path.size() });
  25. }
  26. void Event::set_cancelled_flag()
  27. {
  28. if (m_cancelable && !m_in_passive_listener)
  29. m_cancelled = true;
  30. }
  31. // https://dom.spec.whatwg.org/#concept-event-initialize
  32. void Event::initialize(const String& type, bool bubbles, bool cancelable)
  33. {
  34. m_initialized = true;
  35. m_stop_propagation = false;
  36. m_stop_immediate_propagation = false;
  37. m_cancelled = false;
  38. m_is_trusted = false;
  39. m_target = nullptr;
  40. m_type = type;
  41. m_bubbles = bubbles;
  42. m_cancelable = cancelable;
  43. }
  44. // https://dom.spec.whatwg.org/#dom-event-initevent
  45. void Event::init_event(const String& type, bool bubbles, bool cancelable)
  46. {
  47. if (m_dispatch)
  48. return;
  49. initialize(type, bubbles, cancelable);
  50. }
  51. }