Event.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/WeakPtr.h>
  8. #include <LibCore/Event.h>
  9. #include <LibCore/EventReceiver.h>
  10. namespace Core {
  11. ChildEvent::ChildEvent(Type type, EventReceiver& child, EventReceiver* insertion_before_child)
  12. : Core::Event(type)
  13. , m_child(child.make_weak_ptr())
  14. , m_insertion_before_child(AK::make_weak_ptr_if_nonnull(insertion_before_child))
  15. {
  16. }
  17. EventReceiver* ChildEvent::child()
  18. {
  19. if (auto ref = m_child.strong_ref())
  20. return ref.ptr();
  21. return nullptr;
  22. }
  23. EventReceiver const* ChildEvent::child() const
  24. {
  25. if (auto ref = m_child.strong_ref())
  26. return ref.ptr();
  27. return nullptr;
  28. }
  29. EventReceiver* ChildEvent::insertion_before_child()
  30. {
  31. if (auto ref = m_insertion_before_child.strong_ref())
  32. return ref.ptr();
  33. return nullptr;
  34. }
  35. EventReceiver const* ChildEvent::insertion_before_child() const
  36. {
  37. if (auto ref = m_insertion_before_child.strong_ref())
  38. return ref.ptr();
  39. return nullptr;
  40. }
  41. }