ShadowRoot.cpp 800 B

1234567891011121314151617181920212223242526272829303132333435
  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. EventTarget* ShadowRoot::get_parent(const Event& event)
  16. {
  17. if (!event.composed()) {
  18. auto& events_first_invocation_target = verify_cast<Node>(*event.path().first().invocation_target);
  19. if (events_first_invocation_target.root() == this)
  20. return nullptr;
  21. }
  22. return host();
  23. }
  24. RefPtr<Layout::Node> ShadowRoot::create_layout_node()
  25. {
  26. return adopt_ref(*new Layout::BlockBox(document(), this, CSS::ComputedValues {}));
  27. }
  28. }