UIEvent.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/UIEvents/UIEvent.h>
  8. namespace Web::UIEvents {
  9. WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> UIEvent::create(JS::Realm& realm, FlyString const& event_name)
  10. {
  11. return MUST_OR_THROW_OOM(realm.heap().allocate<UIEvent>(realm, realm, event_name));
  12. }
  13. WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> UIEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, UIEventInit const& event_init)
  14. {
  15. return MUST_OR_THROW_OOM(realm.heap().allocate<UIEvent>(realm, realm, event_name, event_init));
  16. }
  17. UIEvent::UIEvent(JS::Realm& realm, FlyString const& event_name)
  18. : Event(realm, event_name)
  19. {
  20. }
  21. UIEvent::UIEvent(JS::Realm& realm, FlyString const& event_name, UIEventInit const& event_init)
  22. : Event(realm, event_name, event_init)
  23. , m_view(event_init.view)
  24. , m_detail(event_init.detail)
  25. {
  26. }
  27. UIEvent::~UIEvent() = default;
  28. JS::ThrowCompletionOr<void> UIEvent::initialize(JS::Realm& realm)
  29. {
  30. MUST_OR_THROW_OOM(Base::initialize(realm));
  31. set_prototype(&Bindings::ensure_web_prototype<Bindings::UIEventPrototype>(realm, "UIEvent"));
  32. return {};
  33. }
  34. void UIEvent::visit_edges(Cell::Visitor& visitor)
  35. {
  36. Base::visit_edges(visitor);
  37. visitor.visit(m_view.ptr());
  38. }
  39. }