Event.cpp 1.9 KB

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