ShadowRoot.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(const Event& 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. RefPtr<Layout::Node> ShadowRoot::create_layout_node()
  28. {
  29. return adopt_ref(*new Layout::BlockContainer(document(), this, CSS::ComputedValues {}));
  30. }
  31. // https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
  32. String ShadowRoot::inner_html() const
  33. {
  34. return serialize_fragment(/* FIXME: Providing true for the require well-formed flag (which may throw) */);
  35. }
  36. // https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
  37. ExceptionOr<void> ShadowRoot::set_inner_html(String const& markup)
  38. {
  39. auto result = DOMParsing::InnerHTML::inner_html_setter(*this, markup);
  40. if (result.is_exception())
  41. return result.exception();
  42. set_needs_style_update(true);
  43. return {};
  44. }
  45. }