ShadowRoot.cpp 865 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Event.h>
  7. #include <LibWeb/DOM/ShadowRoot.h>
  8. #include <LibWeb/Layout/BlockBox.h>
  9. namespace Web::DOM {
  10. ShadowRoot::ShadowRoot(Document& document, Element& host)
  11. : DocumentFragment(document)
  12. {
  13. set_host(host);
  14. }
  15. // https://dom.spec.whatwg.org/#ref-for-get-the-parent%E2%91%A6
  16. EventTarget* ShadowRoot::get_parent(const Event& event)
  17. {
  18. if (!event.composed()) {
  19. auto& events_first_invocation_target = verify_cast<Node>(*event.path().first().invocation_target);
  20. if (&events_first_invocation_target.root() == this)
  21. return nullptr;
  22. }
  23. return host();
  24. }
  25. RefPtr<Layout::Node> ShadowRoot::create_layout_node()
  26. {
  27. return adopt_ref(*new Layout::BlockBox(document(), this, CSS::ComputedValues {}));
  28. }
  29. }