DocumentFragment.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2020-2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/DocumentFragment.h>
  7. #include <LibWeb/HTML/Window.h>
  8. namespace Web::DOM {
  9. DocumentFragment::DocumentFragment(Document& document)
  10. : ParentNode(document, NodeType::DOCUMENT_FRAGMENT_NODE)
  11. {
  12. }
  13. void DocumentFragment::initialize(JS::Realm& realm)
  14. {
  15. Base::initialize(realm);
  16. set_prototype(&Bindings::ensure_web_prototype<Bindings::DocumentFragmentPrototype>(realm, "DocumentFragment"));
  17. }
  18. void DocumentFragment::visit_edges(Cell::Visitor& visitor)
  19. {
  20. Base::visit_edges(visitor);
  21. visitor.visit(m_host.ptr());
  22. }
  23. void DocumentFragment::set_host(Web::DOM::Element* element)
  24. {
  25. m_host = element;
  26. }
  27. // https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment
  28. WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> DocumentFragment::construct_impl(JS::Realm& realm)
  29. {
  30. auto& window = verify_cast<HTML::Window>(realm.global_object());
  31. return realm.heap().allocate<DocumentFragment>(realm, window.associated_document());
  32. }
  33. }