ShadowRoot.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/DOM/Event.h>
  8. #include <LibWeb/DOM/ShadowRoot.h>
  9. #include <LibWeb/DOMParsing/InnerHTML.h>
  10. #include <LibWeb/Layout/BlockContainer.h>
  11. namespace Web::DOM {
  12. ShadowRoot::ShadowRoot(Document& document, Element& host)
  13. : DocumentFragment(document)
  14. {
  15. set_host(&host);
  16. }
  17. // https://dom.spec.whatwg.org/#ref-for-get-the-parent%E2%91%A6
  18. EventTarget* ShadowRoot::get_parent(Event const& event)
  19. {
  20. if (!event.composed()) {
  21. auto& events_first_invocation_target = verify_cast<Node>(*event.path().first().invocation_target);
  22. if (&events_first_invocation_target.root() == this)
  23. return nullptr;
  24. }
  25. return host();
  26. }
  27. // https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
  28. String ShadowRoot::inner_html() const
  29. {
  30. return serialize_fragment(/* FIXME: Providing true for the require well-formed flag (which may throw) */);
  31. }
  32. // https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
  33. WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(String const& markup)
  34. {
  35. TRY(DOMParsing::inner_html_setter(*this, markup));
  36. set_needs_style_update(true);
  37. return {};
  38. }
  39. }