DocumentFragment.cpp 950 B

123456789101112131415161718192021222324252627282930313233343536
  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. set_prototype(&Bindings::cached_web_prototype(realm(), "DocumentFragment"));
  13. }
  14. void DocumentFragment::visit_edges(Cell::Visitor& visitor)
  15. {
  16. Base::visit_edges(visitor);
  17. visitor.visit(m_host.ptr());
  18. }
  19. void DocumentFragment::set_host(Web::DOM::Element* element)
  20. {
  21. m_host = element;
  22. }
  23. // https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment
  24. JS::NonnullGCPtr<DocumentFragment> DocumentFragment::construct_impl(JS::Realm& realm)
  25. {
  26. auto& window = verify_cast<HTML::Window>(realm.global_object());
  27. return *realm.heap().allocate<DocumentFragment>(realm, window.associated_document());
  28. }
  29. }